- # To be used internally only
- private fun to_immutable: ImmutableRope
- do
- var immutable_self = new ImmutableRope
- immutable_self.parent_node = self.parent_node
- return immutable_self
- end
-
- ############################################################################
- # Rope refined Methods #
- ############################################################################
-
- redef fun subrope(index_from: Int, count: Int): BufferRope
- do
- return super.as(BufferRope)
- end
-
- redef fun *(repeats: Int): BufferRope
- do
- return super.as(BufferRope)
- end
-
- redef fun +(other: Rope): BufferRope
- do
- return super.as(BufferRope)
- end
-
- redef fun multi_concat(ropes: Rope...): BufferRope
- do
- return super.as(BufferRope)
- end
-
- # Refines to add a cache method, calculates only once for every modification
- # the string representation for self
- redef fun to_s
- do
- if self.str_representation == null or is_dirty then
- self.str_representation = flatten
- is_dirty = false
- end
- return self.str_representation.as(not null)
- end
-
-end
-
-# Rope that cannot be modified
-class ImmutableRope
- super Rope
-
- init
- do
- super
- end
-
- init with_string(str)
- do
- super
- end
-
- ############################################################################
- # Rope refined Methods #
- ############################################################################
-
- redef fun subrope(index_from: Int, count: Int): ImmutableRope
- do
- return (super.as(BufferRope)).to_immutable
- end
-
- redef fun *(repeats: Int): ImmutableRope
- do
- return (super.as(BufferRope)).to_immutable
- end
-
- redef fun +(other: Rope): ImmutableRope
- do
- return (super.as(BufferRope)).to_immutable
- end
-
- redef fun multi_concat(ropes: Rope...): ImmutableRope
- do
- return (super.as(BufferRope)).to_immutable
- end
-
-end
-
-############################################
-# Rope view classes #
-############################################
-
-class CharRopeView
- super SequenceRead[Char]
-
- # Targeted Rope for the view
- private var target: Rope
-
- init(tgt: Rope)
- do
- self.target = tgt
- end
-
- redef fun [](position)
- do
- var tuple = target.get_node_for_pos(position)
- return tuple.curr_node.value[tuple.corrected_pos]
- end
-
- redef fun first do return self[0]
-
- redef fun index_of(char)
+ # var rope = new RopeString.from("abcd")
+ # assert rope.substring(1, 2) == "bc"
+ # assert rope.substring(-1, 2) == "a"
+ # assert rope.substring(1, 0) == ""
+ # assert rope.substring(2, 5) == "cd"
+ #
+ redef fun substring(pos, len)