diff options
-rw-r--r-- | string_utils.c | 56 |
1 files changed, 6 insertions, 50 deletions
diff --git a/string_utils.c b/string_utils.c index cbe310f..67ad827 100644 --- a/string_utils.c +++ b/string_utils.c @@ -183,56 +183,12 @@ int String_trim_excess_digits(char *parameter) /*----------------------------------------------------------------------------------------------------------*/
-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;
-
-
- 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) {}
+gboolean String_is_it_numeric(char *parameter) {
- /* 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;
- }
- }
+ GRegex *numeric_regex = g_regex_new ( "\\s*[+-]?(\\d*\\.\\d+|\\d+(\\.\\d*)?)\\s*(e\\s*[+-]?\\d+)?\\s*",
+ G_REGEX_CASELESS,
+ 0,
+ NULL);
- return is_number;
+ return g_regex_match (numeric_regex, parameter, 0, NULL);
}
-
-
|