From f157304896b09661aee090207624d1d07a3d0b1b Mon Sep 17 00:00:00 2001 From: Martin Mares Date: Sat, 14 Aug 2004 15:14:36 +0000 Subject: [PATCH] UTF8_SPACE turned to an inline function. Added utf8_encoding_length() which measures expected length of an UTF-8 sequence according to its first byte. --- lib/unicode.h | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/lib/unicode.h b/lib/unicode.h index ca8bdea3..199b3d70 100644 --- a/lib/unicode.h +++ b/lib/unicode.h @@ -71,7 +71,26 @@ #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 */ -- 2.39.2