lib/standard/string: Added to_oct and to_bin functions to Text
authorLucas Bajolet <r4pass@hotmail.com>
Mon, 25 May 2015 20:13:14 +0000 (16:13 -0400)
committerLucas Bajolet <r4pass@hotmail.com>
Tue, 26 May 2015 15:43:23 +0000 (11:43 -0400)
Signed-off-by: Lucas Bajolet <r4pass@hotmail.com>

lib/standard/string.nit

index 2344659..61af948 100644 (file)
@@ -249,6 +249,16 @@ abstract class Text
        #     assert "ff".to_hex == 255
        fun to_hex: Int do return a_to(16)
 
+       # If `self` contains only digits <= '7', return the corresponding integer.
+       #
+       #     assert "714".to_oct == 460
+       fun to_oct: Int do return a_to(8)
+
+       # If `self` contains only '0' et '1', return the corresponding integer.
+       #
+       #     assert "101101".to_bin == 45
+       fun to_bin: Int do return a_to(2)
+
        # If `self` contains only digits and letters, return the corresponding integer in a given base
        #
        #     assert "120".a_to(3)     == 15