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