martmists
09/26/2022, 6:12 PM\xFF
escapes in strings? I can only find \uFFFF
but this will likely create two bytes instead of oneephemient
09/26/2022, 6:13 PMChar
is a 16-bit valuemartmists
09/26/2022, 6:21 PMfun String.toUByteArray(): UByteArray {
val chunks = chunked(2)
val result = UByteArray(length) {
chunks[it].toUByte(16)
}
return result
}
but ideally I could just use escapes so I could do "somedata\x01\x02\x03"
instead of having to write everything as hexephemient
09/26/2022, 6:24 PM"somedata\u0001\u0002\u0003".toByteArray(Charsets.ISO_8859_1).asUByteArray()
and on multiplatform, you could
"somedata\u0001\u0002\u0003".map { it.code.toUByte() }.toUByteArray()
but there isn't really a good ergonomic way to do thisUByteArray(string.length) { string[it].code.toUByte() }
to skip the intermediate List
martmists
09/26/2022, 6:29 PMephemient
09/26/2022, 6:33 PM'a'
is a UTF-16 code unit