schriter.cpp revision 51cfa1a9a96cad34675a6415fe86dfdf3f525bb6
1/*
2******************************************************************************
3* Copyright (C) 1998-2004, 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 "unicode/chariter.h"
17#include "unicode/schriter.h"
18
19U_NAMESPACE_BEGIN
20
21UOBJECT_DEFINE_RTTI_IMPLEMENTATION(StringCharacterIterator)
22
23StringCharacterIterator::StringCharacterIterator()
24  : UCharCharacterIterator(),
25    text()
26{
27  // NEVER DEFAULT CONSTRUCT!
28}
29
30StringCharacterIterator::StringCharacterIterator(const UnicodeString& textStr)
31  : UCharCharacterIterator(textStr.fArray, textStr.length()),
32    text(textStr)
33{
34    // we had set the input parameter's array, now we need to set our copy's array
35    UCharCharacterIterator::text = this->text.fArray;
36}
37
38StringCharacterIterator::StringCharacterIterator(const UnicodeString& textStr,
39                                                 int32_t textPos)
40  : UCharCharacterIterator(textStr.fArray, textStr.length(), textPos),
41    text(textStr)
42{
43    // we had set the input parameter's array, now we need to set our copy's array
44    UCharCharacterIterator::text = this->text.fArray;
45}
46
47StringCharacterIterator::StringCharacterIterator(const UnicodeString& textStr,
48                                                 int32_t textBegin,
49                                                 int32_t textEnd,
50                                                 int32_t textPos)
51  : UCharCharacterIterator(textStr.fArray, textStr.length(), textBegin, textEnd, textPos),
52    text(textStr)
53{
54    // we had set the input parameter's array, now we need to set our copy's array
55    UCharCharacterIterator::text = this->text.fArray;
56}
57
58StringCharacterIterator::StringCharacterIterator(const StringCharacterIterator& that)
59  : UCharCharacterIterator(that),
60    text(that.text)
61{
62    // we had set the input parameter's array, now we need to set our copy's array
63    UCharCharacterIterator::text = this->text.fArray;
64}
65
66StringCharacterIterator::~StringCharacterIterator() {
67}
68
69StringCharacterIterator&
70StringCharacterIterator::operator=(const StringCharacterIterator& that) {
71    UCharCharacterIterator::operator=(that);
72    text = that.text;
73    // we had set the input parameter's array, now we need to set our copy's array
74    UCharCharacterIterator::text = this->text.fArray;
75    return *this;
76}
77
78UBool
79StringCharacterIterator::operator==(const ForwardCharacterIterator& that) const {
80    if (this == &that) {
81        return TRUE;
82    }
83
84    // do not call UCharCharacterIterator::operator==()
85    // because that checks for array pointer equality
86    // while we compare UnicodeString objects
87
88    if (getDynamicClassID() != that.getDynamicClassID()) {
89        return FALSE;
90    }
91
92    StringCharacterIterator&    realThat = (StringCharacterIterator&)that;
93
94    return text == realThat.text
95        && pos == realThat.pos
96        && begin == realThat.begin
97        && end == realThat.end;
98}
99
100CharacterIterator*
101StringCharacterIterator::clone() const {
102    return new StringCharacterIterator(*this);
103}
104
105void
106StringCharacterIterator::setText(const UnicodeString& newText) {
107    text = newText;
108    UCharCharacterIterator::setText(text.fArray, text.length());
109}
110
111void
112StringCharacterIterator::getText(UnicodeString& result) {
113    result = text;
114}
115U_NAMESPACE_END
116