Scoop API

scoop:scoop.core:0.1.0

src/utf8.scoop

Selected production source · src/utf8.scoop

1// Public failure behavior shares the ordinary core UTF-8 decoder.
2internal fun requireValidUtf8(result: (String?, Long)): String {
3 val value = result._1
4 if (value == None) { throw CharacterCodingException(result._2) }
5 return value!!
6}
8internal fun decodeUtf8(bytes: List<Byte>): (String?, Long) {
9 @Unsafe {
10 return bytes.toArray().withDataPointer(fun(pointer: Ptr<Byte>, length: Long): (String?, Long) {
11 @Unsafe { return coreStringDecodeUtf8(pointer.cast<UInt8>(), length) }
12 })
13 }
15internal fun decodeUtf8Lossy(bytes: List<Byte>): String {
16 @Unsafe {
17 return bytes.toArray().withDataPointer(fun(pointer: Ptr<Byte>, length: Long): String {
18 @Unsafe { return coreStringDecodeUtf8Lossy(pointer.cast<UInt8>(), length) }
19 })
20 }