Vault  4.1
Public Member Functions | Friends
VStringIterator< vstring_ref > Class Template Reference

VStringIterator iterates through a VString over its UTF-8 code points. More...

#include <vstringiterator.h>

List of all members.

Public Member Functions

 VStringIterator (const VStringIterator &iter)
 VStringIterator (vstring_ref source, bool isForwardIterator, bool goToEnd=false)
VStringIteratoroperator= (const VStringIterator &iter)
VCodePoint operator* () const
VStringIterator operator+ (int n) const
VStringIterator operator- (int n) const
VStringIteratoroperator+= (int n)
VStringIteratoroperator-= (int n)
VStringIteratoroperator++ ()
VStringIteratoroperator-- ()
int getCurrentOffset () const


bool operator== (const VStringIterator< vstring_ref > &i1, const VStringIterator< vstring_ref > &i2)
bool operator!= (const VStringIterator< vstring_ref > &i1, const VStringIterator< vstring_ref > &i2)

Detailed Description

template<typename vstring_ref>
class VStringIterator< vstring_ref >

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.

The documentation for this class was generated from the following file:

Copyright ©1997-2014 Trygve Isaacson. All rights reserved. This documentation was generated with Doxygen.