Logo Search packages:      
Sourcecode: fuse-umfuse-fat version File versions  Download package

int unicode_utf8_to_wchar ( wchar_t *restrict  result,
const char *restrict  string,
size_t  size 
)

UTF-8 to wide character.

Parameters:
result where to store the converted wide character;
string buffer containing the UTF-8 character to convert;
size max number of bytes of string to examine;
Return values:
>0 the length in bytes of the processed UTF-8 character, the wide character is stored in result;
-EILSEQ invalid UTF-8 byte sequence;
-ENAMETOOLONG size too small to parse the UTF-8 character.

Definition at line 64 of file utf8.c.

{
      wchar_t wc = 0;
      unsigned k, j;
      if (!size) return -ENAMETOOLONG;
      for (k = 0; k < 4; k++)
            if ((*string & t[k].mask) == t[k].val)
            {
                  if (size < k + 1) return -ENAMETOOLONG;
                  wc = (wchar_t) (unsigned char) *string & ~t[k].mask;
                  for (j = 0; j < k; j++)
                  {
                        if ((*(++string) & 0xC0) != 0x80) return -EILSEQ;
                        wc = (wc << 6) | ((wchar_t) (unsigned char) *string & 0x3F);
                  }
                  *result = wc;
                  return k + 1;
            }
      return -EILSEQ;
}


Generated by  Doxygen 1.6.0   Back to index