diff options
author | Bill Sanders <billysanders@gmail.com> | 2016-10-20 21:54:18 -0700 |
---|---|---|
committer | Bill Sanders <billysanders@gmail.com> | 2016-10-20 21:54:18 -0700 |
commit | 665354171381d58861c62ce0bcc9599e9ff52acc (patch) | |
tree | 5dae7947fd4280215aeabb7f63d7eac708ef699d /src/utils | |
parent | 218442dbac6541b21c779f04070b22f504d8666c (diff) |
fixed isnumeric() to only search for max 1 dot and 1 dash, allowing IP addresses to interpret as strings
Diffstat (limited to 'src/utils')
-rwxr-xr-x | src/utils/string.c | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/src/utils/string.c b/src/utils/string.c index da04d3a..eebb186 100755 --- a/src/utils/string.c +++ b/src/utils/string.c @@ -226,10 +226,23 @@ char * ltrim(char * string, char junk) { // returns 1 if that is the case. 0 otherwise int isnumeric(char * string) { int i, len = strlen(string); - int res = 1; + int res = true; + bool has_dot = false; + bool has_dash = false; for (i=0; i<len; i++) { - if ( string[i] != '.' && string[i] != '-' && ! isdigit(string[i]) ) { - res = 0; + if ( string[i] == '.' && ! has_dot ) { + has_dot = true; + continue; + } + if ( string[i] == '-' && ! has_dash ) { + has_dash = true; + continue; + } + if ( isdigit(string[i]) ) { + continue; + } + else { + res = false; break; } } |