]>
git.saurik.com Git - apple/icu.git/blob - icuSources/common/usetiter.cpp
2 **********************************************************************
3 * Copyright (c) 2002-2003, International Business Machines
4 * Corporation and others. All Rights Reserved.
5 **********************************************************************
7 #include "unicode/usetiter.h"
8 #include "unicode/uniset.h"
9 #include "unicode/unistr.h"
14 UOBJECT_DEFINE_RTTI_IMPLEMENTATION(UnicodeSetIterator
)
18 * @param set set to iterate over
20 UnicodeSetIterator::UnicodeSetIterator(const UnicodeSet
& uSet
) {
25 * Create an iterator. Convenience for when the contents are to be set later.
27 UnicodeSetIterator::UnicodeSetIterator() {
32 UnicodeSetIterator::~UnicodeSetIterator() {
37 * Returns the next element in the set.
38 * @return true if there was another element in the set.
39 * if so, if codepoint == IS_STRING, the value is a string in the string field
40 * else the value is a single code point in the codepoint field.
41 * <br>You are guaranteed that the codepoints are in sorted order, and the strings are in sorted order,
42 * and that all code points are returned before any strings are returned.
43 * <br>Note also that the codepointEnd is undefined after calling this method.
45 UBool
UnicodeSetIterator::next() {
46 if (nextElement
<= endElement
) {
47 codepoint
= codepointEnd
= nextElement
++;
50 if (range
< endRange
) {
52 codepoint
= codepointEnd
= nextElement
++;
56 if (nextString
>= stringCount
) return FALSE
;
57 codepoint
= (UChar32
)IS_STRING
; // signal that value is actually a string
58 string
= (const UnicodeString
*) set
->strings
->elementAt(nextString
++);
63 * @return true if there was another element in the set.
64 * if so, if codepoint == IS_STRING, the value is a string in the string field
65 * else the value is a range of codepoints in the <codepoint, codepointEnd> fields.
66 * <br>Note that the codepoints are in sorted order, and the strings are in sorted order,
67 * and that all code points are returned before any strings are returned.
68 * <br>You are guaranteed that the ranges are in sorted order, and the strings are in sorted order,
69 * and that all ranges are returned before any strings are returned.
70 * <br>You are also guaranteed that ranges are disjoint and non-contiguous.
71 * <br>Note also that the codepointEnd is undefined after calling this method.
73 UBool
UnicodeSetIterator::nextRange() {
74 if (nextElement
<= endElement
) {
75 codepointEnd
= endElement
;
76 codepoint
= nextElement
;
77 nextElement
= endElement
+1;
80 if (range
< endRange
) {
82 codepointEnd
= endElement
;
83 codepoint
= nextElement
;
84 nextElement
= endElement
+1;
88 if (nextString
>= stringCount
) return FALSE
;
89 codepoint
= (UChar32
)IS_STRING
; // signal that value is actually a string
90 string
= (const UnicodeString
*) set
->strings
->elementAt(nextString
++);
95 *@param set the set to iterate over. This allows reuse of the iterator.
97 void UnicodeSetIterator::reset(const UnicodeSet
& uSet
) {
103 * Resets to the start, to allow the iteration to start over again.
105 void UnicodeSetIterator::reset() {
107 // Set up indices to empty iteration
111 endRange
= set
->getRangeCount() - 1;
112 stringCount
= set
->strings
->size();
123 void UnicodeSetIterator::loadRange(int32_t iRange
) {
124 nextElement
= set
->getRangeStart(iRange
);
125 endElement
= set
->getRangeEnd(iRange
);