michael@0: /* michael@0: ********************************************************************** michael@0: * Copyright (C) 1999-2011, International Business Machines michael@0: * Corporation and others. All Rights Reserved. michael@0: ********************************************************************** michael@0: */ michael@0: michael@0: #include "unicode/chariter.h" michael@0: michael@0: U_NAMESPACE_BEGIN michael@0: michael@0: ForwardCharacterIterator::~ForwardCharacterIterator() {} michael@0: ForwardCharacterIterator::ForwardCharacterIterator() michael@0: : UObject() michael@0: {} michael@0: ForwardCharacterIterator::ForwardCharacterIterator(const ForwardCharacterIterator &other) michael@0: : UObject(other) michael@0: {} michael@0: michael@0: michael@0: CharacterIterator::CharacterIterator() michael@0: : textLength(0), pos(0), begin(0), end(0) { michael@0: } michael@0: michael@0: CharacterIterator::CharacterIterator(int32_t length) michael@0: : textLength(length), pos(0), begin(0), end(length) { michael@0: if(textLength < 0) { michael@0: textLength = end = 0; michael@0: } michael@0: } michael@0: michael@0: CharacterIterator::CharacterIterator(int32_t length, int32_t position) michael@0: : textLength(length), pos(position), begin(0), end(length) { michael@0: if(textLength < 0) { michael@0: textLength = end = 0; michael@0: } michael@0: if(pos < 0) { michael@0: pos = 0; michael@0: } else if(pos > end) { michael@0: pos = end; michael@0: } michael@0: } michael@0: michael@0: CharacterIterator::CharacterIterator(int32_t length, int32_t textBegin, int32_t textEnd, int32_t position) michael@0: : textLength(length), pos(position), begin(textBegin), end(textEnd) { michael@0: if(textLength < 0) { michael@0: textLength = 0; michael@0: } michael@0: if(begin < 0) { michael@0: begin = 0; michael@0: } else if(begin > textLength) { michael@0: begin = textLength; michael@0: } michael@0: if(end < begin) { michael@0: end = begin; michael@0: } else if(end > textLength) { michael@0: end = textLength; michael@0: } michael@0: if(pos < begin) { michael@0: pos = begin; michael@0: } else if(pos > end) { michael@0: pos = end; michael@0: } michael@0: } michael@0: michael@0: CharacterIterator::~CharacterIterator() {} michael@0: michael@0: CharacterIterator::CharacterIterator(const CharacterIterator &that) : michael@0: ForwardCharacterIterator(that), michael@0: textLength(that.textLength), pos(that.pos), begin(that.begin), end(that.end) michael@0: { michael@0: } michael@0: michael@0: CharacterIterator & michael@0: CharacterIterator::operator=(const CharacterIterator &that) { michael@0: ForwardCharacterIterator::operator=(that); michael@0: textLength = that.textLength; michael@0: pos = that.pos; michael@0: begin = that.begin; michael@0: end = that.end; michael@0: return *this; michael@0: } michael@0: michael@0: // implementing first[32]PostInc() directly in a subclass should be faster michael@0: // but these implementations make subclassing a little easier michael@0: UChar michael@0: CharacterIterator::firstPostInc(void) { michael@0: setToStart(); michael@0: return nextPostInc(); michael@0: } michael@0: michael@0: UChar32 michael@0: CharacterIterator::first32PostInc(void) { michael@0: setToStart(); michael@0: return next32PostInc(); michael@0: } michael@0: michael@0: U_NAMESPACE_END