lib/core: Added `Text::to_buffer`
authorLucas Bajolet <r4pass@hotmail.com>
Fri, 8 Jul 2016 16:18:15 +0000 (12:18 -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 3376986..f7d8834 100644 (file)
@@ -83,6 +83,9 @@ abstract class Text
        # implementation of an empty string.
        protected fun empty: SELFTYPE is abstract
 
+       # Returns a copy of `self` as a Buffer
+       fun to_buffer: Buffer is abstract
+
        # Gets the first char of the Text
        #
        # DEPRECATED : Use self.chars.first instead
@@ -1356,6 +1359,7 @@ abstract class String
 
        redef fun clone do return self
 
+       redef fun to_buffer do return new Buffer.from_text(self)
 
        redef fun to_camel_case do
                if self.is_upper then return self
@@ -1401,6 +1405,8 @@ abstract class Buffer
        # DEPRECATED : Use self.chars.[]= instead
        fun []=(index: Int, item: Char) is abstract
 
+       redef fun to_buffer do return clone
+
        #~~~nit
        #       var b = new Buffer
        #       b.append("Buffer!")