Module: Internationalization Module Group: Unicode String Processing
Does Not Inherit
advanceCodePoints() data() difference_type iterator_category |
operator size_t() operator*() operator++() operator--() |
operator=() pointer reference RWUConstStringIterator() |
size_type value_type |
#include <rw/i18n/RWUConstStringIterator.h>
RWUConstStringIterator provides read-only access to the code points encoded by the code units within an RWBasicUString. Code points within a given string are accessed in forward or reverse order, starting from the beginning or end of the string, respectively.
Access the beginning of a string using RWUString::beginCodePointIterator(). Use operator*() on a begin iterator to return the first code point in the string.
Access the end of a string using RWUString::endCodePointIterator(). The end iterator references the location just after the last code point in the string.
Use RWUString::beginCodePointIterator() and RWUString::endCodePointIterator() and the comparison operators to determine whether an iterator has reached the beginning or end of the string.
Attempting to dereference or advance an iterator that is positioned past the end of the string, such as the iterator returned by RWUString::endCodePointIterator(), throws RWBoundsErr.
Instances of RWUConstStringIterator are returned from const RWUString objects, and from instances of classes such as RWUBreakSearch. These classes return RWUConstStringIterator instances because the instances cannot be used to modify the source string.
Bounds Checking
Bounds checking always occurs when repositioning or dereferencing an iterator. Any attempt to dereference an iterator that is in the past-the-end condition produces an RWBoundsErr exception.
Conversion Errors
An RWUConstStringIterator converts code units into code points. Code points greater than 0xFFFF are encoded as a pair of surrogate code units within the string. An RWUStringIterator cannot advance over or dereference an incomplete surrogate pair. An iterator throws an RWConversionErr exception if an incomplete surrogate pair is encountered.
#include <rw/i18n/RWUConstStringIterator.h> #include <rw/i18n/RWUString.h> #include <iostream> int main() { // "Hello,\n world.\n"; RWUChar16 buf[16] = { 0x0048, 0x0065, 0x006c, 0x006c, 0x006f, 0x002c, 0x000d, 0x0020, 0x0077, 0x006f, 0x0072, 0x006c, 0x0064, 0x002e, 0x000d, 0x0000 }; // Create the RWUString from the buffer RWUString str(buf); const RWUString& strRef = str; // Iterate backward over all code points in the string RWUConstStringIterator it = strRef.endCodePointIterator(); while (it != strRef.beginCodePointIterator()) { --it; std::cout << std::hex << int(*it) << std::endl; } // while return 0; } // main Results: ======== d 2e 64 6c 72 6f 77 20 d 2c 6f 6c 6c 65 48
RWBasicUString, RWUString, RWUStringIterator, RWUBreakSearch
typedef int difference_type;
Declares a conventional Standard C++ alias for the type used to represent iterator offsets and differences.
typedef RW_SL_STD(bidirectional_iterator_tag) iterator_category;
Declares this class to be a Standard C++ bidirectional iterator.
typedef value_type* pointer;
Declares a conventional Standard C++ alias for the value pointer type.
typedef value_type& reference;
Declares a conventional Standard C++ alias for the value reference type.
typedef size_t size_type;
Declares a conventional Standard C++ alias for the type used to represent sizes and indices.
typedef RWUChar32 value_type;
Declares a conventional Standard C++ alias for the value type returned by this iterator class.
bool operator==(const RWUConstStringIterator& lhs, const RWUConstStringIterator& rhs);
Returns true if both iterators reference the same RWUString, and are positioned at the same code point offset within the RWUString; otherwise, false.
bool operator==(const RWUConstStringIterator& lhs, const RWUStringIterator& rhs);
Returns true if both iterators reference the same RWUString, and are positioned at the same code point offset within RWUString; otherwise, false.
bool operator!=(const RWUConstStringIterator& lhs, const RWUConstStringIterator& rhs);
Returns true if the two iterators reference different RWUString objects, or if the code point offsets referenced by the iterators are different; otherwise, false.
bool operator!=(const RWUConstStringIterator& lhs, const RWUStringIterator& rhs);
Returns true if the two iterators reference different RWUString objects, or if the code point offsets referenced by the iterators are different; otherwise, false.
RWUConstStringIterator();
Constructs a null, non-dereferencable iterator. The instance cannot be used until a dereferencable iterator is assigned to it. Any attempt to reposition or dereference a null iterator throws RWBoundsErr.
RWUConstStringIterator(const RWBasicUString& ustr);
Constructs an RWUConstStringIterator that is positioned at the first element of ustr, or past-the-end of ustr if ustr is empty.
RWUConstStringIterator(const RWUConstStringIterator& iter);
Constructs an RWUConstStringIterator that references the same string and offset as iter.
RWUConstStringIterator(const RWUStringIterator& iter);
Constructs an RWUConstStringIterator that references the same string and offset as iter.
NOTE -- There is no corresponding conversion from RWUConstStringIterator to RWUStringIterator. This preserves const correctness for the iterator classes.
RWUConstStringIterator& operator=(const RWUConstStringIterator& iter);
Assignment operator. Changes self so it references the same string and offset as iter, and returns a reference to self.
RWUConstStringIterator& operator++();
Advances self to the next code point in the string and returns a reference to self.
Throws RWBoundsErr if self is already positioned one past the last code point in the string, or if self is null. The iterator position is left unchanged.
Throws RWConversionErr if the code unit sequence found at the current iterator position contains an incomplete surrogate pair where either the high surrogate or the low surrogate code unit is missing. Self is left pointing at the code unit immediately following the unpaired surrogate code unit, or one past the last code unit of the string if the unpaired surrogate is the last code unit in the string.
RWUConstStringIterator operator++(int);
Advances self to the next code point in the string, and returns a copy of the previous value of self.
Throws RWBoundsErr if self is already positioned one past the last code point in the string, or if self is null. The iterator position is left unchanged.
Throws RWConversionErr if the code unit sequence found at the current iterator position contains an incomplete surrogate pair where either the high surrogate or the low surrogate code unit is missing. Self is left pointing at the code unit immediately following the unpaired surrogate code unit, or one past the last code unit of the string if the unpaired surrogate is the last code unit in the string.
RWUConstStringIterator& operator--();
Advances self to the previous code point in the string and returns a reference to self.
Throws RWBoundsErr if self is already positioned at the beginning of the string, or if self is null. The iterator position is left unchanged.
Throws RWConversionErr if the code unit sequence found at the current iterator position contains an incomplete surrogate pair where either the high surrogate or the low surrogate code unit is missing. Self is left pointing at the unpaired code unit.
RWUConstStringIterator operator--(int);
Advances self to the previous code point in the string and returns a copy of the previous value of self.
Throws RWBoundsErr if self is already positioned at the beginning of the string, or if self is null. The iterator position is left unchanged.
Throws RWConversionErr if the code unit sequence found at the current iterator position contains an incomplete surrogate pair where either the high surrogate or the low surrogate code unit is missing. Self is left pointing at the unpaired code unit.
RWUChar32 operator*() const;
Returns the value of the code point currently referenced by self.
Throws RWBoundsErr if self is null or otherwise references a position outside the bounds of the string.
Throws RWConversionErr if the code unit sequence found at the current iterator position contains an incomplete surrogate pair where either the high surrogate or the low surrogate code unit is missing.
operator size_t() const;
Returns the current code unit offset of self.
void advanceCodePoints(int offset);
Advances self by offset code points.
Throws RWBoundsErr if self is advanced before the first element or after one past the last element in the string. If offset is negative, the iterator is left pointing at the first element in the string. If offset is positive, the iterator is left pointing one past the last element in the string. RWBoundsErr is also thrown if self is null and not dereferencable.
Throws RWConversionErr if an incomplete surrogate pair is encountered where either the high surrogate or the low surrogate code unit is missing. If offset is negative, the iterator is positioned at the code unit immediately preceding the un-paired surrogate code unit, or at the first code unit of the string if the un-paired surrogate is the first code unit in the string. If offset is positive, the iterator is positioned at the code unit immediately following the un-paired surrogate code unit, or one past the last code unit of the string if the un-paired surrogate is the last code unit in the string.
const RWUChar16* data() const;
Returns a pointer to the string contents at the location referenced by self.
The storage referenced by this pointer is owned by the RWBasicUString associated with this iterator. This storage may not be deleted or modified. The pointer becomes invalid if the RWBasicUString is modified or destroyed.
© Copyright Rogue Wave Software, Inc. All Rights Reserved.
Rogue Wave and SourcePro are registered trademarks of Rogue Wave Software, Inc. in the United States and other countries. All other trademarks are the property of their respective owners.
Contact Rogue Wave about documentation or support issues.