I have some formatting defined in common code between ios and android target and just noticed that they treat special chars differently which messes my impl. I can't even properly paste it into slack, so I'll use screenshots to make it clearer, but take
twenti̩
as example. This
i̩
with a little dash at the bottom is treated by kotlin as two separate chars, but swift treats it as one. So when I defined formatting which spans across the whole word in shared code with
text.length
, it calculates it as 7 chars. When I use it in Swift, which thinks of it as 6 chars (via
*let* characters = Array(text)
), I get
Fatal error: Index out of range
. Any ideas how to work with these?
Michal Klimczak
07/27/2021, 3:46 PM
it has something to do with how both systems treat utf16 but I have no idea yet how to approach this
For anyone wondering - this helped https://kotlinlang.slack.com/archives/C0922A726/p1627401848232700. The problem is that kotlin represents strings with utf16 and swift with so called 21-bit unicode scalar value.
Unfortunately I didn't find any better solution than to just create an interface
Copy code
interface TextLengthProvider {
fun length(text: String) : Int
}
and implement it on both platforms (i.e. delegate completely to the swift impl). Could not have used expect/actual, because we're dealing with pure swift here.