when reading unicode characters from an StringRead...
# announcements
p
when reading unicode characters from an StringReader, should I use method #read() returning [Int] values or is there something else to convert the characters into [kotlin.Char] first ? what is the correct way to represent unicode code points?
so basically, after removing -1 Char and Int are equivalent?
kotlin could probably provider a “nicer” method readChar(): Char? instead I guess
since using Int for delivering -1 as a sentinel value feels like a quirk
yeah, I was just thinking of an extension method… thanks for clarifying this, Ruckus 🙂
I just do it like this now:
Copy code
input.read().takeIf { it != -1 }?.toChar()
I use it to implement a tokenizer used by a parser to evaluate expressions
thanks a lot for helping 🙂
with the introduction of value classes it will probably come sooner or later
^ which are currently experimental afaik
‘value class Option<T>’ for the world :-)
true … legacy vs modern api = 1:0 i guess 😛
e
even Kotlin's
indexOf()
uses -1 as a sentinel. that will stay unless there's an inexpensive alternative