lib/standard/text: Move and generalize remove_underscores to Text
authorLucas Bajolet <r4pass@hotmail.com>
Fri, 31 Jul 2015 20:33:57 +0000 (16:33 -0400)
committerLucas Bajolet <r4pass@hotmail.com>
Mon, 3 Aug 2015 14:39:42 +0000 (10:39 -0400)
Signed-off-by: Lucas Bajolet <r4pass@hotmail.com>

lib/standard/text/abstract_text.nit
src/literal.nit

index 97191d2..fe91819 100644 (file)
@@ -231,6 +231,15 @@ abstract class Text
        #     assert "abcd".has_suffix("bcd")        ==  true
        fun has_suffix(suffix: String): Bool do return has_substring(suffix, length - suffix.length)
 
+       # Returns a copy of `self` minus all occurences of `c`
+       #
+       #     assert "__init__".remove_all('_') == "init"
+       fun remove_all(c: Char): String do
+               var b = new Buffer
+               for i in chars do if i != c then b.add i
+               return b.to_s
+       end
+
        # If `self` contains only digits, return the corresponding integer
        #
        #     assert "123".to_i        == 123
index f5f70b0..f9eafa0 100644 (file)
@@ -74,17 +74,6 @@ redef class AExpr
        end
 end
 
-redef class Text
-       private fun remove_underscores: Text do
-               var b = new FlatBuffer
-               for i in chars do
-                       if i == '_' then continue
-                       b.add i
-               end
-               return b
-       end
-end
-
 redef class AIntExpr
        # The value of the literal int once computed.
        var value: nullable Int