|
ICU 73.2
73.2
|
00001 // © 2016 and later: Unicode, Inc. and others. 00002 // License & terms of use: http://www.unicode.org/copyright.html 00003 /* 00004 ****************************************************************************** 00005 * Copyright (C) 1997-2014, International Business Machines 00006 * Corporation and others. All Rights Reserved. 00007 ****************************************************************************** 00008 */ 00009 00033 #ifndef COLEITR_H 00034 #define COLEITR_H 00035 00036 #include "unicode/utypes.h" 00037 00038 #if U_SHOW_CPLUSPLUS_API 00039 00040 #if !UCONFIG_NO_COLLATION 00041 00042 #include "unicode/unistr.h" 00043 #include "unicode/uobject.h" 00044 00045 struct UCollationElements; 00046 struct UHashtable; 00047 00048 U_NAMESPACE_BEGIN 00049 00050 struct CollationData; 00051 00052 class CharacterIterator; 00053 class CollationIterator; 00054 class RuleBasedCollator; 00055 class UCollationPCE; 00056 class UVector32; 00057 00121 class U_I18N_API CollationElementIterator final : public UObject { 00122 public: 00123 00124 // CollationElementIterator public data member ------------------------------ 00125 00126 enum { 00131 NULLORDER = (int32_t)0xffffffff 00132 }; 00133 00134 // CollationElementIterator public constructor/destructor ------------------- 00135 00142 CollationElementIterator(const CollationElementIterator& other); 00143 00148 virtual ~CollationElementIterator(); 00149 00150 // CollationElementIterator public methods ---------------------------------- 00151 00159 bool operator==(const CollationElementIterator& other) const; 00160 00168 bool operator!=(const CollationElementIterator& other) const; 00169 00174 void reset(void); 00175 00183 int32_t next(UErrorCode& status); 00184 00192 int32_t previous(UErrorCode& status); 00193 00200 static inline int32_t primaryOrder(int32_t order); 00201 00208 static inline int32_t secondaryOrder(int32_t order); 00209 00216 static inline int32_t tertiaryOrder(int32_t order); 00217 00227 int32_t getMaxExpansion(int32_t order) const; 00228 00235 int32_t strengthOrder(int32_t order) const; 00236 00243 void setText(const UnicodeString& str, UErrorCode& status); 00244 00251 void setText(CharacterIterator& str, UErrorCode& status); 00252 00259 static inline UBool isIgnorable(int32_t order); 00260 00266 int32_t getOffset(void) const; 00267 00275 void setOffset(int32_t newOffset, UErrorCode& status); 00276 00282 virtual UClassID getDynamicClassID() const override; 00283 00289 static UClassID U_EXPORT2 getStaticClassID(); 00290 00291 #ifndef U_HIDE_INTERNAL_API 00292 00293 static inline CollationElementIterator *fromUCollationElements(UCollationElements *uc) { 00294 return reinterpret_cast<CollationElementIterator *>(uc); 00295 } 00297 static inline const CollationElementIterator *fromUCollationElements(const UCollationElements *uc) { 00298 return reinterpret_cast<const CollationElementIterator *>(uc); 00299 } 00301 inline UCollationElements *toUCollationElements() { 00302 return reinterpret_cast<UCollationElements *>(this); 00303 } 00305 inline const UCollationElements *toUCollationElements() const { 00306 return reinterpret_cast<const UCollationElements *>(this); 00307 } 00308 #endif // U_HIDE_INTERNAL_API 00309 00310 private: 00311 friend class RuleBasedCollator; 00312 friend class UCollationPCE; 00313 00323 CollationElementIterator(const UnicodeString& sourceText, 00324 const RuleBasedCollator* order, UErrorCode& status); 00325 // Note: The constructors should take settings & tailoring, not a collator, 00326 // to avoid circular dependencies. 00327 // However, for operator==() we would need to be able to compare tailoring data for equality 00328 // without making CollationData or CollationTailoring depend on TailoredSet. 00329 // (See the implementation of RuleBasedCollator::operator==().) 00330 // That might require creating an intermediate class that would be used 00331 // by both CollationElementIterator and RuleBasedCollator 00332 // but only contain the part of RBC== related to data and rules. 00333 00343 CollationElementIterator(const CharacterIterator& sourceText, 00344 const RuleBasedCollator* order, UErrorCode& status); 00345 00351 const CollationElementIterator& 00352 operator=(const CollationElementIterator& other); 00353 00354 CollationElementIterator() = delete; // default constructor not implemented 00355 00357 inline int8_t normalizeDir() const { return dir_ == 1 ? 0 : dir_; } 00358 00359 static UHashtable *computeMaxExpansions(const CollationData *data, UErrorCode &errorCode); 00360 00361 static int32_t getMaxExpansion(const UHashtable *maxExpansions, int32_t order); 00362 00363 // CollationElementIterator private data members ---------------------------- 00364 00365 CollationIterator *iter_; // owned 00366 const RuleBasedCollator *rbc_; // aliased 00367 uint32_t otherHalf_; 00372 int8_t dir_; 00378 UVector32 *offsets_; 00379 00380 UnicodeString string_; 00381 }; 00382 00383 // CollationElementIterator inline method definitions -------------------------- 00384 00385 inline int32_t CollationElementIterator::primaryOrder(int32_t order) 00386 { 00387 return (order >> 16) & 0xffff; 00388 } 00389 00390 inline int32_t CollationElementIterator::secondaryOrder(int32_t order) 00391 { 00392 return (order >> 8) & 0xff; 00393 } 00394 00395 inline int32_t CollationElementIterator::tertiaryOrder(int32_t order) 00396 { 00397 return order & 0xff; 00398 } 00399 00400 inline UBool CollationElementIterator::isIgnorable(int32_t order) 00401 { 00402 return (order & 0xffff0000) == 0; 00403 } 00404 00405 U_NAMESPACE_END 00406 00407 #endif /* #if !UCONFIG_NO_COLLATION */ 00408 00409 #endif /* U_SHOW_CPLUSPLUS_API */ 00410 00411 #endif
1.7.6.1