X-Git-Url: http://mj.ucw.cz/gitweb/?a=blobdiff_plain;ds=inline;f=ucw%2Funicode.h;h=c9d6a0c1cde12477e1e88b0f0601272d179d1122;hb=da418321735b159f0ff39366d68203c772f152d4;hp=2bbbc5170635a4fa3c6c275bd42a1c2603467f76;hpb=1cf8ac51f5495ccd5187dc220ffc69e95d6e0cfc;p=libucw.git diff --git a/ucw/unicode.h b/ucw/unicode.h index 2bbbc517..c9d6a0c1 100644 --- a/ucw/unicode.h +++ b/ucw/unicode.h @@ -12,7 +12,12 @@ #ifndef _UCW_UNICODE_H #define _UCW_UNICODE_H -#include "ucw/unaligned.h" +#include + +#ifdef CONFIG_UCW_CLEAN_ABI +#define utf8_strlen ucw_utf8_strlen +#define utf8_strnlen ucw_utf8_strnlen +#endif /* Macros for handling UTF-8 */ @@ -168,7 +173,7 @@ get1: UTF8_GET_NEXT; } /** - * Decode a value from the range `[0, 0xFFFF]` (basic multilignual plane) + * Decode a value from the range `[0, 0xFFFF]` (basic multilingual plane) * or return `UNI_REPLACEMENT` if the encoding has been corrupted. **/ static inline byte *utf8_get(const byte *p, uns *uu) @@ -213,7 +218,7 @@ static inline uns utf8_space(uns u) } /** - * Compute the length of a single UTF-8 character from it's first byte. The encoding must be valid. + * Compute the length of a single UTF-8 character from its first byte. The encoding must be valid. **/ static inline uns utf8_encoding_len(uns c) { @@ -253,7 +258,7 @@ static inline void *utf16_le_put(void *p, uns u) } /** - * Encode an UTF-16BE character from the range `[0, 0xD7FF]` or `[0xE000,0x11FFFF]`; + * Encode a UTF-16BE character from the range `[0, 0xD7FF]` or `[0xE000,0x11FFFF]`; * up to 4 bytes needed. **/ static inline void *utf16_be_put(void *p, uns u) @@ -274,7 +279,7 @@ static inline void *utf16_be_put(void *p, uns u) } /** - * Decode an UTF-16LE character from the range `[0, 0xD7FF]` or `[0xE000,11FFFF]` + * Decode a UTF-16LE character from the range `[0, 0xD7FF]` or `[0xE000,11FFFF]` * or return @repl if the encoding has been corrupted. **/ static inline void *utf16_le_get_repl(const void *p, uns *uu, uns repl) @@ -294,7 +299,7 @@ static inline void *utf16_le_get_repl(const void *p, uns *uu, uns repl) } /** - * Decode an UTF-16BE character from the range `[0, 0xD7FF]` or `[0xE000,11FFFF]` + * Decode a UTF-16BE character from the range `[0, 0xD7FF]` or `[0xE000,11FFFF]` * or return @repl if the encoding has been corrupted. **/ static inline void *utf16_be_get_repl(const void *p, uns *uu, uns repl) @@ -314,7 +319,7 @@ static inline void *utf16_be_get_repl(const void *p, uns *uu, uns repl) } /** - * Decode an UTF-16LE character from the range `[0, 0xD7FF]` or `[0xE000,11FFFF]` + * Decode a UTF-16LE character from the range `[0, 0xD7FF]` or `[0xE000,11FFFF]` * or return `UNI_REPLACEMENT` if the encoding has been corrupted. **/ static inline void *utf16_le_get(const void *p, uns *uu) @@ -323,7 +328,7 @@ static inline void *utf16_le_get(const void *p, uns *uu) } /** - * Decode an UTF-16BE character from the range `[0, 0xD7FF]` or `[0xE000,11FFFF]` + * Decode a UTF-16BE character from the range `[0, 0xD7FF]` or `[0xE000,11FFFF]` * or return `UNI_REPLACEMENT` if the encoding has been corrupted. **/ static inline void *utf16_be_get(const void *p, uns *uu) @@ -332,7 +337,9 @@ static inline void *utf16_be_get(const void *p, uns *uu) } /** - * Check an Unicode value and if it seems to be useless (defined by Ucwlib; it may change in future) return `UNI_REPLACEMENT` instead. + * Basic sanity check on Unicode characters. Return `UNI_REPLACEMENT` if the input + * character is a surrogate, ASCII or Latin-1 control character different from the tab, + * or if it lies outside the basic plane. In all other cases, it acts as an identity. **/ static inline uns unicode_sanitize_char(uns u) { @@ -347,14 +354,14 @@ static inline uns unicode_sanitize_char(uns u) /* unicode-utf8.c */ /** - * Count the number of Unicode character in a zero-terminated UTF-8 string. + * Count the number of Unicode characters in a zero-terminated UTF-8 string. * Returned value for corrupted encoding is undefined, but is never greater than strlen(). **/ -uns utf8_strlen(const byte *str); +size_t utf8_strlen(const byte *str); /** * Same as @utf8_strlen(), but returns at most @n characters. **/ -uns utf8_strnlen(const byte *str, uns n); +size_t utf8_strnlen(const byte *str, size_t n); #endif