[Y-devel] [PATCH] i18n - wchar_t properties

Alexey Boyko smartly at gala.net
Mon Feb 23 21:41:10 GMT 2004


> Patch is against 0.2-release.
> First attempt to convert all properties values to wchar_t. It would be
> good for internalization. Most widgets are accordingly fixed.

You outrun me. ;) I wrote nearly the same. but that is my function to convert 
utf8->ucs4:

size_t
yconvertStringToUCS4(const char *from, wchar_t *to, size_t outBufferLen)
{
  int state = 0;
  size_t strLen = 0;
  wchar_t wc;
  unsigned char c;
  while ((c = *from++)) {
    /* Ascii char or sequence error. reset state anyway. */
    if (c < 128) state = 0;

    if (state == 0) {
      /* Process first char of UTF sequence */
      if (c < 128) {
        /* Ascii char */
        wc = c;
      } else {
        /* check sequence error */
        if ( (c & 0xC0) == 0x80 ) continue;
        /* Search length of sequence */
        char mask = 0x20;
        while (mask) {
          state++;
          if ( (c & mask) == 0 ) {
            wc = c & (mask-1);
            break;
          }
          mask >>= 1;
        }
      }
    } else {
      /* Process next byte of UTF sequence */
      /* Check sequence error */
      if ((c & 0xC0) == 0xC0) {
        state = 0;
        continue;
      }
      wc = (wc << 6) | (c & 0x3F);
      state--;
    }
    if (state == 0) {
      /* Write char if enough room for it, else break */
      if (outBufferLen == 1) break;
      *to++ = wc;
      outBufferLen--;
      strLen++;
    }
  }
  /* Write end of string mark */
  *to = 0;
  return strLen;
}

> This patch
> should not affect client libraries and applications, since all
> communication is still utf8 (and should be so).

I think, client libraries also must accept strings as wchar_t, convert them 
into UTF-8 and pass to server.





More information about the Y-devel mailing list









2026 © www.Y-Windows.Org - All Rights Reserved