diff options
author | root <root@fedora-arm.domain.avtechpulse.com> | 1999-12-31 20:12:42 -0500 |
---|---|---|
committer | root <root@fedora-arm.domain.avtechpulse.com> | 1999-12-31 20:12:42 -0500 |
commit | 52b66ee4a84620966636a8fb87c45437a4a04b04 (patch) | |
tree | b618739c95459df0eaf05f092039b2f15af1743a /string_utils.c | |
parent | 08819acf094883c069e7c3088d5da6a9c24c45b8 (diff) |
many small fixes
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';
}
|