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.2
internal fun requireValidUtf8(result: (String?, Long)): String {3
val value = result._14
if (value == None) { throw CharacterCodingException(result._2) }5
return value!!6
}8
internal 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
}14
}15
internal 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
}21
}