From: Lucas Bajolet Date: Tue, 25 Mar 2014 19:29:48 +0000 (-0400) Subject: stdlib/strings: Moved append to Buffer, now works on all known variants of Text. X-Git-Tag: v0.6.5~7^2~3^2~11 X-Git-Url: http://nitlanguage.org stdlib/strings: Moved append to Buffer, now works on all known variants of Text. Signed-off-by: Lucas Bajolet --- diff --git a/lib/standard/string.nit b/lib/standard/string.nit index f348b75..3b8f02e 100644 --- a/lib/standard/string.nit +++ b/lib/standard/string.nit @@ -946,8 +946,8 @@ abstract class Buffer # Enlarges the subsequent array containing the chars of self fun enlarge(cap: Int) is abstract - # Adds the content of string `s` at the end of self - fun append(s: String) is abstract + # Adds the content of text `s` at the end of self + fun append(s: Text) is abstract end @@ -1036,7 +1036,17 @@ class FlatBuffer do var sl = s.length if capacity < length + sl then enlarge(length + sl) - s.items.copy_to(items, sl, s.index_from, length) + if s isa String then + s.items.copy_to(items, sl, s.index_from, length) + else if s isa FlatBuffer then + s.items.copy_to(items, sl, 0, length) + else + var curr_pos = self.length + for i in s.chars do + items[curr_pos] = i + curr_pos += 1 + end + end length += sl end