# If no transformation is needed, return self as a string
if not has_percent then return to_s
# If no transformation is needed, return self as a string
if not has_percent then return to_s
# "Text is String".copy_to_native(ns, 8, 2, 0)
# assert ns.to_s_unsafe(8) == "xt is St"
#
# "Text is String".copy_to_native(ns, 8, 2, 0)
# assert ns.to_s_unsafe(8) == "xt is St"
#
- fun copy_to_native(dest: NativeString, n, src_offset, dest_offset: Int) do
+ fun copy_to_native(dest: CString, n, src_offset, dest_offset: Int) do
#
# Warning : Might be void in some subclasses, be sure to check
# if set before using it.
#
# Warning : Might be void in some subclasses, be sure to check
# if set before using it.
# Returns a char* starting at position `first_byte`
#
# WARNING: If you choose to use this service, be careful of the following.
#
# Returns a char* starting at position `first_byte`
#
# WARNING: If you choose to use this service, be careful of the following.
#
# Since the GC tracks the use of the pointer for the beginning of the char*, it may be
# deallocated at any moment, rendering the pointer returned by this function invalid.
# Any access to freed memory may very likely cause undefined behaviour or a crash.
# Since the GC tracks the use of the pointer for the beginning of the char*, it may be
# deallocated at any moment, rendering the pointer returned by this function invalid.
# Any access to freed memory may very likely cause undefined behaviour or a crash.
#
# As always, do not modify the content of the String in C code, if this is what you want
# copy locally the char* as Nit Strings are immutable.
#
# As always, do not modify the content of the String in C code, if this is what you want
# copy locally the char* as Nit Strings are immutable.
- # The class name of the object in NativeString format.
- private fun native_class_name: NativeString is intern
+ # The class name of the object in CString format.
+ private fun native_class_name: CString is intern
private fun byte_to_s_len: Int `{
return snprintf(NULL, 0, "0x%02x", self);
`}
private fun byte_to_s_len: Int `{
return snprintf(NULL, 0, "0x%02x", self);
`}
- # C function to convert an nit Int to a NativeString (char*)
- private fun native_byte_to_s(nstr: NativeString, strlen: Int) `{
+ # C function to convert an nit Int to a CString (char*)
+ private fun native_byte_to_s(nstr: CString, strlen: Int) `{
snprintf(nstr, strlen, "0x%02x", self);
`}
snprintf(nstr, strlen, "0x%02x", self);
`}
ns[nslen] = 0u8
native_byte_to_s(ns, nslen + 1)
return ns.to_s_unsafe(nslen)
ns[nslen] = 0u8
native_byte_to_s(ns, nslen + 1)
return ns.to_s_unsafe(nslen)
private fun int_to_s_len: Int `{
return snprintf(NULL, 0, "%ld", self);
`}
private fun int_to_s_len: Int `{
return snprintf(NULL, 0, "%ld", self);
`}
- # C function to convert an nit Int to a NativeString (char*)
- private fun native_int_to_s(nstr: NativeString, strlen: Int) `{
+ # C function to convert an nit Int to a CString (char*)
+ private fun native_int_to_s(nstr: CString, strlen: Int) `{
snprintf(nstr, strlen, "%ld", self);
`}
snprintf(nstr, strlen, "%ld", self);
`}
# Get a `String` from the data at `self` copied into Nit memory
#
# Require: `self` is a null-terminated string.
# Get a `String` from the data at `self` copied into Nit memory
#
# Require: `self` is a null-terminated string.