From: Lucas Bajolet Date: Fri, 7 Mar 2014 18:54:52 +0000 (-0500) Subject: stdlib/strings: Added empty method to unify the production of an empty text. X-Git-Tag: v0.6.5~7^2~3^2~15 X-Git-Url: http://nitlanguage.org?ds=sidebyside stdlib/strings: Added empty method to unify the production of an empty text. Signed-off-by: Lucas Bajolet --- 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