From: NaitLee Date: Mon, 10 Jul 2023 14:03:07 +0000 (+0800) Subject: rename and add comments for wtf8 macro flags X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=724c87c9609ab6d1b8644d2b2dbce1726537ee8d;p=xonotic%2Fdarkplaces.git rename and add comments for wtf8 macro flags Signed-off-by: NaitLee --- diff --git a/utf8lib.c b/utf8lib.c index eba58877..18b5e09d 100644 --- a/utf8lib.c +++ b/utf8lib.c @@ -167,10 +167,10 @@ findchar: // Now check the decoded byte for an overlong encoding if ( (bits >= 2 && ch < 0x80) || - (bits >= 3 && ch < 0x800) || - (bits >= 4 && ch < 0x10000) || - ch >= 0x10FFFF // RFC 3629 - ) + (bits >= 3 && ch < 0x800) || + (bits >= 4 && ch < 0x10000) || + ch >= 0x10FFFF // RFC 3629 + ) { i += bits; //fprintf(stderr, "overlong: %i bytes for %x\n", bits, ch); @@ -931,7 +931,7 @@ int towtf8(const wchar *wstr, int wlen, char *cstr, int maxclen) cstr[p++] = (0x80 | ((point >> 0) & 0x3f)); } else - #if U32 + #if WTF8U32 if (point < 0x10000) #endif { @@ -940,9 +940,9 @@ int towtf8(const wchar *wstr, int wlen, char *cstr, int maxclen) cstr[p++] = (0x80 | ((point >> 6) & 0x3f)); cstr[p++] = (0x80 | ((point >> 0) & 0x3f)); } - #if U32 + #if WTF8U32 else - #if CHECKS + #if WTF8CHECKS if (point < 0x110000) #endif { @@ -971,7 +971,7 @@ int fromwtf8(const char *cstr, int clen, wchar *wstr, int maxwlen) wchar point = byte; int length = 1; if (p + 1 >= maxwlen) break; - #if CHECKS + #if WTF8CHECKS if ((byte & 0xf8) == 0xf8) return -1; #endif @@ -990,7 +990,7 @@ int fromwtf8(const char *cstr, int clen, wchar *wstr, int maxwlen) length = 2; point = byte & 0x1f; } - #if CHECKS + #if WTF8CHECKS else if ((byte & 0xc0) == 0x80) { return -1; @@ -999,7 +999,7 @@ int fromwtf8(const char *cstr, int clen, wchar *wstr, int maxwlen) while (--length) { byte = cstr[i++]; - #if CHECKS + #if WTF8CHECKS if (byte == -1) return -1; else if ((byte & 0xc0) != 0x80) return -1; #endif diff --git a/utf8lib.h b/utf8lib.h index cb7041b9..b50a2065 100644 --- a/utf8lib.h +++ b/utf8lib.h @@ -82,8 +82,8 @@ Uchar u8_tolower(Uchar ch); // WTF-8 encoding to circumvent Windows encodings, be it UTF-16 or random codepages // https://simonsapin.github.io/wtf-8/ -#define U32 0 -#define CHECKS 1 +#define WTF8U32 0 // whether to regard wchar as utf-32 +#define WTF8CHECKS 1 // check for extra sanity in conversion steps typedef wchar_t wchar; int towtf8(const wchar* wstr, int wlen, char* cstr, int maxclen);