lib: replace `String.has(Char)` with `String.has(Pattern)`
authorAlexis Laferrière <alexis.laf@xymus.net>
Mon, 8 Sep 2014 22:27:31 +0000 (18:27 -0400)
committerAlexis Laferrière <alexis.laf@xymus.net>
Mon, 8 Sep 2014 22:27:47 +0000 (18:27 -0400)
Signed-off-by: Alexis Laferrière <alexis.laf@xymus.net>

lib/standard/string.nit
lib/standard/string_search.nit

index 2ae29ef..38bd492 100644 (file)
@@ -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
        #
index 95ac9d5..5aeac25 100644 (file)
@@ -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