pos
Index is expressed in Unicode chars
assert "かきく".as(FlatString).items.char_at(0) == 'か'
If the char at position pos is an invalid Unicode char, the Unicode replacement character � (0xFFFD) will be used.
assert "かきく".as(FlatString).items.char_at(1) == '�'
# Gets the UTF-8 char at index `pos`
#
# Index is expressed in Unicode chars
#
# ~~~raw
# assert "かきく".as(FlatString).items.char_at(0) == 'か'
# ~~~
#
# If the char at position pos is an invalid Unicode char,
# the Unicode replacement character � (0xFFFD) will be used.
#
# ~~~raw
# assert "かきく".as(FlatString).items.char_at(1) == '�'
# ~~~
fun char_at(pos: Int): Char do
var c = self[pos]
if c & 0x80 == 0 then return c.code_point
var b = fetch_4_hchars(pos)
var ret = 0u32
if b & 0xC00000u32 != 0x800000u32 then return 0xFFFD.code_point
if b & 0xE0000000u32 == 0xC0000000u32 then
ret |= (b & 0x1F000000u32) >> 18
ret |= (b & 0x3F0000u32) >> 16
return ret.code_point
end
if not b & 0xC000u32 == 0x8000u32 then return 0xFFFD.code_point
if b & 0xF0000000u32 == 0xE0000000u32 then
ret |= (b & 0xF000000u32) >> 12
ret |= (b & 0x3F0000u32) >> 10
ret |= (b & 0x3F00u32) >> 8
return ret.code_point
end
if not b & 0xC0u32 == 0x80u32 then return 0xFFFD.code_point
if b & 0xF8000000u32 == 0xF0000000u32 then
ret |= (b & 0x7000000u32) >> 6
ret |= (b & 0x3F0000u32) >> 4
ret |= (b & 0x3F00u32) >> 2
ret |= b & 0x3Fu32
return ret.code_point
end
return 0xFFFD.code_point
end
lib/core/text/native.nit:133,2--174,4