]> git.saurik.com Git - apple/icu.git/blob - icuSources/common/chariter.cpp
ICU-6.2.22.tar.gz
[apple/icu.git] / icuSources / common / chariter.cpp
1 /*
2 **********************************************************************
3 * Copyright (C) 1999-2004, International Business Machines
4 * Corporation and others. All Rights Reserved.
5 **********************************************************************
6 */
7
8 #include "unicode/chariter.h"
9
10 U_NAMESPACE_BEGIN
11
12 ForwardCharacterIterator::~ForwardCharacterIterator() {}
13 ForwardCharacterIterator::ForwardCharacterIterator()
14 : UObject()
15 {}
16 ForwardCharacterIterator::ForwardCharacterIterator(const ForwardCharacterIterator &other)
17 : UObject(other)
18 {}
19
20
21 CharacterIterator::CharacterIterator()
22 : textLength(0), pos(0), begin(0), end(0) {
23 }
24
25 CharacterIterator::CharacterIterator(int32_t length)
26 : textLength(length), pos(0), begin(0), end(length) {
27 if(textLength < 0) {
28 textLength = end = 0;
29 }
30 }
31
32 CharacterIterator::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
44 CharacterIterator::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
66 CharacterIterator::CharacterIterator(const CharacterIterator &that) :
67 ForwardCharacterIterator(that),
68 textLength(that.textLength), pos(that.pos), begin(that.begin), end(that.end)
69 {
70 }
71
72 CharacterIterator &
73 CharacterIterator::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
84 UChar
85 CharacterIterator::firstPostInc(void) {
86 setToStart();
87 return nextPostInc();
88 }
89
90 UChar32
91 CharacterIterator::first32PostInc(void) {
92 setToStart();
93 return next32PostInc();
94 }
95
96 U_NAMESPACE_END