]>
git.saurik.com Git - apple/icu.git/blob - icuSources/common/uchriter.cpp
2 ******************************************************************************
3 * Copyright (C) 1998-2004, International Business Machines Corporation and *
4 * others. All Rights Reserved. *
5 ******************************************************************************
8 #include "unicode/uchriter.h"
9 #include "unicode/ustring.h"
14 UOBJECT_DEFINE_RTTI_IMPLEMENTATION(UCharCharacterIterator
)
16 UCharCharacterIterator::UCharCharacterIterator()
17 : CharacterIterator(),
20 // never default construct!
23 UCharCharacterIterator::UCharCharacterIterator(const UChar
* textPtr
,
25 : CharacterIterator(textPtr
!= 0 ? (length
>=0 ? length
: u_strlen(textPtr
)) : 0),
30 UCharCharacterIterator::UCharCharacterIterator(const UChar
* textPtr
,
33 : CharacterIterator(textPtr
!= 0 ? (length
>=0 ? length
: u_strlen(textPtr
)) : 0, position
),
38 UCharCharacterIterator::UCharCharacterIterator(const UChar
* textPtr
,
43 : CharacterIterator(textPtr
!= 0 ? (length
>=0 ? length
: u_strlen(textPtr
)) : 0, textBegin
, textEnd
, position
),
48 UCharCharacterIterator::UCharCharacterIterator(const UCharCharacterIterator
& that
)
49 : CharacterIterator(that
),
54 UCharCharacterIterator
&
55 UCharCharacterIterator::operator=(const UCharCharacterIterator
& that
) {
56 CharacterIterator::operator=(that
);
61 UCharCharacterIterator::~UCharCharacterIterator() {
65 UCharCharacterIterator::operator==(const ForwardCharacterIterator
& that
) const {
70 if (getDynamicClassID() != that
.getDynamicClassID()) {
74 UCharCharacterIterator
& realThat
= (UCharCharacterIterator
&)that
;
76 return text
== realThat
.text
77 && textLength
== realThat
.textLength
78 && pos
== realThat
.pos
79 && begin
== realThat
.begin
80 && end
== realThat
.end
;
84 UCharCharacterIterator::hashCode() const {
85 return uhash_hashUCharsN(text
, textLength
) ^ pos
^ begin
^ end
;
89 UCharCharacterIterator::clone() const {
90 return new UCharCharacterIterator(*this);
94 UCharCharacterIterator::first() {
104 UCharCharacterIterator::firstPostInc() {
114 UCharCharacterIterator::last() {
124 UCharCharacterIterator::setIndex(int32_t position
) {
125 if(position
< begin
) {
127 } else if(position
> end
) {
140 UCharCharacterIterator::current() const {
141 if (pos
>= begin
&& pos
< end
) {
149 UCharCharacterIterator::next() {
153 /* make current() return DONE */
160 UCharCharacterIterator::nextPostInc() {
169 UCharCharacterIterator::hasNext() {
170 return (UBool
)(pos
< end
? TRUE
: FALSE
);
174 UCharCharacterIterator::previous() {
183 UCharCharacterIterator::hasPrevious() {
184 return (UBool
)(pos
> begin
? TRUE
: FALSE
);
188 UCharCharacterIterator::first32() {
193 UTF_NEXT_CHAR(text
, i
, end
, c
);
201 UCharCharacterIterator::first32PostInc() {
205 UTF_NEXT_CHAR(text
, pos
, end
, c
);
213 UCharCharacterIterator::last32() {
217 UTF_PREV_CHAR(text
, begin
, pos
, c
);
225 UCharCharacterIterator::setIndex32(int32_t position
) {
226 if(position
< begin
) {
228 } else if(position
> end
) {
232 UTF_SET_CHAR_START(text
, begin
, position
);
233 int32_t i
= this->pos
= position
;
235 UTF_NEXT_CHAR(text
, i
, end
, c
);
238 this->pos
= position
;
244 UCharCharacterIterator::current32() const {
245 if (pos
>= begin
&& pos
< end
) {
247 UTF_GET_CHAR(text
, begin
, pos
, end
, c
);
255 UCharCharacterIterator::next32() {
257 UTF_FWD_1(text
, pos
, end
);
261 UTF_NEXT_CHAR(text
, i
, end
, c
);
265 /* make current() return DONE */
271 UCharCharacterIterator::next32PostInc() {
274 UTF_NEXT_CHAR(text
, pos
, end
, c
);
282 UCharCharacterIterator::previous32() {
285 UTF_PREV_CHAR(text
, begin
, pos
, c
);
293 UCharCharacterIterator::move(int32_t delta
, CharacterIterator::EOrigin origin
) {
310 } else if(pos
> end
) {
318 UCharCharacterIterator::move32(int32_t delta
, CharacterIterator::EOrigin origin
) {
319 // this implementation relies on the "safe" version of the UTF macros
320 // (or the trustworthiness of the caller)
325 UTF_FWD_N(text
, pos
, end
, delta
);
330 UTF_FWD_N(text
, pos
, end
, delta
);
332 UTF_BACK_N(text
, begin
, pos
, -delta
);
338 UTF_BACK_N(text
, begin
, pos
, -delta
);
348 void UCharCharacterIterator::setText(const UChar
* newText
,
349 int32_t newTextLength
) {
351 if(newText
== 0 || newTextLength
< 0) {
354 end
= textLength
= newTextLength
;
359 UCharCharacterIterator::getText(UnicodeString
& result
) {
360 result
= UnicodeString(text
, textLength
);