if pos == null then pos = 0
if ln == null then ln = length - pos
if ln < 6 then return 0xFFFD.code_point
- var cp = from_utf16_digit(pos + 2)
- if cp < 0xD800 then return cp.code_point
- if cp > 0xDFFF then return cp.code_point
- if cp > 0xDBFF then return 0xFFFD.code_point
+ var cp = from_utf16_digit(pos + 2).to_u32
+ if cp < 0xD800u32 then return cp.code_point
+ if cp > 0xDFFFu32 then return cp.code_point
+ if cp > 0xDBFFu32 then return 0xFFFD.code_point
if ln == 6 then return 0xFFFD.code_point
if ln < 12 then return 0xFFFD.code_point
cp <<= 16
- cp += from_utf16_digit(pos + 8)
- var cplo = cp & 0xFFFF
- if cplo < 0xDC00 then return 0xFFFD.code_point
- if cplo > 0xDFFF then return 0xFFFD.code_point
+ cp += from_utf16_digit(pos + 8).to_u32
+ var cplo = cp & 0xFFFFu32
+ if cplo < 0xDC00u32 then return 0xFFFD.code_point
+ if cplo > 0xDFFFu32 then return 0xFFFD.code_point
return cp.from_utf16_surr.code_point
end
# Decode `self` from percent (or URL) encoding to a clear string
#
- # Replace invalid use of '%' with '?'.
+ # Invalid '%' are not decoded.
#
# assert "aBc09-._~".from_percent_encoding == "aBc09-._~"
# assert "%25%28%29%3c%20%3e".from_percent_encoding == "%()< >"
# assert ".com%2fpost%3fe%3dasdf%26f%3d123".from_percent_encoding == ".com/post?e=asdf&f=123"
# assert "%25%28%29%3C%20%3E".from_percent_encoding == "%()< >"
- # assert "incomplete %".from_percent_encoding == "incomplete ?"
- # assert "invalid % usage".from_percent_encoding == "invalid ? usage"
+ # assert "incomplete %".from_percent_encoding == "incomplete %"
+ # assert "invalid % usage".from_percent_encoding == "invalid % usage"
# assert "%c3%a9%e3%81%82%e3%81%84%e3%81%86".from_percent_encoding == "éあいう"
+ # assert "%1 %A %C3%A9A9".from_percent_encoding == "%1 %A éA9"
fun from_percent_encoding: String
do
var len = byte_length
if c == '%' then
if i + 2 >= length then
# What follows % has been cut off
- buf[l] = '?'.ascii
+ buf[l] = '%'.ascii
else
i += 1
var hex_s = substring(i, 2)
i += 1
else
# What follows a % is not Hex
- buf[l] = '?'.ascii
+ buf[l] = '%'.ascii
i -= 1
end
end
l += 1
end
- return buf.to_s_unsafe(l)
+ return buf.to_s_unsafe(l, copy=false)
end
# Escape the characters `<`, `>`, `&`, `"`, `'` and `/` as HTML/XML entity references.
#
# var ns = new CString(8)
# "Text is String".copy_to_native(ns, 8, 2, 0)
- # assert ns.to_s_unsafe(8) == "xt is St"
+ # assert ns.to_s_with_length(8) == "xt is St"
#
fun copy_to_native(dest: CString, n, src_offset, dest_offset: Int) do
var mypos = src_offset
var ns = new CString(nslen + 1)
ns[nslen] = 0u8
native_byte_to_s(ns, nslen + 1)
- return ns.to_s_unsafe(nslen)
+ return ns.to_s_unsafe(nslen, copy=false, clean=false)
end
end
var ln = u8char_len
var ns = new CString(ln + 1)
u8char_tos(ns, ln)
- return ns.to_s_unsafe(ln)
+ return ns.to_s_unsafe(ln, copy=false, clean=false)
end
# Returns `self` escaped to UTF-16
# other library services rely on UTF-8 compliant characters.
fun to_s_unsafe(byte_length, char_length: nullable Int, copy, clean: nullable Bool): String is abstract
+ # Retro-compatibility service use by execution engines
+ #
+ # TODO remove this method at the next c_src regen.
+ private fun to_s_full(byte_length, char_length: Int): String do return to_s_unsafe(byte_length, char_length, false, false)
+
# Copies the content of `src` to `self`
#
# NOTE: `self` must be large enough to contain `self.byte_length` bytes