lib/standard/ropes: Added constructors for a Rope
authorLucas Bajolet <r4pass@hotmail.com>
Wed, 4 Jun 2014 20:39:12 +0000 (16:39 -0400)
committerLucas Bajolet <r4pass@hotmail.com>
Wed, 4 Jun 2014 20:39:12 +0000 (16:39 -0400)
Signed-off-by: Lucas Bajolet <r4pass@hotmail.com>

lib/standard/ropes.nit

index fc74932..eef9360 100644 (file)
@@ -73,6 +73,19 @@ abstract class Rope
        # Root node, entry point of a Rope.
        private var root: RopeNode
 
+       # Empty Rope
+       init do from("")
+
+       # Creates a new Rope with `s` as root
+       init from(s: String) do
+               if s isa RopeString then root = s.root else root = new Leaf(s.as(FlatString))
+       end
+
+       private init from_root(r: RopeNode)
+       do
+               root = r
+       end
+
        redef fun length do return root.length
 end