ICU 65.1  65.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 
122 public:
123 
124  // CollationElementIterator public data member ------------------------------
125 
126  enum {
131  NULLORDER = (int32_t)0xffffffff
132  };
133 
134  // CollationElementIterator public constructor/destructor -------------------
135 
143 
148  virtual ~CollationElementIterator();
149 
150  // CollationElementIterator public methods ----------------------------------
151 
159  UBool operator==(const CollationElementIterator& other) const;
160 
168  UBool 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;
283 
289  static UClassID U_EXPORT2 getStaticClassID();
290 
291 #ifndef U_HIDE_INTERNAL_API
292 
294  return reinterpret_cast<CollationElementIterator *>(uc);
295  }
298  return reinterpret_cast<const CollationElementIterator *>(uc);
299  }
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 
344  const RuleBasedCollator* order, UErrorCode& status);
345 
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 
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
struct UHashtable UHashtable
Definition: msgfmt.h:43
static CollationElementIterator * fromUCollationElements(UCollationElements *uc)
Definition: coleitr.h:293
const UCollationElements * toUCollationElements() const
Definition: coleitr.h:305
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:96
static int32_t primaryOrder(int32_t order)
Gets the primary order of a collation order.
Definition: coleitr.h:385
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:390
The RuleBasedCollator class provides the implementation of Collator, using data-driven tables...
Definition: tblcoll.h:115
static const CollationElementIterator * fromUCollationElements(const UCollationElements *uc)
Definition: coleitr.h:297
Abstract class that defines an API for iteration on text objects.
Definition: chariter.h:361
static int32_t tertiaryOrder(int32_t order)
Gets the tertiary order of a collation order.
Definition: coleitr.h:395
UBool operator!=(const StringPiece &x, const StringPiece &y)
Global operator != for StringPiece.
Definition: stringpiece.h:251
The CollationElementIterator class is used as an iterator to walk through each character of an intern...
Definition: coleitr.h:121
virtual UClassID getDynamicClassID() const
ICU4C "poor man&#39;s RTTI", returns a UClassID for the actual ICU class.
UCollationElements * toUCollationElements()
Definition: coleitr.h:301
C++ API: Common ICU base class UObject.
UErrorCode
Standard ICU4C error code type, a substitute for exceptions.
Definition: utypes.h:415
#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:294
UObject is the common ICU "boilerplate" class.
Definition: uobject.h:223
int8_t UBool
The ICU boolean type.
Definition: umachine.h:261
static UBool isIgnorable(int32_t order)
Checks if a comparison order is ignorable.
Definition: coleitr.h:400