ICU 71.1 71.1

coleitr.h
Go to the documentation of this file.
1 // © 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
3 /*
4 ******************************************************************************
5 * Copyright (C) 1997-2014, International Business Machines
6 * Corporation and others. All Rights Reserved.
7 ******************************************************************************
8 */
9
33 #ifndef COLEITR_H
34 #define COLEITR_H
35
36 #include "unicode/utypes.h"
37
38 #if U_SHOW_CPLUSPLUS_API
39
40 #if !UCONFIG_NO_COLLATION
41
42 #include "unicode/unistr.h"
43 #include "unicode/uobject.h"
44
45 struct UCollationElements;
46 struct UHashtable;
47
48 U_NAMESPACE_BEGIN
49
50 struct CollationData;
51
52 class CharacterIterator;
53 class CollationIterator;
54 class RuleBasedCollator;
55 class UCollationPCE;
56 class UVector32;
57
121 class U_I18N_API CollationElementIterator U_FINAL : public UObject {
122 public:
123
124 // CollationElementIterator public data member ------------------------------
125
126 enum {
131 NULLORDER = (int32_t)0xffffffff
132 };
133
134 // CollationElementIterator public constructor/destructor -------------------
135
142 CollationElementIterator(const CollationElementIterator& other);
143
148 virtual ~CollationElementIterator();
149
150 // CollationElementIterator public methods ----------------------------------
151
159 bool operator==(const CollationElementIterator& other) const;
160
168 bool operator!=(const CollationElementIterator& other) const;
169
174 void reset(void);
175
183 int32_t next(UErrorCode& status);
184
192 int32_t previous(UErrorCode& status);
193
200 static inline int32_t primaryOrder(int32_t order);
201
208 static inline int32_t secondaryOrder(int32_t order);
209
216 static inline int32_t tertiaryOrder(int32_t order);
217
227 int32_t getMaxExpansion(int32_t order) const;
228
235 int32_t strengthOrder(int32_t order) const;
236
243 void setText(const UnicodeString& str, UErrorCode& status);
244
251 void setText(CharacterIterator& str, UErrorCode& status);
252
259 static inline UBool isIgnorable(int32_t order);
260
266 int32_t getOffset(void) const;
267
275 void setOffset(int32_t newOffset, UErrorCode& status);
276
282 virtual UClassID getDynamicClassID() const override;
283
289 static UClassID U_EXPORT2 getStaticClassID();
290
291 #ifndef U_HIDE_INTERNAL_API
292
293 static inline CollationElementIterator *fromUCollationElements(UCollationElements *uc) {
294 return reinterpret_cast<CollationElementIterator *>(uc);
295 }
297 static inline const CollationElementIterator *fromUCollationElements(const UCollationElements *uc) {
298 return reinterpret_cast<const CollationElementIterator *>(uc);
299 }
301 inline UCollationElements *toUCollationElements() {
302 return reinterpret_cast<UCollationElements *>(this);
303 }
305 inline const UCollationElements *toUCollationElements() const {
306 return reinterpret_cast<const UCollationElements *>(this);
307 }
308 #endif // U_HIDE_INTERNAL_API
309
310 private:
311 friend class RuleBasedCollator;
312 friend class UCollationPCE;
313
323 CollationElementIterator(const UnicodeString& sourceText,
324 const RuleBasedCollator* order, UErrorCode& status);
325 // Note: The constructors should take settings & tailoring, not a collator,
326 // to avoid circular dependencies.
327 // However, for operator==() we would need to be able to compare tailoring data for equality
328 // without making CollationData or CollationTailoring depend on TailoredSet.
329 // (See the implementation of RuleBasedCollator::operator==().)
330 // That might require creating an intermediate class that would be used
331 // by both CollationElementIterator and RuleBasedCollator
332 // but only contain the part of RBC== related to data and rules.
333
343 CollationElementIterator(const CharacterIterator& sourceText,
344 const RuleBasedCollator* order, UErrorCode& status);
345
351 const CollationElementIterator&
352 operator=(const CollationElementIterator& other);
353
354 CollationElementIterator(); // default constructor not implemented
355
357 inline int8_t normalizeDir() const { return dir_ == 1 ? 0 : dir_; }
358
359 static UHashtable *computeMaxExpansions(const CollationData *data, UErrorCode &errorCode);
360
361 static int32_t getMaxExpansion(const UHashtable *maxExpansions, int32_t order);
362
363 // CollationElementIterator private data members ----------------------------
364
365 CollationIterator *iter_; // owned
366 const RuleBasedCollator *rbc_; // aliased
367 uint32_t otherHalf_;
372 int8_t dir_;
378 UVector32 *offsets_;
379
380 UnicodeString string_;
381 };
382
383 // CollationElementIterator inline method definitions --------------------------
384
385 inline int32_t CollationElementIterator::primaryOrder(int32_t order)
386 {
387 return (order >> 16) & 0xffff;
388 }
389
390 inline int32_t CollationElementIterator::secondaryOrder(int32_t order)
391 {
392 return (order >> 8) & 0xff;
393 }
394
395 inline int32_t CollationElementIterator::tertiaryOrder(int32_t order)
396 {
397 return order & 0xff;
398 }
399
400 inline UBool CollationElementIterator::isIgnorable(int32_t order)
401 {
402 return (order & 0xffff0000) == 0;
403 }
404
405 U_NAMESPACE_END
406
407 #endif /* #if !UCONFIG_NO_COLLATION */
408
409 #endif /* U_SHOW_CPLUSPLUS_API */
410
411 #endif
icu::CollationElementIterator::fromUCollationElements
static CollationElementIterator * fromUCollationElements(UCollationElements *uc)
Definition: coleitr.h:293
UCollationElements
struct UCollationElements UCollationElements
The UCollationElements struct.
Definition: ucoleitr.h:39
U_FINAL
#define U_FINAL
Definition: umachine.h:141
UHashtable
struct UHashtable UHashtable
Definition: msgfmt.h:43
icu::CollationElementIterator::toUCollationElements
UCollationElements * toUCollationElements()
Definition: coleitr.h:301
utypes.h
Basic definitions for ICU, for both C and C++ APIs.
U_I18N_API
#define U_I18N_API
Definition: utypes.h:301
UBool
int8_t UBool
The ICU boolean type, a signed-byte integer.
Definition: umachine.h:269
icu::operator==
U_EXPORT UBool operator==(const StringPiece &x, const StringPiece &y)
Global operator == for StringPiece.
icu::UnicodeString
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
Definition: unistr.h:295
icu::UObject
UObject is the common ICU "boilerplate" class.
Definition: uobject.h:223
UClassID
void * UClassID
UClassID is used to identify classes without using the compiler's RTTI.
Definition: uobject.h:96
UErrorCode
UErrorCode
Standard ICU4C error code type, a substitute for exceptions.
Definition: utypes.h:415
icu::UObject::getDynamicClassID
virtual UClassID getDynamicClassID() const
ICU4C "poor man's RTTI", returns a UClassID for the actual ICU class.
icu::RuleBasedCollator
The RuleBasedCollator class provides the implementation of Collator, using data-driven tables.
Definition: tblcoll.h:115
icu::CharacterIterator
Abstract class that defines an API for iteration on text objects.
Definition: chariter.h:361
icu::operator!=
bool operator!=(const StringPiece &x, const StringPiece &y)
Global operator != for StringPiece.
Definition: stringpiece.h:335
icu::CollationElementIterator::fromUCollationElements
static const CollationElementIterator * fromUCollationElements(const UCollationElements *uc)
Definition: coleitr.h:297
uobject.h
C++ API: Common ICU base class UObject.
icu::CollationElementIterator
The CollationElementIterator class is used as an iterator to walk through each character of an inte...
Definition: coleitr.h:121
icu::CollationElementIterator::toUCollationElements
const UCollationElements * toUCollationElements() const
Definition: coleitr.h:305
unistr.h
C++ API: Unicode String.