lib/text: remove_all accept patterns
authorAlexis Laferrière <alexis.laf@xymus.net>
Wed, 26 Aug 2015 14:30:28 +0000 (10:30 -0400)
committerAlexis Laferrière <alexis.laf@xymus.net>
Thu, 27 Aug 2015 17:36:02 +0000 (13:36 -0400)
Signed-off-by: Alexis Laferrière <alexis.laf@xymus.net>

lib/standard/text/abstract_text.nit
lib/standard/text/string_search.nit

index 1faaad3..9a88cc1 100644 (file)
@@ -231,15 +231,6 @@ 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
-
        # Returns `self` as the corresponding integer
        #
        #     assert "123".to_i        == 123
index b360212..deb4478 100644 (file)
@@ -413,4 +413,11 @@ redef class Text
        #     assert "hello".has("ll")
        #     assert not "hello".has("lll")
        fun has(pattern: Pattern): Bool do return pattern.is_in(self)
+
+       # Returns a copy of `self` minus all occurences of `pattern`
+       #
+       #     assert "__init__".remove_all('_') == "init"
+       #     assert "abcd".remove_all("bc") == "ad"
+       #     assert "abcd".remove_all("[ad]".to_re) == "bc"
+       fun remove_all(pattern: Pattern): String do return split(pattern).join
 end