[gnumeric] Search: put search normalization in one place only.



commit c834df8cd745b61e1fa293818311e9c8453303e4
Author: Morten Welinder <terra gnome org>
Date:   Fri Apr 6 14:58:26 2012 -0400

    Search: put search normalization in one place only.
    
    It's unclear what the right normalization is, so centralize things in
    case we want to change.

 ChangeLog                           |    7 +++++++
 src/dialogs/ChangeLog               |    7 +++++++
 src/dialogs/dialog-search-replace.c |    4 ++--
 src/dialogs/dialog-search.c         |    2 +-
 src/search.c                        |   16 ++++++++++++----
 src/search.h                        |    2 ++
 6 files changed, 31 insertions(+), 7 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index facc281..5589b2d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2012-04-06  Morten Welinder  <terra gnome org>
+
+	* src/search.c (gnm_search_normalize): Function to normalize text
+	before search and search/replace.
+	(gnm_search_replace_comment, gnm_search_replace_cell)
+	(gnm_search_replace_value): Use gnm_search_normalize.
+
 2012-03-29  Morten Welinder  <terra gnome org>
 
 	* src/sheet-style.c: Switch to g_slice by default.
diff --git a/src/dialogs/ChangeLog b/src/dialogs/ChangeLog
index 22e245e..a6bad62 100644
--- a/src/dialogs/ChangeLog
+++ b/src/dialogs/ChangeLog
@@ -1,3 +1,10 @@
+2012-04-06  Morten Welinder  <terra gnome org>
+
+	* dialog-search-replace.c (apply_clicked): Use
+	gnm_search_normalize.
+
+	* dialog-search.c (search_clicked): Ditto.
+
 2012-04-01  Andreas J. Guelzow <aguelzow pyrshep ca>
 
 	* dialog-doc-metadata.c (dialog_doc_metadata_get_value_type):
diff --git a/src/dialogs/dialog-search-replace.c b/src/dialogs/dialog-search-replace.c
index 4024d73..f383342 100644
--- a/src/dialogs/dialog-search-replace.c
+++ b/src/dialogs/dialog-search-replace.c
@@ -135,8 +135,8 @@ apply_clicked (G_GNUC_UNUSED GtkWidget *widget, DialogState *dd)
 	i = gnm_gui_group_value (gui, scope_group);
 	scope = (i == -1) ? GNM_SRS_SHEET : (GnmSearchReplaceScope)i;
 
-	search_text = g_utf8_normalize (gtk_entry_get_text (dd->search_text), -1, G_NORMALIZE_DEFAULT);
-	replace_text = g_utf8_normalize (gtk_entry_get_text (dd->replace_text), -1, G_NORMALIZE_DEFAULT);
+	search_text = gnm_search_normalize (gtk_entry_get_text (dd->search_text));
+	replace_text = gnm_search_normalize (gtk_entry_get_text (dd->replace_text));
 
 	sr = g_object_new (GNM_SEARCH_REPLACE_TYPE,
 			   "sheet", wb_control_cur_sheet (WORKBOOK_CONTROL (wbcg)),
diff --git a/src/dialogs/dialog-search.c b/src/dialogs/dialog-search.c
index 1611d14..cf0c894 100644
--- a/src/dialogs/dialog-search.c
+++ b/src/dialogs/dialog-search.c
@@ -322,7 +322,7 @@ search_clicked (G_GNUC_UNUSED GtkWidget *widget, DialogState *dd)
 	is_regexp = (i == 1);
 	is_number = (i == 2);
 
-	text = g_utf8_normalize (gtk_entry_get_text (dd->gentry), -1, G_NORMALIZE_DEFAULT);
+	text = gnm_search_normalize (gtk_entry_get_text (dd->gentry));
 
 	sr = g_object_new (GNM_SEARCH_REPLACE_TYPE,
 			   "sheet", wb_control_cur_sheet (wbc),
diff --git a/src/search.c b/src/search.c
index ed2ba32..e3a864e 100644
--- a/src/search.c
+++ b/src/search.c
@@ -58,6 +58,15 @@ gnm_search_replace_value (GnmSearchReplace *sr,
 			  GnmSearchReplaceValueResult *res);
 
 /* ------------------------------------------------------------------------- */
+
+char *
+gnm_search_normalize (const char *txt)
+{
+	return g_utf8_normalize (txt, -1, G_NORMALIZE_DEFAULT);
+}
+
+/* ------------------------------------------------------------------------- */
+
 static gboolean
 check_number (GnmSearchReplace *sr)
 {
@@ -326,7 +335,7 @@ gnm_search_replace_comment (GnmSearchReplace *sr,
 
 	res->old_text = cell_comment_text_get (res->comment);
 
-	norm_text = g_utf8_normalize (res->old_text, -1, G_NORMALIZE_DEFAULT);
+	norm_text = gnm_search_normalize (res->old_text);
 
 	if (repl) {
 		res->new_text = go_search_replace_string (GO_SEARCH_REPLACE (sr),
@@ -387,8 +396,7 @@ gnm_search_replace_cell (GnmSearchReplace *sr,
 		res->old_text = gnm_cell_get_entered_text (cell);
 		initial_quote = (is_string && res->old_text[0] == '\'');
 
-		actual_src = g_utf8_normalize (res->old_text + (initial_quote ? 1 : 0),
-					       -1, G_NORMALIZE_DEFAULT);
+		actual_src = gnm_search_normalize (res->old_text + initial_quote);
 
 		if (repl) {
 			res->new_text = go_search_replace_string (GO_SEARCH_REPLACE (sr),
@@ -440,7 +448,7 @@ gnm_search_replace_value (GnmSearchReplace *sr,
 	else if (sr->is_number) {
 		return gnm_search_match_value (sr, cell->value);
 	} else {
-		char *val = g_utf8_normalize (value_peek_string (cell->value), -1, G_NORMALIZE_DEFAULT);
+		char *val = gnm_search_normalize (value_peek_string (cell->value));
 		gboolean res = go_search_match_string (GO_SEARCH_REPLACE (sr), val);
 		g_free (val);
 		return res;
diff --git a/src/search.h b/src/search.h
index 93c6031..9e57835 100644
--- a/src/search.h
+++ b/src/search.h
@@ -9,6 +9,8 @@
 
 G_BEGIN_DECLS
 
+char *gnm_search_normalize (const char *txt);
+
 #define GNM_SEARCH_REPLACE_TYPE        (gnm_search_replace_get_type ())
 #define GNM_SEARCH_REPLACE(o)          (G_TYPE_CHECK_INSTANCE_CAST ((o), GNM_SEARCH_REPLACE_TYPE, GnmSearchReplace))
 #define IS_GNM_SEARCH_REPLACE(o)       (G_TYPE_CHECK_INSTANCE_TYPE ((o), GNM_SEARCH_REPLACE_TYPE))



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]