From c9087aa122d4fe8d99199d05eec387f6af90b05c Mon Sep 17 00:00:00 2001 From: Lucas Bajolet Date: Fri, 31 Jul 2015 16:33:57 -0400 Subject: [PATCH] lib/standard/text: Move and generalize remove_underscores to Text Signed-off-by: Lucas Bajolet --- lib/standard/text/abstract_text.nit | 9 +++++++++ src/literal.nit | 11 ----------- 2 files changed, 9 insertions(+), 11 deletions(-) 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 -- 1.7.9.5