Vitor Hugo Schwaab
11/18/2022, 10:05 AMjs()
, avoiding the dynamic
type?
For example:
val sentence = "The quick brown fox jumps over the lazy dog"
val index = 4
val charCode = js("sentence.charCodeAt($index)")
// charCode = 113
Piotr Krzemiński
11/18/2022, 11:02 AMPiotr Krzemiński
11/18/2022, 11:06 AMVitor Hugo Schwaab
11/18/2022, 11:07 AMPiotr Krzemiński
11/18/2022, 11:09 AMsentence[index].code
Vitor Hugo Schwaab
11/18/2022, 11:13 AMString.codePointAt
is just the Kotlin/JVM sugar layer.
And Char.code
is the Kotlin way of doing things.
A @see [Char.code]
in the docs of codePointAt
would be awesome 🙂. But I guess if Java changes the codePointAt
, this documentation would be brokenVitor Hugo Schwaab
11/18/2022, 11:14 AMBig Chungus
11/18/2022, 11:14 AMVitor Hugo Schwaab
11/18/2022, 11:16 AMPiotr Krzemiński
11/18/2022, 11:29 AM@Suppress("NOTHING_TO_INLINE")
inline fun String.charCodeAt(index: Int): Int = asDynamic().charCodeAt(index) as Int
val sentence = "The quick brown fox jumps over the lazy dog"
val index = 3
val charCode = sentence.charCodeAt(index)
maybe it’s possible to do it in a more idiomatic/less noisy way, but this works ☝️Big Chungus
11/18/2022, 11:29 AMBig Chungus
11/18/2022, 11:30 AMPiotr Krzemiński
11/18/2022, 11:31 AMBig Chungus
11/18/2022, 11:31 AM