[gnumeric] D-funcs: string comparisons.
- From: Morten Welinder <mortenw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnumeric] D-funcs: string comparisons.
- Date: Sat, 11 Jun 2016 21:13:16 +0000 (UTC)
commit a6ad2e5673c1e514b0f7066b7579b2f6799e790f
Author: Morten Welinder <terra gnome org>
Date: Sat Jun 11 17:12:57 2016 -0400
D-funcs: string comparisons.
ChangeLog | 5 +++++
samples/excel12/database.xlsx | Bin 9983 -> 10341 bytes
src/value.c | 24 ++++++++++++++++++++----
3 files changed, 25 insertions(+), 4 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index ad1f341..9dc9b56 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -6,6 +6,11 @@
(parse_criteria): Don't anchor matches. This is the right thing
to do for DSUM and friends. Hopefully this doesn't break anything
else.
+ (criteria_inspect_values): Strings are incompatible with
+ non-strings.
+ (criteria_test_less, criteria_test_less_or_equal)
+ (criteria_test_greater, criteria_test_greater_or_equal): handle
+ strings.
2016-05-19 Morten Welinder <terra gnome org>
diff --git a/samples/excel12/database.xlsx b/samples/excel12/database.xlsx
index 778e452..db3581f 100644
Binary files a/samples/excel12/database.xlsx and b/samples/excel12/database.xlsx differ
diff --git a/src/value.c b/src/value.c
index 16712aa..3c4665a 100644
--- a/src/value.c
+++ b/src/value.c
@@ -1501,7 +1501,11 @@ criteria_inspect_values (GnmValue const *x, gnm_float *xr, gnm_float *yr,
return CRIT_FLOAT;
case VALUE_EMPTY:
+ return CRIT_WRONGTYPE;
+
case VALUE_STRING:
+ if (!VALUE_IS_STRING (x))
+ return CRIT_WRONGTYPE;
return CRIT_STRING;
default:
@@ -1577,14 +1581,17 @@ static gboolean
criteria_test_less (GnmValue const *x, GnmCriteria *crit)
{
gnm_float xf, yf;
+ GnmValue const *y = crit->x;
switch (criteria_inspect_values (x, &xf, &yf, crit)) {
default:
g_assert_not_reached ();
case CRIT_NULL:
case CRIT_WRONGTYPE:
- case CRIT_STRING:
return FALSE;
+ case CRIT_STRING:
+ return g_utf8_collate (value_peek_string (x),
+ value_peek_string (y)) < 0;
case CRIT_FLOAT:
return xf < yf;
}
@@ -1594,14 +1601,17 @@ static gboolean
criteria_test_greater (GnmValue const *x, GnmCriteria *crit)
{
gnm_float xf, yf;
+ GnmValue const *y = crit->x;
switch (criteria_inspect_values (x, &xf, &yf, crit)) {
default:
g_assert_not_reached ();
case CRIT_NULL:
case CRIT_WRONGTYPE:
- case CRIT_STRING:
return FALSE;
+ case CRIT_STRING:
+ return g_utf8_collate (value_peek_string (x),
+ value_peek_string (y)) > 0;
case CRIT_FLOAT:
return xf > yf;
}
@@ -1611,14 +1621,17 @@ static gboolean
criteria_test_less_or_equal (GnmValue const *x, GnmCriteria *crit)
{
gnm_float xf, yf;
+ GnmValue const *y = crit->x;
switch (criteria_inspect_values (x, &xf, &yf, crit)) {
default:
g_assert_not_reached ();
case CRIT_NULL:
case CRIT_WRONGTYPE:
- case CRIT_STRING:
return FALSE;
+ case CRIT_STRING:
+ return g_utf8_collate (value_peek_string (x),
+ value_peek_string (y)) <= 0;
case CRIT_FLOAT:
return xf <= yf;
}
@@ -1628,14 +1641,17 @@ static gboolean
criteria_test_greater_or_equal (GnmValue const *x, GnmCriteria *crit)
{
gnm_float xf, yf;
+ GnmValue const *y = crit->x;
switch (criteria_inspect_values (x, &xf, &yf, crit)) {
default:
g_assert_not_reached ();
case CRIT_NULL:
case CRIT_WRONGTYPE:
- case CRIT_STRING:
return FALSE;
+ case CRIT_STRING:
+ return g_utf8_collate (value_peek_string (x),
+ value_peek_string (y)) >= 0;
case CRIT_FLOAT:
return xf >= yf;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]