lib/core: intro to_s_with_copy_and_length
[nit.git] / 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)