~ubuntu-branches/ubuntu/quantal/icu/quantal

« back to all changes in this revision

Viewing changes to source/common/chariter.cpp

  • Committer: Package Import Robot
  • Author(s): Yves Arrouye
  • Date: 2002-03-03 15:31:13 UTC
  • Revision ID: package-import@ubuntu.com-20020303153113-3ssceqlq45xbmbnc
Tags: upstream-2.0-2.1pre20020303
ImportĀ upstreamĀ versionĀ 2.0-2.1pre20020303

Show diffs side-by-side

added added

removed removed

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