stdlib/strings: Moved Substring to Buffer since it was in no way similar to the Strin...
authorLucas Bajolet <r4pass@hotmail.com>
Fri, 28 Feb 2014 20:16:33 +0000 (15:16 -0500)
committerLucas Bajolet <r4pass@hotmail.com>
Mon, 24 Mar 2014 17:01:29 +0000 (13:01 -0400)
Signed-off-by: Lucas Bajolet <r4pass@hotmail.com>

lib/standard/string.nit

index f33bc0b..4b6602a 100644 (file)
@@ -48,23 +48,7 @@ abstract class AbstractString
        # A `from` index < 0 will be replaced by 0.
        # Unless a `count` value is > 0 at the same time.
        # In this case, `from += count` and `count -= from`.
-       fun substring(from: Int, count: Int): String
-       do
-               assert count >= 0
-               count += from
-               if from < 0 then from = 0
-               if count > length then count = length
-               if from < count then
-                       var r = new Buffer.with_capacity(count - from)
-                       while from < count do
-                               r.chars.push(_items[from])
-                               from += 1
-                       end
-                       return r.to_s
-               else
-                       return ""
-               end
-       end
+       fun substring(from: Int, count: Int): String is abstract
 
        # Create a substring from `self` beginning at the `from` position
        #
@@ -942,6 +926,25 @@ class Buffer
        end
 
        readable private var _capacity: Int
+
+       redef fun substring(from, count)
+       do
+               assert count >= 0
+               count += from
+               if from < 0 then from = 0
+               if count > length then count = length
+               if from < count then
+                       var r = new Buffer.with_capacity(count - from)
+                       while from < count do
+                               r.chars.push(_items[from])
+                               from += 1
+                       end
+                       return r.to_s
+               else
+                       return ""
+               end
+       end
+
 end
 
 private class FlatBufferReverseIterator