#ifndef _UCW_UNICODE_H
#define _UCW_UNICODE_H
-#include "ucw/unaligned.h"
+#include <ucw/unaligned.h>
+
+#ifdef CONFIG_UCW_CLEAN_ABI
+#define utf8_strlen ucw_utf8_strlen
+#define utf8_strnlen ucw_utf8_strnlen
+#endif
/* Macros for handling UTF-8 */
}
/**
- * 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)
}
/**
- * 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)
{
}
/**
- * 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)
}
/**
- * 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)
}
/**
- * 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)
}
/**
- * 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)
}
/**
- * 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)
}
/**
- * 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)
{
/* unicode-utf8.c */
/**
- * Count the number of Unicode character in a zero-terminated UTF-8 string.
- * Returned value for corrupted encoding is undefined, but is never greater than `strlen(str)`.
+ * 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