scoop:scoop.core:0.1.0
src/string_iterator.scoop
Selected production source · src/string_iterator.scoop
1
internal class StringIterator(private val text: String) : Iterator<Char> {2
private var byteCursor: Long = 0L4
public override fun next(): Char? {5
if (byteCursor == text.byteLength) { return None }6
val value = coreStringCharacterAtByte(text, byteCursor)7
val code = value.code8
val width = if (code <= 127) { 1L } else {9
if (code <= 2047) { 2L } else {10
if (code <= 65535) { 3L } else { 4L }11
}12
}13
byteCursor = byteCursor + width14
return Some(value)15
}16
}