ICU4C 79
Loading...
Searching...
No Matches
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
14
32
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
46struct UHashtable;
47
48U_NAMESPACE_BEGIN
49
50struct CollationData;
51
52class CharacterIterator;
53class CollationIterator;
54class RuleBasedCollator;
55class UCollationPCE;
56class UVector32;
57
122public:
123
124 // CollationElementIterator public data member ------------------------------
125
126 enum {
131 NULLORDER = static_cast<int32_t>(0xffffffff)
132 };
133
134 // CollationElementIterator public constructor/destructor -------------------
135
143
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();
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
252
259 static inline UBool isIgnorable(int32_t order);
260
266 int32_t getOffset() const;
267
274 void setOffset(int32_t newOffset, UErrorCode& status);
275
281 virtual UClassID getDynamicClassID() const override;
282
288 static UClassID U_EXPORT2 getStaticClassID();
289
290#ifndef U_HIDE_INTERNAL_API
293 return reinterpret_cast<CollationElementIterator *>(uc);
294 }
295
297 return reinterpret_cast<const CollationElementIterator *>(uc);
298 }
299
301 return reinterpret_cast<UCollationElements *>(this);
302 }
303
305 return reinterpret_cast<const UCollationElements *>(this);
306 }
307#endif // U_HIDE_INTERNAL_API
308
309private:
310 friend class RuleBasedCollator;
311 friend class UCollationPCE;
312
322 CollationElementIterator(const UnicodeString& sourceText,
323 const RuleBasedCollator* order, UErrorCode& status);
324 // Note: The constructors should take settings & tailoring, not a collator,
325 // to avoid circular dependencies.
326 // However, for operator==() we would need to be able to compare tailoring data for equality
327 // without making CollationData or CollationTailoring depend on TailoredSet.
328 // (See the implementation of RuleBasedCollator::operator==().)
329 // That might require creating an intermediate class that would be used
330 // by both CollationElementIterator and RuleBasedCollator
331 // but only contain the part of RBC== related to data and rules.
332
343 const RuleBasedCollator* order, UErrorCode& status);
344
351 operator=(const CollationElementIterator& other);
352
353 CollationElementIterator() = delete; // default constructor not implemented
354
356 inline int8_t normalizeDir() const { return dir_ == 1 ? 0 : dir_; }
357
358 static UHashtable *computeMaxExpansions(const CollationData *data, UErrorCode &errorCode);
359
360 static int32_t getMaxExpansion(const UHashtable *maxExpansions, int32_t order);
361
362 // CollationElementIterator private data members ----------------------------
363
364 CollationIterator *iter_; // owned
365 const RuleBasedCollator *rbc_; // aliased
366 uint32_t otherHalf_;
371 int8_t dir_;
377 UVector32 *offsets_;
378
379 UnicodeString string_;
380};
381
382// CollationElementIterator inline method definitions --------------------------
383
384inline int32_t CollationElementIterator::primaryOrder(int32_t order)
385{
386 return (order >> 16) & 0xffff;
387}
388
389inline int32_t CollationElementIterator::secondaryOrder(int32_t order)
390{
391 return (order >> 8) & 0xff;
392}
393
394inline int32_t CollationElementIterator::tertiaryOrder(int32_t order)
395{
396 return order & 0xff;
397}
398
400{
401 return (order & 0xffff0000) == 0;
402}
403
404U_NAMESPACE_END
405
406#endif /* #if !UCONFIG_NO_COLLATION */
407
408#endif /* U_SHOW_CPLUSPLUS_API */
409
410#endif
Abstract class that defines an API for iteration on text objects.
Definition chariter.h:363
The CollationElementIterator class is used as an iterator to walk through each character of an inte...
Definition coleitr.h:121
static UClassID getStaticClassID()
ICU "poor man's RTTI", returns a UClassID for this class.
int32_t strengthOrder(int32_t order) const
Gets the comparison order in the desired strength.
const UCollationElements * toUCollationElements() const
Definition coleitr.h:304
static int32_t primaryOrder(int32_t order)
Gets the primary order of a collation order.
Definition coleitr.h:384
static int32_t secondaryOrder(int32_t order)
Gets the secondary order of a collation order.
Definition coleitr.h:389
int32_t previous(UErrorCode &status)
Get the ordering priority of the previous collation element in the string.
virtual UClassID getDynamicClassID() const override
ICU "poor man's RTTI", returns a UClassID for the actual class.
static UBool isIgnorable(int32_t order)
Checks if a comparison order is ignorable.
Definition coleitr.h:399
bool operator==(const CollationElementIterator &other) const
Returns true if "other" is the same as "this".
static CollationElementIterator * fromUCollationElements(UCollationElements *uc)
Definition coleitr.h:292
UCollationElements * toUCollationElements()
Definition coleitr.h:300
void setText(CharacterIterator &str, UErrorCode &status)
Sets the source string.
bool operator!=(const CollationElementIterator &other) const
Returns true if "other" is not the same as "this".
int32_t getOffset() const
Gets the offset of the currently processed character in the source string.
static const CollationElementIterator * fromUCollationElements(const UCollationElements *uc)
Definition coleitr.h:296
static int32_t tertiaryOrder(int32_t order)
Gets the tertiary order of a collation order.
Definition coleitr.h:394
CollationElementIterator(const CollationElementIterator &other)
Copy constructor.
void setText(const UnicodeString &str, UErrorCode &status)
Sets the source string.
int32_t getMaxExpansion(int32_t order) const
Return the maximum length of any expansion sequences that end with the specified comparison order.
int32_t next(UErrorCode &status)
Gets the ordering priority of the next character in the string.
@ NULLORDER
NULLORDER indicates that an error has occurred while processing.
Definition coleitr.h:131
void reset()
Resets the cursor to the beginning of the string.
void setOffset(int32_t newOffset, UErrorCode &status)
Sets the offset of the currently processed character in the source string.
virtual ~CollationElementIterator()
Destructor.
The RuleBasedCollator class provides the implementation of Collator, using data-driven tables.
Definition tblcoll.h:115
UObject is the common ICU "boilerplate" class.
Definition uobject.h:222
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
Definition unistr.h:303
struct UHashtable UHashtable
Definition msgfmt.h:43
struct UCollationElements UCollationElements
The UCollationElements struct.
Definition ucoleitr.h:39
int8_t UBool
The ICU boolean type, a signed-byte integer.
Definition umachine.h:269
C++ API: Unicode String.
C++ API: Common ICU base class UObject.
void * UClassID
UClassID is used to identify classes without using the compiler's RTTI.
Definition uobject.h:96
Basic definitions for ICU, for both C and C++ APIs.
UErrorCode
Standard ICU4C error code type, a substitute for exceptions.
Definition utypes.h:509
#define U_I18N_API
Set to export library symbols from inside the i18n library, and to import them from outside.
Definition utypes.h:316