[nautilus] search-engine-model: normalize both strings before comparison
- From: Cosimo Cecchi <cosimoc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [nautilus] search-engine-model: normalize both strings before comparison
- Date: Thu, 27 Sep 2012 03:15:20 +0000 (UTC)
commit be8bfc60e3841173c695b310de3836b5cbfdaf1f
Author: Cosimo Cecchi <cosimoc gnome org>
Date: Wed Sep 26 23:01:42 2012 -0400
search-engine-model: normalize both strings before comparison
Or the pattern matching will fail for non-ASCII characters.
https://bugzilla.gnome.org/show_bug.cgi?id=684852
libnautilus-private/nautilus-search-engine-model.c | 34 +++++++++++++-------
1 files changed, 22 insertions(+), 12 deletions(-)
---
diff --git a/libnautilus-private/nautilus-search-engine-model.c b/libnautilus-private/nautilus-search-engine-model.c
index 973f7d0..7f44ecb 100644
--- a/libnautilus-private/nautilus-search-engine-model.c
+++ b/libnautilus-private/nautilus-search-engine-model.c
@@ -88,18 +88,28 @@ emit_finished_idle_cb (gpointer user_data)
}
static gchar *
-prepare_query_pattern (NautilusSearchEngineModel *model)
+prepare_string_for_compare (const gchar *string)
{
- gchar *text, *pattern, *normalized, *lower;
+ gchar *normalized, *res;
+
+ normalized = g_utf8_normalize (string, -1, G_NORMALIZE_NFD);
+ res = g_utf8_strdown (normalized, -1);
+ g_free (normalized);
+
+ return res;
+}
+
+static gchar *
+prepare_pattern_for_comparison (NautilusSearchEngineModel *model)
+{
+ gchar *text, *prepared, *pattern;
text = nautilus_query_get_text (model->details->query);
- normalized = g_utf8_normalize (text, -1, G_NORMALIZE_NFD);
- lower = g_utf8_strdown (normalized, -1);
- pattern = g_strdup_printf ("*%s*", lower);
+ prepared = prepare_string_for_compare (text);
+ pattern = g_strdup_printf ("*%s*", prepared);
+ g_free (prepared);
g_free (text);
- g_free (normalized);
- g_free (lower);
return pattern;
}
@@ -111,26 +121,26 @@ model_directory_ready_cb (NautilusDirectory *directory,
{
NautilusSearchEngineModel *model = user_data;
gchar *uri, *pattern;
- gchar *display_name, *lower;
+ gchar *display_name, *prepared;
GList *files, *l, *hits;
NautilusFile *file;
- pattern = prepare_query_pattern (model);
+ pattern = prepare_pattern_for_comparison (model);
files = nautilus_directory_get_file_list (directory);
hits = NULL;
for (l = files; l != NULL; l = l->next) {
file = l->data;
display_name = nautilus_file_get_display_name (file);
- lower = g_utf8_strdown (display_name, -1);
+ prepared = prepare_string_for_compare (display_name);
- if (g_pattern_match_simple (pattern, lower)) {
+ if (g_pattern_match_simple (pattern, prepared)) {
uri = nautilus_file_get_uri (file);
hits = g_list_prepend (hits, nautilus_search_hit_new (uri));
g_free (uri);
}
- g_free (lower);
+ g_free (prepared);
g_free (display_name);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]