]> git.saurik.com Git - apple/icu.git/blame - icuSources/common/chariter.cpp
ICU-461.12.tar.gz
[apple/icu.git] / icuSources / common / chariter.cpp
CommitLineData
b75a7d8f
A
1/*
2**********************************************************************
374ca955 3* Copyright (C) 1999-2004, International Business Machines
b75a7d8f
A
4* Corporation and others. All Rights Reserved.
5**********************************************************************
6*/
7
8#include "unicode/chariter.h"
9
10U_NAMESPACE_BEGIN
11
374ca955
A
12ForwardCharacterIterator::~ForwardCharacterIterator() {}
13ForwardCharacterIterator::ForwardCharacterIterator()
14: UObject()
15{}
16ForwardCharacterIterator::ForwardCharacterIterator(const ForwardCharacterIterator &other)
17: UObject(other)
18{}
19
20
b75a7d8f
A
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(const CharacterIterator &that) :
67ForwardCharacterIterator(that),
68textLength(that.textLength), pos(that.pos), begin(that.begin), end(that.end)
69{
70}
71
72CharacterIterator &
73CharacterIterator::operator=(const CharacterIterator &that) {
74 ForwardCharacterIterator::operator=(that);
75 textLength = that.textLength;
76 pos = that.pos;
77 begin = that.begin;
78 end = that.end;
79 return *this;
80}
81
82// implementing first[32]PostInc() directly in a subclass should be faster
83// but these implementations make subclassing a little easier
84UChar
85CharacterIterator::firstPostInc(void) {
86 setToStart();
87 return nextPostInc();
88}
89
90UChar32
91CharacterIterator::first32PostInc(void) {
92 setToStart();
93 return next32PostInc();
94}
95
96U_NAMESPACE_END