]> git.xonotic.org Git - xonotic/darkplaces.git/commitdiff
rename and add comments for wtf8 macro flags
authorNaitLee <naitli@foxmail.com>
Mon, 10 Jul 2023 14:03:07 +0000 (22:03 +0800)
committerNaitLee <naitli@foxmail.com>
Mon, 10 Jul 2023 14:03:07 +0000 (22:03 +0800)
Signed-off-by: NaitLee <naitli@foxmail.com>
utf8lib.c
utf8lib.h

index eba58877bd7d3392f031fc3a0aecad52e0440b31..18b5e09d4de73973b62df12875f2cf80c32449f2 100644 (file)
--- 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
index cb7041b961108b877c8a2206237470b9bae18d21..b50a20655c8ce3ce1790dd6a1f81b9dec85b0a3f 100644 (file)
--- 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);