X-Git-Url: https://erislabs.net/gitweb/?a=blobdiff_plain;f=lib%2Funistr%2Fu8-uctomb.c;h=fd33c05cddcf953c5de56771636f48fceb741c09;hb=b2e2010c7c902235b5efb5bd3c6529f61b093aa4;hp=265fe536444b620b1b498f77407d0ac74af8de37;hpb=ac5cf7982cea8a4bb17680b6b9925f301cfa4220;p=gnulib.git diff --git a/lib/unistr/u8-uctomb.c b/lib/unistr/u8-uctomb.c index 265fe5364..fd33c05cd 100644 --- a/lib/unistr/u8-uctomb.c +++ b/lib/unistr/u8-uctomb.c @@ -1,5 +1,5 @@ /* Store a character in UTF-8 string. - Copyright (C) 2002, 2005-2006 Free Software Foundation, Inc. + Copyright (C) 2002, 2005-2006, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it @@ -17,6 +17,11 @@ #include +#if defined IN_LIBUNISTRING +/* Tell unistr.h to declare u8_uctomb as 'extern', not 'static inline'. */ +# include "unistring-notinline.h" +#endif + /* Specification. */ #include "unistr.h" @@ -28,10 +33,10 @@ u8_uctomb (uint8_t *s, ucs4_t uc, int n) if (uc < 0x80) { if (n > 0) - { - s[0] = uc; - return 1; - } + { + s[0] = uc; + return 1; + } /* else return -2, below. */ } else @@ -39,43 +44,43 @@ u8_uctomb (uint8_t *s, ucs4_t uc, int n) int count; if (uc < 0x800) - count = 2; + count = 2; else if (uc < 0x10000) - { - if (uc < 0xd800 || uc >= 0xe000) - count = 3; - else - return -1; - } + { + if (uc < 0xd800 || uc >= 0xe000) + count = 3; + else + return -1; + } #if 0 else if (uc < 0x200000) - count = 4; + count = 4; else if (uc < 0x4000000) - count = 5; + count = 5; else if (uc <= 0x7fffffff) - count = 6; + count = 6; #else else if (uc < 0x110000) - count = 4; + count = 4; #endif else - return -1; + return -1; if (n >= count) - { - switch (count) /* note: code falls through cases! */ - { + { + switch (count) /* note: code falls through cases! */ + { #if 0 - case 6: s[5] = 0x80 | (uc & 0x3f); uc = uc >> 6; uc |= 0x4000000; - case 5: s[4] = 0x80 | (uc & 0x3f); uc = uc >> 6; uc |= 0x200000; + case 6: s[5] = 0x80 | (uc & 0x3f); uc = uc >> 6; uc |= 0x4000000; + case 5: s[4] = 0x80 | (uc & 0x3f); uc = uc >> 6; uc |= 0x200000; #endif - case 4: s[3] = 0x80 | (uc & 0x3f); uc = uc >> 6; uc |= 0x10000; - case 3: s[2] = 0x80 | (uc & 0x3f); uc = uc >> 6; uc |= 0x800; - case 2: s[1] = 0x80 | (uc & 0x3f); uc = uc >> 6; uc |= 0xc0; - /*case 1:*/ s[0] = uc; - } - return count; - } + case 4: s[3] = 0x80 | (uc & 0x3f); uc = uc >> 6; uc |= 0x10000; + case 3: s[2] = 0x80 | (uc & 0x3f); uc = uc >> 6; uc |= 0x800; + case 2: s[1] = 0x80 | (uc & 0x3f); uc = uc >> 6; uc |= 0xc0; + /*case 1:*/ s[0] = uc; + } + return count; + } } return -2; }