]> git.saurik.com Git - apple/icu.git/blame_incremental - icuSources/common/schriter.cpp
ICU-57131.0.1.tar.gz
[apple/icu.git] / icuSources / common / schriter.cpp
... / ...
CommitLineData
1/*
2******************************************************************************
3* Copyright (C) 1998-2012, International Business Machines Corporation and
4* others. All Rights Reserved.
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
16#include "utypeinfo.h" // for 'typeid' to work
17
18#include "unicode/chariter.h"
19#include "unicode/schriter.h"
20
21U_NAMESPACE_BEGIN
22
23UOBJECT_DEFINE_RTTI_IMPLEMENTATION(StringCharacterIterator)
24
25StringCharacterIterator::StringCharacterIterator()
26 : UCharCharacterIterator(),
27 text()
28{
29 // NEVER DEFAULT CONSTRUCT!
30}
31
32StringCharacterIterator::StringCharacterIterator(const UnicodeString& textStr)
33 : UCharCharacterIterator(textStr.getBuffer(), textStr.length()),
34 text(textStr)
35{
36 // we had set the input parameter's array, now we need to set our copy's array
37 UCharCharacterIterator::text = this->text.getBuffer();
38}
39
40StringCharacterIterator::StringCharacterIterator(const UnicodeString& textStr,
41 int32_t textPos)
42 : UCharCharacterIterator(textStr.getBuffer(), textStr.length(), textPos),
43 text(textStr)
44{
45 // we had set the input parameter's array, now we need to set our copy's array
46 UCharCharacterIterator::text = this->text.getBuffer();
47}
48
49StringCharacterIterator::StringCharacterIterator(const UnicodeString& textStr,
50 int32_t textBegin,
51 int32_t textEnd,
52 int32_t textPos)
53 : UCharCharacterIterator(textStr.getBuffer(), textStr.length(), textBegin, textEnd, textPos),
54 text(textStr)
55{
56 // we had set the input parameter's array, now we need to set our copy's array
57 UCharCharacterIterator::text = this->text.getBuffer();
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
65 UCharCharacterIterator::text = this->text.getBuffer();
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
76 UCharCharacterIterator::text = this->text.getBuffer();
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
90 if (typeid(*this) != typeid(that)) {
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;
110 UCharCharacterIterator::setText(text.getBuffer(), text.length());
111}
112
113void
114StringCharacterIterator::getText(UnicodeString& result) {
115 result = text;
116}
117U_NAMESPACE_END