chariter.cpp 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. // © 2016 and later: Unicode, Inc. and others.
  2. // License & terms of use: http://www.unicode.org/copyright.html
  3. /*
  4. **********************************************************************
  5. * Copyright (C) 1999-2011, International Business Machines
  6. * Corporation and others. All Rights Reserved.
  7. **********************************************************************
  8. */
  9. #include "unicode/chariter.h"
  10. U_NAMESPACE_BEGIN
  11. ForwardCharacterIterator::~ForwardCharacterIterator() {}
  12. ForwardCharacterIterator::ForwardCharacterIterator()
  13. : UObject()
  14. {}
  15. ForwardCharacterIterator::ForwardCharacterIterator(const ForwardCharacterIterator &other)
  16. : UObject(other)
  17. {}
  18. CharacterIterator::CharacterIterator()
  19. : textLength(0), pos(0), begin(0), end(0) {
  20. }
  21. CharacterIterator::CharacterIterator(int32_t length)
  22. : textLength(length), pos(0), begin(0), end(length) {
  23. if(textLength < 0) {
  24. textLength = end = 0;
  25. }
  26. }
  27. CharacterIterator::CharacterIterator(int32_t length, int32_t position)
  28. : textLength(length), pos(position), begin(0), end(length) {
  29. if(textLength < 0) {
  30. textLength = end = 0;
  31. }
  32. if(pos < 0) {
  33. pos = 0;
  34. } else if(pos > end) {
  35. pos = end;
  36. }
  37. }
  38. CharacterIterator::CharacterIterator(int32_t length, int32_t textBegin, int32_t textEnd, int32_t position)
  39. : textLength(length), pos(position), begin(textBegin), end(textEnd) {
  40. if(textLength < 0) {
  41. textLength = 0;
  42. }
  43. if(begin < 0) {
  44. begin = 0;
  45. } else if(begin > textLength) {
  46. begin = textLength;
  47. }
  48. if(end < begin) {
  49. end = begin;
  50. } else if(end > textLength) {
  51. end = textLength;
  52. }
  53. if(pos < begin) {
  54. pos = begin;
  55. } else if(pos > end) {
  56. pos = end;
  57. }
  58. }
  59. CharacterIterator::~CharacterIterator() {}
  60. CharacterIterator::CharacterIterator(const CharacterIterator &that) :
  61. ForwardCharacterIterator(that),
  62. textLength(that.textLength), pos(that.pos), begin(that.begin), end(that.end)
  63. {
  64. }
  65. CharacterIterator &
  66. CharacterIterator::operator=(const CharacterIterator &that) {
  67. ForwardCharacterIterator::operator=(that);
  68. textLength = that.textLength;
  69. pos = that.pos;
  70. begin = that.begin;
  71. end = that.end;
  72. return *this;
  73. }
  74. // implementing first[32]PostInc() directly in a subclass should be faster
  75. // but these implementations make subclassing a little easier
  76. char16_t
  77. CharacterIterator::firstPostInc() {
  78. setToStart();
  79. return nextPostInc();
  80. }
  81. UChar32
  82. CharacterIterator::first32PostInc() {
  83. setToStart();
  84. return next32PostInc();
  85. }
  86. U_NAMESPACE_END