core $ ReverseRopeSubstrings :: SELF
Type of this instance, automatically specialized in every classcore :: Object :: class_factory
Implementation used byget_class
to create the specific class.
core :: Object :: defaultinit
core :: IndexedIterator :: defaultinit
core :: Iterator :: defaultinit
core :: Object :: is_same_instance
Return true ifself
and other
are the same instance (i.e. same identity).
core :: Object :: is_same_serialized
Isself
the same as other
in a serialization context?
core :: Object :: is_same_type
Return true ifself
and other
have the same dynamic type.
core :: Object :: native_class_name
The class name of the object in CString format.Iterator
whose elements are sorted by the function
core :: Object :: output_class_name
Display class name on stdout (debug only).
# Substrings of a Rope (i.e. Reverse postfix iterator on leaves)
private class ReverseRopeSubstrings
super IndexedIterator[FlatString]
# Visit Stack
var iter: RopeCharIteratorPiece is noinit
# Position in `Rope`
var pos: Int is noinit
# Current leaf
var str: FlatString is noinit
init from(root: Concat, pos: Int) do
var r = new RopeCharIteratorPiece(root, false, true, null)
var rnod: String = root
var off = pos
loop
if rnod isa Concat then
if off >= rnod._left.length then
off -= rnod._left.length
rnod = rnod._right
r = new RopeCharIteratorPiece(rnod, false, true, r)
else
r.ldone = true
rnod = rnod._left
r = new RopeCharIteratorPiece(rnod, false, true, r)
end
else
str = rnod.as(FlatString)
r.ldone = true
iter = r
self.pos = pos - off
break
end
end
end
redef fun item do return str
redef fun index do return pos
redef fun is_ok do return pos >= 0
redef fun next do
if pos < 0 then return
var curr = iter.prev
var currit = curr.as(not null).node
while curr != null do
currit = curr.node
if not currit isa Concat then
str = currit.as(FlatString)
pos -= str.length
iter = curr
return
end
if not curr.rdone then
curr.rdone = true
curr = new RopeCharIteratorPiece(currit._right, false, false, curr)
continue
end
if not curr.ldone then
curr.ldone = true
curr = new RopeCharIteratorPiece(currit._left, false, false, curr)
continue
end
curr = curr.prev
end
pos = -1
end
end
lib/core/text/ropes.nit:495,1--564,3