]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib: unichar - Move Hangul syllable handling to unicode-transform.c
authorStephan Bosch <stephan.bosch@open-xchange.com>
Fri, 21 Mar 2025 04:45:07 +0000 (05:45 +0100)
committerStephan Bosch <stephan.bosch@open-xchange.com>
Fri, 1 Aug 2025 01:11:19 +0000 (03:11 +0200)
src/lib/unichar.c
src/lib/unicode-transform.c [new file with mode: 0644]

index 8248d5c0d45873fd9b6f567f9d91068a1b64e8ea..43da11443ec8ed4979a73099b2c2744f7bf73945 100644 (file)
@@ -6,9 +6,6 @@
 #include "unicode-data.h"
 #include "unichar.h"
 
-#define HANGUL_FIRST 0xac00
-#define HANGUL_LAST 0xd7a3
-
 const unsigned char utf8_replacement_char[UTF8_REPLACEMENT_CHAR_LEN] =
        { 0xef, 0xbf, 0xbd }; /* 0xfffd */
 
@@ -240,51 +237,7 @@ unichar_t uni_ucs4_to_titlecase(unichar_t chr)
        return chr;
 }
 
-static size_t uni_ucs4_decompose_hangul(unichar_t chr, unichar_t buf[3])
-{
-       /* The Unicode Standard, Section 3.12.2:
-          Hangul Syllable Decomposition
-        */
-
-       static const uint16_t s_base = 0xac00;
-       static const uint16_t l_base = 0x1100;
-       static const uint16_t v_base = 0x1161;
-       static const uint16_t t_base = 0x11a7;
-       static const unsigned int v_count = 21;
-       static const unsigned int t_count = 28;
-       static const unsigned int n_count = (v_count * t_count);
-
-       unsigned int s_index = chr - s_base;
-       unsigned int l_index = s_index / n_count;
-       unsigned int v_index = (s_index % n_count) / t_count;
-       unsigned int t_index = s_index % t_count;
-       uint32_t l_part = l_base + l_index;
-       uint32_t v_part = v_base + v_index;
-
-       if (t_index == 0) {
-               buf[0] = l_part;
-               buf[1] = v_part;
-               return 2;
-       }
-
-       uint32_t t_part = t_base + t_index;
-
-       buf[0] = l_part;
-       buf[1] = v_part;
-       buf[2] = t_part;
-       return 3;
-}
-
-static void uni_ucs4_decompose_hangul_utf8(unichar_t chr, buffer_t *output)
-{
-       unichar_t buf[3];
-       size_t len, i;
-
-       len = uni_ucs4_decompose_hangul(chr, buf);
-
-       for (i = 0; i < len; i++)
-               uni_ucs4_to_utf8_c(buf[i], output);
-}
+#include "unicode-transform.c"
 
 static void
 uni_ucs4_decompose_one_utf8(unichar_t chr, bool canonical, buffer_t *output)
diff --git a/src/lib/unicode-transform.c b/src/lib/unicode-transform.c
new file mode 100644 (file)
index 0000000..5bc2bff
--- /dev/null
@@ -0,0 +1,54 @@
+/* Copyright (c) 2025 Dovecot authors, see the included COPYING file */
+
+#define HANGUL_FIRST 0xac00
+#define HANGUL_LAST 0xd7a3
+
+/*
+ * Hangul syllable (de)composition
+ */
+
+static size_t uni_ucs4_decompose_hangul(unichar_t chr, unichar_t buf[3])
+{
+       /* The Unicode Standard, Section 3.12.2:
+          Hangul Syllable Decomposition
+        */
+
+       static const uint16_t s_base = 0xac00;
+       static const uint16_t l_base = 0x1100;
+       static const uint16_t v_base = 0x1161;
+       static const uint16_t t_base = 0x11a7;
+       static const unsigned int v_count = 21;
+       static const unsigned int t_count = 28;
+       static const unsigned int n_count = (v_count * t_count);
+
+       unsigned int s_index = chr - s_base;
+       unsigned int l_index = s_index / n_count;
+       unsigned int v_index = (s_index % n_count) / t_count;
+       unsigned int t_index = s_index % t_count;
+       uint32_t l_part = l_base + l_index;
+       uint32_t v_part = v_base + v_index;
+
+       if (t_index == 0) {
+               buf[0] = l_part;
+               buf[1] = v_part;
+               return 2;
+       }
+
+       uint32_t t_part = t_base + t_index;
+
+       buf[0] = l_part;
+       buf[1] = v_part;
+       buf[2] = t_part;
+       return 3;
+}
+
+static void uni_ucs4_decompose_hangul_utf8(unichar_t chr, buffer_t *output)
+{
+       unichar_t buf[3];
+       size_t len, i;
+
+       len = uni_ucs4_decompose_hangul(chr, buf);
+
+       for (i = 0; i < len; i++)
+               uni_ucs4_to_utf8_c(buf[i], output);
+}