n
in UTF-8 Stringchar_from
and byte_from
are cached values to seek from.
NOTE: char_from and byte_from are not guaranteed to be valid cache values It it up to the client to ensure the validity of the information
# Gets the byte index of char at position `n` in UTF-8 String
#
# `char_from` and `byte_from` are cached values to seek from.
#
# NOTE: char_from and byte_from are not guaranteed to be valid cache values
# It it up to the client to ensure the validity of the information
fun char_to_byte_index_cached(n, char_from, byte_from: Int): Int do
var ns_i = byte_from
var my_i = char_from
var dist = n - my_i
while dist > 0 do
while dist >= 4 do
var i = fetch_4_chars(ns_i)
if i & 0x80808080u32 != 0u32 then break
ns_i += 4
my_i += 4
dist -= 4
end
if dist == 0 then break
ns_i += length_of_char_at(ns_i)
my_i += 1
dist -= 1
end
while dist < 0 do
while dist <= -4 do
var i = fetch_4_chars(ns_i - 4)
if i & 0x80808080u32 != 0u32 then break
ns_i -= 4
my_i -= 4
dist += 4
end
if dist == 0 then break
ns_i = find_beginning_of_char_at(ns_i - 1)
my_i -= 1
dist += 1
end
return ns_i
end
lib/core/text/native.nit:195,2--236,4