From ddf583d67c35e61714825637c6f1219ede3ba7d5 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Alexis=20Laferri=C3=A8re?= Date: Mon, 8 Sep 2014 18:27:31 -0400 Subject: [PATCH] lib: replace `String.has(Char)` with `String.has(Pattern)` MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Alexis Laferrière --- lib/standard/string.nit | 7 ------- lib/standard/string_search.nit | 9 +++++++++ 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/lib/standard/string.nit b/lib/standard/string.nit index 2ae29ef..38bd492 100644 --- a/lib/standard/string.nit +++ b/lib/standard/string.nit @@ -157,13 +157,6 @@ abstract class Text return self.chars.iterator end - # Is 'c' contained in self ? - # - # DEPRECATED : Use self.chars.has instead - fun has(c: Char): Bool - do - return self.chars.has(c) - end # Gets an Array containing the chars of self # diff --git a/lib/standard/string_search.nit b/lib/standard/string_search.nit index 95ac9d5..5aeac25 100644 --- a/lib/standard/string_search.nit +++ b/lib/standard/string_search.nit @@ -84,6 +84,8 @@ interface Pattern res.add(new Match(s.to_s, i, s.length - i)) return res end + + protected fun is_in(s: Text): Bool do return search_index_in(s, 0) != -1 end # BM_Pattern are pre-compiled string motif for the Boyer-Moore algorithm. @@ -374,4 +376,11 @@ redef class Text do return self.split_with(p).join(string) end + + # Does `self` contains at least one instance of `pattern`? + # + # assert "hello".has('l') + # assert "hello".has("ll") + # assert not "hello".has("lll") + fun has(pattern: Pattern): Bool do return pattern.is_in(self) end -- 1.7.9.5