Scoop API

scoop:scoop.core:0.1.0

src/string_iterator.scoop

Selected production source · src/string_iterator.scoop

1internal class StringIterator(private val text: String) : Iterator<Char> {
2 private var byteCursor: Long = 0L
4 public override fun next(): Char? {
5 if (byteCursor == text.byteLength) { return None }
6 val value = coreStringCharacterAtByte(text, byteCursor)
7 val code = value.code
8 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 + width
14 return Some(value)
15 }