1ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/*
2ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru******************************************************************************
354dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius* Copyright (C) 1998-2012, International Business Machines Corporation and
427f654740f2a26ad62a5c155af9199af9e69b889claireho* others. All Rights Reserved.
5ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru******************************************************************************
6ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru*/
7ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
854dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius#include "utypeinfo.h"  // for 'typeid' to work
927f654740f2a26ad62a5c155af9199af9e69b889claireho
10ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "unicode/uchriter.h"
11ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "unicode/ustring.h"
12103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius#include "unicode/utf16.h"
13103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius#include "ustr_imp.h"
14ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
15ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruU_NAMESPACE_BEGIN
16ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
17ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruUOBJECT_DEFINE_RTTI_IMPLEMENTATION(UCharCharacterIterator)
18ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
19ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruUCharCharacterIterator::UCharCharacterIterator()
20ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  : CharacterIterator(),
21ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  text(0)
22ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{
23ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    // never default construct!
24ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
25ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
26ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruUCharCharacterIterator::UCharCharacterIterator(const UChar* textPtr,
27ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                                               int32_t length)
28ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  : CharacterIterator(textPtr != 0 ? (length>=0 ? length : u_strlen(textPtr)) : 0),
29ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  text(textPtr)
30ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{
31ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
32ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
33ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruUCharCharacterIterator::UCharCharacterIterator(const UChar* textPtr,
34ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                                               int32_t length,
35ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                                               int32_t position)
36ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  : CharacterIterator(textPtr != 0 ? (length>=0 ? length : u_strlen(textPtr)) : 0, position),
37ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  text(textPtr)
38ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{
39ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
40ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
41ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruUCharCharacterIterator::UCharCharacterIterator(const UChar* textPtr,
42ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                                               int32_t length,
43ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                                               int32_t textBegin,
44ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                                               int32_t textEnd,
45ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                                               int32_t position)
46ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  : CharacterIterator(textPtr != 0 ? (length>=0 ? length : u_strlen(textPtr)) : 0, textBegin, textEnd, position),
47ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  text(textPtr)
48ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{
49ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
50ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
51ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruUCharCharacterIterator::UCharCharacterIterator(const UCharCharacterIterator& that)
52ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru: CharacterIterator(that),
53ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  text(that.text)
54ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{
55ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
56ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
57ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruUCharCharacterIterator&
58ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruUCharCharacterIterator::operator=(const UCharCharacterIterator& that) {
59ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    CharacterIterator::operator=(that);
60ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    text = that.text;
61ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    return *this;
62ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
63ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
64ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruUCharCharacterIterator::~UCharCharacterIterator() {
65ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
66ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
67ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruUBool
68ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruUCharCharacterIterator::operator==(const ForwardCharacterIterator& that) const {
69ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (this == &that) {
70ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return TRUE;
71ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
7227f654740f2a26ad62a5c155af9199af9e69b889claireho    if (typeid(*this) != typeid(that)) {
73ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return FALSE;
74ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
75ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
76ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UCharCharacterIterator&    realThat = (UCharCharacterIterator&)that;
77ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
78ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    return text == realThat.text
79ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        && textLength == realThat.textLength
80ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        && pos == realThat.pos
81ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        && begin == realThat.begin
82ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        && end == realThat.end;
83ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
84ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
85ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruint32_t
86ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruUCharCharacterIterator::hashCode() const {
87103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius    return ustr_hashUCharsN(text, textLength) ^ pos ^ begin ^ end;
88ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
89ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
90ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruCharacterIterator*
91ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruUCharCharacterIterator::clone() const {
92ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    return new UCharCharacterIterator(*this);
93ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
94ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
95ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruUChar
96ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruUCharCharacterIterator::first() {
97ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    pos = begin;
98ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if(pos < end) {
99ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return text[pos];
100ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    } else {
101ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return DONE;
102ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
103ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
104ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
105ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruUChar
106ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruUCharCharacterIterator::firstPostInc() {
107ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    pos = begin;
108ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if(pos < end) {
109ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return text[pos++];
110ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    } else {
111ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return DONE;
112ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
113ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
114ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
115ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruUChar
116ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruUCharCharacterIterator::last() {
117ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    pos = end;
118ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if(pos > begin) {
119ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return text[--pos];
120ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    } else {
121ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return DONE;
122ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
123ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
124ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
125ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruUChar
126ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruUCharCharacterIterator::setIndex(int32_t position) {
127ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if(position < begin) {
128ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        pos = begin;
129ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    } else if(position > end) {
130ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        pos = end;
131ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    } else {
132ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        pos = position;
133ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
134ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if(pos < end) {
135ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return text[pos];
136ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    } else {
137ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return DONE;
138ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
139ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
140ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
141ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruUChar
142ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruUCharCharacterIterator::current() const {
143ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (pos >= begin && pos < end) {
144ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return text[pos];
145ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    } else {
146ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return DONE;
147ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
148ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
149ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
150ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruUChar
151ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruUCharCharacterIterator::next() {
152ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (pos + 1 < end) {
153ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return text[++pos];
154ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    } else {
155ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        /* make current() return DONE */
156ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        pos = end;
157ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return DONE;
158ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
159ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
160ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
161ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruUChar
162ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruUCharCharacterIterator::nextPostInc() {
163ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (pos < end) {
164ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return text[pos++];
165ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    } else {
166ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return DONE;
167ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
168ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
169ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
170ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruUBool
171ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruUCharCharacterIterator::hasNext() {
172ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    return (UBool)(pos < end ? TRUE : FALSE);
173ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
174ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
175ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruUChar
176ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruUCharCharacterIterator::previous() {
177ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (pos > begin) {
178ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return text[--pos];
179ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    } else {
180ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return DONE;
181ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
182ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
183ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
184ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruUBool
185ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruUCharCharacterIterator::hasPrevious() {
186ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    return (UBool)(pos > begin ? TRUE : FALSE);
187ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
188ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
189ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruUChar32
190ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruUCharCharacterIterator::first32() {
191ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    pos = begin;
192ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if(pos < end) {
193ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        int32_t i = pos;
194ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        UChar32 c;
195103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius        U16_NEXT(text, i, end, c);
196ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return c;
197ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    } else {
198ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return DONE;
199ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
200ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
201ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
202ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruUChar32
203ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruUCharCharacterIterator::first32PostInc() {
204ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    pos = begin;
205ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if(pos < end) {
206ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        UChar32 c;
207103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius        U16_NEXT(text, pos, end, c);
208ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return c;
209ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    } else {
210ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return DONE;
211ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
212ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
213ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
214ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruUChar32
215ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruUCharCharacterIterator::last32() {
216ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    pos = end;
217ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if(pos > begin) {
218ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        UChar32 c;
219103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius        U16_PREV(text, begin, pos, c);
220ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return c;
221ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    } else {
222ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return DONE;
223ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
224ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
225ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
226ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruUChar32
227ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruUCharCharacterIterator::setIndex32(int32_t position) {
228ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if(position < begin) {
229ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        position = begin;
230ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    } else if(position > end) {
231ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        position = end;
232ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
233ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if(position < end) {
234103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius        U16_SET_CP_START(text, begin, position);
235ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        int32_t i = this->pos = position;
236ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        UChar32 c;
237103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius        U16_NEXT(text, i, end, c);
238ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return c;
239ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    } else {
240ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        this->pos = position;
241ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return DONE;
242ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
243ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
244ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
245ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruUChar32
246ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruUCharCharacterIterator::current32() const {
247ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (pos >= begin && pos < end) {
248ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        UChar32 c;
249103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius        U16_GET(text, begin, pos, end, c);
250ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return c;
251ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    } else {
252ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return DONE;
253ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
254ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
255ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
256ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruUChar32
257ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruUCharCharacterIterator::next32() {
258ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (pos < end) {
259103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius        U16_FWD_1(text, pos, end);
260ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        if(pos < end) {
261ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            int32_t i = pos;
262ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            UChar32 c;
263103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius            U16_NEXT(text, i, end, c);
264ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            return c;
265ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        }
266ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
267ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /* make current() return DONE */
268ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    pos = end;
269ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    return DONE;
270ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
271ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
272ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruUChar32
273ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruUCharCharacterIterator::next32PostInc() {
274ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (pos < end) {
275ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        UChar32 c;
276103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius        U16_NEXT(text, pos, end, c);
277ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return c;
278ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    } else {
279ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return DONE;
280ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
281ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
282ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
283ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruUChar32
284ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruUCharCharacterIterator::previous32() {
285ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (pos > begin) {
286ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        UChar32 c;
287103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius        U16_PREV(text, begin, pos, c);
288ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return c;
289ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    } else {
290ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return DONE;
291ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
292ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
293ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
294ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruint32_t
295ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruUCharCharacterIterator::move(int32_t delta, CharacterIterator::EOrigin origin) {
296ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    switch(origin) {
297ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    case kStart:
298ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        pos = begin + delta;
299ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        break;
300ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    case kCurrent:
301ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        pos += delta;
302ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        break;
303ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    case kEnd:
304ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        pos = end + delta;
305ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        break;
306ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    default:
307ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        break;
308ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
309ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
310ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if(pos < begin) {
311ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        pos = begin;
312ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    } else if(pos > end) {
313ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        pos = end;
314ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
315ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
316ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    return pos;
317ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
318ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
319ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruint32_t
320ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruUCharCharacterIterator::move32(int32_t delta, CharacterIterator::EOrigin origin) {
321ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    // this implementation relies on the "safe" version of the UTF macros
322ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    // (or the trustworthiness of the caller)
323ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    switch(origin) {
324ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    case kStart:
325ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        pos = begin;
326ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        if(delta > 0) {
327103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius            U16_FWD_N(text, pos, end, delta);
328ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        }
329ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        break;
330ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    case kCurrent:
331ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        if(delta > 0) {
332103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius            U16_FWD_N(text, pos, end, delta);
333ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        } else {
334103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius            U16_BACK_N(text, begin, pos, -delta);
335ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        }
336ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        break;
337ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    case kEnd:
338ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        pos = end;
339ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        if(delta < 0) {
340103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius            U16_BACK_N(text, begin, pos, -delta);
341ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        }
342ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        break;
343ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    default:
344ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        break;
345ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
346ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
347ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    return pos;
348ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
349ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
350ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruvoid UCharCharacterIterator::setText(const UChar* newText,
351ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                                     int32_t      newTextLength) {
352ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    text = newText;
353ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if(newText == 0 || newTextLength < 0) {
354ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        newTextLength = 0;
355ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
356ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    end = textLength = newTextLength;
357ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    pos = begin = 0;
358ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
359ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
360ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruvoid
361ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruUCharCharacterIterator::getText(UnicodeString& result) {
362ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    result = UnicodeString(text, textLength);
363ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
364ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
365ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruU_NAMESPACE_END
366