mirror of
https://git.jabber.space/devs/cproof.git
synced 2026-07-30 09:16:22 +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:
@@ -305,8 +305,30 @@ roster_contact_autocomplete__returns__first_when_two_match_and_reset(void** stat
|
||||
roster_destroy();
|
||||
}
|
||||
|
||||
void
|
||||
roster_contact_autocomplete__returns__utf8(void** state)
|
||||
{
|
||||
roster_create();
|
||||
roster_add("Σωκράτης", NULL, NULL, NULL, FALSE);
|
||||
roster_add("Πλάτων", NULL, NULL, NULL, FALSE);
|
||||
|
||||
// Byte-wise (strcmp): Πλάτων (CE A0...) < Σωκράτης (CE A3...)
|
||||
char* result = roster_contact_autocomplete("Π", FALSE, NULL);
|
||||
assert_string_equal("Πλάτων", result);
|
||||
g_free(result);
|
||||
|
||||
roster_reset_search_attempts();
|
||||
|
||||
result = roster_contact_autocomplete("σω", FALSE, NULL);
|
||||
assert_string_equal("Σωκράτης", result);
|
||||
g_free(result);
|
||||
|
||||
roster_destroy();
|
||||
}
|
||||
|
||||
void
|
||||
roster_get_groups__returns__empty_for_no_group(void** state)
|
||||
|
||||
{
|
||||
roster_create();
|
||||
roster_add("person@server.org", NULL, NULL, NULL, FALSE);
|
||||
|
||||
@@ -19,6 +19,7 @@ void roster_contact_autocomplete__returns__null_on_empty_roster(void** state);
|
||||
void roster_contact_autocomplete__returns__second_when_two_match(void** state);
|
||||
void roster_contact_autocomplete__returns__fifth_when_multiple_match(void** state);
|
||||
void roster_contact_autocomplete__returns__first_when_two_match_and_reset(void** state);
|
||||
void roster_contact_autocomplete__returns__utf8(void** state);
|
||||
void roster_get_groups__returns__empty_for_no_group(void** state);
|
||||
void roster_get_groups__returns__one_group(void** state);
|
||||
void roster_get_groups__returns__two_groups(void** state);
|
||||
|
||||
Reference in New Issue
Block a user