lib/core: remove support for ',' in `is_numeric`
[nit.git] / lib / core / text / abstract_text.nit
index e201e0c..4770977 100644 (file)
@@ -305,23 +305,23 @@ abstract class Text
                end
        end
 
-       # Returns `true` if the string contains only Numeric values (and one "," or one "." character)
+       # Is this string in a valid numeric format compatible with `to_f`?
        #
        #     assert "123".is_numeric  == true
        #     assert "1.2".is_numeric  == true
        #     assert "-1.2".is_numeric == true
-       #     assert "1,2".is_numeric  == true
        #     assert "-1.23e-2".is_numeric == true
        #     assert "1..2".is_numeric == false
+       #     assert "".is_numeric     == false
        fun is_numeric: Bool
        do
-               var has_point_or_comma = false
+               var has_point = false
                var e_index = -1
                for i in [0..length[ do
                        var c = chars[i]
                        if not c.is_numeric then
-                               if (c == '.' or c == ',') and not has_point_or_comma then
-                                       has_point_or_comma = true
+                               if c == '.' and not has_point then
+                                       has_point = true
                                else if c == 'e' and e_index == -1 and i > 0 and i < length - 1 and chars[i-1] != '-' then
                                        e_index = i
                                else if c == '-' and i == e_index + 1 and i < length - 1 then
@@ -330,7 +330,7 @@ abstract class Text
                                end
                        end
                end
-               return true
+               return not is_empty
        end
 
        # Returns `true` if the string contains only Hex chars