From: Alexis Laferrière Date: Mon, 8 Sep 2014 22:27:31 +0000 (-0400) Subject: lib: replace `String.has(Char)` with `String.has(Pattern)` X-Git-Tag: v0.6.9~42^2~1 X-Git-Url: http://nitlanguage.org lib: replace `String.has(Char)` with `String.has(Pattern)` Signed-off-by: Alexis Laferrière --- 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