mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
add COMPARE_NEQ support
add some extra tests for valid "how" values and PWARN for invalid ones. git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@6693 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
parent
ca87c3a207
commit
ba18e6db4c
@ -127,27 +127,43 @@ static int string_match_predicate (gpointer object, QueryAccess get_fcn,
|
|||||||
{
|
{
|
||||||
query_string_t pdata = (query_string_t) pd;
|
query_string_t pdata = (query_string_t) pd;
|
||||||
const char *s;
|
const char *s;
|
||||||
|
int ret = 0;
|
||||||
|
|
||||||
VERIFY_PREDICATE (query_string_type);
|
VERIFY_PREDICATE (query_string_type);
|
||||||
|
|
||||||
s = ((query_string_getter)get_fcn) (object);
|
s = ((query_string_getter)get_fcn) (object);
|
||||||
|
|
||||||
|
do {
|
||||||
if (pdata->is_regex) {
|
if (pdata->is_regex) {
|
||||||
regmatch_t match;
|
regmatch_t match;
|
||||||
if (!regexec (&pdata->compiled, s, 1, &match, 0))
|
if (!regexec (&pdata->compiled, s, 1, &match, 0))
|
||||||
return 1;
|
ret = 1;
|
||||||
else
|
|
||||||
return 0;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pdata->options == STRING_MATCH_CASEINSENSITIVE) {
|
if (pdata->options == STRING_MATCH_CASEINSENSITIVE) {
|
||||||
if (strcasestr (s, pdata->matchstring)) return 1;
|
if (strcasestr (s, pdata->matchstring))
|
||||||
return 0;
|
ret = 1;
|
||||||
|
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strstr (s, pdata->matchstring)) return 1;
|
if (strstr (s, pdata->matchstring))
|
||||||
|
ret = 1;
|
||||||
|
|
||||||
|
} while (FALSE);
|
||||||
|
|
||||||
|
switch (how) {
|
||||||
|
case COMPARE_EQUAL:
|
||||||
|
return ret;
|
||||||
|
case COMPARE_NEQ:
|
||||||
|
return !ret;
|
||||||
|
default:
|
||||||
|
PWARN ("bad match type: %d", how);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static int string_compare_func (gpointer a, gpointer b, gint options,
|
static int string_compare_func (gpointer a, gpointer b, gint options,
|
||||||
QueryAccess get_fcn)
|
QueryAccess get_fcn)
|
||||||
@ -258,6 +274,8 @@ static int date_match_predicate (gpointer object, QueryAccess get_fcn,
|
|||||||
return (compare > 0);
|
return (compare > 0);
|
||||||
case COMPARE_GTE:
|
case COMPARE_GTE:
|
||||||
return (compare >= 0);
|
return (compare >= 0);
|
||||||
|
case COMPARE_NEQ:
|
||||||
|
return (compare != 0);
|
||||||
default:
|
default:
|
||||||
PWARN ("bad match type: %d", how);
|
PWARN ("bad match type: %d", how);
|
||||||
return 0;
|
return 0;
|
||||||
@ -351,6 +369,8 @@ static int numeric_match_predicate (gpointer object, QueryAccess get_fcn,
|
|||||||
return (compare > 0);
|
return (compare > 0);
|
||||||
case COMPARE_GTE:
|
case COMPARE_GTE:
|
||||||
return (compare >= 0);
|
return (compare >= 0);
|
||||||
|
case COMPARE_NEQ:
|
||||||
|
return (!compare);
|
||||||
default:
|
default:
|
||||||
PWARN ("bad match type: %d", how);
|
PWARN ("bad match type: %d", how);
|
||||||
return 0;
|
return 0;
|
||||||
@ -513,6 +533,8 @@ static int int64_match_predicate (gpointer object, QueryAccess get_fcn,
|
|||||||
return (val > pdata->val);
|
return (val > pdata->val);
|
||||||
case COMPARE_GTE:
|
case COMPARE_GTE:
|
||||||
return (val >= pdata->val);
|
return (val >= pdata->val);
|
||||||
|
case COMPARE_NEQ:
|
||||||
|
return (val != pdata->val);
|
||||||
default:
|
default:
|
||||||
PWARN ("bad match type: %d", how);
|
PWARN ("bad match type: %d", how);
|
||||||
return 0;
|
return 0;
|
||||||
@ -578,6 +600,8 @@ static int double_match_predicate (gpointer object, QueryAccess get_fcn,
|
|||||||
return (val > pdata->val);
|
return (val > pdata->val);
|
||||||
case COMPARE_GTE:
|
case COMPARE_GTE:
|
||||||
return (val >= pdata->val);
|
return (val >= pdata->val);
|
||||||
|
case COMPARE_NEQ:
|
||||||
|
return (val != pdata->val);
|
||||||
default:
|
default:
|
||||||
PWARN ("bad match type: %d", how);
|
PWARN ("bad match type: %d", how);
|
||||||
return 0;
|
return 0;
|
||||||
@ -633,7 +657,15 @@ static int boolean_match_predicate (gpointer object, QueryAccess get_fcn,
|
|||||||
|
|
||||||
val = ((query_boolean_getter)get_fcn) (object);
|
val = ((query_boolean_getter)get_fcn) (object);
|
||||||
|
|
||||||
|
switch (how) {
|
||||||
|
case COMPARE_EQUAL:
|
||||||
return (val == pdata->val);
|
return (val == pdata->val);
|
||||||
|
case COMPARE_NEQ:
|
||||||
|
return (val != pdata->val);
|
||||||
|
default:
|
||||||
|
PWARN ("bad match type: %d", how);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int boolean_compare_func (gpointer a, gpointer b, gint options,
|
static int boolean_compare_func (gpointer a, gpointer b, gint options,
|
||||||
@ -769,6 +801,8 @@ static int kvp_match_predicate (gpointer object, QueryAccess get_fcn,
|
|||||||
return (compare >= 0);
|
return (compare >= 0);
|
||||||
case COMPARE_GT:
|
case COMPARE_GT:
|
||||||
return (compare > 0);
|
return (compare > 0);
|
||||||
|
case COMPARE_NEQ:
|
||||||
|
return (compare != 0);
|
||||||
default:
|
default:
|
||||||
PWARN ("bad match type: %d", how);
|
PWARN ("bad match type: %d", how);
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -30,7 +30,8 @@ typedef enum {
|
|||||||
COMPARE_LTE,
|
COMPARE_LTE,
|
||||||
COMPARE_EQUAL,
|
COMPARE_EQUAL,
|
||||||
COMPARE_GT,
|
COMPARE_GT,
|
||||||
COMPARE_GTE
|
COMPARE_GTE,
|
||||||
|
COMPARE_NEQ
|
||||||
} query_compare_t;
|
} query_compare_t;
|
||||||
|
|
||||||
#define QUERY_DEFAULT_SORT "GnucashQueryDefaultSortObject"
|
#define QUERY_DEFAULT_SORT "GnucashQueryDefaultSortObject"
|
||||||
|
Loading…
Reference in New Issue
Block a user