X-Git-Url: http://mj.ucw.cz/gitweb/?a=blobdiff_plain;ds=sidebyside;f=lib%2Funicode.h;h=52ea5e687510c4ad1fdbefe6d602c30d5606a4b6;hb=1f71ba3ef3df61706d7aee1ffa981cf6fdee7c4e;hp=79934540c586adefee3459b7dc1e1d24a44ff9d8;hpb=b2f3148f4c3d91c3720f755f77be76e35b3eb867;p=libucw.git diff --git a/lib/unicode.h b/lib/unicode.h index 79934540..52ea5e68 100644 --- a/lib/unicode.h +++ b/lib/unicode.h @@ -15,6 +15,8 @@ #define UNI_REPLACEMENT 0xfffc +/* Encode a character from the basic multilingual plane [0, 0xFFFF] + * (subset of Unicode 4.0); up to 3 bytes needed (RFC2279) */ static inline byte * utf8_put(byte *p, uns u) { @@ -35,6 +37,8 @@ utf8_put(byte *p, uns u) return p; } +/* Encode a value from the range [0, 0x7FFFFFFF]; + * (superset of Unicode 4.0) up to 6 bytes needed (RFC2279) */ static inline byte * utf8_32_put(byte *p, uns u) { @@ -76,7 +80,9 @@ put1: *p++ = 0x80 | (u & 0x3f); #define UTF8_GET_NEXT if (unlikely((*p & 0xc0) != 0x80)) goto bad; u = (u << 6) | (*p++ & 0x3f) -static inline const byte * +/* Decode a character from the basic multilingual plane [0, 0xFFFF] + * or return UNI_REPLACEMENT if the encoding has been corrupted */ +static inline byte * utf8_get(const byte *p, uns *uu) { uns u = *p++; @@ -102,11 +108,13 @@ utf8_get(const byte *p, uns *uu) else goto bad; *uu = u; - return p; + return (byte *)p; } +/* Decode a value from the range [0, 0x7FFFFFFF] + * or return UNI_REPLACEMENT if the encoding has been corrupted */ static inline byte * -utf8_32_get(byte *p, uns *uu) +utf8_32_get(const byte *p, uns *uu) { uns u = *p++; if (u < 0x80) @@ -149,7 +157,7 @@ get1: UTF8_GET_NEXT; else goto bad; *uu = u; - return p; + return (byte *)p; } #define PUT_UTF8(p,u) p = utf8_put(p, u) @@ -202,7 +210,7 @@ utf8_encoding_len(uns c) /* unicode-utf8.c */ -uns utf8_strlen(byte *str); -uns utf8_strnlen(byte *str, uns n); +uns utf8_strlen(const byte *str); +uns utf8_strnlen(const byte *str, uns n); #endif