tblcoll.h

Go to the documentation of this file.
00001 /*
00002 ******************************************************************************
00003 * Copyright (C) 1996-2006, International Business Machines Corporation and
00004 * others. All Rights Reserved.
00005 ******************************************************************************
00006 */
00007 
00054 #ifndef TBLCOLL_H
00055 #define TBLCOLL_H
00056 
00057 #include "unicode/utypes.h"
00058 
00064 #if !UCONFIG_NO_COLLATION
00065 
00066 #include "unicode/coll.h"
00067 #include "unicode/ucol.h"
00068 #include "unicode/sortkey.h"
00069 #include "unicode/normlzr.h"
00070 
00071 U_NAMESPACE_BEGIN
00072 
00076 class StringSearch;
00080 class CollationElementIterator;
00081 
00110 class U_I18N_API RuleBasedCollator : public Collator
00111 {
00112 public:
00113 
00114   // constructor -------------------------------------------------------------
00115 
00125     RuleBasedCollator(const UnicodeString& rules, UErrorCode& status);
00126 
00137     RuleBasedCollator(const UnicodeString& rules,
00138                        ECollationStrength collationStrength,
00139                        UErrorCode& status);
00140 
00151     RuleBasedCollator(const UnicodeString& rules,
00152                     UColAttributeValue decompositionMode,
00153                     UErrorCode& status);
00154 
00166     RuleBasedCollator(const UnicodeString& rules,
00167                     ECollationStrength collationStrength,
00168                     UColAttributeValue decompositionMode,
00169                     UErrorCode& status);
00170 
00177     RuleBasedCollator(const RuleBasedCollator& other);
00178 
00179 
00197     RuleBasedCollator(const uint8_t *bin, int32_t length, 
00198                     const RuleBasedCollator *base, 
00199                     UErrorCode &status);
00200     // destructor --------------------------------------------------------------
00201 
00206     virtual ~RuleBasedCollator();
00207 
00208     // public methods ----------------------------------------------------------
00209 
00215     RuleBasedCollator& operator=(const RuleBasedCollator& other);
00216 
00223     virtual UBool operator==(const Collator& other) const;
00224 
00231     virtual UBool operator!=(const Collator& other) const;
00232 
00239     virtual Collator* clone(void) const;
00240 
00251     virtual CollationElementIterator* createCollationElementIterator(
00252                                            const UnicodeString& source) const;
00253 
00263     virtual CollationElementIterator* createCollationElementIterator(
00264                                          const CharacterIterator& source) const;
00265 
00278     virtual EComparisonResult compare(const UnicodeString& source,
00279                                       const UnicodeString& target) const;
00280 
00281 
00294     virtual UCollationResult compare(const UnicodeString& source,
00295                                       const UnicodeString& target,
00296                                       UErrorCode &status) const;
00297 
00311     virtual EComparisonResult compare(const UnicodeString& source,
00312                                       const UnicodeString&  target,
00313                                       int32_t length) const;
00314 
00328     virtual UCollationResult compare(const UnicodeString& source,
00329                                       const UnicodeString& target,
00330                                       int32_t length,
00331                                       UErrorCode &status) const;
00332 
00366     virtual EComparisonResult compare(const UChar* source, int32_t sourceLength,
00367                                       const UChar* target, int32_t targetLength)
00368                                       const;
00369 
00386     virtual UCollationResult compare(const UChar* source, int32_t sourceLength,
00387                                       const UChar* target, int32_t targetLength,
00388                                       UErrorCode &status) const;
00389 
00402     virtual CollationKey& getCollationKey(const UnicodeString& source,
00403                                           CollationKey& key,
00404                                           UErrorCode& status) const;
00405 
00419     virtual CollationKey& getCollationKey(const UChar *source,
00420                                           int32_t sourceLength,
00421                                           CollationKey& key,
00422                                           UErrorCode& status) const;
00423 
00429     virtual int32_t hashCode(void) const;
00430 
00441     virtual const Locale getLocale(ULocDataLocaleType type, UErrorCode& status) const;
00442 
00449     const UnicodeString& getRules(void) const;
00450 
00456     virtual void getVersion(UVersionInfo info) const;
00457 
00468     int32_t getMaxExpansion(int32_t order) const;
00469 
00480     virtual UClassID getDynamicClassID(void) const;
00481 
00493     static UClassID U_EXPORT2 getStaticClassID(void);
00494 
00503     uint8_t *cloneRuleData(int32_t &length, UErrorCode &status);
00504 
00505 
00516     int32_t cloneBinary(uint8_t *buffer, int32_t capacity, UErrorCode &status);
00517 
00525     void getRules(UColRuleOption delta, UnicodeString &buffer);
00526 
00534     virtual void setAttribute(UColAttribute attr, UColAttributeValue value,
00535                               UErrorCode &status);
00536 
00544     virtual UColAttributeValue getAttribute(UColAttribute attr,
00545                                             UErrorCode &status);
00546 
00557     virtual uint32_t setVariableTop(const UChar *varTop, int32_t len, UErrorCode &status);
00558 
00568     virtual uint32_t setVariableTop(const UnicodeString varTop, UErrorCode &status);
00569 
00577     virtual void setVariableTop(const uint32_t varTop, UErrorCode &status);
00578 
00585     virtual uint32_t getVariableTop(UErrorCode &status) const;
00586 
00596     virtual UnicodeSet *getTailoredSet(UErrorCode &status) const;
00597 
00603     virtual Collator* safeClone(void);
00604 
00615     virtual int32_t getSortKey(const UnicodeString& source, uint8_t *result,
00616                                int32_t resultLength) const;
00617 
00630     virtual int32_t getSortKey(const UChar *source, int32_t sourceLength,
00631                                uint8_t *result, int32_t resultLength) const;
00632 
00643     virtual ECollationStrength getStrength(void) const;
00644 
00651     virtual void setStrength(ECollationStrength newStrength);
00652 
00653 private:
00654 
00655     // private static constants -----------------------------------------------
00656 
00657     static const int32_t UNMAPPED;
00658     static const int32_t CHARINDEX;  // need look up in .commit()
00659     static const int32_t EXPANDCHARINDEX; // Expand index follows
00660     static const int32_t CONTRACTCHARINDEX;  // contract indexes follow
00661 
00662     static const int32_t PRIMARYORDERINCREMENT;
00663     static const int32_t SECONDARYORDERINCREMENT;
00664     static const int32_t TERTIARYORDERINCREMENT;
00665     static const int32_t PRIMARYORDERMASK;
00666     static const int32_t SECONDARYORDERMASK;
00667     static const int32_t TERTIARYORDERMASK;
00668     static const int32_t IGNORABLEMASK;
00669     static const int32_t PRIMARYDIFFERENCEONLY;
00670     static const int32_t SECONDARYDIFFERENCEONLY;
00671     static const int32_t PRIMARYORDERSHIFT;
00672     static const int32_t SECONDARYORDERSHIFT;
00673 
00674     static const int32_t COLELEMENTSTART;
00675     static const int32_t PRIMARYLOWZEROMASK;
00676     static const int32_t RESETSECONDARYTERTIARY;
00677     static const int32_t RESETTERTIARY;
00678 
00679     static const int32_t PRIMIGNORABLE;
00680 
00681     // private data members ---------------------------------------------------
00682 
00683     UBool dataIsOwned;
00684 
00685     UBool isWriteThroughAlias;
00686 
00691     UCollator *ucollator;
00692 
00696     UnicodeString urulestring;
00697 
00698     // friend classes --------------------------------------------------------
00699 
00703     friend class CollationElementIterator;
00704 
00709     friend class Collator;
00710 
00714     friend class StringSearch;
00715 
00716     // private constructors --------------------------------------------------
00717 
00721     RuleBasedCollator();
00722 
00733     RuleBasedCollator(const Locale& desiredLocale, UErrorCode& status);
00734 
00743     void
00744     construct(const UnicodeString& rules,
00745               UColAttributeValue collationStrength,
00746               UColAttributeValue decompositionMode,
00747               UErrorCode& status);
00748 
00749     // private methods -------------------------------------------------------
00750 
00756     void setUCollator(const Locale& locale, UErrorCode& status);
00757 
00763     void setUCollator(const char* locale, UErrorCode& status);
00764 
00772     void setUCollator(UCollator *collator);
00773 
00774 public:
00780     const UCollator * getUCollator();
00781 
00782 protected:
00789     virtual void setLocales(const Locale& requestedLocale, const Locale& validLocale);
00790 
00791 private:
00792 
00793     // if not owned and not a write through alias, copy the ucollator
00794     void checkOwned(void);
00795 
00796     // utility to init rule string used by checkOwned and construct
00797     void setRuleStringFromCollator();
00798 
00805     Collator::EComparisonResult getEComparisonResult(
00806                                             const UCollationResult &result) const;
00807 
00813     Collator::ECollationStrength getECollationStrength(
00814                                         const UCollationStrength &strength) const;
00815 
00821     UCollationStrength getUCollationStrength(
00822       const Collator::ECollationStrength &strength) const;
00823 };
00824 
00825 // inline method implementation ---------------------------------------------
00826 
00827 inline void RuleBasedCollator::setUCollator(const Locale &locale,
00828                                                UErrorCode &status)
00829 {
00830     setUCollator(locale.getName(), status);
00831 }
00832 
00833 
00834 inline void RuleBasedCollator::setUCollator(UCollator     *collator)
00835 {
00836 
00837     if (ucollator && dataIsOwned) {
00838         ucol_close(ucollator);
00839     }
00840     ucollator   = collator;
00841     dataIsOwned = FALSE;
00842     isWriteThroughAlias = TRUE;
00843         setRuleStringFromCollator();
00844 }
00845 
00846 inline const UCollator * RuleBasedCollator::getUCollator()
00847 {
00848     return ucollator;
00849 }
00850 
00851 inline Collator::EComparisonResult RuleBasedCollator::getEComparisonResult(
00852                                            const UCollationResult &result) const
00853 {
00854     switch (result)
00855     {
00856     case UCOL_LESS :
00857         return Collator::LESS;
00858     case UCOL_EQUAL :
00859         return Collator::EQUAL;
00860     default :
00861         return Collator::GREATER;
00862     }
00863 }
00864 
00865 inline Collator::ECollationStrength RuleBasedCollator::getECollationStrength(
00866                                        const UCollationStrength &strength) const
00867 {
00868     switch (strength)
00869     {
00870     case UCOL_PRIMARY :
00871         return Collator::PRIMARY;
00872     case UCOL_SECONDARY :
00873         return Collator::SECONDARY;
00874     case UCOL_TERTIARY :
00875         return Collator::TERTIARY;
00876     case UCOL_QUATERNARY :
00877         return Collator::QUATERNARY;
00878     default :
00879         return Collator::IDENTICAL;
00880     }
00881 }
00882 
00883 inline UCollationStrength RuleBasedCollator::getUCollationStrength(
00884                              const Collator::ECollationStrength &strength) const
00885 {
00886     switch (strength)
00887     {
00888     case Collator::PRIMARY :
00889         return UCOL_PRIMARY;
00890     case Collator::SECONDARY :
00891         return UCOL_SECONDARY;
00892     case Collator::TERTIARY :
00893         return UCOL_TERTIARY;
00894     case Collator::QUATERNARY :
00895         return UCOL_QUATERNARY;
00896     default :
00897         return UCOL_IDENTICAL;
00898     }
00899 }
00900 
00901 U_NAMESPACE_END
00902 
00903 #endif /* #if !UCONFIG_NO_COLLATION */
00904 
00905 #endif

Generated on Mon Aug 13 07:17:24 2007 for ICU 3.6 by  doxygen 1.5.2