[gnumeric] Autofilter: improve matching.



commit 86b3e91532026fa3f17dbe155747c128a3542629
Author: Morten Welinder <terra gnome org>
Date:   Fri Apr 30 10:02:03 2010 -0400

    Autofilter: improve matching.

 ChangeLog          |    5 +++++
 NEWS               |    1 +
 src/sheet-filter.c |   36 ++++++++++++++++++++++++++----------
 3 files changed, 32 insertions(+), 10 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index d09ad9c..bab9739 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2010-04-30  Morten Welinder  <terra gnome org>
+
+	* src/sheet-filter.c (filter_expr_eval): When we're looking for a
+	number, match also strings.  Match strings case insensitively.
+
 2010-04-27  Jean Brefort  <jean brefort normalesup org>
 
 	* configure.in: needs goffice-0.8.3.
diff --git a/NEWS b/NEWS
index b806ddc..57da891 100644
--- a/NEWS
+++ b/NEWS
@@ -21,6 +21,7 @@ Morten:
 	* Fix hidden-sheet problem.  [#616549]
 	* Fix auto-expr problem.  [#575104]
 	* Fix xls-save problems with custom autofilters.
+	* Fix auto-filter problem.  [#383400]
 
 --------------------------------------------------------------------------
 Gnumeric 1.10.2
diff --git a/src/sheet-filter.c b/src/sheet-filter.c
index f2eeda6..9b3e9ae 100644
--- a/src/sheet-filter.c
+++ b/src/sheet-filter.c
@@ -167,41 +167,57 @@ filter_expr_release (FilterExpr *fexpr, unsigned i)
 		value_release (fexpr->val[i]);
 }
 
+static char *
+filter_cell_contents (GnmCell *cell)
+{
+	GOFormat const *format = gnm_cell_get_format (cell);
+	GODateConventions const *date_conv =
+		workbook_date_conv (cell->base.sheet->workbook);
+	return format_value (format, cell->value, NULL, -1, date_conv);
+}
+
 static gboolean
 filter_expr_eval (GnmFilterOp op, GnmValue const *src, GORegexp const *regexp,
 		  GnmCell *cell)
 {
 	GnmValue *target = cell->value;
 	GnmValDiff cmp;
+	GnmValue *fake_val = NULL;
 
 	if (src == NULL) {
-		GOFormat const *format = gnm_cell_get_format (cell);
-		GODateConventions const *date_conv =
-			workbook_date_conv (cell->base.sheet->workbook);
-		char *str = format_value (format, target, NULL, -1, date_conv);
+		char *str = filter_cell_contents (cell);
 		GORegmatch rm;
 		int res = go_regexec (regexp, str, 1, &rm, 0);
+		gboolean whole = (rm.rm_so == 0 && str[rm.rm_eo] == 0);
+
+		g_free (str);
 
 		switch (res) {
 		case GO_REG_OK:
-			if (rm.rm_so == 0 && strlen (str) == (size_t)rm.rm_eo) {
-				g_free (str);
+			if (whole)
 				return op == GNM_FILTER_OP_EQUAL;
-			}
 			/* fall through */
 
 		case GO_REG_NOMATCH:
-			g_free (str);
 			return op == GNM_FILTER_OP_NOT_EQUAL;
 
 		default:
-			g_free (str);
 			g_warning ("Unexpected regexec result");
 			return FALSE;
 		}
 	}
 
-	cmp = value_compare (target, src, TRUE);
+	if (VALUE_IS_STRING (target) && VALUE_IS_NUMBER (src)) {
+		GODateConventions const *date_conv =
+			workbook_date_conv (cell->base.sheet->workbook);
+		char *str = format_value (NULL, src, NULL, -1, date_conv);
+		fake_val = value_new_string_nocopy (str);
+		src = fake_val;
+	}
+
+	cmp = value_compare (target, src, FALSE);
+	value_release (fake_val);
+
 	switch (op) {
 	case GNM_FILTER_OP_EQUAL     : return cmp == IS_EQUAL;
 	case GNM_FILTER_OP_NOT_EQUAL : return cmp != IS_EQUAL;



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