stdlib/strings: Added empty method to unify the production of an empty text.
authorLucas Bajolet <r4pass@hotmail.com>
Fri, 7 Mar 2014 18:54:52 +0000 (13:54 -0500)
committerLucas Bajolet <r4pass@hotmail.com>
Mon, 24 Mar 2014 17:08:52 +0000 (13:08 -0400)
Signed-off-by: Lucas Bajolet <r4pass@hotmail.com>

lib/standard/string.nit

index d808851..d3b0eb9 100644 (file)
@@ -60,6 +60,9 @@ abstract class Text
        #       assert not "foo".is_empty
        fun is_empty: Bool do return self.length == 0
 
+       # Returns an empty Text of the right type
+       fun empty: SELFTYPE is abstract
+
        # Gets the first char of the Text
        #
        # DEPRECATED : Use self.chars.first instead
@@ -624,6 +627,8 @@ class String
                return new String.with_infos(items, to - realFrom + 1, realFrom, to)
        end
 
+       redef fun empty do return "".as(String)
+
        redef fun to_upper: String
        do
                var outstr = calloc_string(self.length + 1)
@@ -987,6 +992,8 @@ class FlatBuffer
 
        redef fun clear do length = 0
 
+       redef fun empty do return new FlatBuffer
+
        redef fun enlarge(cap)
        do
                var c = capacity