mirror of
https://git.jabber.space/devs/cproof.git
synced 2026-07-26 16:06:21 +00:00
feat(tools): support UTF-8 characters in autocompletion
Autocompletion failed for nicknames using non Latin scripts. We used `g_str_to_ascii`, which replaces characters it cannot transliterate with '?', leading search failures and false matches between different scripts. Now we do: Use `g_utf8_casefold` for case-insensitive UTF-8 comparison. This ensures that like 'Σ' correctly match 'σ' across all Unicode scripts, providing correct results for non English nicknames. If we don't fine anything typing a base ASCII character matches an accented one (typing `e` matches `è`). This pass uses `g_str_to_ascii` followed by `g_ascii_strdown` for comparison. It is now restricted to run if the search string itself is valid ASCII, preventing the "everything matches '?'" bug in non Latin scripts. Autocomplete items are sorted using `strcmp`. `g_utf8_collate` provides linguistical ordering for a specific language. But its behavior is locale dependent and undefined when comparing strings from different scripts. `strcmp` does byte-wise ordering that correctly follows Unicode code order for UTF-8 strings.
This commit is contained in:
@@ -233,3 +233,115 @@ autocomplete_complete__returns__previous(void** state)
|
||||
free(result3);
|
||||
free(result4);
|
||||
}
|
||||
|
||||
void
|
||||
autocomplete_complete__returns__greek_false_match(void** state)
|
||||
{
|
||||
Autocomplete ac = autocomplete_new();
|
||||
// Σωκράτης (Socrates) and Πλάτων (Plato)
|
||||
autocomplete_add(ac, "Σωκράτης");
|
||||
autocomplete_add(ac, "Πλάτων");
|
||||
|
||||
char* result = autocomplete_complete(ac, "Π", TRUE, FALSE);
|
||||
|
||||
assert_string_equal("Πλάτων", result);
|
||||
|
||||
autocomplete_free(ac);
|
||||
free(result);
|
||||
}
|
||||
|
||||
void
|
||||
autocomplete_complete__returns__greek(void** state)
|
||||
{
|
||||
Autocomplete ac = autocomplete_new();
|
||||
autocomplete_add(ac, "Αριστοτέλης");
|
||||
|
||||
char* result = autocomplete_complete(ac, "Αριστ", TRUE, FALSE);
|
||||
|
||||
assert_non_null(result);
|
||||
assert_string_equal("Αριστοτέλης", result);
|
||||
|
||||
autocomplete_free(ac);
|
||||
free(result);
|
||||
}
|
||||
|
||||
void
|
||||
autocomplete_complete__returns__greek_case_insensitive(void** state)
|
||||
{
|
||||
Autocomplete ac = autocomplete_new();
|
||||
autocomplete_add(ac, "Σωκράτης");
|
||||
|
||||
// Case insensitive search for Socrates
|
||||
// σω is the lowercase of Σω
|
||||
char* result = autocomplete_complete(ac, "σω", TRUE, FALSE);
|
||||
|
||||
assert_non_null(result);
|
||||
assert_string_equal("Σωκράτης", result);
|
||||
|
||||
autocomplete_free(ac);
|
||||
free(result);
|
||||
}
|
||||
|
||||
void
|
||||
autocomplete_complete__returns__russian(void** state)
|
||||
{
|
||||
Autocomplete ac = autocomplete_new();
|
||||
autocomplete_add(ac, "Достоевский");
|
||||
autocomplete_add(ac, "Толстой");
|
||||
autocomplete_add(ac, "Пушкин");
|
||||
|
||||
char* result = autocomplete_complete(ac, "дост", TRUE, FALSE);
|
||||
|
||||
assert_non_null(result);
|
||||
assert_string_equal("Достоевский", result);
|
||||
|
||||
autocomplete_free(ac);
|
||||
free(result);
|
||||
}
|
||||
|
||||
void
|
||||
autocomplete_complete__returns__chinese(void** state)
|
||||
{
|
||||
Autocomplete ac = autocomplete_new();
|
||||
autocomplete_add(ac, "孙子");
|
||||
autocomplete_add(ac, "诸葛亮");
|
||||
|
||||
char* result = autocomplete_complete(ac, "孙", TRUE, FALSE);
|
||||
|
||||
assert_non_null(result);
|
||||
assert_string_equal("孙子", result);
|
||||
|
||||
autocomplete_free(ac);
|
||||
free(result);
|
||||
}
|
||||
|
||||
void
|
||||
autocomplete_complete__returns__transliterated(void** state)
|
||||
{
|
||||
Autocomplete ac = autocomplete_new();
|
||||
autocomplete_add(ac, "München");
|
||||
|
||||
// Match 'ü' with 'u'
|
||||
char* result = autocomplete_complete(ac, "mun", TRUE, FALSE);
|
||||
|
||||
assert_non_null(result);
|
||||
assert_string_equal("München", result);
|
||||
|
||||
autocomplete_free(ac);
|
||||
free(result);
|
||||
}
|
||||
|
||||
void
|
||||
autocomplete_complete__returns__regular_ascii(void** state)
|
||||
{
|
||||
Autocomplete ac = autocomplete_new();
|
||||
autocomplete_add(ac, "London");
|
||||
|
||||
char* result = autocomplete_complete(ac, "lon", TRUE, FALSE);
|
||||
|
||||
assert_non_null(result);
|
||||
assert_string_equal("London", result);
|
||||
|
||||
autocomplete_free(ac);
|
||||
free(result);
|
||||
}
|
||||
|
||||
@@ -17,5 +17,12 @@ void autocomplete_complete__returns__both_with_accented(void** state);
|
||||
void autocomplete_complete__returns__both_with_base(void** state);
|
||||
void autocomplete_complete__is__case_insensitive(void** state);
|
||||
void autocomplete_complete__returns__previous(void** state);
|
||||
void autocomplete_complete__returns__greek(void** state);
|
||||
void autocomplete_complete__returns__greek_false_match(void** state);
|
||||
void autocomplete_complete__returns__greek_case_insensitive(void** state);
|
||||
void autocomplete_complete__returns__russian(void** state);
|
||||
void autocomplete_complete__returns__chinese(void** state);
|
||||
void autocomplete_complete__returns__transliterated(void** state);
|
||||
void autocomplete_complete__returns__regular_ascii(void** state);
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user