# Returns `self` as a String of `length`.
fun to_s_with_length(length: Int): String is abstract
+
+ # Returns `self` as a String with `bytelen` and `length` set
+ #
+ # SEE: `abstract_text::Text` for more infos on the difference
+ # between `Text::bytelen` and `Text::length`
+ fun to_s_full(bytelen, unilen: Int): String is abstract
end
redef class NativeArray[E]
return str
end
+ redef fun to_s_full(bytelen, unilen) do
+ return new FlatString.full(self, bytelen, 0, bytelen - 1, unilen)
+ end
+
# Returns `self` as a new String.
redef fun to_s_with_copy: FlatString
do
var native_mtype = mmodule.native_string_type
var nat = self.new_var(native_mtype)
self.add("{nat} = \"{string.escape_to_c}\";")
- var length = self.int_instance(string.bytelen)
- self.add("{res} = {self.send(self.get_property("to_s_with_length", native_mtype), [nat, length]).as(not null)};")
+ var bytelen = self.int_instance(string.bytelen)
+ var unilen = self.int_instance(string.length)
+ self.add("{res} = {self.send(self.get_property("to_s_full", native_mtype), [nat, bytelen, unilen]).as(not null)};")
self.add("{name} = {res};")
self.add("\}")
return res
fun string_instance(txt: String): Instance
do
var nat = native_string_instance(txt)
- var res = self.send(self.force_get_primitive_method("to_s_with_length", nat.mtype), [nat, self.int_instance(txt.bytelen)])
+ var res = self.send(self.force_get_primitive_method("to_s_full", nat.mtype), [nat, self.int_instance(txt.bytelen), self.int_instance(txt.length)])
assert res != null
return res
end
do
var native = v.analysis.mainmodule.native_string_type
v.add_type(native)
- var prop = v.get_method(native, "to_s_with_length")
+ var prop = v.get_method(native, "to_s_full")
v.add_monomorphic_send(native, prop)
end
end