core :: RopeCharIterator :: defaultinit
# Forward iterator on the chars of a `Rope`
private class RopeCharIterator
super IndexedIterator[Char]
# Position in current `String`
var pns: Int is noautoinit
# Current `String` being iterated on
var str: String is noautoinit
# Substrings of the Rope
var subs: IndexedIterator[String] is noautoinit
# Maximum position to iterate on (e.g. Rope.length)
var max: Int is noautoinit
# Position (char) in the Rope (0-indexed)
var pos: Int is noautoinit
init from(root: Concat, pos: Int) do
subs = new RopeSubstrings.from(root, pos)
pns = pos - subs.index
self.pos = pos
str = subs.item
max = root.length - 1
end
redef fun item do return str[pns]
redef fun is_ok do return pos <= max
redef fun index do return pos
redef fun next do
pns += 1
pos += 1
if pns < subs.item.length then return
if not subs.is_ok then return
subs.next
if not subs.is_ok then return
str = subs.item
pns = 0
end
end
lib/core/text/ropes.nit:454,1--493,3