ICU 51.2  51.2
tblcoll.h
Go to the documentation of this file.
1 /*
2 ******************************************************************************
3 * Copyright (C) 1996-2013, International Business Machines Corporation and
4 * others. All Rights Reserved.
5 ******************************************************************************
6 */
7 
59 #ifndef TBLCOLL_H
60 #define TBLCOLL_H
61 
62 #include "unicode/utypes.h"
63 
64 
65 #if !UCONFIG_NO_COLLATION
66 
67 #include "unicode/coll.h"
68 #include "unicode/ucol.h"
69 #include "unicode/sortkey.h"
70 #include "unicode/normlzr.h"
71 
73 
77 class StringSearch;
81 class CollationElementIterator;
82 
112 {
113 public:
114 
115  // constructor -------------------------------------------------------------
116 
126  RuleBasedCollator(const UnicodeString& rules, UErrorCode& status);
127 
138  RuleBasedCollator(const UnicodeString& rules,
139  ECollationStrength collationStrength,
140  UErrorCode& status);
141 
152  RuleBasedCollator(const UnicodeString& rules,
153  UColAttributeValue decompositionMode,
154  UErrorCode& status);
155 
167  RuleBasedCollator(const UnicodeString& rules,
168  ECollationStrength collationStrength,
169  UColAttributeValue decompositionMode,
170  UErrorCode& status);
171 
178  RuleBasedCollator(const RuleBasedCollator& other);
179 
180 
198  RuleBasedCollator(const uint8_t *bin, int32_t length,
199  const RuleBasedCollator *base,
200  UErrorCode &status);
201  // destructor --------------------------------------------------------------
202 
207  virtual ~RuleBasedCollator();
208 
209  // public methods ----------------------------------------------------------
210 
216  RuleBasedCollator& operator=(const RuleBasedCollator& other);
217 
224  virtual UBool operator==(const Collator& other) const;
225 
231  virtual Collator* clone(void) const;
232 
243  virtual CollationElementIterator* createCollationElementIterator(
244  const UnicodeString& source) const;
245 
255  virtual CollationElementIterator* createCollationElementIterator(
256  const CharacterIterator& source) const;
257 
258  // Make deprecated versions of Collator::compare() visible.
259  using Collator::compare;
260 
273  virtual UCollationResult compare(const UnicodeString& source,
274  const UnicodeString& target,
275  UErrorCode &status) const;
276 
290  virtual UCollationResult compare(const UnicodeString& source,
291  const UnicodeString& target,
292  int32_t length,
293  UErrorCode &status) const;
294 
311  virtual UCollationResult compare(const UChar* source, int32_t sourceLength,
312  const UChar* target, int32_t targetLength,
313  UErrorCode &status) const;
314 
326  virtual UCollationResult compare(UCharIterator &sIter,
327  UCharIterator &tIter,
328  UErrorCode &status) const;
329 
342  virtual CollationKey& getCollationKey(const UnicodeString& source,
343  CollationKey& key,
344  UErrorCode& status) const;
345 
359  virtual CollationKey& getCollationKey(const UChar *source,
360  int32_t sourceLength,
361  CollationKey& key,
362  UErrorCode& status) const;
363 
369  virtual int32_t hashCode(void) const;
370 
381  virtual Locale getLocale(ULocDataLocaleType type, UErrorCode& status) const;
382 
388  const UnicodeString& getRules(void) const;
389 
395  virtual void getVersion(UVersionInfo info) const;
396 
397 #ifndef U_HIDE_DEPRECATED_API
398 
414  int32_t getMaxExpansion(int32_t order) const;
415 #endif /* U_HIDE_DEPRECATED_API */
416 
427  virtual UClassID getDynamicClassID(void) const;
428 
440  static UClassID U_EXPORT2 getStaticClassID(void);
441 
450  uint8_t *cloneRuleData(int32_t &length, UErrorCode &status);
451 
452 
463  int32_t cloneBinary(uint8_t *buffer, int32_t capacity, UErrorCode &status);
464 
476  void getRules(UColRuleOption delta, UnicodeString &buffer);
477 
485  virtual void setAttribute(UColAttribute attr, UColAttributeValue value,
486  UErrorCode &status);
487 
496  UErrorCode &status) const;
497 
508  virtual uint32_t setVariableTop(const UChar *varTop, int32_t len, UErrorCode &status);
509 
519  virtual uint32_t setVariableTop(const UnicodeString &varTop, UErrorCode &status);
520 
528  virtual void setVariableTop(uint32_t varTop, UErrorCode &status);
529 
536  virtual uint32_t getVariableTop(UErrorCode &status) const;
537 
547  virtual UnicodeSet *getTailoredSet(UErrorCode &status) const;
548 
559  virtual int32_t getSortKey(const UnicodeString& source, uint8_t *result,
560  int32_t resultLength) const;
561 
574  virtual int32_t getSortKey(const UChar *source, int32_t sourceLength,
575  uint8_t *result, int32_t resultLength) const;
576 
590  virtual int32_t getReorderCodes(int32_t *dest,
591  int32_t destCapacity,
592  UErrorCode& status) const;
593 
604  virtual void setReorderCodes(const int32_t* reorderCodes,
605  int32_t reorderCodesLength,
606  UErrorCode& status) ;
607 
624  static int32_t U_EXPORT2 getEquivalentReorderCodes(int32_t reorderCode,
625  int32_t* dest,
626  int32_t destCapacity,
627  UErrorCode& status);
628 
629 private:
630 
631  // private static constants -----------------------------------------------
632 
633  enum {
634  /* need look up in .commit() */
635  CHARINDEX = 0x70000000,
636  /* Expand index follows */
637  EXPANDCHARINDEX = 0x7E000000,
638  /* contract indexes follows */
639  CONTRACTCHARINDEX = 0x7F000000,
640  /* unmapped character values */
641  UNMAPPED = 0xFFFFFFFF,
642  /* primary strength increment */
643  PRIMARYORDERINCREMENT = 0x00010000,
644  /* secondary strength increment */
645  SECONDARYORDERINCREMENT = 0x00000100,
646  /* tertiary strength increment */
647  TERTIARYORDERINCREMENT = 0x00000001,
648  /* mask off anything but primary order */
649  PRIMARYORDERMASK = 0xffff0000,
650  /* mask off anything but secondary order */
651  SECONDARYORDERMASK = 0x0000ff00,
652  /* mask off anything but tertiary order */
653  TERTIARYORDERMASK = 0x000000ff,
654  /* mask off ignorable char order */
655  IGNORABLEMASK = 0x0000ffff,
656  /* use only the primary difference */
657  PRIMARYDIFFERENCEONLY = 0xffff0000,
658  /* use only the primary and secondary difference */
659  SECONDARYDIFFERENCEONLY = 0xffffff00,
660  /* primary order shift */
661  PRIMARYORDERSHIFT = 16,
662  /* secondary order shift */
663  SECONDARYORDERSHIFT = 8,
664  /* starting value for collation elements */
665  COLELEMENTSTART = 0x02020202,
666  /* testing mask for primary low element */
667  PRIMARYLOWZEROMASK = 0x00FF0000,
668  /* reseting value for secondaries and tertiaries */
669  RESETSECONDARYTERTIARY = 0x00000202,
670  /* reseting value for tertiaries */
671  RESETTERTIARY = 0x00000002,
672 
673  PRIMIGNORABLE = 0x0202
674  };
675 
676  // private data members ---------------------------------------------------
677 
678  UBool dataIsOwned;
679 
680  UBool isWriteThroughAlias;
681 
686  UCollator *ucollator;
687 
691  UnicodeString urulestring;
692 
693  // friend classes --------------------------------------------------------
694 
699 
704  friend class Collator;
705 
709  friend class StringSearch;
710 
711  // private constructors --------------------------------------------------
712 
717 
728  RuleBasedCollator(const Locale& desiredLocale, UErrorCode& status);
729 
738  void
739  construct(const UnicodeString& rules,
740  UColAttributeValue collationStrength,
741  UColAttributeValue decompositionMode,
742  UErrorCode& status);
743 
744  // private methods -------------------------------------------------------
745 
751  void setUCollator(const Locale& locale, UErrorCode& status);
752 
758  void setUCollator(const char* locale, UErrorCode& status);
759 
766  void setUCollator(UCollator *collator);
767 
768 public:
769 #ifndef U_HIDE_INTERNAL_API
770 
775  const UCollator * getUCollator();
776 #endif /* U_HIDE_INTERNAL_API */
777 
778 protected:
786  virtual void setLocales(const Locale& requestedLocale, const Locale& validLocale, const Locale& actualLocale);
787 
788 private:
789  // if not owned and not a write through alias, copy the ucollator
790  void checkOwned(void);
791 
792  // utility to init rule string used by checkOwned and construct
793  void setRuleStringFromCollator();
794 
795 public:
819  virtual int32_t internalGetShortDefinitionString(const char *locale,
820  char *buffer,
821  int32_t capacity,
822  UErrorCode &status) const;
823 };
824 
825 // inline method implementation ---------------------------------------------
826 
827 inline void RuleBasedCollator::setUCollator(const Locale &locale,
828  UErrorCode &status)
829 {
830  setUCollator(locale.getName(), status);
831 }
832 
833 
834 inline void RuleBasedCollator::setUCollator(UCollator *collator)
835 {
836 
837  if (ucollator && dataIsOwned) {
838  ucol_close(ucollator);
839  }
840  ucollator = collator;
841  dataIsOwned = FALSE;
842  isWriteThroughAlias = TRUE;
843  setRuleStringFromCollator();
844 }
845 
846 inline const UCollator * RuleBasedCollator::getUCollator()
847 {
848  return ucollator;
849 }
850 
852 
853 #endif /* #if !UCONFIG_NO_COLLATION */
854 
855 #endif