From 8188650125625777803bbaea79cc79061f44313c Mon Sep 17 00:00:00 2001 From: handa Date: Thu, 12 Aug 2010 08:01:28 +0000 Subject: [PATCH] (STRING_CHAR_ADVANCE_UTF8): Sanitize the code. (STRING_CHAR_ADVANCE_UTF16): Likewise. --- src/character.h | 54 +++++++++++++++++++++++++++--------------------------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/src/character.h b/src/character.h index a3bc37e..de73430 100644 --- a/src/character.h +++ b/src/character.h @@ -146,33 +146,33 @@ #define STRING_CHAR STRING_CHAR_UTF8 -#define STRING_CHAR_ADVANCE_UTF8(p) \ - (!(*(p) & 0x80) ? *(p)++ \ - : !(*(p) & 0x20) ? (((*(p)++ & 0x1F) << 6) \ - | (*(p)++ & 0x3F)) \ - : !(*(p) & 0x10) ? (((*(p)++ & 0x0F) << 12) \ - | ((*(p)++ & 0x3F) << 6) \ - | (*(p)++ & 0x3F)) \ - : !(*(p) & 0x08) ? (((*(p)++ & 0x07) << 18) \ - | ((*(p)++ & 0x3F) << 12) \ - | ((*(p)++ & 0x3F) << 6) \ - | (*(p)++ & 0x3F)) \ - : !(*(p) & 0x04) ? (((*(p)++ & 0x03) << 24) \ - | ((*(p)++ & 0x3F) << 18) \ - | ((*(p)++ & 0x3F) << 12) \ - | ((*(p)++ & 0x3F) << 6) \ - | (*(p)++ & 0x3F)) \ - : (((*(p)++ & 0x01) << 30) \ - | ((*(p)++ & 0x3F) << 24) \ - | ((*(p)++ & 0x3F) << 18) \ - | ((*(p)++ & 0x3F) << 12) \ - | ((*(p)++ & 0x3F) << 6) \ - | (*(p)++ & 0x3F))) - -#define STRING_CHAR_ADVANCE_UTF16(p) \ - (((unsigned short) (p)[0] < 0xD800 || (unsigned short) (p)[0] >= 0xDC00) \ - ? *(p)++ \ - : (((*(p)++ - 0xD800) << 10) + (*(p)++ - 0xDC00) + 0x10000)) +#define STRING_CHAR_ADVANCE_UTF8(p) \ + (!(*(p) & 0x80) ? ((p)++, (p)[-1]) \ + : !(*(p) & 0x20) ? ((p) += 2, ((((p)[-2] & 0x1F) << 6) \ + | ((p)[-1] & 0x3F))) \ + : !(*(p) & 0x10) ? ((p) += 3, ((((p)[-3] & 0x0F) << 12) \ + | (((p)[-2] & 0x3F) << 6) \ + | ((p)[-1] & 0x3F))) \ + : !(*(p) & 0x08) ? ((p) += 4, ((((p)[-4] & 0x07) << 18) \ + | (((p)[-3] & 0x3F) << 12) \ + | (((p)[-2] & 0x3F) << 6) \ + | ((p)[-1] & 0x3F))) \ + : !(*(p) & 0x04) ? ((p) += 5, ((((p)[-5] & 0x03) << 24) \ + | (((p)[-4] & 0x3F) << 18) \ + | (((p)[-3] & 0x3F) << 12) \ + | (((p)[-2] & 0x3F) << 6) \ + | ((p)[-1] & 0x3F))) \ + : ((p) += 6, ((((p)[-6] & 0x01) << 30) \ + | (((p)[-5] & 0x3F) << 24) \ + | (((p)[-4] & 0x3F) << 18) \ + | (((p)[-3] & 0x3F) << 12) \ + | (((p)[-2] & 0x3F) << 6) \ + | ((p)[-1] & 0x3F)))) + +#define STRING_CHAR_ADVANCE_UTF16(p) \ + (((p)[0] < 0xD800 || (p)[0] >= 0xDC00) \ + ? ((p)++, (p)[-1]) \ + : ((p) += 2, ((((p)[-2] - 0xD800) << 10) + ((p)[-1] - 0xDC00) + 0x10000))) #define STRING_CHAR_ADVANCE STRING_CHAR_ADVANCE_UTF8 -- 1.7.10.4