From: Alexis Laferrière Date: Fri, 21 Aug 2015 18:41:12 +0000 (-0400) Subject: lib/standard: `Text::to_n` returns 0 as failsafe when receiver is empty X-Git-Tag: v0.7.8~71^2 X-Git-Url: http://nitlanguage.org lib/standard: `Text::to_n` returns 0 as failsafe when receiver is empty Signed-off-by: Alexis Laferrière --- diff --git a/lib/standard/numeric.nit b/lib/standard/numeric.nit index 1d2e30c..92fe49a 100644 --- a/lib/standard/numeric.nit +++ b/lib/standard/numeric.nit @@ -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