]> git.saurik.com Git - apple/icu.git/blame - icuSources/common/schriter.cpp
ICU-57131.0.1.tar.gz
[apple/icu.git] / icuSources / common / schriter.cpp
CommitLineData
b75a7d8f
A
1/*
2******************************************************************************
51004dcb 3* Copyright (C) 1998-2012, International Business Machines Corporation and
729e4ab9 4* others. All Rights Reserved.
b75a7d8f
A
5******************************************************************************
6*
7* File schriter.cpp
8*
9* Modification History:
10*
11* Date Name Description
12* 05/05/99 stephen Cleaned up.
13******************************************************************************
14*/
15
51004dcb 16#include "utypeinfo.h" // for 'typeid' to work
729e4ab9 17
b75a7d8f
A
18#include "unicode/chariter.h"
19#include "unicode/schriter.h"
20
21U_NAMESPACE_BEGIN
22
374ca955 23UOBJECT_DEFINE_RTTI_IMPLEMENTATION(StringCharacterIterator)
b75a7d8f
A
24
25StringCharacterIterator::StringCharacterIterator()
26 : UCharCharacterIterator(),
27 text()
28{
29 // NEVER DEFAULT CONSTRUCT!
30}
31
32StringCharacterIterator::StringCharacterIterator(const UnicodeString& textStr)
46f4442e 33 : UCharCharacterIterator(textStr.getBuffer(), textStr.length()),
b75a7d8f
A
34 text(textStr)
35{
36 // we had set the input parameter's array, now we need to set our copy's array
46f4442e 37 UCharCharacterIterator::text = this->text.getBuffer();
b75a7d8f
A
38}
39
40StringCharacterIterator::StringCharacterIterator(const UnicodeString& textStr,
41 int32_t textPos)
46f4442e 42 : UCharCharacterIterator(textStr.getBuffer(), textStr.length(), textPos),
b75a7d8f
A
43 text(textStr)
44{
45 // we had set the input parameter's array, now we need to set our copy's array
46f4442e 46 UCharCharacterIterator::text = this->text.getBuffer();
b75a7d8f
A
47}
48
49StringCharacterIterator::StringCharacterIterator(const UnicodeString& textStr,
50 int32_t textBegin,
51 int32_t textEnd,
52 int32_t textPos)
46f4442e 53 : UCharCharacterIterator(textStr.getBuffer(), textStr.length(), textBegin, textEnd, textPos),
b75a7d8f
A
54 text(textStr)
55{
56 // we had set the input parameter's array, now we need to set our copy's array
46f4442e 57 UCharCharacterIterator::text = this->text.getBuffer();
b75a7d8f
A
58}
59
60StringCharacterIterator::StringCharacterIterator(const StringCharacterIterator& that)
61 : UCharCharacterIterator(that),
62 text(that.text)
63{
64 // we had set the input parameter's array, now we need to set our copy's array
46f4442e 65 UCharCharacterIterator::text = this->text.getBuffer();
b75a7d8f
A
66}
67
68StringCharacterIterator::~StringCharacterIterator() {
69}
70
71StringCharacterIterator&
72StringCharacterIterator::operator=(const StringCharacterIterator& that) {
73 UCharCharacterIterator::operator=(that);
74 text = that.text;
75 // we had set the input parameter's array, now we need to set our copy's array
46f4442e 76 UCharCharacterIterator::text = this->text.getBuffer();
b75a7d8f
A
77 return *this;
78}
79
80UBool
81StringCharacterIterator::operator==(const ForwardCharacterIterator& that) const {
82 if (this == &that) {
83 return TRUE;
84 }
85
86 // do not call UCharCharacterIterator::operator==()
87 // because that checks for array pointer equality
88 // while we compare UnicodeString objects
89
729e4ab9 90 if (typeid(*this) != typeid(that)) {
b75a7d8f
A
91 return FALSE;
92 }
93
94 StringCharacterIterator& realThat = (StringCharacterIterator&)that;
95
96 return text == realThat.text
97 && pos == realThat.pos
98 && begin == realThat.begin
99 && end == realThat.end;
100}
101
102CharacterIterator*
103StringCharacterIterator::clone() const {
104 return new StringCharacterIterator(*this);
105}
106
107void
108StringCharacterIterator::setText(const UnicodeString& newText) {
109 text = newText;
46f4442e 110 UCharCharacterIterator::setText(text.getBuffer(), text.length());
b75a7d8f
A
111}
112
113void
114StringCharacterIterator::getText(UnicodeString& result) {
115 result = text;
116}
117U_NAMESPACE_END