Skip to content

Commit

Permalink
rename string_to_gnc_numeric to gnc_numeric_from_string
Browse files Browse the repository at this point in the history
  • Loading branch information
christopherlam committed Aug 29, 2023
1 parent 75f6ee1 commit 7ce4198
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 15 deletions.
8 changes: 4 additions & 4 deletions bindings/python/gnucash_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@
gnc_search_customer_on_id, gnc_search_bill_on_id , \
gnc_search_vendor_on_id, gncInvoiceNextID, gncCustomerNextID, \
gncVendorNextID, gncTaxTableGetTables, gnc_numeric_zero, \
gnc_numeric_create, double_to_gnc_numeric, string_to_gnc_numeric, \
gnc_numeric_to_string
gnc_numeric_create, double_to_gnc_numeric, gnc_numeric_from_string, \
gnc_numeric_to_string, gnc_numeric_check

from gnucash.deprecation import (
deprecated_args_session,
Expand Down Expand Up @@ -432,8 +432,8 @@ def __args_to_instance(args):
elif isinstance(arg, float):
return double_to_gnc_numeric(arg, GNC_DENOM_AUTO, GNC_HOW_DENOM_FIXED | GNC_HOW_RND_NEVER)
elif isinstance(arg, str):
instance = gnc_numeric_zero()
if not string_to_gnc_numeric(arg, instance):
instance = gnc_numeric_from_string(arg)
if gnc_numeric_check(instance):
raise TypeError('Failed to convert to GncNumeric: ' + str(args))
return instance
elif isinstance(arg, GncNumeric):
Expand Down
5 changes: 2 additions & 3 deletions gnucash/gnome/dialog-fincalc.c
Original file line number Diff line number Diff line change
Expand Up @@ -194,9 +194,8 @@ gui_to_fi (FinCalcDialog *fcd)
text = gtk_entry_get_text (GTK_ENTRY(entry));
if (text && *text)
{
gnc_numeric out;
gboolean result = string_to_gnc_numeric (text, &out);
if (result)
gnc_numeric out = gnc_numeric_from_string (text);
if (!gnc_numeric_check (out))
npp = gnc_numeric_convert (out, 1, GNC_HOW_RND_TRUNC);
else
npp = gnc_numeric_zero ();
Expand Down
4 changes: 2 additions & 2 deletions gnucash/import-export/log-replay/gnc-log-replay.c
Original file line number Diff line number Diff line change
Expand Up @@ -233,12 +233,12 @@ static split_record interpret_split_record( char *record_line)
}
if (strlen(tok_ptr = my_strtok(NULL, "\t")) != 0)
{
string_to_gnc_numeric(tok_ptr, &(record.amount));
record.amount = gnc_numeric_from_string (tok_ptr);
record.amount_present = TRUE;
}
if (strlen(tok_ptr = my_strtok(NULL, "\t")) != 0)
{
string_to_gnc_numeric(tok_ptr, &(record.value));
record.value = gnc_numeric_from_string (tok_ptr);
record.value_present = TRUE;
}
if (strlen(tok_ptr = my_strtok(NULL, "\t")) != 0)
Expand Down
5 changes: 2 additions & 3 deletions libgnucash/app-utils/gnc-exp-parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,9 @@ gnc_exp_parser_real_init ( gboolean addPredefined )
for (key = keys; key && *key; key++)
{
str_value = g_key_file_get_string(key_file, GEP_GROUP_NAME, *key, NULL);
if (str_value && string_to_gnc_numeric(str_value, &value))
{
value = gnc_numeric_from_string (str_value);
if (!gnc_numeric_check (value))
gnc_exp_parser_set_value (*key, gnc_numeric_reduce (value));
}
}
g_strfreev(keys);
g_key_file_free(key_file);
Expand Down
7 changes: 7 additions & 0 deletions libgnucash/backend/xml/io-gncxml-v1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,13 @@ simple_kvp_value_parser_new (sixtp_end_handler end_handler)
*/

static gboolean
string_to_gnc_numeric(const gchar* str, gnc_numeric *n)
{
*n = gnc_numeric_from_string (str);
return (!gnc_numeric_check (*n));
}

/* ------------------------------------------------------------ */
/* generic type copnversion for kvp types */
#define KVP_CVT_VALUE(TYPE) \
Expand Down
4 changes: 2 additions & 2 deletions libgnucash/backend/xml/sixtp-dom-parsers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -509,8 +509,8 @@ dom_tree_to_gnc_numeric (xmlNodePtr node)
if (!content)
return gnc_numeric_zero ();

gnc_numeric num;
if (!string_to_gnc_numeric (content, &num))
gnc_numeric num = gnc_numeric_from_string (content);
if (gnc_numeric_check (num))
num = gnc_numeric_zero ();

g_free (content);
Expand Down
3 changes: 2 additions & 1 deletion libgnucash/backend/xml/sixtp-utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -611,7 +611,8 @@ generic_gnc_numeric_end_handler (gpointer data_for_children,
num = g_new (gnc_numeric, 1);
if (num)
{
if (string_to_gnc_numeric (txt, num))
*num = gnc_numeric_from_string (txt);
if (!gnc_numeric_check (*num))
{
ok = TRUE;
*result = num;
Expand Down

0 comments on commit 7ce4198

Please sign in to comment.