schriter.cpp 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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. #include "utypeinfo.h" // for 'typeid' to work
  18. #include "unicode/chariter.h"
  19. #include "unicode/schriter.h"
  20. U_NAMESPACE_BEGIN
  21. UOBJECT_DEFINE_RTTI_IMPLEMENTATION(StringCharacterIterator)
  22. StringCharacterIterator::StringCharacterIterator()
  23. : UCharCharacterIterator(),
  24. text()
  25. {
  26. // NEVER DEFAULT CONSTRUCT!
  27. }
  28. StringCharacterIterator::StringCharacterIterator(const UnicodeString& textStr)
  29. : UCharCharacterIterator(textStr.getBuffer(), textStr.length()),
  30. text(textStr)
  31. {
  32. // we had set the input parameter's array, now we need to set our copy's array
  33. UCharCharacterIterator::text = this->text.getBuffer();
  34. }
  35. StringCharacterIterator::StringCharacterIterator(const UnicodeString& textStr,
  36. int32_t textPos)
  37. : UCharCharacterIterator(textStr.getBuffer(), textStr.length(), textPos),
  38. text(textStr)
  39. {
  40. // we had set the input parameter's array, now we need to set our copy's array
  41. UCharCharacterIterator::text = this->text.getBuffer();
  42. }
  43. StringCharacterIterator::StringCharacterIterator(const UnicodeString& textStr,
  44. int32_t textBegin,
  45. int32_t textEnd,
  46. int32_t textPos)
  47. : UCharCharacterIterator(textStr.getBuffer(), textStr.length(), textBegin, textEnd, textPos),
  48. text(textStr)
  49. {
  50. // we had set the input parameter's array, now we need to set our copy's array
  51. UCharCharacterIterator::text = this->text.getBuffer();
  52. }
  53. StringCharacterIterator::StringCharacterIterator(const StringCharacterIterator& that)
  54. : UCharCharacterIterator(that),
  55. text(that.text)
  56. {
  57. // we had set the input parameter's array, now we need to set our copy's array
  58. UCharCharacterIterator::text = this->text.getBuffer();
  59. }
  60. StringCharacterIterator::~StringCharacterIterator() {
  61. }
  62. StringCharacterIterator&
  63. StringCharacterIterator::operator=(const StringCharacterIterator& that) {
  64. UCharCharacterIterator::operator=(that);
  65. text = that.text;
  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. return *this;
  69. }
  70. bool
  71. StringCharacterIterator::operator==(const ForwardCharacterIterator& that) const {
  72. if (this == &that) {
  73. return true;
  74. }
  75. // do not call UCharCharacterIterator::operator==()
  76. // because that checks for array pointer equality
  77. // while we compare UnicodeString objects
  78. if (typeid(*this) != typeid(that)) {
  79. return false;
  80. }
  81. const StringCharacterIterator& realThat = static_cast<const StringCharacterIterator&>(that);
  82. return text == realThat.text
  83. && pos == realThat.pos
  84. && begin == realThat.begin
  85. && end == realThat.end;
  86. }
  87. StringCharacterIterator*
  88. StringCharacterIterator::clone() const {
  89. return new StringCharacterIterator(*this);
  90. }
  91. void
  92. StringCharacterIterator::setText(const UnicodeString& newText) {
  93. text = newText;
  94. UCharCharacterIterator::setText(text.getBuffer(), text.length());
  95. }
  96. void
  97. StringCharacterIterator::getText(UnicodeString& result) {
  98. result = text;
  99. }
  100. U_NAMESPACE_END