ICU 4.8.1.1  4.8.1.1
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
tblcoll.h
Go to the documentation of this file.
1 /*
2 ******************************************************************************
3 * Copyright (C) 1996-2011, 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;
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 
232  virtual UBool operator!=(const Collator& other) const;
233 
240  virtual Collator* clone(void) const;
241 
252  virtual CollationElementIterator* createCollationElementIterator(
253  const UnicodeString& source) const;
254 
264  virtual CollationElementIterator* createCollationElementIterator(
265  const CharacterIterator& source) const;
266 
279  virtual EComparisonResult compare(const UnicodeString& source,
280  const UnicodeString& target) const;
281 
282 
295  virtual UCollationResult compare(const UnicodeString& source,
296  const UnicodeString& target,
297  UErrorCode &status) const;
298 
312  virtual EComparisonResult compare(const UnicodeString& source,
313  const UnicodeString& target,
314  int32_t length) const;
315 
329  virtual UCollationResult compare(const UnicodeString& source,
330  const UnicodeString& target,
331  int32_t length,
332  UErrorCode &status) const;
333 
367  virtual EComparisonResult compare(const UChar* source, int32_t sourceLength,
368  const UChar* target, int32_t targetLength)
369  const;
370 
387  virtual UCollationResult compare(const UChar* source, int32_t sourceLength,
388  const UChar* target, int32_t targetLength,
389  UErrorCode &status) const;
390 
402  virtual UCollationResult compare(UCharIterator &sIter,
403  UCharIterator &tIter,
404  UErrorCode &status) const;
405 
418  virtual CollationKey& getCollationKey(const UnicodeString& source,
419  CollationKey& key,
420  UErrorCode& status) const;
421 
435  virtual CollationKey& getCollationKey(const UChar *source,
436  int32_t sourceLength,
437  CollationKey& key,
438  UErrorCode& status) const;
439 
445  virtual int32_t hashCode(void) const;
446 
457  virtual const Locale getLocale(ULocDataLocaleType type, UErrorCode& status) const;
458 
465  const UnicodeString& getRules(void) const;
466 
472  virtual void getVersion(UVersionInfo info) const;
473 
484  int32_t getMaxExpansion(int32_t order) const;
485 
496  virtual UClassID getDynamicClassID(void) const;
497 
509  static UClassID U_EXPORT2 getStaticClassID(void);
510 
519  uint8_t *cloneRuleData(int32_t &length, UErrorCode &status);
520 
521 
532  int32_t cloneBinary(uint8_t *buffer, int32_t capacity, UErrorCode &status);
533 
541  void getRules(UColRuleOption delta, UnicodeString &buffer);
542 
550  virtual void setAttribute(UColAttribute attr, UColAttributeValue value,
551  UErrorCode &status);
552 
561  UErrorCode &status);
562 
573  virtual uint32_t setVariableTop(const UChar *varTop, int32_t len, UErrorCode &status);
574 
584  virtual uint32_t setVariableTop(const UnicodeString varTop, UErrorCode &status);
585 
593  virtual void setVariableTop(const uint32_t varTop, UErrorCode &status);
594 
601  virtual uint32_t getVariableTop(UErrorCode &status) const;
602 
612  virtual UnicodeSet *getTailoredSet(UErrorCode &status) const;
613 
619  virtual Collator* safeClone(void);
620 
631  virtual int32_t getSortKey(const UnicodeString& source, uint8_t *result,
632  int32_t resultLength) const;
633 
646  virtual int32_t getSortKey(const UChar *source, int32_t sourceLength,
647  uint8_t *result, int32_t resultLength) const;
648 
659  virtual ECollationStrength getStrength(void) const;
660 
667  virtual void setStrength(ECollationStrength newStrength);
668 
682  virtual int32_t U_EXPORT2 getReorderCodes(int32_t *dest,
683  int32_t destCapacity,
684  UErrorCode& status) const;
685 
696  virtual void U_EXPORT2 setReorderCodes(const int32_t* reorderCodes,
697  int32_t reorderCodesLength,
698  UErrorCode& status) ;
699 
716  static int32_t U_EXPORT2 getEquivalentReorderCodes(int32_t reorderCode,
717  int32_t* dest,
718  int32_t destCapacity,
719  UErrorCode& status);
720 
721 
722 private:
723 
724  // private static constants -----------------------------------------------
725 
726  enum {
727  /* need look up in .commit() */
728  CHARINDEX = 0x70000000,
729  /* Expand index follows */
730  EXPANDCHARINDEX = 0x7E000000,
731  /* contract indexes follows */
732  CONTRACTCHARINDEX = 0x7F000000,
733  /* unmapped character values */
734  UNMAPPED = 0xFFFFFFFF,
735  /* primary strength increment */
736  PRIMARYORDERINCREMENT = 0x00010000,
737  /* secondary strength increment */
738  SECONDARYORDERINCREMENT = 0x00000100,
739  /* tertiary strength increment */
740  TERTIARYORDERINCREMENT = 0x00000001,
741  /* mask off anything but primary order */
742  PRIMARYORDERMASK = 0xffff0000,
743  /* mask off anything but secondary order */
744  SECONDARYORDERMASK = 0x0000ff00,
745  /* mask off anything but tertiary order */
746  TERTIARYORDERMASK = 0x000000ff,
747  /* mask off ignorable char order */
748  IGNORABLEMASK = 0x0000ffff,
749  /* use only the primary difference */
750  PRIMARYDIFFERENCEONLY = 0xffff0000,
751  /* use only the primary and secondary difference */
752  SECONDARYDIFFERENCEONLY = 0xffffff00,
753  /* primary order shift */
754  PRIMARYORDERSHIFT = 16,
755  /* secondary order shift */
756  SECONDARYORDERSHIFT = 8,
757  /* starting value for collation elements */
758  COLELEMENTSTART = 0x02020202,
759  /* testing mask for primary low element */
760  PRIMARYLOWZEROMASK = 0x00FF0000,
761  /* reseting value for secondaries and tertiaries */
762  RESETSECONDARYTERTIARY = 0x00000202,
763  /* reseting value for tertiaries */
764  RESETTERTIARY = 0x00000002,
765 
766  PRIMIGNORABLE = 0x0202
767  };
768 
769  // private data members ---------------------------------------------------
770 
771  UBool dataIsOwned;
772 
773  UBool isWriteThroughAlias;
774 
779  UCollator *ucollator;
780 
784  UnicodeString urulestring;
785 
786  // friend classes --------------------------------------------------------
787 
792 
797  friend class Collator;
798 
802  friend class StringSearch;
803 
804  // private constructors --------------------------------------------------
805 
810 
821  RuleBasedCollator(const Locale& desiredLocale, UErrorCode& status);
822 
831  void
832  construct(const UnicodeString& rules,
833  UColAttributeValue collationStrength,
834  UColAttributeValue decompositionMode,
835  UErrorCode& status);
836 
837  // private methods -------------------------------------------------------
838 
844  void setUCollator(const Locale& locale, UErrorCode& status);
845 
851  void setUCollator(const char* locale, UErrorCode& status);
852 
859  void setUCollator(UCollator *collator);
860 
861 public:
867  const UCollator * getUCollator();
868 
869 protected:
877  virtual void setLocales(const Locale& requestedLocale, const Locale& validLocale, const Locale& actualLocale);
878 
879 private:
880 
881  // if not owned and not a write through alias, copy the ucollator
882  void checkOwned(void);
883 
884  // utility to init rule string used by checkOwned and construct
885  void setRuleStringFromCollator();
886 
893  Collator::EComparisonResult getEComparisonResult(
894  const UCollationResult &result) const;
895 
901  Collator::ECollationStrength getECollationStrength(
902  const UCollationStrength &strength) const;
903 
909  UCollationStrength getUCollationStrength(
910  const Collator::ECollationStrength &strength) const;
911 };
912 
913 // inline method implementation ---------------------------------------------
914 
915 inline void RuleBasedCollator::setUCollator(const Locale &locale,
916  UErrorCode &status)
917 {
918  setUCollator(locale.getName(), status);
919 }
920 
921 
922 inline void RuleBasedCollator::setUCollator(UCollator *collator)
923 {
924 
925  if (ucollator && dataIsOwned) {
926  ucol_close(ucollator);
927  }
928  ucollator = collator;
929  dataIsOwned = FALSE;
930  isWriteThroughAlias = TRUE;
931  setRuleStringFromCollator();
932 }
933 
935 {
936  return ucollator;
937 }
938 
939 inline Collator::EComparisonResult RuleBasedCollator::getEComparisonResult(
940  const UCollationResult &result) const
941 {
942  switch (result)
943  {
944  case UCOL_LESS :
945  return Collator::LESS;
946  case UCOL_EQUAL :
947  return Collator::EQUAL;
948  default :
949  return Collator::GREATER;
950  }
951 }
952 
953 inline Collator::ECollationStrength RuleBasedCollator::getECollationStrength(
954  const UCollationStrength &strength) const
955 {
956  switch (strength)
957  {
958  case UCOL_PRIMARY :
959  return Collator::PRIMARY;
960  case UCOL_SECONDARY :
961  return Collator::SECONDARY;
962  case UCOL_TERTIARY :
963  return Collator::TERTIARY;
964  case UCOL_QUATERNARY :
965  return Collator::QUATERNARY;
966  default :
967  return Collator::IDENTICAL;
968  }
969 }
970 
971 inline UCollationStrength RuleBasedCollator::getUCollationStrength(
972  const Collator::ECollationStrength &strength) const
973 {
974  switch (strength)
975  {
976  case Collator::PRIMARY :
977  return UCOL_PRIMARY;
978  case Collator::SECONDARY :
979  return UCOL_SECONDARY;
980  case Collator::TERTIARY :
981  return UCOL_TERTIARY;
982  case Collator::QUATERNARY :
983  return UCOL_QUATERNARY;
984  default :
985  return UCOL_IDENTICAL;
986  }
987 }
988 
990 
991 #endif /* #if !UCONFIG_NO_COLLATION */
992 
993 #endif