From: Lucas Bajolet Date: Fri, 31 Jul 2015 20:33:57 +0000 (-0400) Subject: lib/standard/text: Move and generalize remove_underscores to Text X-Git-Tag: v0.7.8~106^2~4^2~5 X-Git-Url: http://nitlanguage.org lib/standard/text: Move and generalize remove_underscores to Text Signed-off-by: Lucas Bajolet --- diff --git a/lib/standard/text/abstract_text.nit b/lib/standard/text/abstract_text.nit index 97191d2..fe91819 100644 --- a/lib/standard/text/abstract_text.nit +++ b/lib/standard/text/abstract_text.nit @@ -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 diff --git a/src/literal.nit b/src/literal.nit index f5f70b0..f9eafa0 100644 --- a/src/literal.nit +++ b/src/literal.nit @@ -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