[gnumeric] DSUM: Fix criteria "foo" to match also "foobar".



commit 0cc53be66614a1cebdb178b36d59ed5f0190f64c
Author: Morten Welinder <terra gnome org>
Date:   Tue Apr 16 14:14:34 2013 -0400

    DSUM: Fix criteria "foo" to match also "foobar".
    
    That applies to all database functions.  Pattern matching anchors at the
    front, but not at the end.

 ChangeLog                     | 8 ++++++++
 NEWS                          | 1 +
 plugins/fn-lookup/functions.c | 3 ++-
 plugins/fn-string/functions.c | 4 ++--
 src/gutils.c                  | 6 +++---
 src/gutils.h                  | 4 ++--
 src/sheet-filter.c            | 3 ++-
 src/value.c                   | 2 +-
 8 files changed, 21 insertions(+), 10 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 4b25f5f..dfc3186 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2013-04-16  Morten Welinder  <terra gnome org>
+
+       * src/value.c (parse_criteria): Anchor only at start.  Fixes
+       #661800.
+
+       * src/gutils.c (gnm_regcomp_XL): Split argument "full" into
+       "anchor_start" and "anchor_end".  All callers changed.
+
 2013-04-15  Morten Welinder  <terra gnome org>
 
        * src/application.c (add_icon): Plug leak.
diff --git a/NEWS b/NEWS
index 21c327c..c53dd15 100644
--- a/NEWS
+++ b/NEWS
@@ -45,6 +45,7 @@ Morten:
        * Improve entry of non-locale currency amounts.  [#577768]
        * Fix XL import of names with array constants.  [#654211]
        * Fix XL import of booleans/error/empties in array constants.
+       * Fix database criteria anchoring.  [#661800]
 
 --------------------------------------------------------------------------
 Gnumeric 1.12.1
diff --git a/plugins/fn-lookup/functions.c b/plugins/fn-lookup/functions.c
index 4240423..c7ce7f9 100644
--- a/plugins/fn-lookup/functions.c
+++ b/plugins/fn-lookup/functions.c
@@ -585,7 +585,8 @@ wildcard_string_match (const char *key, LookupBisectionCacheItem *bc)
        GORegmatch rm;
        int i, res = LOOKUP_NOT_THERE;
 
-       if (gnm_regcomp_XL (&rx, key, GO_REG_ICASE, TRUE) != GO_REG_OK) {
+       /* FIXME: Do we want to anchor at the end here? */
+       if (gnm_regcomp_XL (&rx, key, GO_REG_ICASE, TRUE, TRUE) != GO_REG_OK) {
                g_warning ("Unexpected regcomp result");
                return LOOKUP_DATA_ERROR;
        }
diff --git a/plugins/fn-string/functions.c b/plugins/fn-string/functions.c
index 176c061..9c4d21c 100644
--- a/plugins/fn-string/functions.c
+++ b/plugins/fn-string/functions.c
@@ -1343,7 +1343,7 @@ gnumeric_search (GnmFuncEvalInfo *ei, GnmValue const * const *argv)
                hay2 = g_utf8_next_char (hay2);
        }
 
-       if (gnm_regcomp_XL (&r, needle, GO_REG_ICASE, FALSE) == GO_REG_OK) {
+       if (gnm_regcomp_XL (&r, needle, GO_REG_ICASE, FALSE, FALSE) == GO_REG_OK) {
                GORegmatch rm;
 
                switch (go_regexec (&r, hay2, 1, &rm, 0)) {
@@ -1412,7 +1412,7 @@ gnumeric_searchb (GnmFuncEvalInfo *ei, GnmValue const * const *argv)
        if (istart > 0)
                istart = g_utf8_next_char(haystack + istart - 1) - haystack;
 
-       if (gnm_regcomp_XL (&r, needle, GO_REG_ICASE, FALSE) == GO_REG_OK) {
+       if (gnm_regcomp_XL (&r, needle, GO_REG_ICASE, FALSE, FALSE) == GO_REG_OK) {
                GORegmatch rm;
 
                switch (go_regexec (&r, haystack + istart, 1, &rm, 0)) {
diff --git a/src/gutils.c b/src/gutils.c
index 1a9e7fe..34c9059 100644
--- a/src/gutils.c
+++ b/src/gutils.c
@@ -336,12 +336,12 @@ gnm_utf8_strtol (const char *s, char **end)
 
 int
 gnm_regcomp_XL (GORegexp *preg, char const *pattern, int cflags,
-               gboolean full)
+               gboolean anchor_start, gboolean anchor_end)
 {
        GString *res = g_string_new (NULL);
        int retval;
 
-       if (full)
+       if (anchor_start)
                g_string_append_c (res, '^');
 
        while (*pattern) {
@@ -367,7 +367,7 @@ gnm_regcomp_XL (GORegexp *preg, char const *pattern, int cflags,
                }
        }
 
-       if (full)
+       if (anchor_end)
                g_string_append_c (res, '$');
 
        retval = go_regcomp (preg, res->str, cflags);
diff --git a/src/gutils.h b/src/gutils.h
index 00952d8..07c06e6 100644
--- a/src/gutils.h
+++ b/src/gutils.h
@@ -24,8 +24,8 @@ long gnm_utf8_strtol (const char *s, char **end);
 
 #define PLUGIN_SUBDIR "plugins"
 
-int gnm_regcomp_XL (GORegexp *preg, char const *pattern,
-                   int cflags, gboolean full);
+int gnm_regcomp_XL (GORegexp *preg, char const *pattern, int cflags,
+                   gboolean anchor_start, gboolean anchor_end);
 
 gboolean gnm_pango_attr_list_equal (PangoAttrList const *l1, PangoAttrList const *l2);
 
diff --git a/src/sheet-filter.c b/src/sheet-filter.c
index d3ad9cb..fd8eead 100644
--- a/src/sheet-filter.c
+++ b/src/sheet-filter.c
@@ -162,7 +162,8 @@ filter_expr_init (FilterExpr *fexpr, unsigned i,
                        workbook_date_conv (filter->sheet->workbook);
 
                if ((op == GNM_FILTER_OP_EQUAL || op == GNM_FILTER_OP_NOT_EQUAL) &&
-                   gnm_regcomp_XL (fexpr->regexp + i, str, GO_REG_ICASE, TRUE) == GO_REG_OK) {
+                   gnm_regcomp_XL (fexpr->regexp + i, str, GO_REG_ICASE, TRUE, TRUE) == GO_REG_OK) {
+                       /* FIXME: Do we want to anchor at the end above?  */
                        fexpr->val[i] = NULL;
                        return;
                }
diff --git a/src/value.c b/src/value.c
index 9dae41b..cc9d697 100644
--- a/src/value.c
+++ b/src/value.c
@@ -1731,7 +1731,7 @@ parse_criteria (GnmValue const *crit_val, GODateConventions const *date_conv)
                len = 1;
        } else {
                res->fun = criteria_test_match;
-               res->has_rx = (gnm_regcomp_XL (&res->rx, criteria, 0, TRUE) == GO_REG_OK);
+               res->has_rx = (gnm_regcomp_XL (&res->rx, criteria, 0, TRUE, FALSE) == GO_REG_OK);
                len = 0;
        }
 


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