From: Lucas Bajolet Date: Mon, 21 Jul 2014 16:03:12 +0000 (-0400) Subject: lib/string_ext/utf8: to_cstring will work on UTF-8 strings now. X-Git-Tag: v0.6.7~9^2~5 X-Git-Url: http://nitlanguage.org lib/string_ext/utf8: to_cstring will work on UTF-8 strings now. Signed-off-by: Lucas Bajolet --- diff --git a/lib/string_experimentations/utf8.nit b/lib/string_experimentations/utf8.nit index 629793c..dc177ca 100644 --- a/lib/string_experimentations/utf8.nit +++ b/lib/string_experimentations/utf8.nit @@ -159,6 +159,16 @@ redef class FlatString self.bytelen = bytelen end + redef fun to_cstring + do + if real_items != null then return real_items.as(not null) + var new_items = calloc_string(bytelen + 1) + self.items.copy_to(new_items, bytelen, index[index_from].pos, 0) + new_items[bytelen] = '\0' + self.real_items = new_items + return new_items + end + redef fun substring(from, count) do assert count >= 0