home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 6 / AACD06.ISO / AACD / Programming / ICU / src / icu / source / common / schriter.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1999-10-19  |  4.5 KB  |  204 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. * File schriter.cpp
  13. *
  14. * Modification History:
  15. *
  16. *   Date        Name        Description
  17. *  05/05/99     stephen     Cleaned up.
  18. *******************************************************************************
  19. */
  20.  
  21. #include "chariter.h"
  22. #include "schriter.h"
  23.  
  24.  
  25. UClassID StringCharacterIterator::fgClassID = 0;
  26.  
  27. StringCharacterIterator::StringCharacterIterator()
  28.   : CharacterIterator(),
  29.     text(),
  30.     pos(0),
  31.     begin(0),
  32.     end(0)
  33. {
  34.   // NEVER DEFAULT CONSTRUCT!
  35. }
  36.  
  37. StringCharacterIterator::StringCharacterIterator(const UnicodeString& text)
  38.   : CharacterIterator(),
  39.     text(text),
  40.     pos(0),
  41.     begin(0),
  42.     end(text.length())
  43. {}
  44.  
  45. StringCharacterIterator::StringCharacterIterator(const UnicodeString&    text,
  46.                          UTextOffset              pos)
  47.   : CharacterIterator(),
  48.     text(text),
  49.     pos(pos),
  50.     begin(0),
  51.     end(text.length())
  52. {
  53.   // the Java code checks the parameters and throws exceptions we've
  54.   // decided to punt on this for the time being because changing this
  55.   // constructor to accept an error code is an API change with
  56.   // significant impact
  57. }
  58.  
  59. StringCharacterIterator::StringCharacterIterator(const UnicodeString&    text,
  60.                          UTextOffset             begin,
  61.                          UTextOffset              end,
  62.                          UTextOffset              pos)
  63.   : CharacterIterator(),
  64.     text(text),
  65.     pos(pos),
  66.     begin(begin),
  67.     end(end)
  68. {
  69.   // the Java code checks the parameters and throws exceptions we've
  70.   // decided to punt on this for the time being because changing this
  71.   // constructor to accept an error code is an API change with
  72.   // significant impact
  73. }
  74.  
  75. StringCharacterIterator::StringCharacterIterator(const StringCharacterIterator& that)
  76.   : CharacterIterator(that),
  77.     text(that.text),
  78.     pos(that.pos),
  79.     begin(that.begin),
  80.     end(that.end)
  81. {
  82. }
  83.  
  84. StringCharacterIterator::~StringCharacterIterator()
  85. {}
  86.  
  87. StringCharacterIterator&
  88. StringCharacterIterator::operator=(const StringCharacterIterator&   that)
  89. {
  90.   text = that.text;
  91.   pos = that.pos;
  92.   begin = that.begin;
  93.   end = that.end;
  94.   return *this;
  95. }
  96.  
  97. bool_t
  98. StringCharacterIterator::operator==(const CharacterIterator& that) const
  99. {
  100.   if (this == &that)
  101.   return TRUE;
  102.     
  103.   if (getDynamicClassID() != that.getDynamicClassID())
  104.   return FALSE;
  105.  
  106.   StringCharacterIterator&    realThat = (StringCharacterIterator&)that;
  107.  
  108.   return text == realThat.text
  109.   && pos == realThat.pos
  110.   && begin == realThat.begin
  111.   && end == realThat.end;
  112. }
  113.  
  114. int32_t
  115. StringCharacterIterator::hashCode() const
  116. {
  117.   return text.hashCode() ^ pos ^ begin ^ end;
  118. }
  119.  
  120. CharacterIterator*
  121. StringCharacterIterator::clone() const
  122. {
  123.   return new StringCharacterIterator(*this);
  124. }
  125.  
  126. UChar
  127. StringCharacterIterator::first()
  128. {
  129.   pos = begin;
  130.   return text.charAt(pos);
  131. }
  132.  
  133. UChar
  134. StringCharacterIterator::last()
  135. {
  136.   pos = end - 1;
  137.   return text.charAt(pos);
  138. }
  139.  
  140. UChar
  141. StringCharacterIterator::setIndex(UTextOffset pos)
  142. {
  143.   // should check "pos" here and return an error code, but changing
  144.   // this function would have significant impact across TIFC, so we
  145.   // decided to hold off
  146.   this->pos = pos;
  147.   return text.charAt(pos);
  148. }
  149.  
  150. UChar
  151. StringCharacterIterator::current() const
  152. {
  153.   if (pos >= begin && pos < end)
  154.     return text.charAt(pos);
  155.   else
  156.     return CharacterIterator::DONE;
  157. }
  158.  
  159. UChar
  160. StringCharacterIterator::next()
  161. {
  162.   if(pos < end - 1) {
  163.     return text.charAt(++pos);
  164.   }
  165.   else {
  166.     pos = end;
  167.     return CharacterIterator::DONE;
  168.   }
  169. }
  170.  
  171. UChar
  172. StringCharacterIterator::previous()
  173. {
  174.   if (pos > begin)
  175.     return text.charAt(--pos);
  176.   else
  177.     return DONE;
  178. }
  179.  
  180. UTextOffset
  181. StringCharacterIterator::startIndex() const
  182. {
  183.   return begin;
  184. }
  185.  
  186. UTextOffset
  187. StringCharacterIterator::endIndex() const
  188. {
  189.   return end;
  190. }
  191.  
  192. UTextOffset
  193. StringCharacterIterator::getIndex() const
  194. {
  195.   return pos;
  196. }
  197.  
  198. void
  199. StringCharacterIterator::getText(UnicodeString& result)
  200. {
  201.   result = text;
  202. }
  203.  
  204.