summaryrefslogtreecommitdiffstats
path: root/src/utils
diff options
context:
space:
mode:
authorAndrés M <andmarti1424@users.noreply.github.com>2021-03-21 11:07:15 -0300
committerGitHub <noreply@github.com>2021-03-21 11:07:15 -0300
commitc8cb3205919b7e224e59edeb187920be94e1a91f (patch)
treef661bf7fe06e68490ad1b207633f887b27044e92 /src/utils
parent4175e52f9c02c6279babb76fa52c1dc5b8fbbf9d (diff)
parentffaa68bd6d5b9d9b5acf3c8763970c2e33c49f1d (diff)
Merge pull request #450 from earthshrink/isnumeric_floats
Fix isnumeric test to recognise floats: affects copy/paste
Diffstat (limited to 'src/utils')
-rwxr-xr-xsrc/utils/string.c27
1 files changed, 17 insertions, 10 deletions
diff --git a/src/utils/string.c b/src/utils/string.c
index 45b269e..f3280dc 100755
--- a/src/utils/string.c
+++ b/src/utils/string.c
@@ -350,10 +350,11 @@ char * ltrim(char * string, char junk) {
int isnumeric(char * string) {
int i, len = strlen(string);
- int res = true;
+ int result = true;
bool has_dot = false;
- bool has_dash = false;
+ bool has_sign = false;
bool has_digit = false;
+ bool has_exponent = false;
for (i=0; i<len; i++) {
if ( string[i] == '.' && ! has_dot ) {
@@ -361,15 +362,21 @@ int isnumeric(char * string) {
continue;
}
- if ( string[i] == '-' ) {
- if (has_digit) {
- res = false;
+ if ( (string[i] == 'e' || string[i] == 'E') && ! has_exponent ) {
+ has_exponent = true;
+ has_sign = false; // allow sign for exponent
+ continue;
+ }
+
+ if ( (string[i] == '-' || string[i] == '+') ) {
+ if (has_digit && ! has_exponent ) {
+ result = false;
break;
}
- if (! has_dash) {
- has_dash = true;
+ if (! has_sign) {
+ has_sign = true;
} else {
- res = false;
+ result = false;
break;
}
continue;
@@ -380,10 +387,10 @@ int isnumeric(char * string) {
continue;
}
- res = false;
+ result = false;
break;
}
- return res;
+ return result;
}
/**