blob: 703a4858e60154d8ef9e6736fbb98e8e71855bad (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
|
/********************************************************************
* COPYRIGHT:
* Copyright (c) 1997-2003, International Business Machines Corporation and
* others. All Rights Reserved.
********************************************************************/
/* file name: sfwdchit.cpp
* encoding: US-ASCII
* tab size: 8 (not used)
* indentation:4
*/
#include "sfwdchit.h"
#include "unicode/ustring.h"
#include "unicode/unistr.h"
#include "uhash.h"
#include "cmemory.h"
// A hash code of kInvalidHashCode indicates that the has code needs
// to be computed. A hash code of kEmptyHashCode is used for empty keys
// and for any key whose computed hash code is kInvalidHashCode.
const int32_t SimpleFwdCharIterator::kInvalidHashCode = 0;
const int32_t SimpleFwdCharIterator::kEmptyHashCode = 1;
#if 0 // not used
SimpleFwdCharIterator::SimpleFwdCharIterator(const UnicodeString& s) {
fHashCode = kInvalidHashCode;
fLen = s.length();
fStart = new UChar[fLen];
if(fStart == NULL) {
fBogus = TRUE;
} else {
fEnd = fStart+fLen;
fCurrent = fStart;
fBogus = FALSE;
s.extract(0, fLen, fStart);
}
}
#endif
SimpleFwdCharIterator::SimpleFwdCharIterator(UChar *s, int32_t len, UBool adopt) {
fHashCode = kInvalidHashCode;
fLen = len==-1 ? u_strlen(s) : len;
if(adopt == FALSE) {
fStart = new UChar[fLen];
if(fStart == NULL) {
fBogus = TRUE;
} else {
uprv_memcpy(fStart, s, fLen);
fEnd = fStart+fLen;
fCurrent = fStart;
fBogus = FALSE;
}
} else { // adopt = TRUE
fCurrent = fStart = s;
fEnd = fStart + fLen;
fBogus = FALSE;
}
}
SimpleFwdCharIterator::~SimpleFwdCharIterator() {
delete[] fStart;
}
#if 0 // not used
UBool SimpleFwdCharIterator::operator==(const ForwardCharacterIterator& that) const {
if(this == &that) {
return TRUE;
}
/*
if(that->fHashCode != kInvalidHashCode && this->fHashCode = that->fHashCode) {
return TRUE;
}
if(this->fStart == that->fStart) {
return TRUE;
}
if(this->fLen == that->fLen && uprv_memcmp(this->fStart, that->fStart, this->fLen) {
return TRUE;
}
*/
return FALSE;
}
#endif
int32_t SimpleFwdCharIterator::hashCode(void) const {
if (fHashCode == kInvalidHashCode)
{
UHashTok key;
key.pointer = fStart;
((SimpleFwdCharIterator *)this)->fHashCode = uhash_hashUChars(key);
}
return fHashCode;
}
UClassID SimpleFwdCharIterator::getDynamicClassID(void) const {
return NULL;
}
UChar SimpleFwdCharIterator::nextPostInc(void) {
if(fCurrent == fEnd) {
return ForwardCharacterIterator::DONE;
} else {
return *(fCurrent)++;
}
}
UChar32 SimpleFwdCharIterator::next32PostInc(void) {
return ForwardCharacterIterator::DONE;
}
UBool SimpleFwdCharIterator::hasNext() {
return fCurrent < fEnd;
}
|