home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / listings / v_10_11 / 1011016a < prev    next >
Text File  |  1992-09-03  |  754b  |  32 lines

  1. #include "xstrxfrm.h"
  2.  
  3. size_t (strxfrm)(char *s1, const char *s2, size_t n)
  4.     {    /* transform s2[] to s1[] by locale-dependent rule */
  5.     size_t nx = 0;
  6.     const unsigned char *s = (const unsigned char *)s2;
  7.     _Cosave state = {0};
  8.  
  9.     while (nx < n)
  10.         {    /* translate and deliver */
  11.         size_t i = _Strxfrm(s1, &s, n - nx, &state);
  12.  
  13.         s1 += i, nx += i;
  14.         if (0 < i && s1[-1] == '\0')
  15.             return (nx - 1);
  16.         else if (*s == '\0')
  17.             s = (const unsigned char *)s2;    /* rescan */
  18.         }
  19.     for (; ; )
  20.         {    /* translate and count */
  21.         char buf[32];
  22.         size_t i = _Strxfrm(buf, &s, sizeof (buf), &state);
  23.  
  24.         nx += i;
  25.         if (0 < i && buf[i - 1] == '\0')
  26.             return (nx - 1);
  27.         else if (*s == '\0')
  28.             s = (const unsigned char *)s2;    /* rescan */
  29.         }
  30.     }
  31.  
  32.