lib/core: Made `Text` cloneable
authorLucas Bajolet <r4pass@hotmail.com>
Fri, 8 Jul 2016 16:16:27 +0000 (12:16 -0400)
committerLucas Bajolet <r4pass@hotmail.com>
Mon, 11 Jul 2016 18:21:38 +0000 (14:21 -0400)
Signed-off-by: Lucas Bajolet <r4pass@hotmail.com>

lib/core/text/abstract_text.nit

index cb6f281..02f2539 100644 (file)
@@ -25,6 +25,7 @@ in "C" `{
 # High-level abstraction for all text representations
 abstract class Text
        super Comparable
+       super Cloneable
 
        redef type OTHER: Text
 
@@ -1245,6 +1246,7 @@ abstract class String
 
        redef fun to_s do return self
 
+       redef fun clone do return self
        # Concatenates `o` to `self`
        #
        #     assert "hello" + "world"  == "helloworld"
@@ -1424,6 +1426,18 @@ abstract class Buffer
        # DEPRECATED : Use self.chars.[]= instead
        fun []=(index: Int, item: Char) is abstract
 
+       #~~~nit
+       #       var b = new Buffer
+       #       b.append("Buffer!")
+       #       var c = b.clone
+       #       assert b == c
+       #~~~
+       redef fun clone do
+               var cln = new Buffer.with_cap(byte_length)
+               cln.append self
+               return cln
+       end
+
        # Adds a char `c` at the end of self
        #
        # DEPRECATED : Use self.chars.add instead