1999-08-16 21:50:52 +00:00
|
|
|
/*
|
|
|
|
*******************************************************************************
|
1999-11-22 20:25:35 +00:00
|
|
|
* Copyright (C) 1998-1999, International Business Machines Corporation and *
|
|
|
|
* others. All Rights Reserved. *
|
1999-08-16 21:50:52 +00:00
|
|
|
*******************************************************************************
|
|
|
|
*/
|
|
|
|
|
1999-12-28 23:39:02 +00:00
|
|
|
#include "unicode/uchriter.h"
|
2000-04-12 19:36:30 +00:00
|
|
|
#include "uhash.h"
|
|
|
|
|
|
|
|
UCharCharacterIterator::UCharCharacterIterator()
|
|
|
|
: CharacterIterator(),
|
|
|
|
text(0),
|
|
|
|
textLength(0),
|
|
|
|
pos(0),
|
|
|
|
begin(0),
|
|
|
|
end(0)
|
|
|
|
{
|
|
|
|
// never default construct!
|
|
|
|
}
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
UCharCharacterIterator::UCharCharacterIterator(const UChar* text,
|
2000-04-12 19:36:30 +00:00
|
|
|
int32_t textLength)
|
1999-08-16 21:50:52 +00:00
|
|
|
: CharacterIterator(),
|
|
|
|
text(text),
|
2000-04-12 19:36:30 +00:00
|
|
|
textLength(textLength),
|
1999-08-16 21:50:52 +00:00
|
|
|
pos(0),
|
|
|
|
begin(0),
|
|
|
|
end(textLength)
|
|
|
|
{
|
2000-04-12 19:36:30 +00:00
|
|
|
if(text == 0 || textLength < 0) {
|
|
|
|
textLength = end = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
UCharCharacterIterator::UCharCharacterIterator(const UChar* text,
|
|
|
|
int32_t textLength,
|
|
|
|
UTextOffset pos)
|
|
|
|
: CharacterIterator(),
|
|
|
|
text(text),
|
|
|
|
textLength(textLength),
|
|
|
|
pos(pos),
|
|
|
|
begin(0),
|
|
|
|
end(textLength)
|
|
|
|
{
|
|
|
|
if(text == 0 || textLength < 0) {
|
|
|
|
textLength = end = 0;
|
|
|
|
}
|
|
|
|
if(pos < 0) {
|
|
|
|
pos = 0;
|
|
|
|
} else if(pos > end) {
|
|
|
|
pos = end;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
UCharCharacterIterator::UCharCharacterIterator(const UChar* text,
|
|
|
|
int32_t textLength,
|
|
|
|
UTextOffset begin,
|
|
|
|
UTextOffset end,
|
|
|
|
UTextOffset pos)
|
|
|
|
: CharacterIterator(),
|
|
|
|
text(text),
|
|
|
|
textLength(textLength),
|
|
|
|
pos(pos),
|
|
|
|
begin(begin),
|
|
|
|
end(end)
|
|
|
|
{
|
|
|
|
if(text == 0 || textLength < 0) {
|
|
|
|
textLength = 0;
|
|
|
|
}
|
|
|
|
if(begin < 0) {
|
|
|
|
begin = 0;
|
|
|
|
} else if(begin > textLength) {
|
|
|
|
begin = textLength;
|
|
|
|
}
|
|
|
|
if(end < begin) {
|
|
|
|
end = begin;
|
|
|
|
} else if(end > textLength) {
|
|
|
|
end = textLength;
|
|
|
|
}
|
|
|
|
if(pos < begin) {
|
|
|
|
pos = begin;
|
|
|
|
} else if(pos > end) {
|
|
|
|
pos = end;
|
|
|
|
}
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
UCharCharacterIterator::UCharCharacterIterator(const UCharCharacterIterator& that)
|
|
|
|
: CharacterIterator(that),
|
|
|
|
text(that.text),
|
2000-04-12 19:36:30 +00:00
|
|
|
textLength(that.textLength),
|
1999-08-16 21:50:52 +00:00
|
|
|
pos(that.pos),
|
|
|
|
begin(that.begin),
|
|
|
|
end(that.end)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
UCharCharacterIterator&
|
2000-04-12 19:36:30 +00:00
|
|
|
UCharCharacterIterator::operator=(const UCharCharacterIterator& that) {
|
1999-08-16 21:50:52 +00:00
|
|
|
text = that.text;
|
2000-04-12 19:36:30 +00:00
|
|
|
textLength = that.textLength;
|
1999-08-16 21:50:52 +00:00
|
|
|
pos = that.pos;
|
|
|
|
begin = that.begin;
|
|
|
|
end = that.end;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2000-04-12 19:36:30 +00:00
|
|
|
UCharCharacterIterator::~UCharCharacterIterator() {
|
|
|
|
}
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
bool_t
|
2000-04-12 19:36:30 +00:00
|
|
|
UCharCharacterIterator::operator==(const CharacterIterator& that) const {
|
|
|
|
if (this == &that) {
|
1999-08-16 21:50:52 +00:00
|
|
|
return TRUE;
|
2000-04-12 19:36:30 +00:00
|
|
|
}
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2000-04-12 19:36:30 +00:00
|
|
|
if (getDynamicClassID() != that.getDynamicClassID()) {
|
1999-08-16 21:50:52 +00:00
|
|
|
return FALSE;
|
2000-04-12 19:36:30 +00:00
|
|
|
}
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
UCharCharacterIterator& realThat = (UCharCharacterIterator&)that;
|
|
|
|
|
|
|
|
return text == realThat.text
|
2000-04-12 19:36:30 +00:00
|
|
|
&& textLength == realThat.textLength
|
1999-08-16 21:50:52 +00:00
|
|
|
&& pos == realThat.pos
|
|
|
|
&& begin == realThat.begin
|
|
|
|
&& end == realThat.end;
|
|
|
|
}
|
|
|
|
|
|
|
|
int32_t
|
2000-04-12 19:36:30 +00:00
|
|
|
UCharCharacterIterator::hashCode() const {
|
|
|
|
return uhash_hashUCharsN(text, textLength) ^ pos ^ begin ^ end;
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
CharacterIterator*
|
2000-04-12 19:36:30 +00:00
|
|
|
UCharCharacterIterator::clone() const {
|
1999-08-16 21:50:52 +00:00
|
|
|
return new UCharCharacterIterator(*this);
|
|
|
|
}
|
|
|
|
|
|
|
|
UChar
|
2000-04-12 19:36:30 +00:00
|
|
|
UCharCharacterIterator::first() {
|
1999-08-16 21:50:52 +00:00
|
|
|
pos = begin;
|
2000-04-12 19:36:30 +00:00
|
|
|
if(pos < end) {
|
|
|
|
return text[pos];
|
|
|
|
} else {
|
|
|
|
return DONE;
|
|
|
|
}
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
2000-04-12 19:36:30 +00:00
|
|
|
UTextOffset
|
|
|
|
UCharCharacterIterator::setToStart() {
|
|
|
|
return pos = begin;
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
UChar
|
2000-04-12 19:36:30 +00:00
|
|
|
UCharCharacterIterator::last() {
|
|
|
|
pos = end;
|
|
|
|
if(pos > begin) {
|
|
|
|
return text[--pos];
|
|
|
|
} else {
|
|
|
|
return DONE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
UTextOffset
|
|
|
|
UCharCharacterIterator::setToEnd() {
|
|
|
|
return pos = end;
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
UChar
|
2000-04-12 19:36:30 +00:00
|
|
|
UCharCharacterIterator::setIndex(UTextOffset pos) {
|
|
|
|
if(pos < begin) {
|
|
|
|
pos = begin;
|
|
|
|
} else if(pos > end) {
|
|
|
|
pos = end;
|
|
|
|
}
|
|
|
|
this->pos = pos;
|
|
|
|
if(pos < end) {
|
1999-08-16 21:50:52 +00:00
|
|
|
return text[pos];
|
2000-04-12 19:36:30 +00:00
|
|
|
} else {
|
|
|
|
return DONE;
|
|
|
|
}
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
UChar
|
2000-04-12 19:36:30 +00:00
|
|
|
UCharCharacterIterator::current() const {
|
|
|
|
if (pos >= begin && pos < end) {
|
1999-08-16 21:50:52 +00:00
|
|
|
return text[pos];
|
2000-04-12 19:36:30 +00:00
|
|
|
} else {
|
|
|
|
return DONE;
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
2000-04-12 19:36:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
UChar
|
|
|
|
UCharCharacterIterator::next() {
|
|
|
|
if (pos + 1 < end) {
|
|
|
|
return text[++pos];
|
|
|
|
} else {
|
|
|
|
/* make current() return DONE */
|
1999-08-16 21:50:52 +00:00
|
|
|
pos = end;
|
2000-04-12 19:36:30 +00:00
|
|
|
return DONE;
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
UChar
|
2000-04-12 19:36:30 +00:00
|
|
|
UCharCharacterIterator::nextPostInc() {
|
|
|
|
if (pos < end) {
|
|
|
|
return text[pos++];
|
|
|
|
} else {
|
|
|
|
return DONE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool_t
|
|
|
|
UCharCharacterIterator::hasNext() {
|
|
|
|
return pos < end ? TRUE : FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
UChar
|
|
|
|
UCharCharacterIterator::previous() {
|
|
|
|
if (pos > begin) {
|
1999-08-16 21:50:52 +00:00
|
|
|
return text[--pos];
|
2000-04-12 19:36:30 +00:00
|
|
|
} else {
|
|
|
|
return DONE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool_t
|
|
|
|
UCharCharacterIterator::hasPrevious() {
|
|
|
|
return pos > begin ? TRUE : FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
UChar32
|
|
|
|
UCharCharacterIterator::first32() {
|
|
|
|
pos = begin;
|
|
|
|
if(pos < end) {
|
|
|
|
UTextOffset i = pos;
|
|
|
|
UChar32 c;
|
|
|
|
UTF_NEXT_CHAR(text, i, end, c);
|
|
|
|
return c;
|
|
|
|
} else {
|
|
|
|
return DONE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
UChar32
|
|
|
|
UCharCharacterIterator::last32() {
|
|
|
|
pos = end;
|
|
|
|
if(pos > begin) {
|
|
|
|
UChar32 c;
|
|
|
|
UTF_PREV_CHAR(text, begin, pos, c);
|
|
|
|
return c;
|
|
|
|
} else {
|
|
|
|
return DONE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
UChar32
|
|
|
|
UCharCharacterIterator::setIndex32(UTextOffset pos) {
|
|
|
|
if(pos < begin) {
|
|
|
|
pos = begin;
|
|
|
|
} else if(pos > end) {
|
|
|
|
pos = end;
|
|
|
|
}
|
|
|
|
if(pos < end) {
|
|
|
|
UTF_SET_CHAR_START(text, begin, pos);
|
|
|
|
UTextOffset i = this->pos = pos;
|
|
|
|
UChar32 c;
|
|
|
|
UTF_NEXT_CHAR(text, i, end, c);
|
|
|
|
return c;
|
|
|
|
} else {
|
|
|
|
this->pos = pos;
|
|
|
|
return DONE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
UChar32
|
|
|
|
UCharCharacterIterator::current32() const {
|
|
|
|
if (pos >= begin && pos < end) {
|
|
|
|
UChar32 c;
|
|
|
|
UTF_GET_CHAR(text, begin, pos, end, c);
|
|
|
|
return c;
|
|
|
|
} else {
|
|
|
|
return DONE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
UChar32
|
|
|
|
UCharCharacterIterator::next32() {
|
|
|
|
if (pos < end) {
|
|
|
|
UTF_FWD_1(text, pos, end);
|
|
|
|
if(pos < end) {
|
|
|
|
UTextOffset i = pos;
|
|
|
|
UChar32 c;
|
|
|
|
UTF_NEXT_CHAR(text, i, end, c);
|
|
|
|
return c;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* make current() return DONE */
|
|
|
|
pos = end;
|
|
|
|
return DONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
UChar32
|
|
|
|
UCharCharacterIterator::next32PostInc() {
|
|
|
|
if (pos < end) {
|
|
|
|
UChar32 c;
|
|
|
|
UTF_NEXT_CHAR(text, pos, end, c);
|
|
|
|
return c;
|
|
|
|
} else {
|
1999-08-16 21:50:52 +00:00
|
|
|
return DONE;
|
2000-04-12 19:36:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
UChar32
|
|
|
|
UCharCharacterIterator::previous32() {
|
|
|
|
if (pos > begin) {
|
|
|
|
UChar32 c;
|
|
|
|
UTF_PREV_CHAR(text, begin, pos, c);
|
|
|
|
return c;
|
|
|
|
} else {
|
|
|
|
return DONE;
|
|
|
|
}
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
UTextOffset
|
2000-04-12 19:36:30 +00:00
|
|
|
UCharCharacterIterator::startIndex() const {
|
1999-08-16 21:50:52 +00:00
|
|
|
return begin;
|
|
|
|
}
|
|
|
|
|
|
|
|
UTextOffset
|
2000-04-12 19:36:30 +00:00
|
|
|
UCharCharacterIterator::endIndex() const {
|
1999-08-16 21:50:52 +00:00
|
|
|
return end;
|
|
|
|
}
|
|
|
|
|
|
|
|
UTextOffset
|
2000-04-12 19:36:30 +00:00
|
|
|
UCharCharacterIterator::getIndex() const {
|
1999-08-16 21:50:52 +00:00
|
|
|
return pos;
|
|
|
|
}
|
|
|
|
|
2000-01-08 02:05:05 +00:00
|
|
|
void UCharCharacterIterator::setText(const UChar* newText,
|
2000-04-12 19:36:30 +00:00
|
|
|
int32_t newTextLength) {
|
2000-01-08 02:05:05 +00:00
|
|
|
text = newText;
|
2000-04-12 19:36:30 +00:00
|
|
|
if(newText == 0 || newTextLength < 0) {
|
|
|
|
newTextLength = 0;
|
|
|
|
}
|
|
|
|
end = textLength = newTextLength;
|
|
|
|
pos = begin = 0;
|
2000-01-08 02:05:05 +00:00
|
|
|
}
|
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
void
|
2000-04-12 19:36:30 +00:00
|
|
|
UCharCharacterIterator::getText(UnicodeString& result) {
|
|
|
|
result = UnicodeString(text, textLength);
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
char UCharCharacterIterator::fgClassID = 0;
|