|
|
|
|
@ -813,122 +813,5 @@ double xaccParseAmount (const char * instr, gncBoolean monetary)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/********************************************************************\
|
|
|
|
|
* xaccParseQIFAmount *
|
|
|
|
|
* parses monetary strings in QIF files *
|
|
|
|
|
* *
|
|
|
|
|
* Args: str -- pointer to string rep of sum *
|
|
|
|
|
* Return: double -- the parsed amount *
|
|
|
|
|
*
|
|
|
|
|
* Note: be careful changing this algorithm. The Quicken-file-format
|
|
|
|
|
* parser depends a lot on the ability of this routine to do what it's
|
|
|
|
|
* doing. Don't break it!
|
|
|
|
|
\********************************************************************/
|
|
|
|
|
|
|
|
|
|
/* The following tokens are used to define the US-style monetary
|
|
|
|
|
* strings. With a bit of cleverness, it should be possible to modify
|
|
|
|
|
* these to handle various international styles ... maybe ... */
|
|
|
|
|
|
|
|
|
|
#define MINUS_SIGN '-'
|
|
|
|
|
#define K_SEP ',' /* thousands separator */
|
|
|
|
|
#define DEC_SEP '.' /* decimal point */
|
|
|
|
|
|
|
|
|
|
double xaccParseQIFAmount (const char * instr)
|
|
|
|
|
{
|
|
|
|
|
char decimal_point = DEC_SEP;
|
|
|
|
|
char thousands_sep = K_SEP;
|
|
|
|
|
char *mstr, *str, *tok;
|
|
|
|
|
double dollars = 0.0;
|
|
|
|
|
int isneg = 0;
|
|
|
|
|
int len;
|
|
|
|
|
|
|
|
|
|
if (!instr) return 0.0;
|
|
|
|
|
mstr = strdup (instr);
|
|
|
|
|
str = mstr;
|
|
|
|
|
|
|
|
|
|
/* strip off garbage at end of the line */
|
|
|
|
|
tok = strchr (str, '\r');
|
|
|
|
|
if (tok) *tok = 0x0;
|
|
|
|
|
tok = strchr (str, '\n');
|
|
|
|
|
if (tok) *tok = 0x0;
|
|
|
|
|
|
|
|
|
|
/* search for a minus sign */
|
|
|
|
|
tok = strchr (str, MINUS_SIGN);
|
|
|
|
|
if (tok) {
|
|
|
|
|
isneg = 1;
|
|
|
|
|
str = tok+sizeof(char);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* figure out separators */
|
|
|
|
|
{
|
|
|
|
|
char *tok1, *tok2;
|
|
|
|
|
|
|
|
|
|
tok1 = strrchr(str, DEC_SEP);
|
|
|
|
|
tok2 = strrchr(str, K_SEP);
|
|
|
|
|
|
|
|
|
|
if (tok1 < tok2)
|
|
|
|
|
{
|
|
|
|
|
decimal_point = K_SEP;
|
|
|
|
|
thousands_sep = DEC_SEP;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* remove comma's */
|
|
|
|
|
tok = strchr (str, thousands_sep);
|
|
|
|
|
while (tok) {
|
|
|
|
|
*tok = 0x0;
|
|
|
|
|
dollars *= 1000.0;
|
|
|
|
|
dollars += ((double) (1000 * atoi (str)));
|
|
|
|
|
str = tok+sizeof(char);
|
|
|
|
|
tok = strchr (str, thousands_sep);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* search for a decimal point */
|
|
|
|
|
tok = strchr (str, decimal_point);
|
|
|
|
|
if (tok) {
|
|
|
|
|
*tok = 0x0;
|
|
|
|
|
dollars += ((double) (atoi (str)));
|
|
|
|
|
str = tok+sizeof(char);
|
|
|
|
|
|
|
|
|
|
/* if there is anything trailing the decimal
|
|
|
|
|
* point, convert it */
|
|
|
|
|
if (str[0]) {
|
|
|
|
|
|
|
|
|
|
/* strip off garbage at end of the line */
|
|
|
|
|
tok = strchr (str, ' ');
|
|
|
|
|
if (tok) *tok = 0x0;
|
|
|
|
|
|
|
|
|
|
/* adjust for number of decimal places */
|
|
|
|
|
len = strlen(str);
|
|
|
|
|
if (6 == len) {
|
|
|
|
|
dollars += 0.000001 * ((double) atoi (str));
|
|
|
|
|
} else
|
|
|
|
|
if (5 == len) {
|
|
|
|
|
dollars += 0.00001 * ((double) atoi (str));
|
|
|
|
|
} else
|
|
|
|
|
if (4 == len) {
|
|
|
|
|
dollars += 0.0001 * ((double) atoi (str));
|
|
|
|
|
} else
|
|
|
|
|
if (3 == len) {
|
|
|
|
|
dollars += 0.001 * ((double) atoi (str));
|
|
|
|
|
} else
|
|
|
|
|
if (2 == len) {
|
|
|
|
|
dollars += 0.01 * ((double) atoi (str));
|
|
|
|
|
} else
|
|
|
|
|
if (1 == len) {
|
|
|
|
|
dollars += 0.1 * ((double) atoi (str));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
dollars += ((double) (atoi (str)));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (isneg) dollars = -dollars;
|
|
|
|
|
|
|
|
|
|
free (mstr);
|
|
|
|
|
return dollars;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/************************* END OF FILE ******************************\
|
|
|
|
|
\********************************************************************/
|
|
|
|
|
|