[PATCH 5/5] kernelbase/locale: Implement sortkey language support

Fabian Maurer dark.shadow4 at web.de
Tue Apr 28 13:17:48 CDT 2020


Signed-off-by: Fabian Maurer <dark.shadow4 at web.de>
---
 dlls/kernel32/tests/locale.c | 20 ++++++++++++++++++++
 dlls/kernelbase/locale.c     | 26 ++++++++++++++++++++++++--
 2 files changed, 44 insertions(+), 2 deletions(-)

diff --git a/dlls/kernel32/tests/locale.c b/dlls/kernel32/tests/locale.c
index 8c976e70fc..e5102bbbf3 100644
--- a/dlls/kernel32/tests/locale.c
+++ b/dlls/kernel32/tests/locale.c
@@ -3222,6 +3222,26 @@ static const struct sorting_test_entry unicode_sorting_tests[] =
     /*  92 */ { L"en-US", 0, L"\x00c6", L"\x0041\x0045", CSTR_EQUAL }, /* Expansion */
     /*  93 */ { L"en-US", 0, L"\x0f5c", L"\x0f5b\x0fb7", CSTR_EQUAL }, /* Expansion */
     /*  94 */ { L"en-US", 0, L"\x05f0", L"\x05d5\x05d5", CSTR_EQUAL }, /* Expansion */
+    /*  95 */ { L"ja-JP", 0, L"\x6df8", L"\x654b\x29e9", CSTR_LESS_THAN  }, /* japanese locale */
+    /*  96 */ { L"ja-JP", 0, L"\x685d\x1239\x1b61", L"\x59b6\x6542\x2a62\x04a7", CSTR_LESS_THAN  }, /* japanese locale */
+    /*  97 */ { L"ja-JP", 0, L"\x62f3\x43e9", L"\x5760", CSTR_LESS_THAN  }, /* japanese locale */
+    /*  98 */ { L"ja-JP", 0, L"\x634c", L"\x2f0d\x5f1c\x7124", CSTR_LESS_THAN  }, /* japanese locale */
+    /*  99 */ { L"ja-JP", 0, L"\x69e7\x0502", L"\x57cc" , CSTR_LESS_THAN }, /* japanese locale */
+    /* 100 */ { L"ja-JP", 0, L"\x7589", L"\x67c5" , CSTR_LESS_THAN }, /* japanese locale */
+    /* 101 */ { L"ja-JP", 0, L"\x5ede\x765c", L"\x7324" , CSTR_GREATER_THAN }, /* japanese locale */
+    /* 102 */ { L"ja-JP", 0, L"\x5c7f\x5961", L"\x7cbe" , CSTR_GREATER_THAN }, /* japanese locale */
+    /* 103 */ { L"ja-JP", 0, L"\x3162", L"\x6a84\x1549\x0b60" , CSTR_GREATER_THAN }, /* japanese locale */
+    /* 104 */ { L"ja-JP", 0, L"\x769e\x448e", L"\x4e6e" , CSTR_LESS_THAN }, /* japanese locale */
+    /* 105 */ { L"ja-JP", 0, L"\x59a4", L"\x5faa\x607c", CSTR_GREATER_THAN  }, /* japanese locale */
+    /* 106 */ { L"ja-JP", 0, L"\x529b", L"\x733f", CSTR_GREATER_THAN  }, /* japanese locale */
+    /* 107 */ { L"ja-JP", 0, L"\x6ff8\x2a0a", L"\x7953\x6712" , CSTR_GREATER_THAN }, /* japanese locale */
+    /* 108 */ { L"ja-JP", 0, L"\x6dfb", L"\x6793", CSTR_LESS_THAN  }, /* japanese locale */
+    /* 109 */ { L"ja-JP", 0, L"\x67ed", L"\x6aa2", CSTR_GREATER_THAN  }, /* japanese locale */
+    /* 110 */ { L"ja-JP", 0, L"\x4e61", L"\x6350\x6b08", CSTR_GREATER_THAN  }, /* japanese locale */
+    /* 111 */ { L"ja-JP", 0, L"\x5118", L"\x53b3\x75b4", CSTR_GREATER_THAN  }, /* japanese locale */
+    /* 112 */ { L"ja-JP", 0, L"\x6bbf", L"\x65a3" , CSTR_LESS_THAN }, /* japanese locale */
+    /* 113 */ { L"ja-JP", 0, L"\x5690", L"\x5fa8", CSTR_GREATER_THAN  }, /* japanese locale */
+    /* 114 */ { L"ja-JP", 0, L"\x61e2", L"\x76e5" , CSTR_GREATER_THAN }, /* japanese locale */
 };

 static void test_unicode_sorting(void)
diff --git a/dlls/kernelbase/locale.c b/dlls/kernelbase/locale.c
index a12b8bdb30..48284741b0 100644
--- a/dlls/kernelbase/locale.c
+++ b/dlls/kernelbase/locale.c
@@ -2517,6 +2517,7 @@ typedef struct _sortkey_data
     list weights_case;
     list weights_special;
     list weights_extra;
+    const struct sortguid* locale;
 } sortkey_data;

 /* List functions */
@@ -2586,9 +2587,28 @@ static void LIST_ADD(list* name, const void *value)

 /* Helper functions */

+static DWORD get_exception(sortkey_data* data, WCHAR ch)
+{
+    if (data->locale && data->locale->except)
+    {
+        DWORD* table = sort.keys + data->locale->except;
+        DWORD hi = ch >> 8;
+        DWORD lo = ch & 0xff;
+        if (table[hi] == hi * 0x100)
+            return 0;
+        if (sort.keys[table[hi] + lo] == sort.keys[hi * 0x100 + lo])
+            return 0;
+        return sort.keys[table[hi] + lo];
+    }
+   return 0;
+}
+
 static BOOL get_char(sortkey_data* data, character_info* info, WCHAR ch)
 {
-    DWORD value = sort.keys[ch];
+    DWORD value = get_exception(data, ch);
+    if (!value)
+        value = sort.keys[ch];
+
     if ((WORD)value == 0x200) /* Expansion */
         return FALSE;

@@ -2596,6 +2616,7 @@ static BOOL get_char(sortkey_data* data, character_info* info, WCHAR ch)
     info->weight_diacritic = (value >> 16) & 0xff;
     info->script_member = (value >> 8) & 0xff;
     info->weight_primary = value & 0xff;
+
     return info->script_member != 0;
 }

@@ -2630,6 +2651,7 @@ static void sortkey_data_init(sortkey_data* data, int flags, const WCHAR* locale
     LIST_INIT(&data->weights_case, sizeof(BYTE));
     LIST_INIT(&data->weights_special, sizeof(BYTE));
     LIST_INIT(&data->weights_extra, sizeof(weight_extra_info));
+    data->locale = get_language_sort(locale);
 }

 static void sortkey_data_destroy(sortkey_data* data)
@@ -5330,7 +5352,7 @@ INT WINAPI DECLSPEC_HOTPATCH LCMapStringEx( const WCHAR *locale, DWORD flags, co
         TRACE( "(%s,0x%08x,%s,%d,%p,%d)\n",
                debugstr_w(locale), flags, debugstr_wn(src, srclen), srclen, dst, dstlen );

-        if (!(ret = sortkey_generate(flags, L"", src, srclen, (BYTE *)dst, dstlen )))
+        if (!(ret = sortkey_generate(flags, locale, src, srclen, (BYTE *)dst, dstlen )))
             SetLastError( ERROR_INSUFFICIENT_BUFFER );
         return ret;
     }
--
2.26.2




More information about the wine-devel mailing list