Home | History | Annotate | Download | only in common
      1 // Copyright (C) 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 
     10 #include "unicode/chariter.h"
     11 
     12 U_NAMESPACE_BEGIN
     13 
     14 ForwardCharacterIterator::~ForwardCharacterIterator() {}
     15 ForwardCharacterIterator::ForwardCharacterIterator()
     16 : UObject()
     17 {}
     18 ForwardCharacterIterator::ForwardCharacterIterator(const ForwardCharacterIterator &other)
     19 : UObject(other)
     20 {}
     21 
     22 
     23 CharacterIterator::CharacterIterator()
     24 : textLength(0), pos(0), begin(0), end(0) {
     25 }
     26 
     27 CharacterIterator::CharacterIterator(int32_t length)
     28 : textLength(length), pos(0), begin(0), end(length) {
     29     if(textLength < 0) {
     30         textLength = end = 0;
     31     }
     32 }
     33 
     34 CharacterIterator::CharacterIterator(int32_t length, int32_t position)
     35 : textLength(length), pos(position), begin(0), end(length) {
     36     if(textLength < 0) {
     37         textLength = end = 0;
     38     }
     39     if(pos < 0) {
     40         pos = 0;
     41     } else if(pos > end) {
     42         pos = end;
     43     }
     44 }
     45 
     46 CharacterIterator::CharacterIterator(int32_t length, int32_t textBegin, int32_t textEnd, int32_t position)
     47 : textLength(length), pos(position), begin(textBegin), end(textEnd) {
     48     if(textLength < 0) {
     49         textLength = 0;
     50     }
     51     if(begin < 0) {
     52         begin = 0;
     53     } else if(begin > textLength) {
     54         begin = textLength;
     55     }
     56     if(end < begin) {
     57         end = begin;
     58     } else if(end > textLength) {
     59         end = textLength;
     60     }
     61     if(pos < begin) {
     62         pos = begin;
     63     } else if(pos > end) {
     64         pos = end;
     65     }
     66 }
     67 
     68 CharacterIterator::~CharacterIterator() {}
     69 
     70 CharacterIterator::CharacterIterator(const CharacterIterator &that) :
     71 ForwardCharacterIterator(that),
     72 textLength(that.textLength), pos(that.pos), begin(that.begin), end(that.end)
     73 {
     74 }
     75 
     76 CharacterIterator &
     77 CharacterIterator::operator=(const CharacterIterator &that) {
     78     ForwardCharacterIterator::operator=(that);
     79     textLength = that.textLength;
     80     pos = that.pos;
     81     begin = that.begin;
     82     end = that.end;
     83     return *this;
     84 }
     85 
     86 // implementing first[32]PostInc() directly in a subclass should be faster
     87 // but these implementations make subclassing a little easier
     88 UChar
     89 CharacterIterator::firstPostInc(void) {
     90     setToStart();
     91     return nextPostInc();
     92 }
     93 
     94 UChar32
     95 CharacterIterator::first32PostInc(void) {
     96     setToStart();
     97     return next32PostInc();
     98 }
     99 
    100 U_NAMESPACE_END
    101