ICU 64.2  64.2
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 
47 
48 struct CollationData;
49 
50 class CharacterIterator;
51 class CollationIterator;
52 class RuleBasedCollator;
53 class UCollationPCE;
54 class UVector32;
55 
120 public:
121 
122  // CollationElementIterator public data member ------------------------------
123 
124  enum {
129  NULLORDER = (int32_t)0xffffffff
130  };
131 
132  // CollationElementIterator public constructor/destructor -------------------
133 
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 
292  return reinterpret_cast<CollationElementIterator *>(uc);
293  }
296  return reinterpret_cast<const CollationElementIterator *>(uc);
297  }
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 
342  const RuleBasedCollator* order, UErrorCode& status);
343 
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 
399 {
400  return (order & 0xffff0000) == 0;
401 }
402 
404 
405 #endif /* #if !UCONFIG_NO_COLLATION */
406 
407 #endif
struct UHashtable UHashtable
Definition: msgfmt.h:41
static CollationElementIterator * fromUCollationElements(UCollationElements *uc)
Definition: coleitr.h:291
const UCollationElements * toUCollationElements() const
Definition: coleitr.h:303
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:383
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:301
static int32_t secondaryOrder(int32_t order)
Gets the secondary order of a collation order.
Definition: coleitr.h:388
#define U_NAMESPACE_BEGIN
This is used to begin a declaration of a public ICU C++ API.
Definition: uversion.h:137
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:295
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:393
UBool operator!=(const StringPiece &x, const StringPiece &y)
Global operator != for StringPiece.
Definition: stringpiece.h:218
The CollationElementIterator class is used as an iterator to walk through each character of an intern...
Definition: coleitr.h:119
virtual UClassID getDynamicClassID() const
ICU4C "poor man&#39;s RTTI", returns a UClassID for the actual ICU class.
UCollationElements * toUCollationElements()
Definition: coleitr.h:299
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:138
UErrorCode
Error code to replace exception handling, so that the code is compatible with all C++ compilers...
Definition: utypes.h:401
#define U_FINAL
Defined to the C++11 "final" keyword if available.
Definition: umachine.h:140
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:289
UObject is the common ICU "boilerplate" class.
Definition: uobject.h:223
int8_t UBool
The ICU boolean type.
Definition: umachine.h:225
static UBool isIgnorable(int32_t order)
Checks if a comparison order is ignorable.
Definition: coleitr.h:398