lib/string_search: avoid covariant array on `split_once_on`
authorJean Privat <jean@pryen.org>
Fri, 17 Apr 2015 01:06:35 +0000 (08:06 +0700)
committerJean Privat <jean@pryen.org>
Fri, 17 Apr 2015 02:09:18 +0000 (09:09 +0700)
Signed-off-by: Jean Privat <jean@pryen.org>

lib/standard/string_search.nit

index 3a885ad..437341f 100644 (file)
@@ -388,8 +388,14 @@ redef class Text
        fun split_once_on(p: Pattern): Array[SELFTYPE]
        do
                var m = p.search_in(self, 0)
-               if m == null then return [self]
-               return new Array[SELFTYPE].with_items(substring(0, m.from), substring_from(m.after))
+               var res = new Array[SELFTYPE]
+               if m == null then
+                       res.add self
+               else
+                       res.add substring(0, m.from)
+                       res.add substring_from(m.after)
+               end
+               return res
        end
 
        # Replace all occurences of a pattern with a string