37 #include "qofundo-p.h"
45 strncasestr (
const guchar * str1,
const guchar * str2,
size_t len)
47 while (*str1 && len--)
49 if (toupper (*str1) == toupper (*str2))
51 if (strncasecmp (str1, str2, strlen (str2)) == 0)
52 return (gchar *) str1;
59 #ifndef HAVE_STRCASESTR
63 strcasestr (
const gchar * str1,
const gchar * str2)
65 size_t len = strlen (str1);
78 gint retval = strcmp ((da), (db));
84 else if ((!(da)) && (db))
86 else if ((da) && (!(db)))
98 gint retval = strcasecmp ((da), (db));
104 else if ((!(da)) && (db))
106 else if ((da) && (!(db)))
115 return strcmp (da, db);
116 if (!da && db && 0 == db[0])
118 if (!db && da && 0 == da[0])
127 #define MAX_DIGITS 50
133 gchar buf[MAX_DIGITS];
134 gulong broke[MAX_DIGITS];
136 gulong places = 0, reval;
138 if ((2 > base) || (36 < base))
143 for (i = 0; i < MAX_DIGITS; i++)
154 for (i = places - 2; i >= 0; i--)
156 reval += broke[i + 1];
162 for (i = 0; i < (gint) places; i++)
166 buf[places - 1 - i] = 0x30 + broke[i];
170 buf[places - 1 - i] = 0x41 - 10 + broke[i];
175 return g_strdup (buf);
181 if (isnan (d1) && isnan (d2))
202 while (*s && isspace (*s))
210 while (*s && isdigit (*s))
216 while (*s && isspace (*s))
237 len = strspn (val,
"\a\b\t\n\v\f\r ");
262 if (strstr (p,
"true"))
264 if (strstr (p,
"TRUE"))
266 if (strstr (p,
"yes"))
268 if (strstr (p,
"YES"))
286 if (1 < inst->editlevel)
288 if (0 >= inst->editlevel)
295 if (undo_data->undo_operation_open)
298 if (be && qof_backend_begin_exists (be))
299 qof_backend_run_begin (be, inst);
314 if (0 < inst->editlevel)
318 if (be && qof_backend_commit_exists (be))
319 qof_backend_run_commit (be, inst);
323 if (undo_data->undo_operation_open)
336 if (g_utf8_validate (
string, -1, NULL))
338 value = g_locale_to_utf8 (
string, -1, NULL, NULL, NULL);
341 PWARN (
" unable to convert from locale %s",
string);
342 PINFO (
"trying to convert from ISO-8859-15.");
343 value = g_convert (
string, -1,
"UTF-8",
"ISO-8859-15",
347 PERR (
" conversion failed");
359 static GCache *qof_string_cache = NULL;
361 #ifdef THESE_CAN_BE_USEFUL_FOR_DEGUGGING
363 g_str_hash_KEY (gconstpointer v)
365 return g_str_hash (v);
369 g_str_hash_VAL (gconstpointer v)
371 return g_str_hash (v);
375 g_strdup_VAL (gpointer v)
381 g_strdup_KEY (gpointer v)
386 g_free_VAL (gpointer v)
391 g_free_KEY (gpointer v)
397 qof_util_str_equal (gconstpointer v, gconstpointer v2)
399 return (v && v2) ? g_str_equal (v, v2) : FALSE;
402 #ifdef QOF_DISABLE_DEPRECATED
410 if (!qof_string_cache)
412 qof_string_cache = g_cache_new ((GCacheNewFunc) g_strdup,
414 (GCacheDupFunc) g_strdup,
420 return qof_string_cache;
426 if (qof_string_cache)
427 g_cache_destroy (qof_string_cache);
428 qof_string_cache = NULL;
453 const GUID *param_guid;
455 gdouble param_double, (*double_getter) (QofEntity *,
const QofParam *);
456 gboolean param_boolean, (*boolean_getter) (QofEntity *,
const QofParam *);
457 gint32 param_i32, (*int32_getter) (QofEntity *,
const QofParam *);
458 gint64 param_i64, (*int64_getter) (QofEntity *,
const QofParam *);
459 gchar param_char, (*char_getter) (QofEntity *,
const QofParam *);
463 g_return_val_if_fail (ent && param, NULL);
464 paramType = param->param_type;
467 param_string = g_strdup (param->param_getfcn (ent, param));
468 if (param_string == NULL)
479 param_qt = param->param_getfcn (ent, param);
483 #ifndef QOF_DISABLE_DEPRECATED
492 param_ts = date_getter (ent, param);
493 param_t = param_ts.tv_sec;
496 param_string = g_strdup (param_date);
501 if ((
safe_strcmp (paramType, QOF_TYPE_NUMERIC) == 0) ||
506 param_numeric = numeric_getter (ent, param);
513 param_guid = param->param_getfcn (ent, param);
515 param_string = g_strdup (param_sa);
522 (gint32 (*)(QofEntity *,
const QofParam *)) param->param_getfcn;
523 param_i32 = int32_getter (ent, param);
524 param_string = g_strdup_printf (
"%d", param_i32);
531 (gint64 (*)(QofEntity *,
const QofParam *)) param->param_getfcn;
532 param_i64 = int64_getter (ent, param);
533 param_string = g_strdup_printf (
"%" G_GINT64_FORMAT, param_i64);
540 (double (*)(QofEntity *,
const QofParam *)) param->param_getfcn;
541 param_double = double_getter (ent, param);
542 param_string = g_strdup_printf (
"%f", param_double);
546 if (
safe_strcmp (paramType, QOF_TYPE_BOOLEAN) == 0)
549 (gboolean (*)(QofEntity *,
const QofParam *)) param->param_getfcn;
550 param_boolean = boolean_getter (ent, param);
552 if (param_boolean == TRUE)
554 param_string = g_strdup (
"true");
558 param_string = g_strdup (
"false");
567 frame = param->param_getfcn (ent, param);
571 GHashTable *hash = kvp_frame_get_hash (frame);
572 param_string = g_strdup_printf (
"%s(%d)", QOF_TYPE_KVP,
573 g_hash_table_size (hash));
580 (gchar (*)(QofEntity *,
const QofParam *)) param->param_getfcn;
581 param_char = char_getter (ent, param);
583 return g_strdup_printf (
"%c", param_char);
589 col = param->param_getfcn (ent, param);
591 return g_strdup_printf (
"%s(%d)",
596 QofEntity *child = NULL;
597 child = param->param_getfcn (ent, param);
609 book = param->param_getfcn (ent, param);
610 PINFO (
" book param %p", book);
613 PINFO (
" backend=%p", be);
618 param_string = g_strdup (be->
fullpath);
619 PINFO (
" fullpath=%s", param_string);
626 PINFO (
" book GUID=%s", param_sa);
627 param_string = g_strdup (param_sa);
632 QofEntity *child = NULL;
633 child = param->param_getfcn (ent, param);
640 return g_strdup (
"");
645 const gchar * value_string)
647 void (*string_setter) (
QofEntity *,
const gchar *);
651 void (*double_setter) (
QofEntity *, gdouble);
652 void (*boolean_setter) (
QofEntity *, gboolean);
653 void (*i32_setter) (
QofEntity *, gint32);
654 void (*i64_setter) (
QofEntity *, gint64);
655 void (*char_setter) (
QofEntity *, gchar);
660 g_return_val_if_fail (ent, FALSE);
661 g_return_val_if_fail (param, FALSE);
662 g_return_val_if_fail (value_string, FALSE);
664 if (
safe_strcmp (param->param_type, QOF_TYPE_STRING) == 0)
668 const gchar *)) param->param_setfcn;
669 if (string_setter != NULL)
670 string_setter (ent, value_string);
673 if (
safe_strcmp (param->param_type, QOF_TYPE_TIME) == 0)
685 if ((time_setter != NULL) && (qof_time_is_valid (qt)))
686 time_setter (ent, qt);
690 #ifndef QOF_DISABLE_DEPRECATED
697 if ((
safe_strcmp (param->param_type, QOF_TYPE_NUMERIC) == 0) ||
698 (
safe_strcmp (param->param_type, QOF_TYPE_DEBCRED) == 0))
707 if (numeric_setter != NULL)
708 numeric_setter (ent, num);
711 if (
safe_strcmp (param->param_type, QOF_TYPE_GUID) == 0)
719 const GUID *)) param->param_setfcn;
722 if (guid_setter != NULL)
723 guid_setter (ent, guid);
726 if (
safe_strcmp (param->param_type, QOF_TYPE_INT32) == 0)
733 (void (*)(
QofEntity *, gint32)) param->param_setfcn;
735 (gint32) strtol (value_string, &tail, 0);
736 if ((i32_setter != NULL) && (errno == 0))
738 i32_setter (ent, i32);
741 if (
safe_strcmp (param->param_type, QOF_TYPE_INT64) == 0)
747 i64 = strtoll (value_string, &tail, 0);
749 (void (*)(
QofEntity *, gint64)) param->param_setfcn;
750 if ((i64_setter != NULL) && (errno == 0))
751 i64_setter (ent, i64);
754 if (
safe_strcmp (param->param_type, QOF_TYPE_DOUBLE) == 0)
760 db = strtod (value_string, &tail);
762 (void (*)(
QofEntity *, gdouble)) param->param_setfcn;
763 if ((double_setter != NULL) && (errno == 0))
764 double_setter (ent, db);
767 if (
safe_strcmp (param->param_type, QOF_TYPE_BOOLEAN) == 0)
773 (void (*)(
QofEntity *, gboolean)) param->param_setfcn;
775 if ((val > 1) || (val < 0))
777 b = (val == 1) ? TRUE : FALSE;
778 if (boolean_setter != NULL)
779 boolean_setter (ent, val);
782 if (
safe_strcmp (param->param_type, QOF_TYPE_KVP) == 0)
795 if (
safe_strcmp (param->param_type, QOF_TYPE_CHAR) == 0)
798 (void (*)(
QofEntity *, gchar)) param->param_setfcn;
799 if (char_setter != NULL)
800 char_setter (ent, value_string[0]);
838 qof_object_initialize ();
846 qof_query_shutdown ();
847 qof_object_shutdown ();