[gnumeric] SUMIF: fix issues with bools.



commit 1be1c50a7b018314ad698c22b4f91fb04312d53d
Author: Morten Welinder <terra gnome org>
Date:   Fri Dec 11 09:55:00 2009 -0500

    SUMIF: fix issues with bools.

 ChangeLog    |    4 ++++
 src/gutils.c |    5 ++++-
 src/value.c  |   48 +++++++++++++++++++++++++++++++++---------------
 3 files changed, 41 insertions(+), 16 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 97c8c07..c4f5aa5 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2009-12-11  Morten Welinder  <terra gnome org>
+
+	* src/value.c (criteria_inspect_values): Fix bool issues.
+
 2009-12-10  Morten Welinder  <terra gnome org>
 
 	* src/value.c (parse_criteria): If the criteria is a string that
diff --git a/src/gutils.c b/src/gutils.c
index 8607bc2..cf46b28 100644
--- a/src/gutils.c
+++ b/src/gutils.c
@@ -176,7 +176,10 @@ gnm_regcomp_XL (GORegexp *preg, char const *pattern, int cflags,
 			break;
 
 		case '~':
-			pattern++;
+			if (pattern[1] == '*' ||
+			    pattern[1] == '?' ||
+			    pattern[1] == '~')
+				pattern++;
 			/* Fall through */
 		default:
 			pattern = go_regexp_quote1 (res, pattern);
diff --git a/src/value.c b/src/value.c
index 9cc76ea..8e5fbe6 100644
--- a/src/value.c
+++ b/src/value.c
@@ -1351,27 +1351,45 @@ criteria_inspect_values (GnmValue const *x, gnm_float *xr, gnm_float *yr,
 	if (x == NULL || y == NULL)
 		return CRIT_NULL;
 
-	if (!VALUE_IS_NUMBER (y))
-		return CRIT_STRING;
-	*yr = value_get_as_float (y);
-
-	if (VALUE_IS_NUMBER (x)) {
-		if (VALUE_IS_BOOLEAN (y) != VALUE_IS_BOOLEAN (x))
+	switch (y->type) {
+	case VALUE_BOOLEAN:
+		/* If we're searching for a bool -- even one that is
+		   from a string search value -- we match only bools.  */
+		if (!VALUE_IS_BOOLEAN (x))
 			return CRIT_WRONGTYPE;
 		*xr = value_get_as_float (x);
+		*yr = value_get_as_float (y);
 		return CRIT_FLOAT;
-	}
 
-	vx = format_match (value_peek_string (x), NULL, crit->date_conv);
-	if (VALUE_IS_EMPTY (vx) ||
-	    VALUE_IS_BOOLEAN (y) != VALUE_IS_BOOLEAN (vx)) {
-		value_release (vx);
+	case VALUE_EMPTY:
+	case VALUE_STRING:
+		return CRIT_STRING;
+
+	default:
+		g_warning ("This should not happen.  Please report.");
 		return CRIT_WRONGTYPE;
-	}
 
-	*xr = value_get_as_float (vx);
-	value_release (vx);
-	return CRIT_FLOAT;
+	case VALUE_FLOAT:
+		*yr = value_get_as_float (y);
+
+		if (VALUE_IS_BOOLEAN (x))
+			return CRIT_WRONGTYPE;
+		else if (VALUE_IS_FLOAT (x)) {
+			*xr = value_get_as_float (x);
+			return CRIT_FLOAT;
+		}
+
+		vx = format_match (value_peek_string (x), NULL, crit->date_conv);
+		if (VALUE_IS_EMPTY (vx) ||
+		    VALUE_IS_BOOLEAN (y) != VALUE_IS_BOOLEAN (vx)) {
+			value_release (vx);
+			return CRIT_WRONGTYPE;
+		}
+
+		*xr = value_get_as_float (vx);
+		value_release (vx);
+		return CRIT_FLOAT;
+	}
 }
 
 



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