lib/standard/ropes: Adapted substring iterators to new API.
authorLucas Bajolet <r4pass@hotmail.com>
Thu, 24 Jul 2014 14:19:55 +0000 (10:19 -0400)
committerLucas Bajolet <r4pass@hotmail.com>
Thu, 24 Jul 2014 14:22:11 +0000 (10:22 -0400)
Signed-off-by: Lucas Bajolet <r4pass@hotmail.com>

lib/bufferized_ropes.nit

index 5f49b72..a47bc0a 100644 (file)
@@ -334,6 +334,35 @@ redef class RopeString
 
 end
 
+redef class SubstringsIterator
+
+       # Compute the bounds of the current substring and makes the substring
+       redef fun make_substring
+       do
+               var l = nodes.item
+               var s = l.str
+               var min = 0
+               var length = l.length
+               if nodes.index < pos then
+                       min = pos - nodes.index
+               end
+               substring = s.lazy_substring(min, length)
+       end
+
+end
+
+redef class ReverseSubstringsIterator
+
+       redef fun make_substring
+       do
+               var l = leaves.item
+               var s = l.str
+               if pos > (leaves.index + l.length - 1) then return
+               str = s.lazy_substring(0, (pos - leaves.index + 1))
+       end
+
+end
+
 # Default size of a buffer in a rope leaf.
 fun buf_len: Int do return 200