]>
git.saurik.com Git - apple/icu.git/blob - icuSources/test/intltest/sfwdchit.cpp
1 // © 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
3 /********************************************************************
5 * Copyright (c) 1997-2003, International Business Machines Corporation and
6 * others. All Rights Reserved.
7 ********************************************************************/
8 /* file name: sfwdchit.cpp
10 * tab size: 8 (not used)
15 #include "unicode/ustring.h"
16 #include "unicode/unistr.h"
20 // A hash code of kInvalidHashCode indicates that the has code needs
21 // to be computed. A hash code of kEmptyHashCode is used for empty keys
22 // and for any key whose computed hash code is kInvalidHashCode.
23 const int32_t SimpleFwdCharIterator::kInvalidHashCode
= 0;
24 const int32_t SimpleFwdCharIterator::kEmptyHashCode
= 1;
27 SimpleFwdCharIterator::SimpleFwdCharIterator(const UnicodeString
& s
) {
29 fHashCode
= kInvalidHashCode
;
31 fStart
= new UChar
[fLen
];
38 s
.extract(0, fLen
, fStart
);
44 SimpleFwdCharIterator::SimpleFwdCharIterator(UChar
*s
, int32_t len
, UBool adopt
) {
46 fHashCode
= kInvalidHashCode
;
48 fLen
= len
==-1 ? u_strlen(s
) : len
;
51 fStart
= new UChar
[fLen
];
55 uprv_memcpy(fStart
, s
, fLen
);
60 } else { // adopt = TRUE
61 fCurrent
= fStart
= s
;
68 SimpleFwdCharIterator::~SimpleFwdCharIterator() {
73 UBool
SimpleFwdCharIterator::operator==(const ForwardCharacterIterator
& that
) const {
78 if(that->fHashCode != kInvalidHashCode && this->fHashCode = that->fHashCode) {
82 if(this->fStart == that->fStart) {
86 if(this->fLen == that->fLen && uprv_memcmp(this->fStart, that->fStart, this->fLen) {
94 int32_t SimpleFwdCharIterator::hashCode(void) const {
95 if (fHashCode
== kInvalidHashCode
)
99 ((SimpleFwdCharIterator
*)this)->fHashCode
= uhash_hashUChars(key
);
104 UClassID
SimpleFwdCharIterator::getDynamicClassID(void) const {
108 UChar
SimpleFwdCharIterator::nextPostInc(void) {
109 if(fCurrent
== fEnd
) {
110 return ForwardCharacterIterator::DONE
;
112 return *(fCurrent
)++;
116 UChar32
SimpleFwdCharIterator::next32PostInc(void) {
117 return ForwardCharacterIterator::DONE
;
120 UBool
SimpleFwdCharIterator::hasNext() {
121 return fCurrent
< fEnd
;