00001 /* 00002 ***************************************************************************************** 00003 * Copyright (C) 1997-1999, International Business Machines 00004 * Corporation and others. All Rights Reserved. 00005 ***************************************************************************************** 00006 */ 00007 //=============================================================================== 00008 // 00009 // File coleitr.h 00010 // 00011 // 00012 // 00013 // Created by: Helena Shih 00014 // 00015 // Modification History: 00016 // 00017 // Date Name Description 00018 // 00019 // 8/18/97 helena Added internal API documentation. 00020 // 08/03/98 erm Synched with 1.2 version CollationElementIterator.java 00021 // 12/10/99 aliu Ported Thai collation support from Java. 00022 //=============================================================================== 00023 00024 #ifndef COLEITR_H 00025 #define COLEITR_H 00026 00027 00028 #include "unicode/unistr.h" 00029 #include "unicode/tblcoll.h" 00030 #include "unicode/chariter.h" 00031 00032 class Normalizer; 00033 class VectorOfPToContractElement; 00034 class RuleBasedCollator; 00035 00086 class U_I18N_API CollationElementIterator 00087 { 00088 public: 00092 static int32_t const NULLORDER; 00093 00097 ~CollationElementIterator(); 00102 UBool operator==(const CollationElementIterator& other) const; 00103 00108 UBool operator!=(const CollationElementIterator& other) const; 00109 00114 void reset(void); 00122 int32_t next(UErrorCode& status); 00130 int32_t previous(UErrorCode& status); 00131 00138 static int32_t primaryOrder(int32_t order); 00145 static int32_t secondaryOrder(int32_t order); 00152 static int32_t tertiaryOrder(int32_t order); 00161 int32_t getMaxExpansion(int32_t order) const; 00162 00163 public: 00170 int32_t strengthOrder(int32_t order) const; 00177 void setText(const UnicodeString& str, 00178 UErrorCode& status); 00185 void setText(CharacterIterator& str, 00186 UErrorCode& status); 00193 static UBool isIgnorable(int32_t order); 00199 UTextOffset getOffset(void) const; 00207 void setOffset(UTextOffset newOffset, 00208 UErrorCode& status); 00209 /* CollationElementIterator should not be subclassed. */ 00210 protected: 00224 CollationElementIterator( const UnicodeString& sourceText, 00225 const RuleBasedCollator* order, 00226 UErrorCode& status); 00227 00241 CollationElementIterator( const CharacterIterator& sourceText, 00242 const RuleBasedCollator* order, 00243 UErrorCode& status); 00248 const CollationElementIterator& 00249 operator=(const CollationElementIterator& other); 00250 public: 00255 CollationElementIterator(const CollationElementIterator& other); 00256 //============================================================ 00257 // privates 00258 //============================================================ 00259 private: 00263 CollationElementIterator(); 00267 CollationElementIterator(const RuleBasedCollator* order); 00268 00277 int32_t nextContractChar( UChar32 ch, 00278 UErrorCode& status); 00279 00288 int32_t prevContractChar( UChar32 ch, 00289 UErrorCode& status); 00290 00291 inline static UBool isThaiPreVowel(UChar32 ch); 00292 00293 inline static UBool isThaiBaseConsonant(UChar32 ch); 00294 00295 VectorOfInt* makeReorderedBuffer(UChar colFirst, 00296 int32_t lastValue, 00297 VectorOfInt* lastExpansion, 00298 UBool forward, UErrorCode& status); 00299 00300 friend class RuleBasedCollator; 00301 static const int32_t UNMAPPEDCHARVALUE; 00302 00303 Normalizer* text; // owning 00304 00305 VectorOfInt* bufferAlias; // not owned 00306 00315 VectorOfInt* ownBuffer; 00316 00324 VectorOfInt* reorderBuffer; 00325 00326 int32_t expIndex; 00327 UnicodeString key; 00328 const RuleBasedCollator* orderAlias; 00329 }; 00330 00331 00337 inline int32_t 00338 CollationElementIterator::primaryOrder(int32_t order) 00339 { 00340 order &= RuleBasedCollator::PRIMARYORDERMASK; 00341 return (order >> RuleBasedCollator::PRIMARYORDERSHIFT); 00342 } 00348 inline int32_t 00349 CollationElementIterator::secondaryOrder(int32_t order) 00350 { 00351 order = order & RuleBasedCollator::SECONDARYORDERMASK; 00352 return (order >> RuleBasedCollator::SECONDARYORDERSHIFT); 00353 } 00359 inline int32_t 00360 CollationElementIterator::tertiaryOrder(int32_t order) 00361 { 00362 return (order &= RuleBasedCollator::TERTIARYORDERMASK); 00363 } 00364 00365 inline int32_t 00366 CollationElementIterator::getMaxExpansion(int32_t order) const 00367 { 00368 return orderAlias->getMaxExpansion(order); 00369 } 00370 00371 inline UBool 00372 CollationElementIterator::isIgnorable(int32_t order) 00373 { 00374 return (primaryOrder(order) == 0); 00375 } 00376 00381 inline UBool CollationElementIterator::isThaiPreVowel(UChar32 ch) { 00382 return ((uint32_t)ch - 0xe40) <= (0xe44 - 0xe40); 00383 } 00384 00388 inline UBool CollationElementIterator::isThaiBaseConsonant(UChar32 ch) { 00389 return ((uint32_t)ch - 0xe01) <= (0xe2e - 0xe01); 00390 } 00391 00392 #endif