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