home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 6 / AACD06.ISO / AACD / Programming / ICU / src / icu / source / common / uchriter.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1999-08-16  |  3.2 KB  |  157 lines

  1. /*
  2. *******************************************************************************
  3. *                                                                             *
  4. * COPYRIGHT:                                                                  *
  5. *   (C) Copyright International Business Machines Corporation, 1998-1999      *
  6. *   Licensed Material - Program-Property of IBM - All Rights Reserved.        *
  7. *   US Government Users Restricted Rights - Use, duplication, or disclosure   *
  8. *   restricted by GSA ADP Schedule Contract with IBM Corp.                    *
  9. *                                                                             *
  10. *******************************************************************************
  11. */
  12.  
  13. #include "uchriter.h"
  14.  
  15. UCharCharacterIterator::UCharCharacterIterator(const UChar* text,
  16.                            int32_t textLength)
  17.   : CharacterIterator(),
  18.   text(text),
  19.   pos(0),
  20.   begin(0),
  21.   end(textLength)
  22. {
  23. }
  24.  
  25. UCharCharacterIterator::UCharCharacterIterator(const UCharCharacterIterator& that)
  26. : CharacterIterator(that),
  27.   text(that.text),
  28.   pos(that.pos),
  29.   begin(that.begin),
  30.   end(that.end)
  31. {
  32. }
  33.  
  34. UCharCharacterIterator&
  35. UCharCharacterIterator::operator=(const UCharCharacterIterator&   that)
  36. {
  37.     text = that.text;
  38.     pos = that.pos;
  39.     begin = that.begin;
  40.     end = that.end;
  41.     return *this;
  42. }
  43.  
  44. UCharCharacterIterator::~UCharCharacterIterator()
  45. {}
  46.  
  47. bool_t
  48. UCharCharacterIterator::operator==(const CharacterIterator& that) const
  49. {
  50.     if (this == &that)
  51.         return TRUE;
  52.     
  53.     if (getDynamicClassID() != that.getDynamicClassID())
  54.         return FALSE;
  55.  
  56.     UCharCharacterIterator&    realThat = (UCharCharacterIterator&)that;
  57.  
  58.     return text == realThat.text
  59.         && pos == realThat.pos
  60.         && begin == realThat.begin
  61.         && end == realThat.end;
  62. }
  63.  
  64. int32_t
  65. UCharCharacterIterator::hashCode() const
  66. {
  67.     return pos ^ begin ^ end;
  68. }
  69.  
  70. CharacterIterator*
  71. UCharCharacterIterator::clone() const
  72. {
  73.     return new UCharCharacterIterator(*this);
  74. }
  75.  
  76. UChar
  77. UCharCharacterIterator::first()
  78. {
  79.     pos = begin;
  80.     return text[pos];
  81. }
  82.  
  83. UChar
  84. UCharCharacterIterator::last()
  85. {
  86.     pos = end - 1;
  87.     return text[pos];
  88. }
  89.  
  90. UChar
  91. UCharCharacterIterator::setIndex(UTextOffset pos)
  92. {
  93.     // should check "pos" here and return an error code, but changing this
  94.     // function would have significant impact across TIFC, so we decided to hold off
  95.     this->pos = pos;
  96.     return text[pos];
  97. }
  98.  
  99. UChar
  100. UCharCharacterIterator::current() const
  101. {
  102.     if (pos >= begin && pos < end)
  103.         return text[pos];
  104.     else
  105.         return CharacterIterator::DONE;
  106. }
  107.  
  108. UChar
  109. UCharCharacterIterator::next()
  110. {
  111.     if (pos < end - 1)
  112.     {
  113.         pos += 1;
  114.         return text[pos];
  115.     }
  116.     else
  117.     {
  118.         pos = end;
  119.         return CharacterIterator::DONE;
  120.     }
  121. }
  122.  
  123. UChar
  124. UCharCharacterIterator::previous()
  125. {
  126.     if (pos > begin)
  127.         return text[--pos];
  128.     else
  129.         return DONE;
  130. }
  131.  
  132. UTextOffset
  133. UCharCharacterIterator::startIndex() const
  134. {
  135.     return begin;
  136. }
  137.  
  138. UTextOffset
  139. UCharCharacterIterator::endIndex() const
  140. {
  141.     return end;
  142. }
  143.  
  144. UTextOffset
  145. UCharCharacterIterator::getIndex() const
  146. {
  147.     return pos;
  148. }
  149.  
  150. void
  151. UCharCharacterIterator::getText(UnicodeString& result)
  152. {
  153.     result = UnicodeString(text, end);
  154. }
  155.  
  156. char UCharCharacterIterator::fgClassID = 0;
  157.