• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
10 U_NAMESPACE_BEGIN
11 
~ForwardCharacterIterator()12 ForwardCharacterIterator::~ForwardCharacterIterator() {}
ForwardCharacterIterator()13 ForwardCharacterIterator::ForwardCharacterIterator()
14 : UObject()
15 {}
ForwardCharacterIterator(const ForwardCharacterIterator & other)16 ForwardCharacterIterator::ForwardCharacterIterator(const ForwardCharacterIterator &other)
17 : UObject(other)
18 {}
19 
20 
CharacterIterator()21 CharacterIterator::CharacterIterator()
22 : textLength(0), pos(0), begin(0), end(0) {
23 }
24 
CharacterIterator(int32_t length)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 
CharacterIterator(int32_t length,int32_t position)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 
CharacterIterator(int32_t length,int32_t textBegin,int32_t textEnd,int32_t position)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 
~CharacterIterator()66 CharacterIterator::~CharacterIterator() {}
67 
CharacterIterator(const CharacterIterator & that)68 CharacterIterator::CharacterIterator(const CharacterIterator &that) :
69 ForwardCharacterIterator(that),
70 textLength(that.textLength), pos(that.pos), begin(that.begin), end(that.end)
71 {
72 }
73 
74 CharacterIterator &
operator =(const CharacterIterator & that)75 CharacterIterator::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
86 UChar
firstPostInc(void)87 CharacterIterator::firstPostInc(void) {
88     setToStart();
89     return nextPostInc();
90 }
91 
92 UChar32
first32PostInc(void)93 CharacterIterator::first32PostInc(void) {
94     setToStart();
95     return next32PostInc();
96 }
97 
98 U_NAMESPACE_END
99