1/* 2********************************************************************** 3* Copyright (C) 1999-2011, International Business Machines 4* Corporation and others. All Rights Reserved. 5********************************************************************** 6*/ 7 8#include "unicode/chariter.h" 9 10U_NAMESPACE_BEGIN 11 12ForwardCharacterIterator::~ForwardCharacterIterator() {} 13ForwardCharacterIterator::ForwardCharacterIterator() 14: UObject() 15{} 16ForwardCharacterIterator::ForwardCharacterIterator(const ForwardCharacterIterator &other) 17: UObject(other) 18{} 19 20 21CharacterIterator::CharacterIterator() 22: textLength(0), pos(0), begin(0), end(0) { 23} 24 25CharacterIterator::CharacterIterator(int32_t length) 26: textLength(length), pos(0), begin(0), end(length) { 27 if(textLength < 0) { 28 textLength = end = 0; 29 } 30} 31 32CharacterIterator::CharacterIterator(int32_t length, int32_t position) 33: textLength(length), pos(position), begin(0), end(length) { 34 if(textLength < 0) { 35 textLength = end = 0; 36 } 37 if(pos < 0) { 38 pos = 0; 39 } else if(pos > end) { 40 pos = end; 41 } 42} 43 44CharacterIterator::CharacterIterator(int32_t length, int32_t textBegin, int32_t textEnd, int32_t position) 45: textLength(length), pos(position), begin(textBegin), end(textEnd) { 46 if(textLength < 0) { 47 textLength = 0; 48 } 49 if(begin < 0) { 50 begin = 0; 51 } else if(begin > textLength) { 52 begin = textLength; 53 } 54 if(end < begin) { 55 end = begin; 56 } else if(end > textLength) { 57 end = textLength; 58 } 59 if(pos < begin) { 60 pos = begin; 61 } else if(pos > end) { 62 pos = end; 63 } 64} 65 66CharacterIterator::~CharacterIterator() {} 67 68CharacterIterator::CharacterIterator(const CharacterIterator &that) : 69ForwardCharacterIterator(that), 70textLength(that.textLength), pos(that.pos), begin(that.begin), end(that.end) 71{ 72} 73 74CharacterIterator & 75CharacterIterator::operator=(const CharacterIterator &that) { 76 ForwardCharacterIterator::operator=(that); 77 textLength = that.textLength; 78 pos = that.pos; 79 begin = that.begin; 80 end = that.end; 81 return *this; 82} 83 84// implementing first[32]PostInc() directly in a subclass should be faster 85// but these implementations make subclassing a little easier 86UChar 87CharacterIterator::firstPostInc(void) { 88 setToStart(); 89 return nextPostInc(); 90} 91 92UChar32 93CharacterIterator::first32PostInc(void) { 94 setToStart(); 95 return next32PostInc(); 96} 97 98U_NAMESPACE_END 99