fix gstr.IsNumeric
@@ -50,7 +50,10 @@ func IsLetter(b byte) bool {
// IsNumeric checks whether the given string s is numeric.
// Note that float string like "123.456" is also numeric.
func IsNumeric(s string) bool {
- length := len(s)
+ var (
+ dotCount = 0
+ length = len(s)
+ )
if length == 0 {
return false
}
@@ -59,6 +62,7 @@ func IsNumeric(s string) bool {
continue
}
if s[i] == '.' {
+ dotCount++
if i > 0 && i < len(s)-1 {
continue
} else {
@@ -69,6 +73,9 @@ func IsNumeric(s string) bool {
return false
}
}
+ if dotCount > 1 {
+ return false
+ }
return true
}
