stdlib/strings: Added empty method to unify the production of an empty text.
[nit.git] / 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