mirror of
https://github.com/profanity-im/profanity.git
synced 2024-12-04 14:46:46 -05:00
Autocomplete accent and case insensitive
This commit is contained in:
parent
b19e02db91
commit
b5e0106526
@ -330,10 +330,17 @@ autocomplete_param_no_with_func(const char *const input, char *command, int arg_
|
|||||||
static gchar*
|
static gchar*
|
||||||
_search_from(Autocomplete ac, GSList *curr, gboolean quote)
|
_search_from(Autocomplete ac, GSList *curr, gboolean quote)
|
||||||
{
|
{
|
||||||
|
gchar *search_str_ascii = g_str_to_ascii(ac->search_str, NULL);
|
||||||
|
gchar *search_str_lower = g_ascii_strdown(search_str_ascii, -1);
|
||||||
|
g_free(search_str_ascii);
|
||||||
|
|
||||||
while(curr) {
|
while(curr) {
|
||||||
|
gchar *curr_ascii = g_str_to_ascii(curr->data, NULL);
|
||||||
|
gchar *curr_lower = g_ascii_strdown(curr_ascii, -1);
|
||||||
|
g_free(curr_ascii);
|
||||||
|
|
||||||
// match found
|
// match found
|
||||||
if (strncmp(curr->data, ac->search_str, strlen(ac->search_str)) == 0) {
|
if (strncmp(curr_lower, search_str_lower, strlen(search_str_lower)) == 0) {
|
||||||
|
|
||||||
// set pointer to last found
|
// set pointer to last found
|
||||||
ac->last_found = curr;
|
ac->last_found = curr;
|
||||||
@ -347,16 +354,22 @@ _search_from(Autocomplete ac, GSList *curr, gboolean quote)
|
|||||||
gchar *result = quoted->str;
|
gchar *result = quoted->str;
|
||||||
g_string_free(quoted, FALSE);
|
g_string_free(quoted, FALSE);
|
||||||
|
|
||||||
|
g_free(search_str_lower);
|
||||||
|
g_free(curr_lower);
|
||||||
return result;
|
return result;
|
||||||
|
|
||||||
// otherwise just return the string
|
// otherwise just return the string
|
||||||
} else {
|
} else {
|
||||||
|
g_free(search_str_lower);
|
||||||
|
g_free(curr_lower);
|
||||||
return strdup(curr->data);
|
return strdup(curr->data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
g_free(curr_lower);
|
||||||
curr = g_slist_next(curr);
|
curr = g_slist_next(curr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
g_free(search_str_lower);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -117,3 +117,55 @@ void add_two_same_updates(void **state)
|
|||||||
autocomplete_clear(ac);
|
autocomplete_clear(ac);
|
||||||
g_slist_free_full(result, g_free);
|
g_slist_free_full(result, g_free);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void complete_accented_with_accented(void **state)
|
||||||
|
{
|
||||||
|
Autocomplete ac = autocomplete_new();
|
||||||
|
autocomplete_add(ac, "èâîô");
|
||||||
|
|
||||||
|
char *result = autocomplete_complete(ac, "èâ", TRUE);
|
||||||
|
|
||||||
|
assert_string_equal("èâîô", result);
|
||||||
|
|
||||||
|
autocomplete_clear(ac);
|
||||||
|
}
|
||||||
|
|
||||||
|
void complete_accented_with_base(void **state)
|
||||||
|
{
|
||||||
|
Autocomplete ac = autocomplete_new();
|
||||||
|
autocomplete_add(ac, "èâîô");
|
||||||
|
|
||||||
|
char *result = autocomplete_complete(ac, "ea", TRUE);
|
||||||
|
|
||||||
|
assert_string_equal("èâîô", result);
|
||||||
|
|
||||||
|
autocomplete_clear(ac);
|
||||||
|
}
|
||||||
|
|
||||||
|
void complete_both_with_accented(void **state)
|
||||||
|
{
|
||||||
|
Autocomplete ac = autocomplete_new();
|
||||||
|
autocomplete_add(ac, "eaooooo");
|
||||||
|
autocomplete_add(ac, "èâîô");
|
||||||
|
|
||||||
|
char *result1 = autocomplete_complete(ac, "èâ", TRUE);
|
||||||
|
char *result2 = autocomplete_complete(ac, result1, TRUE);
|
||||||
|
|
||||||
|
assert_string_equal("èâîô", result2);
|
||||||
|
|
||||||
|
autocomplete_clear(ac);
|
||||||
|
}
|
||||||
|
|
||||||
|
void complete_both_with_base(void **state)
|
||||||
|
{
|
||||||
|
Autocomplete ac = autocomplete_new();
|
||||||
|
autocomplete_add(ac, "eaooooo");
|
||||||
|
autocomplete_add(ac, "èâîô");
|
||||||
|
|
||||||
|
char *result1 = autocomplete_complete(ac, "ea", TRUE);
|
||||||
|
char *result2 = autocomplete_complete(ac, result1, TRUE);
|
||||||
|
|
||||||
|
assert_string_equal("èâîô", result2);
|
||||||
|
|
||||||
|
autocomplete_clear(ac);
|
||||||
|
}
|
||||||
|
@ -8,3 +8,7 @@ void add_two_and_complete_returns_second(void **state);
|
|||||||
void add_two_adds_two(void **state);
|
void add_two_adds_two(void **state);
|
||||||
void add_two_same_adds_one(void **state);
|
void add_two_same_adds_one(void **state);
|
||||||
void add_two_same_updates(void **state);
|
void add_two_same_updates(void **state);
|
||||||
|
void complete_accented_with_accented(void **state);
|
||||||
|
void complete_accented_with_base(void **state);
|
||||||
|
void complete_both_with_accented(void **state);
|
||||||
|
void complete_both_with_base(void **state);
|
||||||
|
@ -90,6 +90,10 @@ int main(int argc, char* argv[]) {
|
|||||||
unit_test(add_two_adds_two),
|
unit_test(add_two_adds_two),
|
||||||
unit_test(add_two_same_adds_one),
|
unit_test(add_two_same_adds_one),
|
||||||
unit_test(add_two_same_updates),
|
unit_test(add_two_same_updates),
|
||||||
|
unit_test(complete_accented_with_accented),
|
||||||
|
unit_test(complete_accented_with_base),
|
||||||
|
unit_test(complete_both_with_accented),
|
||||||
|
unit_test(complete_both_with_base),
|
||||||
|
|
||||||
unit_test(create_jid_from_null_returns_null),
|
unit_test(create_jid_from_null_returns_null),
|
||||||
unit_test(create_jid_from_empty_string_returns_null),
|
unit_test(create_jid_from_empty_string_returns_null),
|
||||||
|
Loading…
Reference in New Issue
Block a user