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

int unicode_wchar_to_utf8 ( char *  s,
wchar_t  wc,
size_t  size 
)

Wide character to UTF-8.

Parameters:
s where to store the converted UTF-8 character;
wc the wide character to convert;
size max number of bytes to store in s;
Return values:
>0 the length in bytes of the converted UTF-8 character, stored in s;
-EINVAL invalid wide character (don't know how to convert it to UTF-8);
-ENAMETOOLONG size too small to store the UTF-8 character.

Definition at line 94 of file utf8.c.

{
      if (wc >= 0)
      {
            if (wc < 0x000080)
            {
                  if (size < 1) return -ENAMETOOLONG;
                  *s = (char) wc;
                  return 1;
            }
            if (wc < 0x000800)
            {
                  if (size < 2) return -ENAMETOOLONG;
                  *(s + 1) = (char) (0x80 | (wc & 0x3F)); wc >>= 6;
                  *s = (char) (0xC0 | wc);
                  return 2;
            }
            if (wc < 0x010000)
            {
                  if (size < 3) return -ENAMETOOLONG;
                  *(s + 2) = (char) (0x80 | (wc & 0x3F)); wc >>= 6;
                  *(s + 1) = (char) (0x80 | (wc & 0x3F)); wc >>= 6;
                  *s = (char) (0xE0 | wc);
                  return 3;
            }
            if (wc < 0x200000)
            {
                  if (size < 4) return -ENAMETOOLONG;
                  *(s + 3) = (char) (0x80 | (wc & 0x3F)); wc >>= 6;
                  *(s + 2) = (char) (0x80 | (wc & 0x3F)); wc >>= 6;
                  *(s + 1) = (char) (0x80 | (wc & 0x3F)); wc >>= 6;
                  *s = (char) (0xF0 | wc);
                  return 4;
            }
      }
      return -EINVAL;
}


Generated by  Doxygen 1.6.0   Back to index