]>
git.saurik.com Git - apple/icu.git/blob - icuSources/common/uchriter.cpp
2 ******************************************************************************
3 * Copyright (C) 1998-2012, International Business Machines Corporation and
4 * others. All Rights Reserved.
5 ******************************************************************************
8 #include "utypeinfo.h" // for 'typeid' to work
10 #include "unicode/uchriter.h"
11 #include "unicode/ustring.h"
12 #include "unicode/utf16.h"
17 UOBJECT_DEFINE_RTTI_IMPLEMENTATION(UCharCharacterIterator
)
19 UCharCharacterIterator::UCharCharacterIterator()
20 : CharacterIterator(),
23 // never default construct!
26 UCharCharacterIterator::UCharCharacterIterator(const UChar
* textPtr
,
28 : CharacterIterator(textPtr
!= 0 ? (length
>=0 ? length
: u_strlen(textPtr
)) : 0),
33 UCharCharacterIterator::UCharCharacterIterator(const UChar
* textPtr
,
36 : CharacterIterator(textPtr
!= 0 ? (length
>=0 ? length
: u_strlen(textPtr
)) : 0, position
),
41 UCharCharacterIterator::UCharCharacterIterator(const UChar
* textPtr
,
46 : CharacterIterator(textPtr
!= 0 ? (length
>=0 ? length
: u_strlen(textPtr
)) : 0, textBegin
, textEnd
, position
),
51 UCharCharacterIterator::UCharCharacterIterator(const UCharCharacterIterator
& that
)
52 : CharacterIterator(that
),
57 UCharCharacterIterator
&
58 UCharCharacterIterator::operator=(const UCharCharacterIterator
& that
) {
59 CharacterIterator::operator=(that
);
64 UCharCharacterIterator::~UCharCharacterIterator() {
68 UCharCharacterIterator::operator==(const ForwardCharacterIterator
& that
) const {
72 if (typeid(*this) != typeid(that
)) {
76 UCharCharacterIterator
& realThat
= (UCharCharacterIterator
&)that
;
78 return text
== realThat
.text
79 && textLength
== realThat
.textLength
80 && pos
== realThat
.pos
81 && begin
== realThat
.begin
82 && end
== realThat
.end
;
86 UCharCharacterIterator::hashCode() const {
87 return ustr_hashUCharsN(text
, textLength
) ^ pos
^ begin
^ end
;
91 UCharCharacterIterator::clone() const {
92 return new UCharCharacterIterator(*this);
96 UCharCharacterIterator::first() {
106 UCharCharacterIterator::firstPostInc() {
116 UCharCharacterIterator::last() {
126 UCharCharacterIterator::setIndex(int32_t position
) {
127 if(position
< begin
) {
129 } else if(position
> end
) {
142 UCharCharacterIterator::current() const {
143 if (pos
>= begin
&& pos
< end
) {
151 UCharCharacterIterator::next() {
155 /* make current() return DONE */
162 UCharCharacterIterator::nextPostInc() {
171 UCharCharacterIterator::hasNext() {
172 return (UBool
)(pos
< end
? TRUE
: FALSE
);
176 UCharCharacterIterator::previous() {
185 UCharCharacterIterator::hasPrevious() {
186 return (UBool
)(pos
> begin
? TRUE
: FALSE
);
190 UCharCharacterIterator::first32() {
195 U16_NEXT(text
, i
, end
, c
);
203 UCharCharacterIterator::first32PostInc() {
207 U16_NEXT(text
, pos
, end
, c
);
215 UCharCharacterIterator::last32() {
219 U16_PREV(text
, begin
, pos
, c
);
227 UCharCharacterIterator::setIndex32(int32_t position
) {
228 if(position
< begin
) {
230 } else if(position
> end
) {
234 U16_SET_CP_START(text
, begin
, position
);
235 int32_t i
= this->pos
= position
;
237 U16_NEXT(text
, i
, end
, c
);
240 this->pos
= position
;
246 UCharCharacterIterator::current32() const {
247 if (pos
>= begin
&& pos
< end
) {
249 U16_GET(text
, begin
, pos
, end
, c
);
257 UCharCharacterIterator::next32() {
259 U16_FWD_1(text
, pos
, end
);
263 U16_NEXT(text
, i
, end
, c
);
267 /* make current() return DONE */
273 UCharCharacterIterator::next32PostInc() {
276 U16_NEXT(text
, pos
, end
, c
);
284 UCharCharacterIterator::previous32() {
287 U16_PREV(text
, begin
, pos
, c
);
295 UCharCharacterIterator::move(int32_t delta
, CharacterIterator::EOrigin origin
) {
312 } else if(pos
> end
) {
320 UCharCharacterIterator::move32(int32_t delta
, CharacterIterator::EOrigin origin
) {
321 // this implementation relies on the "safe" version of the UTF macros
322 // (or the trustworthiness of the caller)
327 U16_FWD_N(text
, pos
, end
, delta
);
332 U16_FWD_N(text
, pos
, end
, delta
);
334 U16_BACK_N(text
, begin
, pos
, -delta
);
340 U16_BACK_N(text
, begin
, pos
, -delta
);
350 void UCharCharacterIterator::setText(const UChar
* newText
,
351 int32_t newTextLength
) {
353 if(newText
== 0 || newTextLength
< 0) {
356 end
= textLength
= newTextLength
;
361 UCharCharacterIterator::getText(UnicodeString
& result
) {
362 result
= UnicodeString(text
, textLength
);