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

tblcoll.h

00001 /*
00002 ******************************************************************************
00003 * Copyright (C) 1996-2001, 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/coll.h"
00058 #include "unicode/sortkey.h"
00059 #include "unicode/normlzr.h"
00060 
00061 U_NAMESPACE_BEGIN
00062 
00063 class StringSearch;
00064 class CollationElementIterator;
00065 
00093 class U_I18N_API RuleBasedCollator : public Collator
00094 {
00095 public:
00096 
00097   // constructor -------------------------------------------------------------
00098 
00108     RuleBasedCollator(const UnicodeString& rules, UErrorCode& status);
00109 
00120   RuleBasedCollator(const UnicodeString& rules,
00121                        ECollationStrength collationStrength,
00122                        UErrorCode& status);
00123 
00134   RuleBasedCollator(const UnicodeString& rules,
00135                     UColAttributeValue decompositionMode,
00136                     UErrorCode& status);
00137 
00149   RuleBasedCollator(const UnicodeString& rules,
00150                     ECollationStrength collationStrength,
00151                     UColAttributeValue decompositionMode,
00152                     UErrorCode& status);
00153 
00160     RuleBasedCollator(const RuleBasedCollator& other);
00161 
00162   // destructor --------------------------------------------------------------
00163 
00168     virtual ~RuleBasedCollator();
00169 
00170   // public methods ----------------------------------------------------------
00171 
00177     RuleBasedCollator& operator=(const RuleBasedCollator& other);
00178 
00185   virtual UBool operator==(const Collator& other) const;
00186 
00193   virtual UBool operator!=(const Collator& other) const;
00194 
00201   virtual Collator* clone(void) const;
00202 
00213     virtual CollationElementIterator* createCollationElementIterator(
00214                                            const UnicodeString& source) const;
00215 
00225   virtual CollationElementIterator* createCollationElementIterator(
00226                                        const CharacterIterator& source) const;
00227 
00240   virtual EComparisonResult compare(const UnicodeString& source,
00241                                     const UnicodeString& target) const;
00242 
00243 
00257   virtual EComparisonResult compare(const UnicodeString& source,
00258                                     const UnicodeString&  target,
00259                                     int32_t length) const;
00260 
00294   virtual EComparisonResult compare(const UChar* source, int32_t sourceLength,
00295                                     const UChar* target, int32_t targetLength)
00296                                     const;
00297 
00310   virtual CollationKey& getCollationKey(const UnicodeString& source,
00311                                         CollationKey& key,
00312                                         UErrorCode& status) const;
00313 
00326   virtual CollationKey& getCollationKey(const UChar *source,
00327                                         int32_t sourceLength,
00328                                         CollationKey& key,
00329                                         UErrorCode& status) const;
00330 
00336   virtual int32_t hashCode(void) const;
00337 
00347   virtual const Locale getLocale(ULocDataLocaleType type, UErrorCode& status) const;
00348 
00355   const UnicodeString& getRules(void) const;
00356 
00362   virtual void getVersion(UVersionInfo info) const;
00363 
00374   int32_t getMaxExpansion(int32_t order) const;
00375 
00386   virtual UClassID getDynamicClassID(void) const
00387   {
00388     return RuleBasedCollator::getStaticClassID();
00389   }
00390 
00402   static UClassID getStaticClassID(void)
00403   {
00404     return (UClassID)&fgClassID;
00405   }
00406 
00415   uint8_t *cloneRuleData(int32_t &length, UErrorCode &status);
00416 
00424   void getRules(UColRuleOption delta, UnicodeString &buffer);
00425 
00433   virtual void setAttribute(UColAttribute attr, UColAttributeValue value,
00434                             UErrorCode &status);
00435 
00443   virtual UColAttributeValue getAttribute(UColAttribute attr,
00444                                           UErrorCode &status);
00445 
00456   virtual uint32_t setVariableTop(const UChar *varTop, int32_t len, UErrorCode &status);
00457 
00467   virtual uint32_t setVariableTop(const UnicodeString varTop, UErrorCode &status);
00468 
00476   virtual void setVariableTop(const uint32_t varTop, UErrorCode &status);
00477 
00484   virtual uint32_t getVariableTop(UErrorCode &status) const;
00485 
00491   virtual Collator* safeClone(void);
00492 
00502   virtual int32_t getSortKey(const UnicodeString& source, uint8_t *result,
00503                              int32_t resultLength) const;
00504 
00517   virtual int32_t getSortKey(const UChar *source, int32_t sourceLength,
00518                              uint8_t *result, int32_t resultLength) const;
00519 
00530   virtual ECollationStrength getStrength(void) const;
00531 
00538   virtual void setStrength(ECollationStrength newStrength);
00539 
00540   // deprecated functions ---------------------------------------------------
00541 
00552   RuleBasedCollator(const UnicodeString& rules,
00553                     Normalizer::EMode decompositionMode,
00554                     UErrorCode& status);
00555 
00567   RuleBasedCollator(const UnicodeString& rules,
00568                     ECollationStrength collationStrength,
00569                     Normalizer::EMode decompositionMode,
00570                     UErrorCode& status);
00571 
00579   virtual void setDecomposition(Normalizer::EMode  mode);
00580 
00587   virtual Normalizer::EMode getDecomposition(void) const;
00588 
00589 private:
00590 
00591   // private static constants -----------------------------------------------
00592 
00593   static const int32_t UNMAPPED;
00594   static const int32_t CHARINDEX;  // need look up in .commit()
00595   static const int32_t EXPANDCHARINDEX; // Expand index follows
00596   static const int32_t CONTRACTCHARINDEX;  // contract indexes follow
00597 
00598   static const int32_t PRIMARYORDERINCREMENT;
00599   static const int32_t SECONDARYORDERINCREMENT;
00600   static const int32_t TERTIARYORDERINCREMENT;
00601   static const int32_t PRIMARYORDERMASK;
00602   static const int32_t SECONDARYORDERMASK;
00603   static const int32_t TERTIARYORDERMASK;
00604   static const int32_t IGNORABLEMASK;
00605   static const int32_t PRIMARYDIFFERENCEONLY;
00606   static const int32_t SECONDARYDIFFERENCEONLY;
00607   static const int32_t PRIMARYORDERSHIFT;
00608   static const int32_t SECONDARYORDERSHIFT;
00609 
00610   static const int32_t COLELEMENTSTART;
00611   static const int32_t PRIMARYLOWZEROMASK;
00612   static const int32_t RESETSECONDARYTERTIARY;
00613   static const int32_t RESETTERTIARY;
00614 
00615   static const int32_t PRIMIGNORABLE;
00616 
00617   static const int16_t FILEID;
00618   static const char    kFilenameSuffix[];
00619 
00620   // private static variables -----------------------------------------------
00621 
00625   static const char fgClassID;
00626 
00627   // private data members ---------------------------------------------------
00628 
00629   UBool dataIsOwned;
00630 
00635   UCollator *ucollator;
00636 
00640   UnicodeString *urulestring;
00641 
00642   // friend classes --------------------------------------------------------
00643 
00647   friend class CollationElementIterator;
00648 
00653   friend class Collator;
00654 
00658   friend class StringSearch;
00659 
00660   // private constructors --------------------------------------------------
00661 
00665   RuleBasedCollator();
00666 
00671   RuleBasedCollator(UCollator *collator, UnicodeString *rule);
00672 
00683   RuleBasedCollator(const Locale& desiredLocale, UErrorCode& status);
00684 
00686   void
00687   construct(const UnicodeString& rules,
00688             UColAttributeValue collationStrength,
00689             UColAttributeValue decompositionMode,
00690             UErrorCode& status);
00691 
00692   // private methods -------------------------------------------------------
00693 
00699   void setUCollator(const Locale& locale, UErrorCode& status);
00700 
00706   void setUCollator(const char* locale, UErrorCode& status);
00707 
00712   void setUCollator(UCollator *collator);
00713 
00721   void setUCollator(UCollator *collator, UnicodeString *rules);
00722 
00727   const UCollator * getUCollator();
00728 
00734   Collator::EComparisonResult getEComparisonResult(
00735                                           const UCollationResult &result) const;
00736 
00742   Collator::ECollationStrength getECollationStrength(
00743                                       const UCollationStrength &strength) const;
00744 
00750   UCollationStrength getUCollationStrength(
00751     const Collator::ECollationStrength &strength) const;
00752 };
00753 
00754 // inline method implementation ---------------------------------------------
00755 
00756 inline UBool RuleBasedCollator::operator!=(const Collator& other) const
00757 {
00758   return !(*this == other);
00759 }
00760 
00761 inline void RuleBasedCollator::setUCollator(const char *locale,
00762                                                UErrorCode &status)
00763 {
00764   if (U_FAILURE(status))
00765     return;
00766   if (ucollator && dataIsOwned)
00767     ucol_close(ucollator);
00768   ucollator = ucol_open(locale, &status);
00769 }
00770 
00771 inline void RuleBasedCollator::setUCollator(const Locale &locale,
00772                                                UErrorCode &status)
00773 {
00774   setUCollator(locale.getName(), status);
00775 }
00776 
00777 inline void RuleBasedCollator::setUCollator(UCollator *collator)
00778 {
00779   if (ucollator && dataIsOwned) {
00780     ucol_close(ucollator);
00781   }
00782   ucollator = collator;
00783 }
00784 
00785 inline void RuleBasedCollator::setUCollator(UCollator     *collator, 
00786                                             UnicodeString *rules)
00787 {
00788     if (ucollator && dataIsOwned) {
00789         ucol_close(ucollator);
00790         delete urulestring;
00791     }
00792     ucollator   = collator;
00793     urulestring = rules;
00794     dataIsOwned = FALSE;
00795 }
00796 
00797 inline const UCollator * RuleBasedCollator::getUCollator()
00798 {
00799     return ucollator;
00800 }
00801 
00802 inline Collator::EComparisonResult RuleBasedCollator::getEComparisonResult(
00803                                            const UCollationResult &result) const
00804 {
00805   switch (result)
00806   {
00807   case UCOL_LESS :
00808     return Collator::LESS;
00809   case UCOL_EQUAL :
00810     return Collator::EQUAL;
00811   default :
00812     return Collator::GREATER;
00813   }
00814 }
00815 
00816 inline Collator::ECollationStrength RuleBasedCollator::getECollationStrength(
00817                                        const UCollationStrength &strength) const
00818 {
00819   switch (strength)
00820   {
00821   case UCOL_PRIMARY :
00822     return Collator::PRIMARY;
00823   case UCOL_SECONDARY :
00824     return Collator::SECONDARY;
00825   case UCOL_TERTIARY :
00826     return Collator::TERTIARY;
00827   case UCOL_QUATERNARY :
00828     return Collator::QUATERNARY;   
00829   default :
00830     return Collator::IDENTICAL;
00831   }
00832 }
00833 
00834 inline UCollationStrength RuleBasedCollator::getUCollationStrength(
00835                              const Collator::ECollationStrength &strength) const
00836 {
00837   switch (strength)
00838   {
00839   case Collator::PRIMARY :
00840     return UCOL_PRIMARY;
00841   case Collator::SECONDARY :
00842     return UCOL_SECONDARY;
00843   case Collator::TERTIARY :
00844     return UCOL_TERTIARY;
00845   case Collator::QUATERNARY :
00846     return UCOL_QUATERNARY;
00847   default :
00848     return UCOL_IDENTICAL;
00849   }
00850 }
00851 
00852 U_NAMESPACE_END
00853 
00854 #endif

Generated on Sun May 22 18:45:01 2005 for ICU 2.1 by  doxygen 1.4.2