src: remove clients of protected Pattern methods
authorJean Privat <jean@pryen.org>
Mon, 24 Mar 2014 19:24:37 +0000 (15:24 -0400)
committerJean Privat <jean@pryen.org>
Tue, 25 Mar 2014 15:17:41 +0000 (11:17 -0400)
Use the public API in String instead.
Eg. `String::search` instead of `Pattern::search_in`

Signed-off-by: Jean Privat <jean@pryen.org>

lib/base64.nit
src/debugger.nit
tests/bench_string_append.nit
tests/sav/test_string_search.res
tests/test_string_search.nit

index 9c57166..2d941e9 100644 (file)
@@ -87,12 +87,12 @@ redef class String
                var steps = length / 4
                var result_length = steps*3
 
-               var padding_begin = padding.search_index_in( self, 0 )
+               var padding_begin = self.search(padding)
                var padding_count : Int
-               if padding_begin == -1 then
+               if padding_begin == null then
                        padding_count = 0
                else
-                       padding_count = length - padding_begin
+                       padding_count = length - padding_begin.from
                        steps -= 1
                        result_length -= padding_count
                end
index 02276be..b037c36 100644 (file)
@@ -109,7 +109,7 @@ redef class ToolContext
                                message_sorter.sort(messages)
 
                                for m in messages do
-                                       if "Warning".search_in(m.text, 0) == null then had_error = true
+                                       if m.text.search("Warning") == null then had_error = true
                                        stderr.write("{m.to_color_string}\n")
                                end
                        end
index 6a2d643..a08bfb6 100644 (file)
@@ -33,16 +33,15 @@ while i < n do
        s = s2.to_s
        i = i + 1
 end
-print("Je dis «Je dis".search_all_in(s).length)
+print(s.search_all("Je dis «Je dis").length)
 
 i = 0
 var j = 0
 while j >= 0 do
-       j = "Je dis «Je dis".search_index_in(s, j)
-       if j >= 0 then
-               i = i + 1
-               j = j + 1
-       end
+       var r = s.search_from("Je dis «Je dis", j)
+       if r == null then break
+       i = i + 1
+       j = r.from + 1
 end
 print(i)
 
index c8277d4..76c6e5c 100644 (file)
@@ -3,25 +3,25 @@ searches:
 * [1, 2[ = " "
 * [8, 9[ = " "
 splits:
-* [0, 1[ = "A"
-* [2, 8[ = "simple"
-* [9, 16[ = "example"
+* "A"
+* "simple"
+* "example"
 join: A, simple, example
 string: "A simple example" ; pattern: "ple"
 searches:
 * [5, 8[ = "ple"
 * [13, 16[ = "ple"
 splits:
-* [0, 5[ = "A sim"
-* [8, 13[ = " exam"
-* [16, 16[ = ""
+* "A sim"
+* " exam"
+* ""
 join: A sim,  exam, 
 string: "A simple example" ; pattern: "ple"
 searches:
 * [5, 8[ = "ple"
 * [13, 16[ = "ple"
 splits:
-* [0, 5[ = "A sim"
-* [8, 13[ = " exam"
-* [16, 16[ = ""
+* "A sim"
+* " exam"
+* ""
 join: A sim,  exam, 
index 26aaf9d..0702869 100644 (file)
@@ -23,11 +23,11 @@ fun search_and_split(s: String, p: Pattern)
            print("* [{m.from}, {m.after}[ = \"{m}\"")
        end
        print("splits:")
-       for m in p.split_in(s) do
-           print("* [{m.from}, {m.after}[ = \"{m}\"")
+       for m in s.split(p) do
+           print("* \"{m}\"")
        end
 
-       print("join: {s.split_with(p).join(", ")}")
+       print("join: {s.split(p).join(", ")}")
     end
     
 search_and_split("A simple example", ' ')