ICU 58.2  58.2
coleitr.h
Go to the documentation of this file.
1 // Copyright (C) 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 
47 
48 struct CollationData;
49 
50 class CollationIterator;
51 class RuleBasedCollator;
52 class UCollationPCE;
53 class UVector32;
54 
119 public:
120 
121  // CollationElementIterator public data member ------------------------------
122 
123  enum {
128  NULLORDER = (int32_t)0xffffffff
129  };
130 
131  // CollationElementIterator public constructor/destructor -------------------
132 
140 
145  virtual ~CollationElementIterator();
146 
147  // CollationElementIterator public methods ----------------------------------
148 
156  UBool operator==(const CollationElementIterator& other) const;
157 
165  UBool operator!=(const CollationElementIterator& other) const;
166 
171  void reset(void);
172 
180  int32_t next(UErrorCode& status);
181 
189  int32_t previous(UErrorCode& status);
190 
197  static inline int32_t primaryOrder(int32_t order);
198 
205  static inline int32_t secondaryOrder(int32_t order);
206 
213  static inline int32_t tertiaryOrder(int32_t order);
214 
224  int32_t getMaxExpansion(int32_t order) const;
225 
232  int32_t strengthOrder(int32_t order) const;
233 
240  void setText(const UnicodeString& str, UErrorCode& status);
241 
248  void setText(CharacterIterator& str, UErrorCode& status);
249 
256  static inline UBool isIgnorable(int32_t order);
257 
263  int32_t getOffset(void) const;
264 
272  void setOffset(int32_t newOffset, UErrorCode& status);
273 
279  virtual UClassID getDynamicClassID() const;
280 
286  static UClassID U_EXPORT2 getStaticClassID();
287 
288 #ifndef U_HIDE_INTERNAL_API
289 
291  return reinterpret_cast<CollationElementIterator *>(uc);
292  }
295  return reinterpret_cast<const CollationElementIterator *>(uc);
296  }
299  return reinterpret_cast<UCollationElements *>(this);
300  }
302  inline const UCollationElements *toUCollationElements() const {
303  return reinterpret_cast<const UCollationElements *>(this);
304  }
305 #endif // U_HIDE_INTERNAL_API
306 
307 private:
308  friend class RuleBasedCollator;
309  friend class UCollationPCE;
310 
320  CollationElementIterator(const UnicodeString& sourceText,
321  const RuleBasedCollator* order, UErrorCode& status);
322  // Note: The constructors should take settings & tailoring, not a collator,
323  // to avoid circular dependencies.
324  // However, for operator==() we would need to be able to compare tailoring data for equality
325  // without making CollationData or CollationTailoring depend on TailoredSet.
326  // (See the implementation of RuleBasedCollator::operator==().)
327  // That might require creating an intermediate class that would be used
328  // by both CollationElementIterator and RuleBasedCollator
329  // but only contain the part of RBC== related to data and rules.
330 
341  const RuleBasedCollator* order, UErrorCode& status);
342 
349  operator=(const CollationElementIterator& other);
350 
351  CollationElementIterator(); // default constructor not implemented
352 
354  inline int8_t normalizeDir() const { return dir_ == 1 ? 0 : dir_; }
355 
356  static UHashtable *computeMaxExpansions(const CollationData *data, UErrorCode &errorCode);
357 
358  static int32_t getMaxExpansion(const UHashtable *maxExpansions, int32_t order);
359 
360  // CollationElementIterator private data members ----------------------------
361 
362  CollationIterator *iter_; // owned
363  const RuleBasedCollator *rbc_; // aliased
364  uint32_t otherHalf_;
369  int8_t dir_;
375  UVector32 *offsets_;
376 
377  UnicodeString string_;
378 };
379 
380 // CollationElementIterator inline method definitions --------------------------
381 
382 inline int32_t CollationElementIterator::primaryOrder(int32_t order)
383 {
384  return (order >> 16) & 0xffff;
385 }
386 
387 inline int32_t CollationElementIterator::secondaryOrder(int32_t order)
388 {
389  return (order >> 8) & 0xff;
390 }
391 
392 inline int32_t CollationElementIterator::tertiaryOrder(int32_t order)
393 {
394  return order & 0xff;
395 }
396 
398 {
399  return (order & 0xffff0000) == 0;
400 }
401 
403 
404 #endif /* #if !UCONFIG_NO_COLLATION */
405 
406 #endif
static CollationElementIterator * fromUCollationElements(UCollationElements *uc)
Definition: coleitr.h:290
virtual UClassID getDynamicClassID() const
ICU4C "poor man&#39;s RTTI", returns a UClassID for the actual ICU class.
C++ API: Unicode String.
U_EXPORT UBool operator==(const StringPiece &x, const StringPiece &y)
Global operator == for StringPiece.
void * UClassID
UClassID is used to identify classes without using the compiler&#39;s RTTI.
Definition: uobject.h:93
static int32_t primaryOrder(int32_t order)
Gets the primary order of a collation order.
Definition: coleitr.h:382
struct UCollationElements UCollationElements
The UCollationElements struct.
Definition: ucoleitr.h:39
#define U_I18N_API
Set to export library symbols from inside the i18n library, and to import them from outside...
Definition: utypes.h:360
static int32_t secondaryOrder(int32_t order)
Gets the secondary order of a collation order.
Definition: coleitr.h:387
#define U_NAMESPACE_BEGIN
This is used to begin a declaration of a public ICU C++ API.
Definition: uversion.h:131
The RuleBasedCollator class provides the implementation of Collator, using data-driven tables...
Definition: tblcoll.h:113
static const CollationElementIterator * fromUCollationElements(const UCollationElements *uc)
Definition: coleitr.h:294
Abstract class that defines an API for iteration on text objects.
Definition: chariter.h:358
static int32_t tertiaryOrder(int32_t order)
Gets the tertiary order of a collation order.
Definition: coleitr.h:392
UBool operator!=(const StringPiece &x, const StringPiece &y)
Global operator != for StringPiece.
Definition: stringpiece.h:220
The CollationElementIterator class is used as an iterator to walk through each character of an intern...
Definition: coleitr.h:118
UCollationElements * toUCollationElements()
Definition: coleitr.h:298
C++ API: Common ICU base class UObject.
#define U_NAMESPACE_END
This is used to end a declaration of a public ICU C++ API.
Definition: uversion.h:132
UErrorCode
Error code to replace exception handling, so that the code is compatible with all C++ compilers...
Definition: utypes.h:396
Basic definitions for ICU, for both C and C++ APIs.
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
Definition: unistr.h:295
const UCollationElements * toUCollationElements() const
Definition: coleitr.h:302
UObject is the common ICU "boilerplate" class.
Definition: uobject.h:223
int8_t UBool
The ICU boolean type.
Definition: umachine.h:259
static UBool isIgnorable(int32_t order)
Checks if a comparison order is ignorable.
Definition: coleitr.h:397