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