]>
git.saurik.com Git - apple/icu.git/blob - icuSources/test/intltest/sfwdchit.cpp
1 /********************************************************************
3 * Copyright (c) 1997-2003, International Business Machines Corporation and
4 * others. All Rights Reserved.
5 ********************************************************************/
6 /* file name: sfwdchit.cpp
8 * tab size: 8 (not used)
13 #include "unicode/ustring.h"
14 #include "unicode/unistr.h"
18 // A hash code of kInvalidHashCode indicates that the has code needs
19 // to be computed. A hash code of kEmptyHashCode is used for empty keys
20 // and for any key whose computed hash code is kInvalidHashCode.
21 const int32_t SimpleFwdCharIterator::kInvalidHashCode
= 0;
22 const int32_t SimpleFwdCharIterator::kEmptyHashCode
= 1;
25 SimpleFwdCharIterator::SimpleFwdCharIterator(const UnicodeString
& s
) {
27 fHashCode
= kInvalidHashCode
;
29 fStart
= new UChar
[fLen
];
36 s
.extract(0, fLen
, fStart
);
42 SimpleFwdCharIterator::SimpleFwdCharIterator(UChar
*s
, int32_t len
, UBool adopt
) {
44 fHashCode
= kInvalidHashCode
;
46 fLen
= len
==-1 ? u_strlen(s
) : len
;
49 fStart
= new UChar
[fLen
];
53 uprv_memcpy(fStart
, s
, fLen
);
58 } else { // adopt = TRUE
59 fCurrent
= fStart
= s
;
66 SimpleFwdCharIterator::~SimpleFwdCharIterator() {
71 UBool
SimpleFwdCharIterator::operator==(const ForwardCharacterIterator
& that
) const {
76 if(that->fHashCode != kInvalidHashCode && this->fHashCode = that->fHashCode) {
80 if(this->fStart == that->fStart) {
84 if(this->fLen == that->fLen && uprv_memcmp(this->fStart, that->fStart, this->fLen) {
92 int32_t SimpleFwdCharIterator::hashCode(void) const {
93 if (fHashCode
== kInvalidHashCode
)
97 ((SimpleFwdCharIterator
*)this)->fHashCode
= uhash_hashUChars(key
);
102 UClassID
SimpleFwdCharIterator::getDynamicClassID(void) const {
106 UChar
SimpleFwdCharIterator::nextPostInc(void) {
107 if(fCurrent
== fEnd
) {
108 return ForwardCharacterIterator::DONE
;
110 return *(fCurrent
)++;
114 UChar32
SimpleFwdCharIterator::next32PostInc(void) {
115 return ForwardCharacterIterator::DONE
;
118 UBool
SimpleFwdCharIterator::hasNext() {
119 return fCurrent
< fEnd
;