Which way Kotlin-Native deals with Strings? I mean...
# kotlin-native
m
Which way Kotlin-Native deals with Strings? I mean, '65K chars will be enough for everyone' was a mistake, UTF-16 has surrogate pairs, and Java's 16-bit `char`s are not actually characters (graphemes), just UTF-16 words. And I really like the way Rust deals with strings: 'UTF-8 everywhere' and 'grapheme cluster is a thing'. Sorry if the answer is obvious, I've never read anything about KN.
d
For things like this, the Native back-end would be pretty much the same as the JVM one. So UTF-16.
If you want some sort of documentation this is the best I could find. https://github.com/JetBrains/kotlin-native/issues/1185
👍 1
n
Strings on the JVM are UTF-8 based. Most Unix based systems (incl Linux) use UTF-8 as the default encoding. UTF-16 isn't backwards compatible with UTF-8.
o
To provide APIs required by Kotlin stdlib with decent speed we internally use utf-16, interop works with utf-8
m
But length of String and String constant is 32 bit, AFAIK.
o
Yes, up to 2^31 utf-16 characters