X-Git-Url: https://git.dogcows.com/gitweb?p=chaz%2Fhomebank;a=blobdiff_plain;f=src%2Fhb-misc.c;fp=src%2Fhb-misc.c;h=ec904c9cd7572348e856660ecf2193efada9ad59;hp=e8f4ea632af999aad250eb14a9925b0a7ee1d31f;hb=5499ff44ef50b751b58f27fd13594f7dd4f959b7;hpb=a6c6b0df5492c2160ed97e3a376bdb2fe7c5ebc4 diff --git a/src/hb-misc.c b/src/hb-misc.c index e8f4ea6..ec904c9 100644 --- a/src/hb-misc.c +++ b/src/hb-misc.c @@ -570,6 +570,62 @@ hb_strdup_nobrackets (const gchar *str) } +/* if we found a . or , within last x digits it might be a dchar */ +static gchar hb_string_raw_amount_guess_dchar(const gchar *s, gint len, gshort digit) +{ +gint nbc, nbd, i; +gchar gdc='?'; + + DB( g_print(" digit=%d maxidx=%d\n", digit, len-digit-1) ); + + nbc = nbd = 0; + for(i=len-1;i>=0;i--) + { + DB( g_print(" [%2d] '%c' %d %d '%c'\n", i, s[i], nbc, nbd, gdc) ); + //store rightmost ,. within digit-1 + if( i>=(len-digit-1) ) + { + if(s[i]=='.' || s[i]==',') + gdc=s[i]; + } + if(s[i]=='.') nbd++; + else if(s[i]==',') nbc++; + } + if( gdc=='.' && nbd > 1) gdc='?'; + else if( gdc==',' && nbc > 1) gdc='?'; + + return gdc; +} + + +gchar *hb_string_dup_raw_amount_clean(const gchar *string, gint digits) +{ +gint l; +gchar *new_str, *d; +gchar gdc; +const gchar *p = string; + + l = strlen(string); + gdc = hb_string_raw_amount_guess_dchar(string, l, digits); + + new_str = d = g_malloc (l+1); + while(*p) + { + if(*p=='-' || g_ascii_isdigit(*p) ) + *d++ = *p; + else + if( *p==gdc ) + { + *d++ = '.'; + } + p++; + } + *d++ = '\0'; + + return new_str; +} + + static gboolean hb_date_parser_get_nums(gchar *string, gint *n1, gint *n2, gint *n3) {