lib/core: intro to_s_with_copy_and_length
authorAlexis Laferrière <alexis.laf@xymus.net>
Fri, 15 Apr 2016 22:01:35 +0000 (18:01 -0400)
committerAlexis Laferrière <alexis.laf@xymus.net>
Mon, 18 Apr 2016 19:23:13 +0000 (15:23 -0400)
Signed-off-by: Alexis Laferrière <alexis.laf@xymus.net>

lib/core/text/flat.nit

index 18fdabe..3647344 100644 (file)
@@ -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)