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
23U_NAMESPACE_BEGIN
24
25UOBJECT_DEFINE_RTTI_IMPLEMENTATION(StringCharacterIterator)
26
27StringCharacterIterator::StringCharacterIterator()
28 : UCharCharacterIterator(),
29 text()
30{
31 // NEVER DEFAULT CONSTRUCT!
32}
33
34StringCharacterIterator::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
42StringCharacterIterator::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
51StringCharacterIterator::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
62StringCharacterIterator::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
70StringCharacterIterator::~StringCharacterIterator() {
71}
72
73StringCharacterIterator&
74StringCharacterIterator::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
82UBool
83StringCharacterIterator::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 StringCharacterIterator& realThat = (StringCharacterIterator&)that;
97
98 return text == realThat.text
99 && pos == realThat.pos
100 && begin == realThat.begin
101 && end == realThat.end;
102}
103
104StringCharacterIterator*
105StringCharacterIterator::clone() const {
106 return new StringCharacterIterator(*this);
107}
108
109void
110StringCharacterIterator::setText(const UnicodeString& newText) {
111 text = newText;
112 UCharCharacterIterator::setText(text.getBuffer(), text.length());
113}
114
115void
116StringCharacterIterator::getText(UnicodeString& result) {
117 result = text;
118}
119U_NAMESPACE_END
120