lib/standard: `Text::to_n` returns 0 as failsafe when receiver is empty
authorAlexis Laferrière <alexis.laf@xymus.net>
Fri, 21 Aug 2015 18:41:12 +0000 (14:41 -0400)
committerAlexis Laferrière <alexis.laf@xymus.net>
Sat, 22 Aug 2015 21:46:34 +0000 (17:46 -0400)
Signed-off-by: Alexis Laferrière <alexis.laf@xymus.net>

lib/standard/numeric.nit

index 1d2e30c..92fe49a 100644 (file)
@@ -30,9 +30,11 @@ redef class Text
        # assert "0.0".to_n == 0.0
        # assert ".12345".to_n == 0.12345
        # assert "12345".to_n == 12345
+       # assert "".to_n == 0
        # ~~~~
        fun to_n: Numeric
        do
+               if is_empty then return 0
                if chars.has('.') then return to_f
                return to_i
        end