diff options
Diffstat (limited to 'string_utils.c')
-rw-r--r-- | string_utils.c | 67 |
1 files changed, 15 insertions, 52 deletions
diff --git a/string_utils.c b/string_utils.c index 31ef0ff..1ee96db 100644 --- a/string_utils.c +++ b/string_utils.c @@ -18,18 +18,18 @@ END DESCRIPTION **********************************************************/ void Float_To_Text(int decimal_digits,float number_in, gchar ** text_out)
{
+ g_assert (*text_out == NULL);
+
if (fabs(number_in)<1.1*smallest_allowed_number) {
if (number_in<0.0) {
- *text_out = g_strdup("-0.000000000");
- *text_out[decimal_digits+3]=0;
+ *text_out = g_strdup_printf("-0.%0*d",decimal_digits,0);
} else {
- *text_out = g_strdup("0.000000000");
- *text_out[decimal_digits+2]=0;
+ *text_out = g_strdup_printf("0.%0*d",decimal_digits,0);
}
+ return;
}
- if(*text_out == NULL) *text_out = g_strdup_printf("%.*e", decimal_digits, number_in);
- else g_sprintf (*text_out, "%.*e", decimal_digits, number_in);
+ *text_out = g_strdup_printf("%.*e", decimal_digits, number_in);
}
@@ -187,54 +187,17 @@ int String_is_it_numeric(char *parameter) /* this function takes a parameter like "1e+6" or "on" and determines if it is numeric or not */
/* it is similar to the Parser_get_unit function */
- int i;
- int j;
- int is_number;
-
- is_number=0;
- i=0;
+ // FIXME - replace in calling code with strtof
+ gchar *testme = g_strdup (parameter);
+ g_strstrip (parameter);
+
+ char * p;
+ strtof (testme, &p);
+
+ g_free (testme);
- if (isdigit(parameter[0]) || parameter[0]=='+' || parameter[0] == '-' || parameter[0] == '.') {
- for (i=1; (i < strlen(parameter)) && isdigit(parameter[i]); ++i) {}
-
- if (i < strlen(parameter))
- if ( parameter[i]=='.' )
- for (++i; (i < strlen(parameter)) && isdigit(parameter[i]); ++i) {}
-
- /* suck out spaces */
- while ( (i<strlen(parameter)) && (isspace(parameter[i])) ) {
- for(j=i; j<strlen(parameter); ++j) {
- parameter[j]=parameter[j+1];
- }
- parameter[j]=0;
- }
-
- if (i < strlen(parameter)) {
- if ( (parameter[i]=='e' && parameter[i+1]=='-')
- || (parameter[i]=='e' && parameter[i+1]=='+') ) {
- for (i+=2; (i < strlen(parameter)) && isdigit(parameter[i]); ++i) {}
- }
- else if (parameter[i]=='e' && isdigit(parameter[i+1]) ) {
- for (i+=2; (i < strlen(parameter)) && isdigit(parameter[i]); ++i) {}
- }
- }
-
- /* suck out spaces */
- while ( (i<strlen(parameter)) && (isspace(parameter[i])) ) {
- for(j=i; j<strlen(parameter); ++j) {
- parameter[j]=parameter[j+1];
- }
- parameter[j]=0;
- }
-
- if ((i = strlen(parameter))) {
- is_number=1;
- parameter[i]=0;
- }
- }
-
- return is_number;
+ return *p == '\0';
}
|