From e62e8740b609f92a2340b438b13060783fb1924c Mon Sep 17 00:00:00 2001 From: Lucas Bajolet Date: Fri, 7 Mar 2014 13:54:52 -0500 Subject: [PATCH] stdlib/strings: Added empty method to unify the production of an empty text. Signed-off-by: Lucas Bajolet --- lib/standard/string.nit | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/standard/string.nit b/lib/standard/string.nit index d808851..d3b0eb9 100644 --- a/lib/standard/string.nit +++ b/lib/standard/string.nit @@ -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 -- 1.7.9.5