From: Alexis Laferrière Date: Fri, 15 Apr 2016 22:01:35 +0000 (-0400) Subject: lib/core: intro to_s_with_copy_and_length X-Git-Url: http://nitlanguage.org lib/core: intro to_s_with_copy_and_length Signed-off-by: Alexis Laferrière --- diff --git a/lib/core/text/flat.nit b/lib/core/text/flat.nit index 18fdabe..3647344 100644 --- a/lib/core/text/flat.nit +++ b/lib/core/text/flat.nit @@ -1185,9 +1185,11 @@ redef class NativeString end # Returns `self` as a new String. - redef fun to_s_with_copy: FlatString + redef fun to_s_with_copy do return to_s_with_copy_and_length(cstring_length) + + # Get a `String` from `length` bytes at `self` copied into Nit memory + fun to_s_with_copy_and_length(length: Int): String do - var length = cstring_length var r = clean_utf8(length) if r.items != self then return r var new_self = new NativeString(length + 1)