![]() |
Vault
4.1
|
VStringIterator iterates through a VString over its UTF-8 code points. More...
#include <vstringiterator.h>
Public Member Functions | |
VStringIterator (const VStringIterator &iter) | |
VStringIterator (vstring_ref source, bool isForwardIterator, bool goToEnd=false) | |
VStringIterator & | operator= (const VStringIterator &iter) |
VCodePoint | operator* () const |
VStringIterator | operator+ (int n) const |
VStringIterator | operator- (int n) const |
VStringIterator & | operator+= (int n) |
VStringIterator & | operator-= (int n) |
VStringIterator & | operator++ () |
VStringIterator & | operator-- () |
int | getCurrentOffset () const |
Friends | |
bool | operator== (const VStringIterator< vstring_ref > &i1, const VStringIterator< vstring_ref > &i2) |
bool | operator!= (const VStringIterator< vstring_ref > &i1, const VStringIterator< vstring_ref > &i2) |
VStringIterator iterates through a VString over its UTF-8 code points.
That is, as you iterate, the (*()) operator returns the VCodePoint at the current iterator position. Normal forward iteration is done by calling VString::begin() to get the start, and testing inquality with VString::end(). You simply increment/decrement the iterator to move forwards and backwards. Reverse iteration is done by calling VString::rbegin() to get the "start" (really the last code point) and testing inquality with VString::rend(). Increment a reverse iterator goes backwards in the string. You can also use +/- and +=/-= operators to increment and decrement, in addition to the more common ++/--. If you go out of bounds with incrementing/decrementing/addition/subtraction, a VRangeException will be thrown.
VStringIterator is the proper way to grab some random-indexed Unicode value out of a string. In contrast, if you just write this: char c = s[5]; then you are just getting the 5th byte as a C char, which is fine and works for many things like search or search-and-replace, but is not Unicode-aware in terms of say, "get me the 5th character of the string". Instead, if you need to be Unicode-aware in your string manipulation, you would write: VCodePoint cp = *(s.begin() + 5);
(TODO: Maybe I should rewrite the VString operators to do this internally, and rename the byte-oriented accessors.)
Internal implementation notes: Think of the string as an array of n code points. (In reality they are of different sizes.) We of course keep an index into the string's array of bytes, but always incrementing and decrementing across actual code point boundaries.
Definition at line 54 of file vstringiterator.h.