mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
* src/app-utils/gnc-ui-util.[ch]: add a function to parse a numeric
with the caller providing all the locale-specific information git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@8847 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
parent
743889ead0
commit
e703054fb7
@ -6,6 +6,9 @@
|
||||
(pthread code is kept within some #ifdef's, just in case we decide to
|
||||
put it back in later).
|
||||
|
||||
* src/app-utils/gnc-ui-util.[ch]: add a function to parse a numeric
|
||||
with the caller providing all the locale-specific information
|
||||
|
||||
2003-07-09 Christian Stimming <stimming@tuhh.de>
|
||||
|
||||
* README: Added remark about gnucash-docs.
|
||||
|
@ -1634,6 +1634,36 @@ xaccParseAmount (const char * in_str, gboolean monetary, gnc_numeric *result,
|
||||
char **endstr)
|
||||
{
|
||||
struct lconv *lc = gnc_localeconv();
|
||||
|
||||
char negative_sign;
|
||||
char decimal_point;
|
||||
char group_separator;
|
||||
char *group;
|
||||
|
||||
negative_sign = lc->negative_sign[0];
|
||||
if (monetary)
|
||||
{
|
||||
group_separator = lc->mon_thousands_sep[0];
|
||||
decimal_point = lc->mon_decimal_point[0];
|
||||
group = lc->mon_grouping;
|
||||
}
|
||||
else
|
||||
{
|
||||
group_separator = lc->thousands_sep[0];
|
||||
decimal_point = lc->decimal_point[0];
|
||||
group = lc->grouping;
|
||||
}
|
||||
|
||||
return xaccParseAmountExtended(in_str, monetary, negative_sign, decimal_point,
|
||||
group_separator, group, NULL, result, endstr);
|
||||
}
|
||||
|
||||
gboolean
|
||||
xaccParseAmountExtended (const char * in_str, gboolean monetary,
|
||||
char negative_sign, char decimal_point,
|
||||
char group_separator, char *group, char *ignore_list,
|
||||
gnc_numeric *result, char **endstr)
|
||||
{
|
||||
gboolean is_negative;
|
||||
gboolean got_decimal;
|
||||
gboolean need_paren;
|
||||
@ -1644,10 +1674,6 @@ xaccParseAmount (const char * in_str, gboolean monetary, gnc_numeric *result,
|
||||
|
||||
ParseState state;
|
||||
|
||||
char negative_sign;
|
||||
char decimal_point;
|
||||
char group_separator;
|
||||
|
||||
const char *in;
|
||||
char *out_str;
|
||||
char *out;
|
||||
@ -1659,18 +1685,6 @@ xaccParseAmount (const char * in_str, gboolean monetary, gnc_numeric *result,
|
||||
if (in_str == NULL)
|
||||
return FALSE;
|
||||
|
||||
negative_sign = lc->negative_sign[0];
|
||||
if (monetary)
|
||||
{
|
||||
group_separator = lc->mon_thousands_sep[0];
|
||||
decimal_point = lc->mon_decimal_point[0];
|
||||
}
|
||||
else
|
||||
{
|
||||
group_separator = lc->thousands_sep[0];
|
||||
decimal_point = lc->decimal_point[0];
|
||||
}
|
||||
|
||||
/* 'out_str' will be used to store digits for numeric conversion.
|
||||
* 'out' will be used to traverse out_str. */
|
||||
out = out_str = g_new(char, strlen(in_str) + 1);
|
||||
@ -1694,6 +1708,12 @@ xaccParseAmount (const char * in_str, gboolean monetary, gnc_numeric *result,
|
||||
{
|
||||
ParseState next_state = state;
|
||||
|
||||
/* Ignore anything in the 'ignore list' */
|
||||
if (ignore_list && *in != '\0' && strchr(ignore_list, *in) != NULL) {
|
||||
in++;
|
||||
continue;
|
||||
}
|
||||
|
||||
/* Note we never need to check for then end of 'in_str' explicitly.
|
||||
* The 'else' clauses on all the state transitions will handle that. */
|
||||
switch (state)
|
||||
@ -1947,13 +1967,10 @@ xaccParseAmount (const char * in_str, gboolean monetary, gnc_numeric *result,
|
||||
{
|
||||
gboolean good_grouping = TRUE;
|
||||
GList *node;
|
||||
char *group;
|
||||
|
||||
group = monetary ? lc->mon_grouping : lc->grouping;
|
||||
|
||||
/* The groups were built in reverse order. This
|
||||
* is the easiest order to verify them in. */
|
||||
for (node = group_data; node; node = node->next)
|
||||
for (node = group_data; group && node; node = node->next)
|
||||
{
|
||||
/* Verify group size */
|
||||
if (*group != GPOINTER_TO_INT(node->data))
|
||||
|
@ -257,6 +257,19 @@ int xaccSPrintAmount (char *buf, gnc_numeric val, GNCPrintAmountInfo info);
|
||||
gboolean xaccParseAmount (const char * in_str, gboolean monetary,
|
||||
gnc_numeric *result, char **endstr);
|
||||
|
||||
/*
|
||||
* xaccParseAmountExtended is just like xaccParseAmount except the
|
||||
* caller must provide all the locale-specific information.
|
||||
*
|
||||
* Note: if group is NULL, no group-size verification will take place.
|
||||
* ignore_list is a list of characters that are completely ignored
|
||||
* while processing the input string. If NULL, nothing is ignored.
|
||||
*/
|
||||
gboolean
|
||||
xaccParseAmountExtended (const char * in_str, gboolean monetary,
|
||||
char negative_sign, char decimal_point,
|
||||
char group_separator, char *group, char *ignore_list,
|
||||
gnc_numeric *result, char **endstr);
|
||||
|
||||
/* Automatic decimal place conversion *******************************/
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user