00001 /* 00002 ****************************************************************************** 00003 * Copyright (C) 1997-2014, International Business Machines 00004 * Corporation and others. All Rights Reserved. 00005 ****************************************************************************** 00006 */ 00007 00031 #ifndef COLEITR_H 00032 #define COLEITR_H 00033 00034 #include "unicode/utypes.h" 00035 00036 #if !UCONFIG_NO_COLLATION 00037 00038 #include "unicode/unistr.h" 00039 #include "unicode/uobject.h" 00040 00041 struct UCollationElements; 00042 struct UHashtable; 00043 00044 U_NAMESPACE_BEGIN 00045 00046 struct CollationData; 00047 00048 class CollationIterator; 00049 class RuleBasedCollator; 00050 class UCollationPCE; 00051 class UVector32; 00052 00116 class U_I18N_API CollationElementIterator U_FINAL : public UObject { 00117 public: 00118 00119 // CollationElementIterator public data member ------------------------------ 00120 00121 enum { 00126 NULLORDER = (int32_t)0xffffffff 00127 }; 00128 00129 // CollationElementIterator public constructor/destructor ------------------- 00130 00137 CollationElementIterator(const CollationElementIterator& other); 00138 00143 virtual ~CollationElementIterator(); 00144 00145 // CollationElementIterator public methods ---------------------------------- 00146 00154 UBool operator==(const CollationElementIterator& other) const; 00155 00163 UBool operator!=(const CollationElementIterator& other) const; 00164 00169 void reset(void); 00170 00178 int32_t next(UErrorCode& status); 00179 00187 int32_t previous(UErrorCode& status); 00188 00195 static inline int32_t primaryOrder(int32_t order); 00196 00203 static inline int32_t secondaryOrder(int32_t order); 00204 00211 static inline int32_t tertiaryOrder(int32_t order); 00212 00222 int32_t getMaxExpansion(int32_t order) const; 00223 00230 int32_t strengthOrder(int32_t order) const; 00231 00238 void setText(const UnicodeString& str, UErrorCode& status); 00239 00246 void setText(CharacterIterator& str, UErrorCode& status); 00247 00254 static inline UBool isIgnorable(int32_t order); 00255 00261 int32_t getOffset(void) const; 00262 00270 void setOffset(int32_t newOffset, UErrorCode& status); 00271 00277 virtual UClassID getDynamicClassID() const; 00278 00284 static UClassID U_EXPORT2 getStaticClassID(); 00285 00286 #ifndef U_HIDE_INTERNAL_API 00287 00288 static inline CollationElementIterator *fromUCollationElements(UCollationElements *uc) { 00289 return reinterpret_cast<CollationElementIterator *>(uc); 00290 } 00292 static inline const CollationElementIterator *fromUCollationElements(const UCollationElements *uc) { 00293 return reinterpret_cast<const CollationElementIterator *>(uc); 00294 } 00296 inline UCollationElements *toUCollationElements() { 00297 return reinterpret_cast<UCollationElements *>(this); 00298 } 00300 inline const UCollationElements *toUCollationElements() const { 00301 return reinterpret_cast<const UCollationElements *>(this); 00302 } 00303 #endif // U_HIDE_INTERNAL_API 00304 00305 private: 00306 friend class RuleBasedCollator; 00307 friend class UCollationPCE; 00308 00318 CollationElementIterator(const UnicodeString& sourceText, 00319 const RuleBasedCollator* order, UErrorCode& status); 00320 // Note: The constructors should take settings & tailoring, not a collator, 00321 // to avoid circular dependencies. 00322 // However, for operator==() we would need to be able to compare tailoring data for equality 00323 // without making CollationData or CollationTailoring depend on TailoredSet. 00324 // (See the implementation of RuleBasedCollator::operator==().) 00325 // That might require creating an intermediate class that would be used 00326 // by both CollationElementIterator and RuleBasedCollator 00327 // but only contain the part of RBC== related to data and rules. 00328 00338 CollationElementIterator(const CharacterIterator& sourceText, 00339 const RuleBasedCollator* order, UErrorCode& status); 00340 00346 const CollationElementIterator& 00347 operator=(const CollationElementIterator& other); 00348 00349 CollationElementIterator(); // default constructor not implemented 00350 00352 inline int8_t normalizeDir() const { return dir_ == 1 ? 0 : dir_; } 00353 00354 static UHashtable *computeMaxExpansions(const CollationData *data, UErrorCode &errorCode); 00355 00356 static int32_t getMaxExpansion(const UHashtable *maxExpansions, int32_t order); 00357 00358 // CollationElementIterator private data members ---------------------------- 00359 00360 CollationIterator *iter_; // owned 00361 const RuleBasedCollator *rbc_; // aliased 00362 uint32_t otherHalf_; 00367 int8_t dir_; 00373 UVector32 *offsets_; 00374 00375 UnicodeString string_; 00376 }; 00377 00378 // CollationElementIterator inline method definitions -------------------------- 00379 00380 inline int32_t CollationElementIterator::primaryOrder(int32_t order) 00381 { 00382 return (order >> 16) & 0xffff; 00383 } 00384 00385 inline int32_t CollationElementIterator::secondaryOrder(int32_t order) 00386 { 00387 return (order >> 8) & 0xff; 00388 } 00389 00390 inline int32_t CollationElementIterator::tertiaryOrder(int32_t order) 00391 { 00392 return order & 0xff; 00393 } 00394 00395 inline UBool CollationElementIterator::isIgnorable(int32_t order) 00396 { 00397 return (order & 0xffff0000) == 0; 00398 } 00399 00400 U_NAMESPACE_END 00401 00402 #endif /* #if !UCONFIG_NO_COLLATION */ 00403 00404 #endif
1.6.1