From: Lucas Bajolet Date: Mon, 23 Jun 2014 15:23:33 +0000 (-0400) Subject: lib/standard/ropes: Added BufferLeaf to constructors. X-Git-Tag: v0.6.7~18^2~7 X-Git-Url: http://nitlanguage.org lib/standard/ropes: Added BufferLeaf to constructors. Signed-off-by: Lucas Bajolet --- diff --git a/lib/bufferized_ropes.nit b/lib/bufferized_ropes.nit index 0dac054..0d9353e 100644 --- a/lib/bufferized_ropes.nit +++ b/lib/bufferized_ropes.nit @@ -25,4 +25,24 @@ private class BufferLeaf end +redef class Rope + + # Empty Rope + init do root = new BufferLeaf(new FlatBuffer.with_capacity(buf_len)) + +end + +redef class RopeString + + init from(s: String) do + if s.length < buf_len then + var b = new FlatBuffer.with_capacity(buf_len) + b.append(s) + root = new BufferLeaf(b) + else + if s isa RopeString then root = s.root else root = new StringLeaf(s.as(FlatString)) + end + end + +end