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-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/utypes.h"
00058 
00059 #if !UCONFIG_NO_COLLATION
00060 
00061 #include "unicode/coll.h"
00062 #include "unicode/sortkey.h"
00063 #include "unicode/normlzr.h"
00064 
00065 U_NAMESPACE_BEGIN
00066 
00070 class StringSearch;
00074 class CollationElementIterator;
00075 
00104 class U_I18N_API RuleBasedCollator : public Collator
00105 {
00106 public:
00107 
00108   // constructor -------------------------------------------------------------
00109 
00119     RuleBasedCollator(const UnicodeString& rules, UErrorCode& status);
00120 
00131   RuleBasedCollator(const UnicodeString& rules,
00132                        ECollationStrength collationStrength,
00133                        UErrorCode& status);
00134 
00145   RuleBasedCollator(const UnicodeString& rules,
00146                     UColAttributeValue decompositionMode,
00147                     UErrorCode& status);
00148 
00160   RuleBasedCollator(const UnicodeString& rules,
00161                     ECollationStrength collationStrength,
00162                     UColAttributeValue decompositionMode,
00163                     UErrorCode& status);
00164 
00171     RuleBasedCollator(const RuleBasedCollator& other);
00172 
00173   // destructor --------------------------------------------------------------
00174 
00179     virtual ~RuleBasedCollator();
00180 
00181   // public methods ----------------------------------------------------------
00182 
00188     RuleBasedCollator& operator=(const RuleBasedCollator& other);
00189 
00196   virtual UBool operator==(const Collator& other) const;
00197 
00204   virtual UBool operator!=(const Collator& other) const;
00205 
00212   virtual Collator* clone(void) const;
00213 
00224     virtual CollationElementIterator* createCollationElementIterator(
00225                                            const UnicodeString& source) const;
00226 
00236   virtual CollationElementIterator* createCollationElementIterator(
00237                                        const CharacterIterator& source) const;
00238 
00251   virtual EComparisonResult compare(const UnicodeString& source,
00252                                     const UnicodeString& target) const;
00253 
00254 
00268   virtual EComparisonResult compare(const UnicodeString& source,
00269                                     const UnicodeString&  target,
00270                                     int32_t length) const;
00271 
00305   virtual EComparisonResult compare(const UChar* source, int32_t sourceLength,
00306                                     const UChar* target, int32_t targetLength)
00307                                     const;
00308 
00321   virtual CollationKey& getCollationKey(const UnicodeString& source,
00322                                         CollationKey& key,
00323                                         UErrorCode& status) const;
00324 
00337   virtual CollationKey& getCollationKey(const UChar *source,
00338                                         int32_t sourceLength,
00339                                         CollationKey& key,
00340                                         UErrorCode& status) const;
00341 
00347   virtual int32_t hashCode(void) const;
00348 
00359   virtual const Locale getLocale(ULocDataLocaleType type, UErrorCode& status) const;
00360 
00367   const UnicodeString& getRules(void) const;
00368 
00374   virtual void getVersion(UVersionInfo info) const;
00375 
00386   int32_t getMaxExpansion(int32_t order) const;
00387 
00398   virtual UClassID getDynamicClassID(void) const
00399   {
00400     return RuleBasedCollator::getStaticClassID();
00401   }
00402 
00414   static UClassID getStaticClassID(void)
00415   {
00416     return (UClassID)&fgClassID;
00417   }
00418 
00427   uint8_t *cloneRuleData(int32_t &length, UErrorCode &status);
00428 
00436   void getRules(UColRuleOption delta, UnicodeString &buffer);
00437 
00445   virtual void setAttribute(UColAttribute attr, UColAttributeValue value,
00446                             UErrorCode &status);
00447 
00455   virtual UColAttributeValue getAttribute(UColAttribute attr,
00456                                           UErrorCode &status);
00457 
00468   virtual uint32_t setVariableTop(const UChar *varTop, int32_t len, UErrorCode &status);
00469 
00479   virtual uint32_t setVariableTop(const UnicodeString varTop, UErrorCode &status);
00480 
00488   virtual void setVariableTop(const uint32_t varTop, UErrorCode &status);
00489 
00496   virtual uint32_t getVariableTop(UErrorCode &status) const;
00497 
00507   virtual UnicodeSet *getTailoredSet(UErrorCode &status) const;
00508 
00514   virtual Collator* safeClone(void);
00515 
00526   virtual int32_t getSortKey(const UnicodeString& source, uint8_t *result,
00527                              int32_t resultLength) const;
00528 
00541   virtual int32_t getSortKey(const UChar *source, int32_t sourceLength,
00542                              uint8_t *result, int32_t resultLength) const;
00543 
00554   virtual ECollationStrength getStrength(void) const;
00555 
00562   virtual void setStrength(ECollationStrength newStrength);
00563 
00564 #ifdef ICU_NORMALIZER_USE_DEPRECATES
00565   // obsolete functions ---------------------------------------------------
00566 
00577   RuleBasedCollator(const UnicodeString& rules,
00578                     Normalizer::EMode decompositionMode,
00579                     UErrorCode& status);
00580 
00592   RuleBasedCollator(const UnicodeString& rules,
00593                     ECollationStrength collationStrength,
00594                     Normalizer::EMode decompositionMode,
00595                     UErrorCode& status);
00596 
00604   virtual void setDecomposition(Normalizer::EMode  mode);
00605 
00612   virtual Normalizer::EMode getDecomposition(void) const;
00613 #endif /* ICU_NORMALIZER_USE_DEPRECATES */
00614 
00615 private:
00616 
00617   // private static constants -----------------------------------------------
00618 
00619   static const int32_t UNMAPPED;
00620   static const int32_t CHARINDEX;  // need look up in .commit()
00621   static const int32_t EXPANDCHARINDEX; // Expand index follows
00622   static const int32_t CONTRACTCHARINDEX;  // contract indexes follow
00623 
00624   static const int32_t PRIMARYORDERINCREMENT;
00625   static const int32_t SECONDARYORDERINCREMENT;
00626   static const int32_t TERTIARYORDERINCREMENT;
00627   static const int32_t PRIMARYORDERMASK;
00628   static const int32_t SECONDARYORDERMASK;
00629   static const int32_t TERTIARYORDERMASK;
00630   static const int32_t IGNORABLEMASK;
00631   static const int32_t PRIMARYDIFFERENCEONLY;
00632   static const int32_t SECONDARYDIFFERENCEONLY;
00633   static const int32_t PRIMARYORDERSHIFT;
00634   static const int32_t SECONDARYORDERSHIFT;
00635 
00636   static const int32_t COLELEMENTSTART;
00637   static const int32_t PRIMARYLOWZEROMASK;
00638   static const int32_t RESETSECONDARYTERTIARY;
00639   static const int32_t RESETTERTIARY;
00640 
00641   static const int32_t PRIMIGNORABLE;
00642 
00643   static const int16_t FILEID;
00644   static const char    kFilenameSuffix[];
00645 
00646   // private static variables -----------------------------------------------
00647 
00651   static const char fgClassID;
00652 
00653   // private data members ---------------------------------------------------
00654 
00655   UBool dataIsOwned;
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 
00755   const UCollator * getUCollator();
00756 
00762   Collator::EComparisonResult getEComparisonResult(
00763                                           const UCollationResult &result) const;
00764 
00770   Collator::ECollationStrength getECollationStrength(
00771                                       const UCollationStrength &strength) const;
00772 
00778   UCollationStrength getUCollationStrength(
00779     const Collator::ECollationStrength &strength) const;
00780 };
00781 
00782 // inline method implementation ---------------------------------------------
00783 
00784 inline UBool RuleBasedCollator::operator!=(const Collator& other) const
00785 {
00786   return !(*this == other);
00787 }
00788 
00789 inline void RuleBasedCollator::setUCollator(const char *locale,
00790                                                UErrorCode &status)
00791 {
00792   if (U_FAILURE(status))
00793     return;
00794   if (ucollator && dataIsOwned)
00795     ucol_close(ucollator);
00796   ucollator = ucol_open(locale, &status);
00797 }
00798 
00799 inline void RuleBasedCollator::setUCollator(const Locale &locale,
00800                                                UErrorCode &status)
00801 {
00802   setUCollator(locale.getName(), status);
00803 }
00804 
00805 inline void RuleBasedCollator::setUCollator(UCollator     *collator, 
00806                                             UnicodeString *rules)
00807 {
00808     if (ucollator && dataIsOwned) {
00809         ucol_close(ucollator);
00810         delete urulestring;
00811     }
00812     ucollator   = collator;
00813     urulestring = rules;
00814     dataIsOwned = FALSE;
00815 }
00816 
00817 inline const UCollator * RuleBasedCollator::getUCollator()
00818 {
00819     return ucollator;
00820 }
00821 
00822 inline Collator::EComparisonResult RuleBasedCollator::getEComparisonResult(
00823                                            const UCollationResult &result) const
00824 {
00825   switch (result)
00826   {
00827   case UCOL_LESS :
00828     return Collator::LESS;
00829   case UCOL_EQUAL :
00830     return Collator::EQUAL;
00831   default :
00832     return Collator::GREATER;
00833   }
00834 }
00835 
00836 inline Collator::ECollationStrength RuleBasedCollator::getECollationStrength(
00837                                        const UCollationStrength &strength) const
00838 {
00839   switch (strength)
00840   {
00841   case UCOL_PRIMARY :
00842     return Collator::PRIMARY;
00843   case UCOL_SECONDARY :
00844     return Collator::SECONDARY;
00845   case UCOL_TERTIARY :
00846     return Collator::TERTIARY;
00847   case UCOL_QUATERNARY :
00848     return Collator::QUATERNARY;   
00849   default :
00850     return Collator::IDENTICAL;
00851   }
00852 }
00853 
00854 inline UCollationStrength RuleBasedCollator::getUCollationStrength(
00855                              const Collator::ECollationStrength &strength) const
00856 {
00857   switch (strength)
00858   {
00859   case Collator::PRIMARY :
00860     return UCOL_PRIMARY;
00861   case Collator::SECONDARY :
00862     return UCOL_SECONDARY;
00863   case Collator::TERTIARY :
00864     return UCOL_TERTIARY;
00865   case Collator::QUATERNARY :
00866     return UCOL_QUATERNARY;
00867   default :
00868     return UCOL_IDENTICAL;
00869   }
00870 }
00871 
00872 U_NAMESPACE_END
00873 
00874 #endif /* #if !UCONFIG_NO_COLLATION */
00875 
00876 #endif

Generated on Wed Dec 18 16:49:48 2002 for ICU 2.4 by doxygen1.2.11.1 written by Dimitri van Heesch, © 1997-2001