An iterator over the characters (Unicode code points) in a String
. Typically created by
String.iter
.
String iterators pair a string with a valid byte index. This allows efficient character-by-character
processing of strings while avoiding the need to manually ensure that byte indices are used with the
correct strings.
An iterator is valid if the position i
is valid for the string s
, meaning 0 β€ i β€ s.endPos
and i
lies on a UTF8 byte boundary. If i = s.endPos
, the iterator is at the end of the string.
Most operations on iterators return unspecified values if the iterator is not valid. The functions
in the String.Iterator
API rule out the creation of invalid iterators, with two exceptions:
-
Iterator.next iter
is invalid if iter
is already at the end of the string (iter.atEnd
is
true
), and
-
Iterator.forward iter n
/Iterator.nextn iter n
is invalid if n
is strictly greater than the
number of remaining characters.
Constructor
Fields
s : String
The string being iterated over.
i : String.Pos
The current UTF-8 byte position in the string s
.
This position is not guaranteed to be valid for the string. If the position is not valid, then the
current character is (default : Char)
, similar to String.get
on an invalid position.