From: Lucas Bajolet Date: Tue, 25 Mar 2014 19:31:24 +0000 (-0400) Subject: stdlib/strings: Modified constructor for Buffer, now works with any kind of text. X-Git-Tag: v0.6.5~7^2~3^2~8 X-Git-Url: http://nitlanguage.org stdlib/strings: Modified constructor for Buffer, now works with any kind of text. Signed-off-by: Lucas Bajolet --- diff --git a/lib/standard/string.nit b/lib/standard/string.nit index cbd6c09..30abdd9 100644 --- a/lib/standard/string.nit +++ b/lib/standard/string.nit @@ -1023,12 +1023,22 @@ class FlatBuffer with_capacity(5) end - init from(s: String) + init from(s: Text) do capacity = s.length + 1 length = s.length items = calloc_string(capacity) - s.items.copy_to(items, length, s.index_from, 0) + if s isa FlatString then + s.items.copy_to(items, length, s.index_from, 0) + else if s isa FlatBuffer then + s.items.copy_to(items, length, 0, 0) + else + var curr_pos = 0 + for i in s.chars do + items[curr_pos] = i + curr_pos += 1 + end + end end # Create a new empty string with a given capacity.