Main Page | Class Hierarchy | Alphabetical List | Data Structures | File List | Data Fields | Globals | Related Pages

tblcoll.h

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;
00284   virtual EComparisonResult compare(const UnicodeString& source,
00285                                     const UnicodeString&  target,
00286                                     int32_t length) const;
00287 
00301   virtual UCollationResult compare(const UnicodeString& source,
00302                                     const UnicodeString& target,
00303                                     int32_t length,
00304                                     UErrorCode &status) const;
00305 
00339   virtual EComparisonResult compare(const UChar* source, int32_t sourceLength,
00340                                     const UChar* target, int32_t targetLength)
00341                                     const;
00342 
00359   virtual UCollationResult compare(const UChar* source, int32_t sourceLength,
00360                                     const UChar* target, int32_t targetLength,
00361                                     UErrorCode &status) const;
00362 
00375   virtual CollationKey& getCollationKey(const UnicodeString& source,
00376                                         CollationKey& key,
00377                                         UErrorCode& status) const;
00378 
00392   virtual CollationKey& getCollationKey(const UChar *source,
00393                                         int32_t sourceLength,
00394                                         CollationKey& key,
00395                                         UErrorCode& status) const;
00396 
00402   virtual int32_t hashCode(void) const;
00403 
00414   virtual const Locale getLocale(ULocDataLocaleType type, UErrorCode& status) const;
00415 
00422   const UnicodeString& getRules(void) const;
00423 
00429   virtual void getVersion(UVersionInfo info) const;
00430 
00441   int32_t getMaxExpansion(int32_t order) const;
00442 
00453   virtual UClassID getDynamicClassID(void) const;
00454 
00466   static UClassID getStaticClassID(void);
00467 
00476   uint8_t *cloneRuleData(int32_t &length, UErrorCode &status);
00477 
00485   void getRules(UColRuleOption delta, UnicodeString &buffer);
00486 
00494   virtual void setAttribute(UColAttribute attr, UColAttributeValue value,
00495                             UErrorCode &status);
00496 
00504   virtual UColAttributeValue getAttribute(UColAttribute attr,
00505                                           UErrorCode &status);
00506 
00517   virtual uint32_t setVariableTop(const UChar *varTop, int32_t len, UErrorCode &status);
00518 
00528   virtual uint32_t setVariableTop(const UnicodeString varTop, UErrorCode &status);
00529 
00537   virtual void setVariableTop(const uint32_t varTop, UErrorCode &status);
00538 
00545   virtual uint32_t getVariableTop(UErrorCode &status) const;
00546 
00556   virtual UnicodeSet *getTailoredSet(UErrorCode &status) const;
00557 
00563   virtual Collator* safeClone(void);
00564 
00575   virtual int32_t getSortKey(const UnicodeString& source, uint8_t *result,
00576                              int32_t resultLength) const;
00577 
00590   virtual int32_t getSortKey(const UChar *source, int32_t sourceLength,
00591                              uint8_t *result, int32_t resultLength) const;
00592 
00603   virtual ECollationStrength getStrength(void) const;
00604 
00611   virtual void setStrength(ECollationStrength newStrength);
00612 
00613 private:
00614 
00615   // private static constants -----------------------------------------------
00616 
00617   static const int32_t UNMAPPED;
00618   static const int32_t CHARINDEX;  // need look up in .commit()
00619   static const int32_t EXPANDCHARINDEX; // Expand index follows
00620   static const int32_t CONTRACTCHARINDEX;  // contract indexes follow
00621 
00622   static const int32_t PRIMARYORDERINCREMENT;
00623   static const int32_t SECONDARYORDERINCREMENT;
00624   static const int32_t TERTIARYORDERINCREMENT;
00625   static const int32_t PRIMARYORDERMASK;
00626   static const int32_t SECONDARYORDERMASK;
00627   static const int32_t TERTIARYORDERMASK;
00628   static const int32_t IGNORABLEMASK;
00629   static const int32_t PRIMARYDIFFERENCEONLY;
00630   static const int32_t SECONDARYDIFFERENCEONLY;
00631   static const int32_t PRIMARYORDERSHIFT;
00632   static const int32_t SECONDARYORDERSHIFT;
00633 
00634   static const int32_t COLELEMENTSTART;
00635   static const int32_t PRIMARYLOWZEROMASK;
00636   static const int32_t RESETSECONDARYTERTIARY;
00637   static const int32_t RESETTERTIARY;
00638 
00639   static const int32_t PRIMIGNORABLE;
00640 
00641   static const int16_t FILEID;
00642   static const char    kFilenameSuffix[];
00643 
00644   // private static variables -----------------------------------------------
00645 
00649   static const char fgClassID;
00650 
00651   // private data members ---------------------------------------------------
00652 
00653   UBool dataIsOwned;
00654 
00655   UBool isWriteThroughAlias;
00656 
00661   UCollator *ucollator;
00662 
00666   UnicodeString *urulestring;
00667 
00668   // friend classes --------------------------------------------------------
00669 
00673   friend class CollationElementIterator;
00674 
00679   friend class Collator;
00680 
00684   friend class StringSearch;
00685 
00686   // private constructors --------------------------------------------------
00687 
00691   RuleBasedCollator();
00692 
00698   RuleBasedCollator(UCollator *collator, UnicodeString *rule);
00699 
00710   RuleBasedCollator(const Locale& desiredLocale, UErrorCode& status);
00711 
00720   void
00721   construct(const UnicodeString& rules,
00722             UColAttributeValue collationStrength,
00723             UColAttributeValue decompositionMode,
00724             UErrorCode& status);
00725 
00726   // private methods -------------------------------------------------------
00727 
00733   void setUCollator(const Locale& locale, UErrorCode& status);
00734 
00740   void setUCollator(const char* locale, UErrorCode& status);
00741 
00749   void setUCollator(UCollator *collator, UnicodeString *rules);
00750 
00751 public:
00757   const UCollator * getUCollator();
00758 
00759 protected:
00766   virtual void setLocales(const Locale& requestedLocale, const Locale& validLocale);
00767 
00768 private:
00769 
00770   // if not owned and not a write through alias, copy the ucollator
00771   void checkOwned(void);
00772 
00773   // utility to init rule string used by checkOwned and construct
00774   void setRuleStringFromCollator(UErrorCode& status);
00775 
00782   Collator::EComparisonResult getEComparisonResult(
00783                                           const UCollationResult &result) const;
00784 
00790   Collator::ECollationStrength getECollationStrength(
00791                                       const UCollationStrength &strength) const;
00792 
00798   UCollationStrength getUCollationStrength(
00799     const Collator::ECollationStrength &strength) const;
00800 };
00801 
00802 // inline method implementation ---------------------------------------------
00803 
00804 inline UClassID
00805 RuleBasedCollator::getStaticClassID(void)
00806 { return (UClassID)&fgClassID; }
00807 
00808 inline UClassID
00809 RuleBasedCollator::getDynamicClassID(void) const
00810 { return RuleBasedCollator::getStaticClassID(); }
00811 
00812 inline UBool RuleBasedCollator::operator!=(const Collator& other) const
00813 {
00814   return !(*this == other);
00815 }
00816 
00817 inline void RuleBasedCollator::setUCollator(const Locale &locale,
00818                                                UErrorCode &status)
00819 {
00820   setUCollator(locale.getName(), status);
00821 }
00822 
00823 
00824 inline void RuleBasedCollator::setUCollator(UCollator     *collator, 
00825                                             UnicodeString *rules)
00826 {
00827     if (ucollator && dataIsOwned) {
00828         ucol_close(ucollator);
00829         delete urulestring;
00830     }
00831     ucollator   = collator;
00832     urulestring = rules;
00833     dataIsOwned = FALSE;
00834         isWriteThroughAlias = TRUE;
00835 }
00836 
00837 inline const UCollator * RuleBasedCollator::getUCollator()
00838 {
00839     return ucollator;
00840 }
00841 
00842 inline Collator::EComparisonResult RuleBasedCollator::getEComparisonResult(
00843                                            const UCollationResult &result) const
00844 {
00845   switch (result)
00846   {
00847   case UCOL_LESS :
00848     return Collator::LESS;
00849   case UCOL_EQUAL :
00850     return Collator::EQUAL;
00851   default :
00852     return Collator::GREATER;
00853   }
00854 }
00855 
00856 inline Collator::ECollationStrength RuleBasedCollator::getECollationStrength(
00857                                        const UCollationStrength &strength) const
00858 {
00859   switch (strength)
00860   {
00861   case UCOL_PRIMARY :
00862     return Collator::PRIMARY;
00863   case UCOL_SECONDARY :
00864     return Collator::SECONDARY;
00865   case UCOL_TERTIARY :
00866     return Collator::TERTIARY;
00867   case UCOL_QUATERNARY :
00868     return Collator::QUATERNARY;   
00869   default :
00870     return Collator::IDENTICAL;
00871   }
00872 }
00873 
00874 inline UCollationStrength RuleBasedCollator::getUCollationStrength(
00875                              const Collator::ECollationStrength &strength) const
00876 {
00877   switch (strength)
00878   {
00879   case Collator::PRIMARY :
00880     return UCOL_PRIMARY;
00881   case Collator::SECONDARY :
00882     return UCOL_SECONDARY;
00883   case Collator::TERTIARY :
00884     return UCOL_TERTIARY;
00885   case Collator::QUATERNARY :
00886     return UCOL_QUATERNARY;
00887   default :
00888     return UCOL_IDENTICAL;
00889   }
00890 }
00891 
00892 U_NAMESPACE_END
00893 
00894 #endif /* #if !UCONFIG_NO_COLLATION */
00895 
00896 #endif

Generated on Wed Sep 3 17:47:09 2003 for ICU 2.6 by doxygen 1.3.2