From 08579fbdd0a1824a5141f1b8fae93eff44961a4a Mon Sep 17 00:00:00 2001 From: Lucas Bajolet Date: Wed, 4 Jun 2014 16:39:12 -0400 Subject: [PATCH] lib/standard/ropes: Added constructors for a Rope Signed-off-by: Lucas Bajolet --- lib/standard/ropes.nit | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/lib/standard/ropes.nit b/lib/standard/ropes.nit index fc74932..eef9360 100644 --- a/lib/standard/ropes.nit +++ b/lib/standard/ropes.nit @@ -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 -- 1.7.9.5