]> mj.ucw.cz Git - libucw.git/commitdiff
UTF8_SPACE turned to an inline function.
authorMartin Mares <mj@ucw.cz>
Sat, 14 Aug 2004 15:14:36 +0000 (15:14 +0000)
committerMartin Mares <mj@ucw.cz>
Sat, 14 Aug 2004 15:14:36 +0000 (15:14 +0000)
Added utf8_encoding_length() which measures expected length of an UTF-8
sequence according to its first byte.

lib/unicode.h

index ca8bdea3b2f51011367c0a87f74fb7bcaa94a5e8..199b3d7042cd2e3e511cb4b8f0584750ae5c0c4e 100644 (file)
 
 #define UTF8_SKIP_BWD(p) while ((--*(p) & 0xc0) == 0x80)
 
-#define UTF8_SPACE(u) ((u) < 0x80 ? 1 : (u) < 0x800 ? 2 : 3)
+static inline uns
+utf8_space(uns u)
+{
+  if (u < 0x80)
+    return 1;
+  if (u < 0x800)
+    return 2;
+  return 3;
+}
+
+static inline uns
+utf8_encoding_len(uns c)
+{
+  if (c < 0x80)
+    return 1;
+  ASSERT(c >= 0xc0 && c < 0xf0);
+  if (c < 0xe0)
+    return 2;
+  return 3;
+}
 
 /* unicode-utf8.c */