• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2 ******************************************************************************
3 * Copyright (C) 1998-2010, 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 <typeinfo>  // for 'typeid' to work
17 
18 #include "unicode/chariter.h"
19 #include "unicode/schriter.h"
20 
21 U_NAMESPACE_BEGIN
22 
UOBJECT_DEFINE_RTTI_IMPLEMENTATION(StringCharacterIterator)23 UOBJECT_DEFINE_RTTI_IMPLEMENTATION(StringCharacterIterator)
24 
25 StringCharacterIterator::StringCharacterIterator()
26   : UCharCharacterIterator(),
27     text()
28 {
29   // NEVER DEFAULT CONSTRUCT!
30 }
31 
StringCharacterIterator(const UnicodeString & textStr)32 StringCharacterIterator::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 
StringCharacterIterator(const UnicodeString & textStr,int32_t textPos)40 StringCharacterIterator::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 
StringCharacterIterator(const UnicodeString & textStr,int32_t textBegin,int32_t textEnd,int32_t textPos)49 StringCharacterIterator::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 
StringCharacterIterator(const StringCharacterIterator & that)60 StringCharacterIterator::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 
~StringCharacterIterator()68 StringCharacterIterator::~StringCharacterIterator() {
69 }
70 
71 StringCharacterIterator&
operator =(const StringCharacterIterator & that)72 StringCharacterIterator::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 
80 UBool
operator ==(const ForwardCharacterIterator & that) const81 StringCharacterIterator::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 
102 CharacterIterator*
clone() const103 StringCharacterIterator::clone() const {
104     return new StringCharacterIterator(*this);
105 }
106 
107 void
setText(const UnicodeString & newText)108 StringCharacterIterator::setText(const UnicodeString& newText) {
109     text = newText;
110     UCharCharacterIterator::setText(text.getBuffer(), text.length());
111 }
112 
113 void
getText(UnicodeString & result)114 StringCharacterIterator::getText(UnicodeString& result) {
115     result = text;
116 }
117 U_NAMESPACE_END
118