]>
git.saurik.com Git - apple/icu.git/blob - icuSources/common/uchriter.cpp
2 ******************************************************************************
3 * Copyright (C) 1998-2010, International Business Machines Corporation and
4 * others. All Rights Reserved.
5 ******************************************************************************
8 #include <typeinfo> // for 'typeid' to work
10 #include "unicode/uchriter.h"
11 #include "unicode/ustring.h"
16 UOBJECT_DEFINE_RTTI_IMPLEMENTATION(UCharCharacterIterator
)
18 UCharCharacterIterator::UCharCharacterIterator()
19 : CharacterIterator(),
22 // never default construct!
25 UCharCharacterIterator::UCharCharacterIterator(const UChar
* textPtr
,
27 : CharacterIterator(textPtr
!= 0 ? (length
>=0 ? length
: u_strlen(textPtr
)) : 0),
32 UCharCharacterIterator::UCharCharacterIterator(const UChar
* textPtr
,
35 : CharacterIterator(textPtr
!= 0 ? (length
>=0 ? length
: u_strlen(textPtr
)) : 0, position
),
40 UCharCharacterIterator::UCharCharacterIterator(const UChar
* textPtr
,
45 : CharacterIterator(textPtr
!= 0 ? (length
>=0 ? length
: u_strlen(textPtr
)) : 0, textBegin
, textEnd
, position
),
50 UCharCharacterIterator::UCharCharacterIterator(const UCharCharacterIterator
& that
)
51 : CharacterIterator(that
),
56 UCharCharacterIterator
&
57 UCharCharacterIterator::operator=(const UCharCharacterIterator
& that
) {
58 CharacterIterator::operator=(that
);
63 UCharCharacterIterator::~UCharCharacterIterator() {
67 UCharCharacterIterator::operator==(const ForwardCharacterIterator
& that
) const {
71 if (typeid(*this) != typeid(that
)) {
75 UCharCharacterIterator
& realThat
= (UCharCharacterIterator
&)that
;
77 return text
== realThat
.text
78 && textLength
== realThat
.textLength
79 && pos
== realThat
.pos
80 && begin
== realThat
.begin
81 && end
== realThat
.end
;
85 UCharCharacterIterator::hashCode() const {
86 return uhash_hashUCharsN(text
, textLength
) ^ pos
^ begin
^ end
;
90 UCharCharacterIterator::clone() const {
91 return new UCharCharacterIterator(*this);
95 UCharCharacterIterator::first() {
105 UCharCharacterIterator::firstPostInc() {
115 UCharCharacterIterator::last() {
125 UCharCharacterIterator::setIndex(int32_t position
) {
126 if(position
< begin
) {
128 } else if(position
> end
) {
141 UCharCharacterIterator::current() const {
142 if (pos
>= begin
&& pos
< end
) {
150 UCharCharacterIterator::next() {
154 /* make current() return DONE */
161 UCharCharacterIterator::nextPostInc() {
170 UCharCharacterIterator::hasNext() {
171 return (UBool
)(pos
< end
? TRUE
: FALSE
);
175 UCharCharacterIterator::previous() {
184 UCharCharacterIterator::hasPrevious() {
185 return (UBool
)(pos
> begin
? TRUE
: FALSE
);
189 UCharCharacterIterator::first32() {
194 UTF_NEXT_CHAR(text
, i
, end
, c
);
202 UCharCharacterIterator::first32PostInc() {
206 UTF_NEXT_CHAR(text
, pos
, end
, c
);
214 UCharCharacterIterator::last32() {
218 UTF_PREV_CHAR(text
, begin
, pos
, c
);
226 UCharCharacterIterator::setIndex32(int32_t position
) {
227 if(position
< begin
) {
229 } else if(position
> end
) {
233 UTF_SET_CHAR_START(text
, begin
, position
);
234 int32_t i
= this->pos
= position
;
236 UTF_NEXT_CHAR(text
, i
, end
, c
);
239 this->pos
= position
;
245 UCharCharacterIterator::current32() const {
246 if (pos
>= begin
&& pos
< end
) {
248 UTF_GET_CHAR(text
, begin
, pos
, end
, c
);
256 UCharCharacterIterator::next32() {
258 UTF_FWD_1(text
, pos
, end
);
262 UTF_NEXT_CHAR(text
, i
, end
, c
);
266 /* make current() return DONE */
272 UCharCharacterIterator::next32PostInc() {
275 UTF_NEXT_CHAR(text
, pos
, end
, c
);
283 UCharCharacterIterator::previous32() {
286 UTF_PREV_CHAR(text
, begin
, pos
, c
);
294 UCharCharacterIterator::move(int32_t delta
, CharacterIterator::EOrigin origin
) {
311 } else if(pos
> end
) {
319 UCharCharacterIterator::move32(int32_t delta
, CharacterIterator::EOrigin origin
) {
320 // this implementation relies on the "safe" version of the UTF macros
321 // (or the trustworthiness of the caller)
326 UTF_FWD_N(text
, pos
, end
, delta
);
331 UTF_FWD_N(text
, pos
, end
, delta
);
333 UTF_BACK_N(text
, begin
, pos
, -delta
);
339 UTF_BACK_N(text
, begin
, pos
, -delta
);
349 void UCharCharacterIterator::setText(const UChar
* newText
,
350 int32_t newTextLength
) {
352 if(newText
== 0 || newTextLength
< 0) {
355 end
= textLength
= newTextLength
;
360 UCharCharacterIterator::getText(UnicodeString
& result
) {
361 result
= UnicodeString(text
, textLength
);