/*
- * Sherlock Library -- Unicode Characters
+ * UCW Library -- Unicode Characters
*
* (c) 1997--2004 Martin Mares <mj@ucw.cz>
* (c) 2004 Robert Spalek <robert@ucw.cz>
* of the GNU Lesser General Public License.
*/
-#ifndef _UNICODE_H
-#define _UNICODE_H
+#ifndef _UCW_UNICODE_H
+#define _UCW_UNICODE_H
/* Macros for handling UTF-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)
{
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)
{
}
else
ASSERT(0);
+ return p;
}
#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++;
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)
else
goto bad;
*uu = u;
- return p;
+ return (byte *)p;
}
#define PUT_UTF8(p,u) p = utf8_put(p, u)
/* 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);
+uns utf8_check(const byte *str);
#endif