- Main Page
- Modules
- Data Structures
- Files
- Related Pages

- Search for |

- File List
- Globals

# tblcoll.h

Go to the documentation of this file.

    00001 /*
    00002 ******************************************************************************
    00003 * Copyright (C) 1996-2007, 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     enum {
    00658         /* need look up in .commit() */
    00659         CHARINDEX = 0x70000000,
    00660         /* Expand index follows */
    00661         EXPANDCHARINDEX = 0x7E000000,
    00662         /* contract indexes follows */
    00663         CONTRACTCHARINDEX = 0x7F000000,
    00664         /* unmapped character values */
    00665         UNMAPPED = 0xFFFFFFFF,
    00666         /* primary strength increment */
    00667         PRIMARYORDERINCREMENT = 0x00010000,
    00668         /* secondary strength increment */
    00669         SECONDARYORDERINCREMENT = 0x00000100,
    00670         /* tertiary strength increment */
    00671         TERTIARYORDERINCREMENT = 0x00000001,
    00672         /* mask off anything but primary order */
    00673         PRIMARYORDERMASK = 0xffff0000,
    00674         /* mask off anything but secondary order */
    00675         SECONDARYORDERMASK = 0x0000ff00,
    00676         /* mask off anything but tertiary order */
    00677         TERTIARYORDERMASK = 0x000000ff,
    00678         /* mask off ignorable char order */
    00679         IGNORABLEMASK = 0x0000ffff,
    00680         /* use only the primary difference */
    00681         PRIMARYDIFFERENCEONLY = 0xffff0000,
    00682         /* use only the primary and secondary difference */
    00683         SECONDARYDIFFERENCEONLY = 0xffffff00,
    00684         /* primary order shift */
    00685         PRIMARYORDERSHIFT = 16,
    00686         /* secondary order shift */
    00687         SECONDARYORDERSHIFT = 8,
    00688         /* starting value for collation elements */
    00689         COLELEMENTSTART = 0x02020202,
    00690         /* testing mask for primary low element */
    00691         PRIMARYLOWZEROMASK = 0x00FF0000,
    00692         /* reseting value for secondaries and tertiaries */
    00693         RESETSECONDARYTERTIARY = 0x00000202,
    00694         /* reseting value for tertiaries */
    00695         RESETTERTIARY = 0x00000002,
    00696
    00697         PRIMIGNORABLE = 0x0202
    00698     };
    00699
    00700     // private data members ---------------------------------------------------
    00701
    00702     UBool dataIsOwned;
    00703
    00704     UBool isWriteThroughAlias;
    00705
    00710     UCollator *ucollator;
    00711
    00715     UnicodeString urulestring;
    00716
    00717     // friend classes --------------------------------------------------------
    00718
    00722     friend class CollationElementIterator;
    00723
    00728     friend class Collator;
    00729
    00733     friend class StringSearch;
    00734
    00735     // private constructors --------------------------------------------------
    00736
    00740     RuleBasedCollator();
    00741
    00752     RuleBasedCollator(const Locale& desiredLocale, UErrorCode& status);
    00753
    00762     void
    00763     construct(const UnicodeString& rules,
    00764               UColAttributeValue collationStrength,
    00765               UColAttributeValue decompositionMode,
    00766               UErrorCode& status);
    00767
    00768     // private methods -------------------------------------------------------
    00769
    00775     void setUCollator(const Locale& locale, UErrorCode& status);
    00776
    00782     void setUCollator(const char* locale, UErrorCode& status);
    00783
    00791     void setUCollator(UCollator *collator);
    00792
    00793 public:
    00799     const UCollator * getUCollator();
    00800
    00801 protected:
    00808     virtual void setLocales(const Locale& requestedLocale, const Locale& validLocale);
    00809
    00810 private:
    00811
    00812     // if not owned and not a write through alias, copy the ucollator
    00813     void checkOwned(void);
    00814
    00815     // utility to init rule string used by checkOwned and construct
    00816     void setRuleStringFromCollator();
    00817
    00824     Collator::EComparisonResult getEComparisonResult(
    00825                                             const UCollationResult &result) const;
    00826
    00832     Collator::ECollationStrength getECollationStrength(
    00833                                         const UCollationStrength &strength) const;
    00834
    00840     UCollationStrength getUCollationStrength(
    00841       const Collator::ECollationStrength &strength) const;
    00842 };
    00843
    00844 // inline method implementation ---------------------------------------------
    00845
    00846 inline void RuleBasedCollator::setUCollator(const Locale &locale,
    00847                                                UErrorCode &status)
    00848 {
    00849     setUCollator(locale.getName(), status);
    00850 }
    00851
    00852
    00853 inline void RuleBasedCollator::setUCollator(UCollator     *collator)
    00854 {
    00855
    00856     if (ucollator && dataIsOwned) {
    00857         ucol_close(ucollator);
    00858     }
    00859     ucollator   = collator;
    00860     dataIsOwned = FALSE;
    00861     isWriteThroughAlias = TRUE;
    00862     setRuleStringFromCollator();
    00863 }
    00864
    00865 inline const UCollator * RuleBasedCollator::getUCollator()
    00866 {
    00867     return ucollator;
    00868 }
    00869
    00870 inline Collator::EComparisonResult RuleBasedCollator::getEComparisonResult(
    00871                                            const UCollationResult &result) const
    00872 {
    00873     switch (result)
    00874     {
    00875     case UCOL_LESS :
    00876         return Collator::LESS;
    00877     case UCOL_EQUAL :
    00878         return Collator::EQUAL;
    00879     default :
    00880         return Collator::GREATER;
    00881     }
    00882 }
    00883
    00884 inline Collator::ECollationStrength RuleBasedCollator::getECollationStrength(
    00885                                        const UCollationStrength &strength) const
    00886 {
    00887     switch (strength)
    00888     {
    00889     case UCOL_PRIMARY :
    00890         return Collator::PRIMARY;
    00891     case UCOL_SECONDARY :
    00892         return Collator::SECONDARY;
    00893     case UCOL_TERTIARY :
    00894         return Collator::TERTIARY;
    00895     case UCOL_QUATERNARY :
    00896         return Collator::QUATERNARY;
    00897     default :
    00898         return Collator::IDENTICAL;
    00899     }
    00900 }
    00901
    00902 inline UCollationStrength RuleBasedCollator::getUCollationStrength(
    00903                              const Collator::ECollationStrength &strength) const
    00904 {
    00905     switch (strength)
    00906     {
    00907     case Collator::PRIMARY :
    00908         return UCOL_PRIMARY;
    00909     case Collator::SECONDARY :
    00910         return UCOL_SECONDARY;
    00911     case Collator::TERTIARY :
    00912         return UCOL_TERTIARY;
    00913     case Collator::QUATERNARY :
    00914         return UCOL_QUATERNARY;
    00915     default :
    00916         return UCOL_IDENTICAL;
    00917     }
    00918 }
    00919
    00920 U_NAMESPACE_END
    00921
    00922 #endif /* #if !UCONFIG_NO_COLLATION */
    00923
    00924 #endif