[gnumeric] More conditions for conditional formatting
- From: Andreas J. Guelzow <guelzow src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnumeric] More conditions for conditional formatting
- Date: Thu, 7 Jul 2011 06:27:30 +0000 (UTC)
commit a5e7a192263638c5892fb165a5cb2fa2e806a3ba
Author: Andreas J Guelzow <aguelzow pyrshep ca>
Date: Thu Jul 7 00:25:43 2011 -0600
More conditions for conditional formatting
2011-07-07 Andreas J. Guelzow <aguelzow pyrshep ca>
* src/style-conditions.c (gnm_style_conditions_eval): fix the sense
of the comparison (the value string is expected to be smaller than
the cell string) and avoid infinite loops.
2011-07-07 Andreas J. Guelzow <aguelzow pyrshep ca>
* dialog-cell-format-cond.c (c_fmt_dialog_chooser_load_combo): enable
more conditions
ChangeLog | 6 ++++++
src/dialogs/ChangeLog | 5 +++++
src/dialogs/dialog-cell-format-cond.c | 12 ++++++------
src/style-conditions.c | 32 +++++---------------------------
4 files changed, 22 insertions(+), 33 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 5f7c83b..90fc880 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2011-07-07 Andreas J. Guelzow <aguelzow pyrshep ca>
+
+ * src/style-conditions.c (gnm_style_conditions_eval): fix the sense
+ of the comparison (the value string is expected to be smaller than
+ the cell string) and avoid infinite loops.
+
2011-07-06 Andreas J. Guelzow <aguelzow pyrshep ca>
* component/Gnumeric-embed.xml.in: add menu item
diff --git a/src/dialogs/ChangeLog b/src/dialogs/ChangeLog
index e8fb8da..236d71c 100644
--- a/src/dialogs/ChangeLog
+++ b/src/dialogs/ChangeLog
@@ -1,3 +1,8 @@
+2011-07-07 Andreas J. Guelzow <aguelzow pyrshep ca>
+
+ * dialog-cell-format-cond.c (c_fmt_dialog_chooser_load_combo): enable
+ more conditions
+
2011-07-06 Andreas J. Guelzow <aguelzow pyrshep ca>
* cell-format-cond-def.ui: add expression entry labels
diff --git a/src/dialogs/dialog-cell-format-cond.c b/src/dialogs/dialog-cell-format-cond.c
index 03af1c0..33608b0 100644
--- a/src/dialogs/dialog-cell-format-cond.c
+++ b/src/dialogs/dialog-cell-format-cond.c
@@ -283,12 +283,12 @@ c_fmt_dialog_chooser_load_combo (CFormatChooseState *state)
{ N_("Cell value is \xe2\x89\xa7 x."), GNM_STYLE_COND_GTE, 1},
{ N_("Cell value is \xe2\x89\xa6 x."), GNM_STYLE_COND_LTE, 1},
/* { N_("Expression x evaluates to TRUE."), GNM_STYLE_COND_CUSTOM, 1}, */
- /* { N_("Cell contains the string x."), GNM_STYLE_COND_CONTAINS_STR, 1}, */
- /* { N_("Cell does not contain the string x."), GNM_STYLE_COND_NOT_CONTAINS_STR, 1}, */
- /* { N_("Cell value begins with the string x."), GNM_STYLE_COND_BEGINS_WITH_STR, 1}, */
- /* { N_("Cell value does not begin with the string x."), GNM_STYLE_COND_NOT_BEGINS_WITH_STR, 1}, */
- /* { N_("Cell value ends with the string x."), GNM_STYLE_COND_ENDS_WITH_STR, 1}, */
- /* { N_("Cell value does not end with the string x."), GNM_STYLE_COND_NOT_ENDS_WITH_STR, 1}, */
+ { N_("Cell contains the string x."), GNM_STYLE_COND_CONTAINS_STR, 1},
+ { N_("Cell does not contain the string x."), GNM_STYLE_COND_NOT_CONTAINS_STR, 1},
+ { N_("Cell value begins with the string x."), GNM_STYLE_COND_BEGINS_WITH_STR, 1},
+ { N_("Cell value does not begin with the string x."), GNM_STYLE_COND_NOT_BEGINS_WITH_STR, 1},
+ { N_("Cell value ends with the string x."), GNM_STYLE_COND_ENDS_WITH_STR, 1},
+ { N_("Cell value does not end with the string x."), GNM_STYLE_COND_NOT_ENDS_WITH_STR, 1},
/* with two expressions */
{ N_("Cell value is between x and y (incl.)."), GNM_STYLE_COND_BETWEEN, 2},
{ N_("Cell value is not between x and y (incl.)."), GNM_STYLE_COND_NOT_BETWEEN, 2}
diff --git a/src/style-conditions.c b/src/style-conditions.c
index 123ab60..f50073a 100644
--- a/src/style-conditions.c
+++ b/src/style-conditions.c
@@ -307,13 +307,9 @@ gnm_style_conditions_eval (GnmStyleConditions const *sc, GnmEvalPos const *ep)
case GNM_STYLE_COND_LTE: use_this = (diff != IS_GREATER); break;
}
} else if (cv && VALUE_IS_STRING (cv)) {
- char const *valstring;
- char *ptr;
- char *ptr2;
+ char const *valstring = value_peek_string (val);
char const *cvstring = value_peek_string (cv);
- int slen = strlen (cvstring);
- valstring = value_peek_string (val);
switch (cond->op) {
default : g_warning ("Unknown condition operator %d", cond->op);
break;
@@ -324,34 +320,16 @@ gnm_style_conditions_eval (GnmStyleConditions const *sc, GnmEvalPos const *ep)
use_this = (NULL == strstr (cvstring, valstring));
break;
case GNM_STYLE_COND_BEGINS_WITH_STR :
- use_this = (0 == strncmp (cvstring, valstring, slen));
+ use_this = g_str_has_prefix (cvstring, valstring);
break;
case GNM_STYLE_COND_NOT_BEGINS_WITH_STR :
- use_this = (0 != strncmp (cvstring, valstring, slen));
+ use_this = !g_str_has_prefix (cvstring, valstring);
break;
case GNM_STYLE_COND_ENDS_WITH_STR :
- /* gedanken experiment: valuestr="foofoo"; cvstring="foo"
- * This loop solves the problem.
- * First, make sure ptr2 is NULL in case it never gets assigned*/
- ptr2 = NULL;
- while ((ptr = strstr (cvstring,valstring))) {
- /*ptr2 will point to the beginning of the last match*/
- ptr2 = ptr;
- }
- /*If it matches; is it the *end* match?*/
- use_this = (ptr != NULL) && (0 == strcmp (ptr2, valstring));
+ use_this = g_str_has_suffix (cvstring, valstring);
break;
case GNM_STYLE_COND_NOT_ENDS_WITH_STR :
- /*gedanken experiment: valuestr="foofoo"; cvstring="foo"
- * This loop solves the problem.
- *First, make sure ptr2 is NULL in case it never gets assigned*/
- ptr2 = NULL;
- while ((ptr = strstr (cvstring,valstring))) {
- /*ptr2 will point to the beginning of the last match*/
- ptr2 = ptr;
- }
- /*If it matches; is it the *end* match?*/
- use_this = (ptr == NULL) || (0 != strcmp (ptr2, valstring));
+ use_this = !g_str_has_suffix (cvstring, valstring);
break;
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]