Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Search  

tblcoll.h

Go to the documentation of this file.
00001 /*
00002 ******************************************************************************
00003 * Copyright (C) 1996-2003, 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 
00059 #if !UCONFIG_NO_COLLATION
00060 
00061 #include "unicode/coll.h"
00062 #include "unicode/ucol.h"
00063 #include "unicode/sortkey.h"
00064 #include "unicode/normlzr.h"
00065 
00066 U_NAMESPACE_BEGIN
00067 
00071 class StringSearch;
00075 class CollationElementIterator;
00076 
00105 class U_I18N_API RuleBasedCollator : public Collator
00106 {
00107 public:
00108 
00109   // constructor -------------------------------------------------------------
00110 
00120     RuleBasedCollator(const UnicodeString& rules, UErrorCode& status);
00121 
00132     RuleBasedCollator(const UnicodeString& rules,
00133                        ECollationStrength collationStrength,
00134                        UErrorCode& status);
00135 
00146     RuleBasedCollator(const UnicodeString& rules,
00147                     UColAttributeValue decompositionMode,
00148                     UErrorCode& status);
00149 
00161     RuleBasedCollator(const UnicodeString& rules,
00162                     ECollationStrength collationStrength,
00163                     UColAttributeValue decompositionMode,
00164                     UErrorCode& status);
00165 
00172     RuleBasedCollator(const RuleBasedCollator& other);
00173 
00174     // destructor --------------------------------------------------------------
00175 
00180     virtual ~RuleBasedCollator();
00181 
00182     // public methods ----------------------------------------------------------
00183 
00189     RuleBasedCollator& operator=(const RuleBasedCollator& other);
00190 
00197     virtual UBool operator==(const Collator& other) const;
00198 
00205     virtual UBool operator!=(const Collator& other) const;
00206 
00213     virtual Collator* clone(void) const;
00214 
00225     virtual CollationElementIterator* createCollationElementIterator(
00226                                            const UnicodeString& source) const;
00227 
00237     virtual CollationElementIterator* createCollationElementIterator(
00238                                          const CharacterIterator& source) const;
00239 
00252     virtual EComparisonResult compare(const UnicodeString& source,
00253                                       const UnicodeString& target) const;
00254 
00255 
00268     virtual UCollationResult compare(const UnicodeString& source,
00269                                       const UnicodeString& target,
00270                                       UErrorCode &status) const;
00271 
00285     virtual EComparisonResult compare(const UnicodeString& source,
00286                                       const UnicodeString&  target,
00287                                       int32_t length) const;
00288 
00302     virtual UCollationResult compare(const UnicodeString& source,
00303                                       const UnicodeString& target,
00304                                       int32_t length,
00305                                       UErrorCode &status) const;
00306 
00340     virtual EComparisonResult compare(const UChar* source, int32_t sourceLength,
00341                                       const UChar* target, int32_t targetLength)
00342                                       const;
00343 
00360     virtual UCollationResult compare(const UChar* source, int32_t sourceLength,
00361                                       const UChar* target, int32_t targetLength,
00362                                       UErrorCode &status) const;
00363 
00376     virtual CollationKey& getCollationKey(const UnicodeString& source,
00377                                           CollationKey& key,
00378                                           UErrorCode& status) const;
00379 
00393     virtual CollationKey& getCollationKey(const UChar *source,
00394                                           int32_t sourceLength,
00395                                           CollationKey& key,
00396                                           UErrorCode& status) const;
00397 
00403     virtual int32_t hashCode(void) const;
00404 
00415     virtual const Locale getLocale(ULocDataLocaleType type, UErrorCode& status) const;
00416 
00423     const UnicodeString& getRules(void) const;
00424 
00430     virtual void getVersion(UVersionInfo info) const;
00431 
00442     int32_t getMaxExpansion(int32_t order) const;
00443 
00454     virtual UClassID getDynamicClassID(void) const;
00455 
00467     static UClassID getStaticClassID(void);
00468 
00477     uint8_t *cloneRuleData(int32_t &length, UErrorCode &status);
00478 
00486     void getRules(UColRuleOption delta, UnicodeString &buffer);
00487 
00495     virtual void setAttribute(UColAttribute attr, UColAttributeValue value,
00496                               UErrorCode &status);
00497 
00505     virtual UColAttributeValue getAttribute(UColAttribute attr,
00506                                             UErrorCode &status);
00507 
00518     virtual uint32_t setVariableTop(const UChar *varTop, int32_t len, UErrorCode &status);
00519 
00529     virtual uint32_t setVariableTop(const UnicodeString varTop, UErrorCode &status);
00530 
00538     virtual void setVariableTop(const uint32_t varTop, UErrorCode &status);
00539 
00546     virtual uint32_t getVariableTop(UErrorCode &status) const;
00547 
00557     virtual UnicodeSet *getTailoredSet(UErrorCode &status) const;
00558 
00564     virtual Collator* safeClone(void);
00565 
00576     virtual int32_t getSortKey(const UnicodeString& source, uint8_t *result,
00577                                int32_t resultLength) const;
00578 
00591     virtual int32_t getSortKey(const UChar *source, int32_t sourceLength,
00592                                uint8_t *result, int32_t resultLength) const;
00593 
00604     virtual ECollationStrength getStrength(void) const;
00605 
00612     virtual void setStrength(ECollationStrength newStrength);
00613 
00614 private:
00615 
00616     // private static constants -----------------------------------------------
00617 
00618     static const int32_t UNMAPPED;
00619     static const int32_t CHARINDEX;  // need look up in .commit()
00620     static const int32_t EXPANDCHARINDEX; // Expand index follows
00621     static const int32_t CONTRACTCHARINDEX;  // contract indexes follow
00622 
00623     static const int32_t PRIMARYORDERINCREMENT;
00624     static const int32_t SECONDARYORDERINCREMENT;
00625     static const int32_t TERTIARYORDERINCREMENT;
00626     static const int32_t PRIMARYORDERMASK;
00627     static const int32_t SECONDARYORDERMASK;
00628     static const int32_t TERTIARYORDERMASK;
00629     static const int32_t IGNORABLEMASK;
00630     static const int32_t PRIMARYDIFFERENCEONLY;
00631     static const int32_t SECONDARYDIFFERENCEONLY;
00632     static const int32_t PRIMARYORDERSHIFT;
00633     static const int32_t SECONDARYORDERSHIFT;
00634 
00635     static const int32_t COLELEMENTSTART;
00636     static const int32_t PRIMARYLOWZEROMASK;
00637     static const int32_t RESETSECONDARYTERTIARY;
00638     static const int32_t RESETTERTIARY;
00639 
00640     static const int32_t PRIMIGNORABLE;
00641 
00642     // private data members ---------------------------------------------------
00643 
00644     UBool dataIsOwned;
00645 
00646     UBool isWriteThroughAlias;
00647 
00652     UCollator *ucollator;
00653 
00657     UnicodeString *urulestring;
00658 
00659     // friend classes --------------------------------------------------------
00660 
00664     friend class CollationElementIterator;
00665 
00670     friend class Collator;
00671 
00675     friend class StringSearch;
00676 
00677     // private constructors --------------------------------------------------
00678 
00682     RuleBasedCollator();
00683 
00689     RuleBasedCollator(UCollator *collator, UnicodeString *rule);
00690 
00701     RuleBasedCollator(const Locale& desiredLocale, UErrorCode& status);
00702 
00711     void
00712     construct(const UnicodeString& rules,
00713               UColAttributeValue collationStrength,
00714               UColAttributeValue decompositionMode,
00715               UErrorCode& status);
00716 
00717     // private methods -------------------------------------------------------
00718 
00724     void setUCollator(const Locale& locale, UErrorCode& status);
00725 
00731     void setUCollator(const char* locale, UErrorCode& status);
00732 
00740     void setUCollator(UCollator *collator, UnicodeString *rules);
00741 
00742 public:
00748     const UCollator * getUCollator();
00749 
00750 protected:
00757     virtual void setLocales(const Locale& requestedLocale, const Locale& validLocale);
00758 
00759 private:
00760 
00761     // if not owned and not a write through alias, copy the ucollator
00762     void checkOwned(void);
00763 
00764     // utility to init rule string used by checkOwned and construct
00765     void setRuleStringFromCollator(UErrorCode& status);
00766 
00773     Collator::EComparisonResult getEComparisonResult(
00774                                             const UCollationResult &result) const;
00775 
00781     Collator::ECollationStrength getECollationStrength(
00782                                         const UCollationStrength &strength) const;
00783 
00789     UCollationStrength getUCollationStrength(
00790       const Collator::ECollationStrength &strength) const;
00791 };
00792 
00793 // inline method implementation ---------------------------------------------
00794 
00795 inline void RuleBasedCollator::setUCollator(const Locale &locale,
00796                                                UErrorCode &status)
00797 {
00798     setUCollator(locale.getName(), status);
00799 }
00800 
00801 
00802 inline void RuleBasedCollator::setUCollator(UCollator     *collator,
00803                                             UnicodeString *rules)
00804 {
00805     if (ucollator && dataIsOwned) {
00806         ucol_close(ucollator);
00807         delete urulestring;
00808     }
00809     ucollator   = collator;
00810     urulestring = rules;
00811     dataIsOwned = FALSE;
00812     isWriteThroughAlias = TRUE;
00813 }
00814 
00815 inline const UCollator * RuleBasedCollator::getUCollator()
00816 {
00817     return ucollator;
00818 }
00819 
00820 inline Collator::EComparisonResult RuleBasedCollator::getEComparisonResult(
00821                                            const UCollationResult &result) const
00822 {
00823     switch (result)
00824     {
00825     case UCOL_LESS :
00826         return Collator::LESS;
00827     case UCOL_EQUAL :
00828         return Collator::EQUAL;
00829     default :
00830         return Collator::GREATER;
00831     }
00832 }
00833 
00834 inline Collator::ECollationStrength RuleBasedCollator::getECollationStrength(
00835                                        const UCollationStrength &strength) const
00836 {
00837     switch (strength)
00838     {
00839     case UCOL_PRIMARY :
00840         return Collator::PRIMARY;
00841     case UCOL_SECONDARY :
00842         return Collator::SECONDARY;
00843     case UCOL_TERTIARY :
00844         return Collator::TERTIARY;
00845     case UCOL_QUATERNARY :
00846         return Collator::QUATERNARY;
00847     default :
00848         return Collator::IDENTICAL;
00849     }
00850 }
00851 
00852 inline UCollationStrength RuleBasedCollator::getUCollationStrength(
00853                              const Collator::ECollationStrength &strength) const
00854 {
00855     switch (strength)
00856     {
00857     case Collator::PRIMARY :
00858         return UCOL_PRIMARY;
00859     case Collator::SECONDARY :
00860         return UCOL_SECONDARY;
00861     case Collator::TERTIARY :
00862         return UCOL_TERTIARY;
00863     case Collator::QUATERNARY :
00864         return UCOL_QUATERNARY;
00865     default :
00866         return UCOL_IDENTICAL;
00867     }
00868 }
00869 
00870 U_NAMESPACE_END
00871 
00872 #endif /* #if !UCONFIG_NO_COLLATION */
00873 
00874 #endif

Generated on Mon Nov 24 14:35:38 2003 for ICU 2.8 by doxygen1.2.11.1 written by Dimitri van Heesch, © 1997-2001