diff --git a/ChangeLog b/ChangeLog index 2701d86dc8..45bede0f18 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2006-09-25 Derek Atkins + + [ Lots of files ]: + Add a new QOF_TYPE_NUMSTRING to add numeric sorts. (#150799). + This new type is like QOF_TYPE_STRING but it sorts numerically + (first) and then sorts alphanumerically (by the tail of the + number). Added the QOF Type, the gnome-search support, and + modified TRANS_NUM to use the new type. + 2006-09-23 Derek Atkins * src/ledger-core/split-register*.c: diff --git a/lib/libqof/qof/qofbookmerge.c b/lib/libqof/qof/qofbookmerge.c index b7ecfb966f..1d65e87d93 100644 --- a/lib/libqof/qof/qofbookmerge.c +++ b/lib/libqof/qof/qofbookmerge.c @@ -126,7 +126,8 @@ qof_book_merge_compare(QofBookMergeData *mergeData ) mergeParamName = qtparam->param_name; g_return_val_if_fail(mergeParamName != NULL, -1); mergeType = qtparam->param_type; - if(safe_strcmp(mergeType, QOF_TYPE_STRING) == 0) { + if(safe_strcmp(mergeType, QOF_TYPE_STRING) == 0 || + safe_strcmp(mergeType, QOF_TYPE_NUMSTRING) == 0) { stringImport = qtparam->param_getfcn(mergeEnt,qtparam); stringTarget = qtparam->param_getfcn(targetEnt,qtparam); /* very strict string matches may need to be relaxed. */ @@ -643,7 +644,8 @@ qof_book_merge_commit_rule_loop( g_return_if_fail(rule->mergeParam->data); cm_param = rule->mergeParam->data; rule->mergeType = cm_param->param_type; - if(safe_strcmp(rule->mergeType, QOF_TYPE_STRING) == 0) { + if(safe_strcmp(rule->mergeType, QOF_TYPE_STRING) == 0 || + safe_strcmp(rule->mergeType, QOF_TYPE_NUMSTRING) == 0) { cm_string = cm_param->param_getfcn(rule->importEnt, cm_param); string_setter = (void(*)(QofEntity*, const gchar*))cm_param->param_setfcn; if(string_setter != NULL) { string_setter(rule->targetEnt, cm_string); } @@ -836,7 +838,8 @@ qof_book_merge_param_as_string(QofParam *qtparam, QofEntity *qtEnt) param_string = NULL; paramType = qtparam->param_type; - if(safe_strcmp(paramType, QOF_TYPE_STRING) == 0) { + if(safe_strcmp(paramType, QOF_TYPE_STRING) == 0 || + safe_strcmp(paramType, QOF_TYPE_NUMSTRING) == 0) { param_string = g_strdup(qtparam->param_getfcn(qtEnt,qtparam)); if(param_string == NULL) { param_string = ""; } return param_string; diff --git a/lib/libqof/qof/qofclass.c b/lib/libqof/qof/qofclass.c index b2a83a46b0..85145edcb9 100644 --- a/lib/libqof/qof/qofclass.c +++ b/lib/libqof/qof/qofclass.c @@ -274,6 +274,7 @@ find_reference_param_cb(QofParam *param, gpointer user_data) b = (struct param_ref_list*)user_data; if((param->param_getfcn == NULL)||(param->param_setfcn == NULL)) { return; } if(0 == safe_strcmp(param->param_type, QOF_TYPE_STRING)) { return; } + if(0 == safe_strcmp(param->param_type, QOF_TYPE_NUMSTRING)) { return; } if(0 == safe_strcmp(param->param_type, QOF_TYPE_NUMERIC)) { return; } if(0 == safe_strcmp(param->param_type, QOF_TYPE_DATE)) { return; } if(0 == safe_strcmp(param->param_type, QOF_TYPE_CHAR)) { return; } diff --git a/lib/libqof/qof/qofclass.h b/lib/libqof/qof/qofclass.h index ba50dc5c3d..3b43e4bedf 100644 --- a/lib/libqof/qof/qofclass.h +++ b/lib/libqof/qof/qofclass.h @@ -83,6 +83,8 @@ single reference between two known objects. */ #define QOF_TYPE_STRING "string" +#define QOF_TYPE_NUMSTRING "numstring" /**< a string that sorts in numeric + order instead of typological order */ #define QOF_TYPE_DATE "date" #define QOF_TYPE_NUMERIC "numeric" #define QOF_TYPE_DEBCRED "debcred" diff --git a/lib/libqof/qof/qofquery-deserial.c b/lib/libqof/qof/qofquery-deserial.c index 0caac184c9..25c72a281c 100644 --- a/lib/libqof/qof/qofquery-deserial.c +++ b/lib/libqof/qof/qofquery-deserial.c @@ -694,6 +694,7 @@ int main (int argc, char * argv[]) { "aflt", QOF_TYPE_DOUBLE, NULL, NULL}, { "abool", QOF_TYPE_BOOLEAN, NULL, NULL}, { "astr", QOF_TYPE_STRING, NULL, NULL}, + { "nstr", QOF_TYPE_NUMSTRING, NULL, NULL}, { "adate", QOF_TYPE_DATE, NULL, NULL}, { "anum", QOF_TYPE_NUMERIC, NULL, NULL}, { "achar", QOF_TYPE_CHAR, NULL, NULL}, diff --git a/lib/libqof/qof/qofquery-serialize.c b/lib/libqof/qof/qofquery-serialize.c index 66dff5b756..606a7568d5 100644 --- a/lib/libqof/qof/qofquery-serialize.c +++ b/lib/libqof/qof/qofquery-serialize.c @@ -240,7 +240,8 @@ qof_query_pred_data_to_xml (QofQueryPredData *pd) } return topnode; } - if (!safe_strcmp (pd->type_name, QOF_TYPE_STRING)) + if (!safe_strcmp (pd->type_name, QOF_TYPE_STRING) || + !safe_strcmp (pd->type_name, QOF_TYPE_NUMSTRING)) { topnode = xmlNewNode (NULL, "qofquery:pred-string"); PUT_HOW ("qofquery:compare", pd->how, LT, LTE, EQUAL, GT, GTE, NEQ); @@ -555,6 +556,7 @@ int main (int argc, char * argv[]) { "aint", QOF_TYPE_INT32, NULL, NULL}, { "aint64", QOF_TYPE_INT64, NULL, NULL}, { "astr", QOF_TYPE_STRING, NULL, NULL}, + { "nstr", QOF_TYPE_NUMSTRING, NULL, NULL}, { NULL }, }; diff --git a/lib/libqof/qof/qofquery.c b/lib/libqof/qof/qofquery.c index 50af741305..071c678945 100644 --- a/lib/libqof/qof/qofquery.c +++ b/lib/libqof/qof/qofquery.c @@ -1693,7 +1693,8 @@ qof_query_printValueForParam (QofQueryPredData *pd, GString * gs) } return; } - if (!safe_strcmp (pd->type_name, QOF_TYPE_STRING)) + if (!safe_strcmp (pd->type_name, QOF_TYPE_STRING) || + !safe_strcmp (pd->type_name, QOF_TYPE_NUMSTRING)) { query_string_t pdata = (query_string_t) pd; g_string_append_printf (gs, " Match type %s", diff --git a/lib/libqof/qof/qofquerycore.c b/lib/libqof/qof/qofquerycore.c index 6a960656cd..6719fecf7a 100644 --- a/lib/libqof/qof/qofquerycore.c +++ b/lib/libqof/qof/qofquerycore.c @@ -24,6 +24,7 @@ #include "config.h" #include +#include #include "qof.h" #include "qofquerycore-p.h" @@ -54,6 +55,7 @@ static QueryPredDataFree qof_query_predicate_free (QofType type); /* Core Type Predicate helpers */ typedef const char * (*query_string_getter) (gpointer, QofParam *); static const char * query_string_type = QOF_TYPE_STRING; +static const char * query_numstring_type = QOF_TYPE_NUMSTRING; typedef Timespec (*query_date_getter) (gpointer, QofParam *); static const char * query_date_type = QOF_TYPE_DATE; @@ -124,19 +126,17 @@ static GHashTable *predEqualTable = NULL; /* *******************************************************************/ /* TYPE-HANDLING FUNCTIONS */ -/* QOF_TYPE_STRING */ +/* QOF_TYPE_STRING and QOF_TYPE_NUMSTRING / common functions */ static int -string_match_predicate (gpointer object, - QofParam *getter, - QofQueryPredData *pd) +string_match_predicate_common (gpointer object, + QofParam *getter, + QofQueryPredData *pd) { query_string_t pdata = (query_string_t) pd; const char *s; int ret = 0; - VERIFY_PREDICATE (query_string_type); - s = ((query_string_getter)getter->param_getfcn) (object, getter); if (!s) s = ""; @@ -166,6 +166,81 @@ string_match_predicate (gpointer object, } } +static void +string_free_pdata_common (QofQueryPredData *pd) +{ + query_string_t pdata = (query_string_t) pd; + + if (pdata->is_regex) + regfree (&pdata->compiled); + else + g_free (pdata->matchstring); + + g_free (pdata); +} + +static QofQueryPredData * +qof_query_string_predicate_common (QofQueryCompare how, + const char *str, QofStringMatch options, + gboolean is_regex, + const char* type) +{ + query_string_t pdata; + + g_return_val_if_fail (str, NULL); + g_return_val_if_fail (*str != '\0', NULL); + g_return_val_if_fail (how == QOF_COMPARE_EQUAL || how == QOF_COMPARE_NEQ, NULL); + + pdata = g_new0 (query_string_def, 1); + pdata->pd.type_name = type; + pdata->pd.how = how; + pdata->options = options; + pdata->matchstring = g_strdup (str); + + if (is_regex) { + int flags = REG_EXTENDED; + if (options == QOF_STRING_MATCH_CASEINSENSITIVE) + flags |= REG_ICASE; + + regcomp(&pdata->compiled, str, flags); + pdata->is_regex = TRUE; + } + + return ((QofQueryPredData*)pdata); +} + +static gboolean +string_predicate_equal (QofQueryPredData *p1, QofQueryPredData *p2) +{ + query_string_t pd1 = (query_string_t) p1; + query_string_t pd2 = (query_string_t) p2; + + if (pd1->options != pd2->options) return FALSE; + if (pd1->is_regex != pd2->is_regex) return FALSE; + return (safe_strcmp (pd1->matchstring, pd2->matchstring) == 0); +} + +static char * +string_to_string (gpointer object, QofParam *getter) +{ + const char *res; + res = ((query_string_getter)getter->param_getfcn)(object, getter); + if (res) + return g_strdup (res); + return NULL; +} + +/* QOF_QUERY_STRING */ + +static int +string_match_predicate (gpointer object, + QofParam *getter, + QofQueryPredData *pd) +{ + VERIFY_PREDICATE (query_string_type); + return string_match_predicate_common(object, getter, pd); +} + static int string_compare_func (gpointer a, gpointer b, gint options, QofParam *getter) @@ -185,16 +260,8 @@ string_compare_func (gpointer a, gpointer b, gint options, static void string_free_pdata (QofQueryPredData *pd) { - query_string_t pdata = (query_string_t) pd; - VERIFY_PDATA (query_string_type); - - if (pdata->is_regex) - regfree (&pdata->compiled); - else - g_free (pdata->matchstring); - - g_free (pdata); + return string_free_pdata_common(pd); } static QofQueryPredData * @@ -204,20 +271,10 @@ string_copy_predicate (QofQueryPredData *pd) VERIFY_PDATA_R (query_string_type); - return qof_query_string_predicate (pd->how, pdata->matchstring, - pdata->options, - pdata->is_regex); -} - -static gboolean -string_predicate_equal (QofQueryPredData *p1, QofQueryPredData *p2) -{ - query_string_t pd1 = (query_string_t) p1; - query_string_t pd2 = (query_string_t) p2; - - if (pd1->options != pd2->options) return FALSE; - if (pd1->is_regex != pd2->is_regex) return FALSE; - return (safe_strcmp (pd1->matchstring, pd2->matchstring) == 0); + return qof_query_string_predicate_common (pd->how, pdata->matchstring, + pdata->options, + pdata->is_regex, + query_string_type); } QofQueryPredData * @@ -225,38 +282,78 @@ qof_query_string_predicate (QofQueryCompare how, const char *str, QofStringMatch options, gboolean is_regex) { - query_string_t pdata; - - g_return_val_if_fail (str, NULL); - g_return_val_if_fail (*str != '\0', NULL); - g_return_val_if_fail (how == QOF_COMPARE_EQUAL || how == QOF_COMPARE_NEQ, NULL); - - pdata = g_new0 (query_string_def, 1); - pdata->pd.type_name = query_string_type; - pdata->pd.how = how; - pdata->options = options; - pdata->matchstring = g_strdup (str); - - if (is_regex) { - int flags = REG_EXTENDED; - if (options == QOF_STRING_MATCH_CASEINSENSITIVE) - flags |= REG_ICASE; - - regcomp(&pdata->compiled, str, flags); - pdata->is_regex = TRUE; - } - - return ((QofQueryPredData*)pdata); + return qof_query_string_predicate_common(how, str, options, is_regex, + query_string_type); } -static char * -string_to_string (gpointer object, QofParam *getter) +/* QOF_QUERY_NUMSTRING */ + +static int +numstring_match_predicate (gpointer object, + QofParam *getter, + QofQueryPredData *pd) { - const char *res; - res = ((query_string_getter)getter->param_getfcn)(object, getter); - if (res) - return g_strdup (res); - return NULL; + VERIFY_PREDICATE (query_numstring_type); + return string_match_predicate_common(object, getter, pd); +} + +static int +numstring_compare_func (gpointer a, gpointer b, gint options, + QofParam *getter) +{ + const char *s1, *s2; + char *sr1, *sr2; + long i1, i2; + g_return_val_if_fail (a && b && getter &&getter->param_getfcn, COMPARE_ERROR); + + s1 = ((query_string_getter)getter->param_getfcn) (a, getter); + s2 = ((query_string_getter)getter->param_getfcn) (b, getter); + + // Deal with NULL strings + if (s1 == s2) return 0; + if (!s1 && s2) return -1; + if (s1 && !s2) return 1; + + // Convert to integers and test + i1 = strtol(s1, &sr1, 0); + i2 = strtol(s2, &sr2, 0); + if (i1 < i2) return -1; + if (i1 > i2) return 1; + + // If the integers match, then test the REST of the string as text. + if (options == QOF_STRING_MATCH_CASEINSENSITIVE) + return safe_strcasecmp (sr1, sr2); + + return safe_strcmp (sr1, sr2); +} + +static void +numstring_free_pdata (QofQueryPredData *pd) +{ + VERIFY_PDATA (query_numstring_type); + return string_free_pdata_common(pd); +} + +static QofQueryPredData * +numstring_copy_predicate (QofQueryPredData *pd) +{ + query_string_t pdata = (query_string_t) pd; + + VERIFY_PDATA_R (query_numstring_type); + + return qof_query_string_predicate_common (pd->how, pdata->matchstring, + pdata->options, + pdata->is_regex, + query_numstring_type); +} + +QofQueryPredData * +qof_query_numstring_predicate (QofQueryCompare how, + const char *str, QofStringMatch options, + gboolean is_regex) +{ + return qof_query_string_predicate_common(how, str, options, is_regex, + query_numstring_type); } /* QOF_TYPE_DATE =================================================== */ @@ -1661,6 +1758,9 @@ static void init_tables (void) { QOF_TYPE_STRING, string_match_predicate, string_compare_func, string_copy_predicate, string_free_pdata, string_to_string, string_predicate_equal }, + { QOF_TYPE_NUMSTRING, numstring_match_predicate, numstring_compare_func, + numstring_copy_predicate, numstring_free_pdata, string_to_string, + string_predicate_equal }, { QOF_TYPE_DATE, date_match_predicate, date_compare_func, date_copy_predicate, date_free_pdata, date_to_string, date_predicate_equal }, diff --git a/lib/libqof/qof/qofquerycore.h b/lib/libqof/qof/qofquerycore.h index 4964573a70..1e86099960 100644 --- a/lib/libqof/qof/qofquerycore.h +++ b/lib/libqof/qof/qofquerycore.h @@ -141,6 +141,11 @@ QofQueryPredData *qof_query_string_predicate (QofQueryCompare how, QofStringMatch options, gboolean is_regex); +QofQueryPredData *qof_query_numstring_predicate (QofQueryCompare how, + const gchar *str, + QofStringMatch options, + gboolean is_regex); + QofQueryPredData *qof_query_date_predicate (QofQueryCompare how, QofDateMatch options, Timespec date); diff --git a/lib/libqof/qof/qofsession.c b/lib/libqof/qof/qofsession.c index dbc46691af..f0b9cde51d 100644 --- a/lib/libqof/qof/qofsession.c +++ b/lib/libqof/qof/qofsession.c @@ -426,7 +426,8 @@ qof_entity_foreach_copy(gpointer data, gpointer user_data) cm_param = (QofParam*) data; g_return_if_fail(cm_param != NULL); context->param = cm_param; - if(safe_strcmp(cm_param->param_type, QOF_TYPE_STRING) == 0) { + if(safe_strcmp(cm_param->param_type, QOF_TYPE_STRING) == 0 || + safe_strcmp(cm_param->param_type, QOF_TYPE_NUMSTRING) == 0) { cm_string = (gchar*)cm_param->param_getfcn(importEnt, cm_param); if(cm_string) { string_setter = (void(*)(QofEntity*, const char*))cm_param->param_setfcn; diff --git a/lib/libqof/qof/qofsql.c b/lib/libqof/qof/qofsql.c index 127ba02758..0a04f6e505 100644 --- a/lib/libqof/qof/qofsql.c +++ b/lib/libqof/qof/qofsql.c @@ -308,7 +308,8 @@ handle_single_condition (QofSqlQuery *query, sql_condition * cond) return NULL; } - if (!strcmp (param_type, QOF_TYPE_STRING)) + if (!strcmp (param_type, QOF_TYPE_STRING) || + !strcmp (param_type, QOF_TYPE_NUMSTRING)) { pred_data = qof_query_string_predicate (qop, /* comparison to make */ @@ -605,7 +606,8 @@ qof_sql_insertCB(const QofParam *param, const gchar *insert_string, QofSqlQuery ENTER (" param=%s param_type=%s type=%s content=%s", param->param_name, param->param_type, type, insert_string); - if(safe_strcmp(param->param_type, QOF_TYPE_STRING) == 0) { + if(safe_strcmp(param->param_type, QOF_TYPE_STRING) == 0 || + safe_strcmp(param->param_type, QOF_TYPE_NUMSTRING) == 0) { string_setter = (void(*)(QofEntity*, const char*))param->param_setfcn; if(string_setter != NULL) { string_setter(ent, insert_string); } registered_type = TRUE; diff --git a/lib/libqof/qof/qofutil.c b/lib/libqof/qof/qofutil.c index 10d2285f98..0758879c5a 100644 --- a/lib/libqof/qof/qofutil.c +++ b/lib/libqof/qof/qofutil.c @@ -416,7 +416,8 @@ qof_util_param_as_string(QofEntity *ent, QofParam *param) param_string = NULL; known_type = FALSE; paramType = param->param_type; - if(safe_strcmp(paramType, QOF_TYPE_STRING) == 0) { + if(safe_strcmp(paramType, QOF_TYPE_STRING) == 0 || + safe_strcmp(paramType, QOF_TYPE_NUMSTRING) == 0) { param_string = g_strdup(param->param_getfcn(ent, param)); if(param_string == NULL) { param_string = ""; } known_type = TRUE; diff --git a/src/backend/postgres/gncquery.c b/src/backend/postgres/gncquery.c index 6558b97253..10768cd1bc 100644 --- a/src/backend/postgres/gncquery.c +++ b/src/backend/postgres/gncquery.c @@ -958,7 +958,8 @@ sqlQuery_build(sqlQuery * sq, Query * q) more_and = 0; } - } else if (!safe_strcmp(pd->type_name, QOF_TYPE_STRING)) { + } else if (!safe_strcmp(pd->type_name, QOF_TYPE_STRING) || + !safe_strcmp(pd->type_name, QOF_TYPE_NUMSTRING)) { query_string_t pdata = (query_string_t) pd; if (!safe_strcmp(path->data, SPLIT_ACTION)) { diff --git a/src/engine/Query.c b/src/engine/Query.c index ff7ae77b93..670500534d 100644 --- a/src/engine/Query.c +++ b/src/engine/Query.c @@ -319,6 +319,32 @@ xaccQueryAddStringMatch (Query* q, const char *matchstring, qof_query_add_term (q, param_list, pred_data, op); } +void +xaccQueryAddNumStringMatch (Query* q, const char *matchstring, + int case_sens, int use_regexp, QofQueryOp op, + const char * path, ...) +{ + QofQueryPredData *pred_data; + GSList *param_list; + va_list ap; + + if (!path || !q) + return; + + pred_data = qof_query_numstring_predicate (QOF_COMPARE_EQUAL, (char *)matchstring, + (case_sens ? QOF_STRING_MATCH_NORMAL : + QOF_STRING_MATCH_CASEINSENSITIVE), + use_regexp); + if (!pred_data) + return; + + va_start (ap, path); + param_list = build_param_list_internal (path, ap); + va_end (ap); + + qof_query_add_term (q, param_list, pred_data, op); +} + void xaccQueryAddNumericMatch (Query *q, gnc_numeric amount, QofNumericMatch sign, QofQueryCompare how, QofQueryOp op, diff --git a/src/engine/Query.h b/src/engine/Query.h index 4bcedb5117..a2b80f2c44 100644 --- a/src/engine/Query.h +++ b/src/engine/Query.h @@ -127,11 +127,15 @@ void xaccQueryAddStringMatch (Query* q, const char *matchstring, int case_sens, int use_regexp, QofQueryOp op, const char * path, ...); +void xaccQueryAddNumStringMatch (Query* q, const char *matchstring, + int case_sens, int use_regexp, QofQueryOp op, + const char * path, ...); + #define xaccQueryAddDescriptionMatch(q,m,c,r,o) \ xaccQueryAddStringMatch ((q), (m), (c), (r), (o), SPLIT_TRANS, \ TRANS_DESCRIPTION, NULL) #define xaccQueryAddNumberMatch(q,m,c,r,o) \ - xaccQueryAddStringMatch ((q), (m), (c), (r), (o), SPLIT_TRANS, \ + xaccQueryAddNumStringMatch ((q), (m), (c), (r), (o), SPLIT_TRANS, \ TRANS_NUM, NULL) #define xaccQueryAddActionMatch(q,m,c,r,o) \ xaccQueryAddStringMatch ((q), (m), (c), (r), (o), SPLIT_ACTION, \ diff --git a/src/engine/Transaction.c b/src/engine/Transaction.c index a2a9a417e4..0a549de326 100644 --- a/src/engine/Transaction.c +++ b/src/engine/Transaction.c @@ -1966,7 +1966,7 @@ trans_is_balanced_p (const Transaction *trans) gboolean xaccTransRegister (void) { static QofParam params[] = { - { TRANS_NUM, QOF_TYPE_STRING, + { TRANS_NUM, QOF_TYPE_NUMSTRING, (QofAccessFunc)xaccTransGetNum, (QofSetterFunc)qofTransSetNum }, { TRANS_DESCRIPTION, QOF_TYPE_STRING, diff --git a/src/engine/engine-helpers.c b/src/engine/engine-helpers.c index d439cdf5a0..dc4eca3a36 100644 --- a/src/engine/engine-helpers.c +++ b/src/engine/engine-helpers.c @@ -864,7 +864,8 @@ gnc_queryterm2scm (QofQueryTerm *qt) qt_scm = scm_cons (scm_str2symbol (pd->type_name), qt_scm); qt_scm = scm_cons (gnc_query_compare2scm (pd->how), qt_scm); - if (!safe_strcmp (pd->type_name, QOF_TYPE_STRING)) { + if (!safe_strcmp (pd->type_name, QOF_TYPE_STRING) || + !safe_strcmp (pd->type_name, QOF_TYPE_NUMSTRING)) { query_string_t pdata = (query_string_t) pd; qt_scm = scm_cons (gnc_query_string2scm (pdata->options), qt_scm); @@ -969,7 +970,8 @@ gnc_scm2query_term_query_v2 (SCM qt_scm) /* Now compute the predicate */ - if (!safe_strcmp (type, QOF_TYPE_STRING)) + if (!safe_strcmp (type, QOF_TYPE_STRING) || + !safe_strcmp (type, QOF_TYPE_NUMSTRING)) { QofStringMatch options; gboolean is_regex; @@ -991,8 +993,12 @@ gnc_scm2query_term_query_v2 (SCM qt_scm) matchstring = SCM_STRING_CHARS (scm); - pd = qof_query_string_predicate (compare_how, matchstring, - options, is_regex); + if (!safe_strcmp (type, QOF_TYPE_STRING)) + pd = qof_query_string_predicate (compare_how, matchstring, + options, is_regex); + else + pd = qof_query_numstring_predicate (compare_how, matchstring, + options, is_regex); } else if (!safe_strcmp (type, QOF_TYPE_DATE)) { diff --git a/src/gnome-search/search-core-type.c b/src/gnome-search/search-core-type.c index 4756530f6c..45a7e363d6 100644 --- a/src/gnome-search/search-core-type.c +++ b/src/gnome-search/search-core-type.c @@ -255,6 +255,8 @@ init_table (void) { gnc_search_core_register_type (QUERYCORE_STRING, (GNCSearchCoreNew) gnc_search_string_new); + gnc_search_core_register_type (QOF_TYPE_NUMSTRING, + (GNCSearchCoreNew) gnc_search_string_new_numstring); gnc_search_core_register_type (QUERYCORE_DATE, (GNCSearchCoreNew) gnc_search_date_new); gnc_search_core_register_type (QUERYCORE_INT64, diff --git a/src/gnome-search/search-string.c b/src/gnome-search/search-string.c index ed1aa7e531..ae8ac3fa32 100644 --- a/src/gnome-search/search-string.c +++ b/src/gnome-search/search-string.c @@ -112,6 +112,7 @@ gnc_search_string_init (GNCSearchString *o) o->value = NULL; o->how = SEARCH_STRING_CONTAINS; o->ign_case = TRUE; + o->is_numstring = FALSE; } static void @@ -139,6 +140,21 @@ gnc_search_string_new (void) return o; } +/** + * gnc_search_string_new_numstring: + * + * Create a new GNCSearchString object for a NumString. + * + * Return value: A new #GNCSearchString object. + **/ +GNCSearchString * +gnc_search_string_new_numstring (void) +{ + GNCSearchString *o = g_object_new(GNC_TYPE_SEARCH_STRING, NULL); + o->is_numstring = TRUE; + return o; +} + void gnc_search_string_set_value (GNCSearchString *fi, const char *value) { @@ -359,7 +375,10 @@ static QueryPredData_t gncs_get_predicate (GNCSearchCoreType *fe) if (ss->ign_case) options = STRING_MATCH_CASEINSENSITIVE; - return gncQueryStringPredicate (how, ss->value, options, is_regex); + if (ss->is_numstring) + return qof_query_numstring_predicate (how, ss->value, options, is_regex); + else + return gncQueryStringPredicate (how, ss->value, options, is_regex); } static GNCSearchCoreType *gncs_clone(GNCSearchCoreType *fe) @@ -369,7 +388,10 @@ static GNCSearchCoreType *gncs_clone(GNCSearchCoreType *fe) g_return_val_if_fail (fse, NULL); g_return_val_if_fail (IS_GNCSEARCH_STRING (fse), NULL); - se = gnc_search_string_new (); + if (fse->is_numstring) + se = gnc_search_string_new_numstring (); + else + se = gnc_search_string_new (); gnc_search_string_set_value (se, fse->value); gnc_search_string_set_how (se, fse->how); gnc_search_string_set_case (se, fse->ign_case); diff --git a/src/gnome-search/search-string.h b/src/gnome-search/search-string.h index fcdc921c7e..df4f544d9b 100644 --- a/src/gnome-search/search-string.h +++ b/src/gnome-search/search-string.h @@ -44,6 +44,9 @@ struct _GNCSearchString { GNCSearchString_Type how; gboolean ign_case; char * value; + + /* Is this is String or a NumString */ + gboolean is_numstring; }; struct _GNCSearchStringClass { @@ -56,6 +59,7 @@ struct _GNCSearchStringClass { guint gnc_search_string_get_type (void); GNCSearchString *gnc_search_string_new (void); +GNCSearchString *gnc_search_string_new_numstring(void); /* methods */ void gnc_search_string_set_value(GNCSearchString *fi, const char *value);