stdlib/strings: Introduced virtual types for Text classes, used later for factorization.
authorLucas Bajolet <r4pass@hotmail.com>
Mon, 24 Mar 2014 17:08:43 +0000 (13:08 -0400)
committerLucas Bajolet <r4pass@hotmail.com>
Mon, 24 Mar 2014 17:08:43 +0000 (13:08 -0400)
Signed-off-by: Lucas Bajolet <r4pass@hotmail.com>

lib/standard/string.nit

index 703db45..d808851 100644 (file)
@@ -31,6 +31,12 @@ abstract class Text
 
        redef type OTHER: Text
 
+       # Type of the view on self (.chars)
+       type SELFVIEW: StringCharView
+
+       # Type of self (used for factorization of several methods, ex : substring_from, empty...)
+       type SELFTYPE: Text
+
        # Gets a view on the chars of the Text object
        fun chars: StringCharView is abstract
 
@@ -574,6 +580,9 @@ class String
        super FlatText
        super StringCapable
 
+       redef type SELFTYPE: String
+       redef type SELFVIEW: FlatStringCharView
+
        # Index in _items of the start of the string
        private var index_from: Int
 
@@ -921,6 +930,9 @@ end
 abstract class Buffer
        super Text
 
+       redef type SELFVIEW: BufferCharView
+       redef type SELFTYPE: Buffer
+
        # Modifies the char contained at pos `index`
        #
        # DEPRECATED : Use self.chars.[]= instead
@@ -949,6 +961,9 @@ class FlatBuffer
        super StringCapable
        super Buffer
 
+       redef type SELFVIEW: FlatBufferCharView
+       redef type SELFTYPE: FlatBuffer
+
        redef var chars: FlatBufferCharView = new FlatBufferCharView(self)
 
        var capacity: Int