intl/icu/source/common/chariter.cpp

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/intl/icu/source/common/chariter.cpp	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,98 @@
     1.4 +/*
     1.5 +**********************************************************************
     1.6 +*   Copyright (C) 1999-2011, International Business Machines
     1.7 +*   Corporation and others.  All Rights Reserved.
     1.8 +**********************************************************************
     1.9 +*/
    1.10 +
    1.11 +#include "unicode/chariter.h"
    1.12 +
    1.13 +U_NAMESPACE_BEGIN
    1.14 +
    1.15 +ForwardCharacterIterator::~ForwardCharacterIterator() {}
    1.16 +ForwardCharacterIterator::ForwardCharacterIterator()
    1.17 +: UObject()
    1.18 +{}
    1.19 +ForwardCharacterIterator::ForwardCharacterIterator(const ForwardCharacterIterator &other)
    1.20 +: UObject(other)
    1.21 +{}
    1.22 +
    1.23 +
    1.24 +CharacterIterator::CharacterIterator()
    1.25 +: textLength(0), pos(0), begin(0), end(0) {
    1.26 +}
    1.27 +
    1.28 +CharacterIterator::CharacterIterator(int32_t length)
    1.29 +: textLength(length), pos(0), begin(0), end(length) {
    1.30 +    if(textLength < 0) {
    1.31 +        textLength = end = 0;
    1.32 +    }
    1.33 +}
    1.34 +
    1.35 +CharacterIterator::CharacterIterator(int32_t length, int32_t position)
    1.36 +: textLength(length), pos(position), begin(0), end(length) {
    1.37 +    if(textLength < 0) {
    1.38 +        textLength = end = 0;
    1.39 +    }
    1.40 +    if(pos < 0) {
    1.41 +        pos = 0;
    1.42 +    } else if(pos > end) {
    1.43 +        pos = end;
    1.44 +    }
    1.45 +}
    1.46 +
    1.47 +CharacterIterator::CharacterIterator(int32_t length, int32_t textBegin, int32_t textEnd, int32_t position)
    1.48 +: textLength(length), pos(position), begin(textBegin), end(textEnd) {
    1.49 +    if(textLength < 0) {
    1.50 +        textLength = 0;
    1.51 +    }
    1.52 +    if(begin < 0) {
    1.53 +        begin = 0;
    1.54 +    } else if(begin > textLength) {
    1.55 +        begin = textLength;
    1.56 +    }
    1.57 +    if(end < begin) {
    1.58 +        end = begin;
    1.59 +    } else if(end > textLength) {
    1.60 +        end = textLength;
    1.61 +    }
    1.62 +    if(pos < begin) {
    1.63 +        pos = begin;
    1.64 +    } else if(pos > end) {
    1.65 +        pos = end;
    1.66 +    }
    1.67 +}
    1.68 +
    1.69 +CharacterIterator::~CharacterIterator() {}
    1.70 +
    1.71 +CharacterIterator::CharacterIterator(const CharacterIterator &that) :
    1.72 +ForwardCharacterIterator(that),
    1.73 +textLength(that.textLength), pos(that.pos), begin(that.begin), end(that.end)
    1.74 +{
    1.75 +}
    1.76 +
    1.77 +CharacterIterator &
    1.78 +CharacterIterator::operator=(const CharacterIterator &that) {
    1.79 +    ForwardCharacterIterator::operator=(that);
    1.80 +    textLength = that.textLength;
    1.81 +    pos = that.pos;
    1.82 +    begin = that.begin;
    1.83 +    end = that.end;
    1.84 +    return *this;
    1.85 +}
    1.86 +
    1.87 +// implementing first[32]PostInc() directly in a subclass should be faster
    1.88 +// but these implementations make subclassing a little easier
    1.89 +UChar
    1.90 +CharacterIterator::firstPostInc(void) {
    1.91 +    setToStart();
    1.92 +    return nextPostInc();
    1.93 +}
    1.94 +
    1.95 +UChar32
    1.96 +CharacterIterator::first32PostInc(void) {
    1.97 +    setToStart();
    1.98 +    return next32PostInc();
    1.99 +}
   1.100 +
   1.101 +U_NAMESPACE_END

mercurial