]>
git.saurik.com Git - apple/icu.git/blob - icuSources/common/usetiter.cpp
2 **********************************************************************
3 * Copyright (c) 2002-2006, 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
) {
26 * Create an iterator. Convenience for when the contents are to be set later.
28 UnicodeSetIterator::UnicodeSetIterator() {
34 UnicodeSetIterator::~UnicodeSetIterator() {
39 * Returns the next element in the set.
40 * @return true if there was another element in the set.
41 * if so, if codepoint == IS_STRING, the value is a string in the string field
42 * else the value is a single code point in the codepoint field.
43 * <br>You are guaranteed that the codepoints are in sorted order, and the strings are in sorted order,
44 * and that all code points are returned before any strings are returned.
45 * <br>Note also that the codepointEnd is undefined after calling this method.
47 UBool
UnicodeSetIterator::next() {
48 if (nextElement
<= endElement
) {
49 codepoint
= codepointEnd
= nextElement
++;
53 if (range
< endRange
) {
55 codepoint
= codepointEnd
= nextElement
++;
60 if (nextString
>= stringCount
) return FALSE
;
61 codepoint
= (UChar32
)IS_STRING
; // signal that value is actually a string
62 string
= (const UnicodeString
*) set
->strings
->elementAt(nextString
++);
67 * @return true if there was another element in the set.
68 * if so, if codepoint == IS_STRING, the value is a string in the string field
69 * else the value is a range of codepoints in the <codepoint, codepointEnd> fields.
70 * <br>Note that the codepoints are in sorted order, and the strings are in sorted order,
71 * and that all code points are returned before any strings are returned.
72 * <br>You are guaranteed that the ranges are in sorted order, and the strings are in sorted order,
73 * and that all ranges are returned before any strings are returned.
74 * <br>You are also guaranteed that ranges are disjoint and non-contiguous.
75 * <br>Note also that the codepointEnd is undefined after calling this method.
77 UBool
UnicodeSetIterator::nextRange() {
79 if (nextElement
<= endElement
) {
80 codepointEnd
= endElement
;
81 codepoint
= nextElement
;
82 nextElement
= endElement
+1;
85 if (range
< endRange
) {
87 codepointEnd
= endElement
;
88 codepoint
= nextElement
;
89 nextElement
= endElement
+1;
93 if (nextString
>= stringCount
) return FALSE
;
94 codepoint
= (UChar32
)IS_STRING
; // signal that value is actually a string
95 string
= (const UnicodeString
*) set
->strings
->elementAt(nextString
++);
100 *@param set the set to iterate over. This allows reuse of the iterator.
102 void UnicodeSetIterator::reset(const UnicodeSet
& uSet
) {
108 * Resets to the start, to allow the iteration to start over again.
110 void UnicodeSetIterator::reset() {
112 // Set up indices to empty iteration
116 endRange
= set
->getRangeCount() - 1;
117 stringCount
= set
->strings
->size();
129 void UnicodeSetIterator::loadRange(int32_t iRange
) {
130 nextElement
= set
->getRangeStart(iRange
);
131 endElement
= set
->getRangeEnd(iRange
);
135 const UnicodeString
& UnicodeSetIterator::getString() {
136 if (string
==NULL
&& codepoint
!=(UChar32
)IS_STRING
) {
137 if (cpString
== NULL
) {
138 cpString
= new UnicodeString();
140 if (cpString
!= NULL
) {
141 cpString
->setTo((UChar32
)codepoint
);