summaryrefslogtreecommitdiff
path: root/string_utils.c
diff options
context:
space:
mode:
authorroot <root@fedora-arm.domain.avtechpulse.com>1999-12-31 20:36:36 -0500
committerroot <root@fedora-arm.domain.avtechpulse.com>1999-12-31 20:36:36 -0500
commit21f8e7cd6cc06e25f1a49c1cf2b26879150de38f (patch)
treeba6052a01f5833c7726ea18a4b52cda5391cdbd8 /string_utils.c
parent839c01f7c250431644bd827e21f7363314ef3f13 (diff)
re-add old is_numeric detector - new code couldn't handle ".1" or "2"
Diffstat (limited to 'string_utils.c')
-rw-r--r--string_utils.c53
1 files changed, 44 insertions, 9 deletions
diff --git a/string_utils.c b/string_utils.c
index 1ee96db..cbe310f 100644
--- a/string_utils.c
+++ b/string_utils.c
@@ -181,23 +181,58 @@ int String_trim_excess_digits(char *parameter)
return OK;
}
+
/*----------------------------------------------------------------------------------------------------------*/
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 */
- // FIXME - replace in calling code with strtof
+ int i;
+ int j;
+ int is_number;
+
+ is_number=0;
+ i=0;
+
+
+ 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) {}
- gchar *testme = g_strdup (parameter);
- g_strstrip (parameter);
-
- char * p;
- strtof (testme, &p);
-
- g_free (testme);
+ /* 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 *p == '\0';
+ return is_number;
}