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