ICU 63.1 63.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 !UCONFIG_NO_COLLATION
39
40 #include "unicode/unistr.h"
41 #include "unicode/uobject.h"
42
43 struct UCollationElements;
44 struct UHashtable;
45
46 U_NAMESPACE_BEGIN
47
48 struct CollationData;
49
50 class CharacterIterator;
51 class CollationIterator;
52 class RuleBasedCollator;
53 class UCollationPCE;
54 class UVector32;
55
119 class U_I18N_API CollationElementIterator U_FINAL : public UObject {
120 public:
121
122 // CollationElementIterator public data member ------------------------------
123
124 enum {
129 NULLORDER = (int32_t)0xffffffff
130 };
131
132 // CollationElementIterator public constructor/destructor -------------------
133
140 CollationElementIterator(const CollationElementIterator& other);
141
146 virtual ~CollationElementIterator();
147
148 // CollationElementIterator public methods ----------------------------------
149
157 UBool operator==(const CollationElementIterator& other) const;
158
166 UBool operator!=(const CollationElementIterator& other) const;
167
172 void reset(void);
173
181 int32_t next(UErrorCode& status);
182
190 int32_t previous(UErrorCode& status);
191
198 static inline int32_t primaryOrder(int32_t order);
199
206 static inline int32_t secondaryOrder(int32_t order);
207
214 static inline int32_t tertiaryOrder(int32_t order);
215
225 int32_t getMaxExpansion(int32_t order) const;
226
233 int32_t strengthOrder(int32_t order) const;
234
241 void setText(const UnicodeString& str, UErrorCode& status);
242
249 void setText(CharacterIterator& str, UErrorCode& status);
250
257 static inline UBool isIgnorable(int32_t order);
258
264 int32_t getOffset(void) const;
265
273 void setOffset(int32_t newOffset, UErrorCode& status);
274
280 virtual UClassID getDynamicClassID() const;
281
287 static UClassID U_EXPORT2 getStaticClassID();
288
289 #ifndef U_HIDE_INTERNAL_API
290
291 static inline CollationElementIterator *fromUCollationElements(UCollationElements *uc) {
292 return reinterpret_cast<CollationElementIterator *>(uc);
293 }
295 static inline const CollationElementIterator *fromUCollationElements(const UCollationElements *uc) {
296 return reinterpret_cast<const CollationElementIterator *>(uc);
297 }
299 inline UCollationElements *toUCollationElements() {
300 return reinterpret_cast<UCollationElements *>(this);
301 }
303 inline const UCollationElements *toUCollationElements() const {
304 return reinterpret_cast<const UCollationElements *>(this);
305 }
306 #endif // U_HIDE_INTERNAL_API
307
308 private:
309 friend class RuleBasedCollator;
310 friend class UCollationPCE;
311
321 CollationElementIterator(const UnicodeString& sourceText,
322 const RuleBasedCollator* order, UErrorCode& status);
323 // Note: The constructors should take settings & tailoring, not a collator,
324 // to avoid circular dependencies.
325 // However, for operator==() we would need to be able to compare tailoring data for equality
326 // without making CollationData or CollationTailoring depend on TailoredSet.
327 // (See the implementation of RuleBasedCollator::operator==().)
328 // That might require creating an intermediate class that would be used
329 // by both CollationElementIterator and RuleBasedCollator
330 // but only contain the part of RBC== related to data and rules.
331
341 CollationElementIterator(const CharacterIterator& sourceText,
342 const RuleBasedCollator* order, UErrorCode& status);
343
349 const CollationElementIterator&
350 operator=(const CollationElementIterator& other);
351
352 CollationElementIterator(); // default constructor not implemented
353
355 inline int8_t normalizeDir() const { return dir_ == 1 ? 0 : dir_; }
356
357 static UHashtable *computeMaxExpansions(const CollationData *data, UErrorCode &errorCode);
358
359 static int32_t getMaxExpansion(const UHashtable *maxExpansions, int32_t order);
360
361 // CollationElementIterator private data members ----------------------------
362
363 CollationIterator *iter_; // owned
364 const RuleBasedCollator *rbc_; // aliased
365 uint32_t otherHalf_;
370 int8_t dir_;
376 UVector32 *offsets_;
377
378 UnicodeString string_;
379 };
380
381 // CollationElementIterator inline method definitions --------------------------
382
383 inline int32_t CollationElementIterator::primaryOrder(int32_t order)
384 {
385 return (order >> 16) & 0xffff;
386 }
387
388 inline int32_t CollationElementIterator::secondaryOrder(int32_t order)
389 {
390 return (order >> 8) & 0xff;
391 }
392
393 inline int32_t CollationElementIterator::tertiaryOrder(int32_t order)
394 {
395 return order & 0xff;
396 }
397
398 inline UBool CollationElementIterator::isIgnorable(int32_t order)
399 {
400 return (order & 0xffff0000) == 0;
401 }
402
403 U_NAMESPACE_END
404
405 #endif /* #if !UCONFIG_NO_COLLATION */
406
407 #endif
UHashtable
struct UHashtable UHashtable
Definition: msgfmt.h:41
icu::CollationElementIterator::fromUCollationElements
static CollationElementIterator * fromUCollationElements(UCollationElements *uc)
Definition: coleitr.h:291
icu::CollationElementIterator::toUCollationElements
const UCollationElements * toUCollationElements() const
Definition: coleitr.h:303
unistr.h
C++ API: Unicode String.
icu::operator==
U_EXPORT UBool operator==(const StringPiece &x, const StringPiece &y)
Global operator == for StringPiece.
UClassID
void * UClassID
UClassID is used to identify classes without using the compiler&#39;s RTTI.
Definition: uobject.h:90
UCollationElements
struct UCollationElements UCollationElements
The UCollationElements struct.
Definition: ucoleitr.h:39
U_I18N_API
#define U_I18N_API
Set to export library symbols from inside the i18n library, and to import them from outside...
Definition: utypes.h:301
U_NAMESPACE_BEGIN
#define U_NAMESPACE_BEGIN
This is used to begin a declaration of a public ICU C++ API.
Definition: uversion.h:137
icu::RuleBasedCollator
The RuleBasedCollator class provides the implementation of Collator, using data-driven tables...
Definition: tblcoll.h:113
icu::CollationElementIterator::fromUCollationElements
static const CollationElementIterator * fromUCollationElements(const UCollationElements *uc)
Definition: coleitr.h:295
icu::CharacterIterator
Abstract class that defines an API for iteration on text objects.
Definition: chariter.h:358
icu::operator!=
UBool operator!=(const StringPiece &x, const StringPiece &y)
Global operator != for StringPiece.
Definition: stringpiece.h:218
icu::CollationElementIterator
The CollationElementIterator class is used as an iterator to walk through each character of an inter...
Definition: coleitr.h:119
icu::UObject::getDynamicClassID
virtual UClassID getDynamicClassID() const
ICU4C "poor man&#39;s RTTI", returns a UClassID for the actual ICU class.
icu::CollationElementIterator::toUCollationElements
UCollationElements * toUCollationElements()
Definition: coleitr.h:299
uobject.h
C++ API: Common ICU base class UObject.
U_NAMESPACE_END
#define U_NAMESPACE_END
This is used to end a declaration of a public ICU C++ API.
Definition: uversion.h:138
UErrorCode
UErrorCode
Error code to replace exception handling, so that the code is compatible with all C++ compilers...
Definition: utypes.h:401
U_FINAL
#define U_FINAL
Defined to the C++11 "final" keyword if available.
Definition: umachine.h:140
utypes.h
Basic definitions for ICU, for both C and C++ APIs.
icu::UnicodeString
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
Definition: unistr.h:289
icu::UObject
UObject is the common ICU "boilerplate" class.
Definition: uobject.h:220
UBool
int8_t UBool
The ICU boolean type.
Definition: umachine.h:225