tblcoll.h

Go to the documentation of this file.
00001 /*
00002 ******************************************************************************
00003 * Copyright (C) 1996-2005, 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 
00728     RuleBasedCollator(UCollator *collator, UnicodeString *rule);
00729 
00740     RuleBasedCollator(const Locale& desiredLocale, UErrorCode& status);
00741 
00750     void
00751     construct(const UnicodeString& rules,
00752               UColAttributeValue collationStrength,
00753               UColAttributeValue decompositionMode,
00754               UErrorCode& status);
00755 
00756     // private methods -------------------------------------------------------
00757 
00763     void setUCollator(const Locale& locale, UErrorCode& status);
00764 
00770     void setUCollator(const char* locale, UErrorCode& status);
00771 
00779     void setUCollator(UCollator *collator, UnicodeString *rules);
00780 
00781 public:
00787     const UCollator * getUCollator();
00788 
00789 protected:
00796     virtual void setLocales(const Locale& requestedLocale, const Locale& validLocale);
00797 
00798 private:
00799 
00800     // if not owned and not a write through alias, copy the ucollator
00801     void checkOwned(void);
00802 
00803     // utility to init rule string used by checkOwned and construct
00804     void setRuleStringFromCollator(UErrorCode& status);
00805 
00812     Collator::EComparisonResult getEComparisonResult(
00813                                             const UCollationResult &result) const;
00814 
00820     Collator::ECollationStrength getECollationStrength(
00821                                         const UCollationStrength &strength) const;
00822 
00828     UCollationStrength getUCollationStrength(
00829       const Collator::ECollationStrength &strength) const;
00830 };
00831 
00832 // inline method implementation ---------------------------------------------
00833 
00834 inline void RuleBasedCollator::setUCollator(const Locale &locale,
00835                                                UErrorCode &status)
00836 {
00837     setUCollator(locale.getName(), status);
00838 }
00839 
00840 
00841 inline void RuleBasedCollator::setUCollator(UCollator     *collator,
00842                                             UnicodeString *rules)
00843 {
00844     if (ucollator && dataIsOwned) {
00845         ucol_close(ucollator);
00846         delete urulestring;
00847     }
00848     ucollator   = collator;
00849     urulestring = rules;
00850     dataIsOwned = FALSE;
00851     isWriteThroughAlias = TRUE;
00852 }
00853 
00854 inline const UCollator * RuleBasedCollator::getUCollator()
00855 {
00856     return ucollator;
00857 }
00858 
00859 inline Collator::EComparisonResult RuleBasedCollator::getEComparisonResult(
00860                                            const UCollationResult &result) const
00861 {
00862     switch (result)
00863     {
00864     case UCOL_LESS :
00865         return Collator::LESS;
00866     case UCOL_EQUAL :
00867         return Collator::EQUAL;
00868     default :
00869         return Collator::GREATER;
00870     }
00871 }
00872 
00873 inline Collator::ECollationStrength RuleBasedCollator::getECollationStrength(
00874                                        const UCollationStrength &strength) const
00875 {
00876     switch (strength)
00877     {
00878     case UCOL_PRIMARY :
00879         return Collator::PRIMARY;
00880     case UCOL_SECONDARY :
00881         return Collator::SECONDARY;
00882     case UCOL_TERTIARY :
00883         return Collator::TERTIARY;
00884     case UCOL_QUATERNARY :
00885         return Collator::QUATERNARY;
00886     default :
00887         return Collator::IDENTICAL;
00888     }
00889 }
00890 
00891 inline UCollationStrength RuleBasedCollator::getUCollationStrength(
00892                              const Collator::ECollationStrength &strength) const
00893 {
00894     switch (strength)
00895     {
00896     case Collator::PRIMARY :
00897         return UCOL_PRIMARY;
00898     case Collator::SECONDARY :
00899         return UCOL_SECONDARY;
00900     case Collator::TERTIARY :
00901         return UCOL_TERTIARY;
00902     case Collator::QUATERNARY :
00903         return UCOL_QUATERNARY;
00904     default :
00905         return UCOL_IDENTICAL;
00906     }
00907 }
00908 
00909 U_NAMESPACE_END
00910 
00911 #endif /* #if !UCONFIG_NO_COLLATION */
00912 
00913 #endif

Generated on Tue Sep 13 11:08:15 2005 for ICU 3.4 by  doxygen 1.4.4