Branch: refs/heads/master Author: Enrico Tröger enrico.troeger@uvena.de Committer: Enrico Tröger enrico.troeger@uvena.de Date: Sun, 05 Jan 2025 10:43:42 UTC Commit: 54551a2879e61fc43b59029406a8684f85df69db https://github.com/geany/geany/commit/54551a2879e61fc43b59029406a8684f85df69...
Log Message: ----------- Move UTF-8 capable sub string matching from plugin manager to utils
Modified Paths: -------------- src/plugins.c src/utils.c src/utils.h
Modified: src/plugins.c 44 lines changed, 1 insertions(+), 43 deletions(-) =================================================================== @@ -1663,48 +1663,6 @@ static gint pm_tree_sort_func(GtkTreeModel *model, GtkTreeIter *a, GtkTreeIter * }
-static gboolean pm_tree_search(const gchar *key, const gchar *haystack) -{ - gchar *normalized_string = NULL; - gchar *normalized_key = NULL; - gchar *case_normalized_string = NULL; - gchar *case_normalized_key = NULL; - gboolean matched = TRUE; - - normalized_string = g_utf8_normalize(haystack, -1, G_NORMALIZE_ALL); - normalized_key = g_utf8_normalize(key, -1, G_NORMALIZE_ALL); - - if (normalized_string != NULL && normalized_key != NULL) - { - GString *stripped_key; - gchar **subkey, **subkeys; - - case_normalized_string = g_utf8_casefold(normalized_string, -1); - case_normalized_key = g_utf8_casefold(normalized_key, -1); - stripped_key = g_string_new(case_normalized_key); - do {} while (utils_string_replace_all(stripped_key, " ", " ")); - subkeys = g_strsplit(stripped_key->str, " ", -1); - g_string_free(stripped_key, TRUE); - foreach_strv(subkey, subkeys) - { - if (strstr(case_normalized_string, *subkey) == NULL) - { - matched = FALSE; - break; - } - } - g_strfreev(subkeys); - } - - g_free(normalized_key); - g_free(normalized_string); - g_free(case_normalized_key); - g_free(case_normalized_string); - - return matched; -} - - static gboolean pm_tree_filter_func(GtkTreeModel *model, GtkTreeIter *iter, gpointer user_data) { Plugin *plugin; @@ -1721,7 +1679,7 @@ static gboolean pm_tree_filter_func(GtkTreeModel *model, GtkTreeIter *iter, gpoi filename = g_path_get_basename(plugin->filename); haystack = g_strjoin(" ", plugin->info.name, plugin->info.description, plugin->info.author, filename, NULL); - matched = pm_tree_search(key, haystack); + matched = utils_utf8_substring_match(key, haystack); g_free(haystack); g_free(filename);
Modified: src/utils.c 48 lines changed, 48 insertions(+), 0 deletions(-) =================================================================== @@ -475,6 +475,54 @@ gchar *utils_utf8_strdown(const gchar *str) }
+/* Returns @c TRUE if @a key is a substring of @a haystack, case-insensitive. + * Applies @c g_utf8_normalize and @c g_utf8_casefold on both input strings before comparison. + */ +gboolean utils_utf8_substring_match(const gchar *key, const gchar *haystack) +{ + gchar *normalized_string = NULL; + gchar *normalized_key = NULL; + gchar *case_normalized_string = NULL; + gchar *case_normalized_key = NULL; + gboolean matched = TRUE; + + g_return_val_if_fail(key != NULL, FALSE); + g_return_val_if_fail(haystack != NULL, FALSE); + + normalized_string = g_utf8_normalize(haystack, -1, G_NORMALIZE_ALL); + normalized_key = g_utf8_normalize(key, -1, G_NORMALIZE_ALL); + + if (normalized_string != NULL && normalized_key != NULL) + { + GString *stripped_key; + gchar **subkey, **subkeys; + + case_normalized_string = g_utf8_casefold(normalized_string, -1); + case_normalized_key = g_utf8_casefold(normalized_key, -1); + stripped_key = g_string_new(case_normalized_key); + do {} while (utils_string_replace_all(stripped_key, " ", " ")); + subkeys = g_strsplit(stripped_key->str, " ", -1); + g_string_free(stripped_key, TRUE); + foreach_strv(subkey, subkeys) + { + if (strstr(case_normalized_string, *subkey) == NULL) + { + matched = FALSE; + break; + } + } + g_strfreev(subkeys); + } + + g_free(normalized_key); + g_free(normalized_string); + g_free(case_normalized_key); + g_free(case_normalized_string); + + return matched; +} + + /** * A replacement function for g_strncasecmp() to compare strings case-insensitive. * It converts both strings into lowercase using g_utf8_strdown() and then compare
Modified: src/utils.h 2 lines changed, 2 insertions(+), 0 deletions(-) =================================================================== @@ -338,6 +338,8 @@ gchar *utils_get_os_info_string(void);
gchar *utils_utf8_strdown(const gchar *str);
+gboolean utils_utf8_substring_match(const gchar *key, const gchar *haystack); + #endif /* GEANY_PRIVATE */
G_END_DECLS
-------------- This E-Mail was brought to you by github_commit_mail.py (Source: https://github.com/geany/infrastructure).