From: Lucas Bajolet Date: Wed, 4 Jun 2014 20:39:12 +0000 (-0400) Subject: lib/standard/ropes: Added constructors for a Rope X-Git-Tag: v0.6.6~43^2~25 X-Git-Url: http://nitlanguage.org lib/standard/ropes: Added constructors for a Rope Signed-off-by: Lucas Bajolet --- 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