index += 1;
if (index < strlen) {
ch = str.charAt(index);
} else {
ch = 0;
}
If I was using kotlin, I'd do it even cleaner: inline fun String.at(index: Int): Char? =
if (index >= 0 && index < length) charAt(index)
else null
[...]
index += 1
ch = str.at(index) ?: 0;
The bytecode is exactly the same, but I’d argue it’s much cleaner