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