coll.h

Go to the documentation of this file.
00001 /*
00002 ******************************************************************************
00003 *   Copyright (C) 1996-2012, International Business Machines                 *
00004 *   Corporation and others.  All Rights Reserved.                            *
00005 ******************************************************************************
00006 */
00007 
00049 #ifndef COLL_H
00050 #define COLL_H
00051 
00052 #include "unicode/utypes.h"
00053 
00054 #if !UCONFIG_NO_COLLATION
00055 
00056 #include "unicode/uobject.h"
00057 #include "unicode/ucol.h"
00058 #include "unicode/normlzr.h"
00059 #include "unicode/locid.h"
00060 #include "unicode/uniset.h"
00061 #include "unicode/umisc.h"
00062 #include "unicode/uiter.h"
00063 #include "unicode/stringpiece.h"
00064 
00065 U_NAMESPACE_BEGIN
00066 
00067 class StringEnumeration;
00068 
00069 #if !UCONFIG_NO_SERVICE
00070 
00073 class CollatorFactory;
00074 #endif
00075 
00079 class CollationKey;
00080 
00177 class U_I18N_API Collator : public UObject {
00178 public:
00179 
00180     // Collator public enums -----------------------------------------------
00181 
00207     enum ECollationStrength
00208     {
00209         PRIMARY    = UCOL_PRIMARY,  // 0
00210         SECONDARY  = UCOL_SECONDARY,  // 1
00211         TERTIARY   = UCOL_TERTIARY,  // 2
00212         QUATERNARY = UCOL_QUATERNARY,  // 3
00213         IDENTICAL  = UCOL_IDENTICAL  // 15
00214     };
00215 
00226     enum EComparisonResult
00227     {
00228         LESS = UCOL_LESS,  // -1
00229         EQUAL = UCOL_EQUAL,  // 0
00230         GREATER = UCOL_GREATER  // 1
00231     };
00232 
00233     // Collator public destructor -----------------------------------------
00234 
00239     virtual ~Collator();
00240 
00241     // Collator public methods --------------------------------------------
00242 
00261     virtual UBool operator==(const Collator& other) const;
00262 
00270     virtual UBool operator!=(const Collator& other) const;
00271 
00277     virtual Collator* clone(void) const = 0;
00278 
00298     static Collator* U_EXPORT2 createInstance(UErrorCode&  err);
00299 
00323     static Collator* U_EXPORT2 createInstance(const Locale& loc, UErrorCode& err);
00324 
00325 #ifdef U_USE_COLLATION_OBSOLETE_2_6
00326 
00349     static Collator *createInstance(const Locale &loc, UVersionInfo version, UErrorCode &err);
00350 #endif
00351 
00363     virtual EComparisonResult compare(const UnicodeString& source,
00364                                       const UnicodeString& target) const;
00365 
00378     virtual UCollationResult compare(const UnicodeString& source,
00379                                       const UnicodeString& target,
00380                                       UErrorCode &status) const = 0;
00381 
00394     virtual EComparisonResult compare(const UnicodeString& source,
00395                                       const UnicodeString& target,
00396                                       int32_t length) const;
00397 
00411     virtual UCollationResult compare(const UnicodeString& source,
00412                                       const UnicodeString& target,
00413                                       int32_t length,
00414                                       UErrorCode &status) const = 0;
00415 
00449     virtual EComparisonResult compare(const UChar* source, int32_t sourceLength,
00450                                       const UChar* target, int32_t targetLength)
00451                                       const;
00452 
00469     virtual UCollationResult compare(const UChar* source, int32_t sourceLength,
00470                                       const UChar* target, int32_t targetLength,
00471                                       UErrorCode &status) const = 0;
00472 
00484     virtual UCollationResult compare(UCharIterator &sIter,
00485                                      UCharIterator &tIter,
00486                                      UErrorCode &status) const;
00487 
00501     virtual UCollationResult compareUTF8(const StringPiece &source,
00502                                          const StringPiece &target,
00503                                          UErrorCode &status) const;
00504 
00520     virtual CollationKey& getCollationKey(const UnicodeString&  source,
00521                                           CollationKey& key,
00522                                           UErrorCode& status) const = 0;
00523 
00540     virtual CollationKey& getCollationKey(const UChar*source,
00541                                           int32_t sourceLength,
00542                                           CollationKey& key,
00543                                           UErrorCode& status) const = 0;
00548     virtual int32_t hashCode(void) const = 0;
00549 
00562     virtual Locale getLocale(ULocDataLocaleType type, UErrorCode& status) const = 0;
00563 
00573     UBool greater(const UnicodeString& source, const UnicodeString& target)
00574                   const;
00575 
00585     UBool greaterOrEqual(const UnicodeString& source,
00586                          const UnicodeString& target) const;
00587 
00597     UBool equals(const UnicodeString& source, const UnicodeString& target) const;
00598 
00609     virtual ECollationStrength getStrength(void) const;
00610 
00629     virtual void setStrength(ECollationStrength newStrength);
00630 
00646      virtual int32_t getReorderCodes(int32_t *dest,
00647                                      int32_t destCapacity,
00648                                      UErrorCode& status) const;
00649 
00664      virtual void setReorderCodes(const int32_t* reorderCodes,
00665                                   int32_t reorderCodesLength,
00666                                   UErrorCode& status) ;
00667 
00686     static int32_t U_EXPORT2 getEquivalentReorderCodes(int32_t reorderCode,
00687                                 int32_t* dest,
00688                                 int32_t destCapacity,
00689                                 UErrorCode& status);
00690 
00700     static UnicodeString& U_EXPORT2 getDisplayName(const Locale& objectLocale,
00701                                          const Locale& displayLocale,
00702                                          UnicodeString& name);
00703 
00712     static UnicodeString& U_EXPORT2 getDisplayName(const Locale& objectLocale,
00713                                          UnicodeString& name);
00714 
00726     static const Locale* U_EXPORT2 getAvailableLocales(int32_t& count);
00727 
00736     static StringEnumeration* U_EXPORT2 getAvailableLocales(void);
00737 
00747     static StringEnumeration* U_EXPORT2 getKeywords(UErrorCode& status);
00748 
00760     static StringEnumeration* U_EXPORT2 getKeywordValues(const char *keyword, UErrorCode& status);
00761 
00778     static StringEnumeration* U_EXPORT2 getKeywordValuesForLocale(const char* keyword, const Locale& locale,
00779                                                                     UBool commonlyUsed, UErrorCode& status);
00780 
00808     static Locale U_EXPORT2 getFunctionalEquivalent(const char* keyword, const Locale& locale,
00809                                           UBool& isAvailable, UErrorCode& status);
00810 
00811 #if !UCONFIG_NO_SERVICE
00812 
00820     static URegistryKey U_EXPORT2 registerInstance(Collator* toAdopt, const Locale& locale, UErrorCode& status);
00821 
00829     static URegistryKey U_EXPORT2 registerFactory(CollatorFactory* toAdopt, UErrorCode& status);
00830 
00841     static UBool U_EXPORT2 unregister(URegistryKey key, UErrorCode& status);
00842 #endif /* UCONFIG_NO_SERVICE */
00843 
00849     virtual void getVersion(UVersionInfo info) const = 0;
00850 
00861     virtual UClassID getDynamicClassID(void) const = 0;
00862 
00871     virtual void setAttribute(UColAttribute attr, UColAttributeValue value,
00872                               UErrorCode &status) = 0;
00873 
00882     virtual UColAttributeValue getAttribute(UColAttribute attr,
00883                                             UErrorCode &status) const = 0;
00884 
00895     virtual uint32_t setVariableTop(const UChar *varTop, int32_t len, UErrorCode &status) = 0;
00896 
00906     virtual uint32_t setVariableTop(const UnicodeString &varTop, UErrorCode &status) = 0;
00907 
00915     virtual void setVariableTop(uint32_t varTop, UErrorCode &status) = 0;
00916 
00923     virtual uint32_t getVariableTop(UErrorCode &status) const = 0;
00924 
00934     virtual UnicodeSet *getTailoredSet(UErrorCode &status) const;
00935 
00943     virtual Collator* safeClone(void) const;
00944 
00957     virtual int32_t getSortKey(const UnicodeString& source,
00958                               uint8_t* result,
00959                               int32_t resultLength) const = 0;
00960 
00976     virtual int32_t getSortKey(const UChar*source, int32_t sourceLength,
00977                                uint8_t*result, int32_t resultLength) const = 0;
00978 
01016     static int32_t U_EXPORT2 getBound(const uint8_t       *source,
01017             int32_t             sourceLength,
01018             UColBoundMode       boundType,
01019             uint32_t            noOfLevels,
01020             uint8_t             *result,
01021             int32_t             resultLength,
01022             UErrorCode          &status);
01023 
01024 
01025 protected:
01026 
01027     // Collator protected constructors -------------------------------------
01028 
01036     Collator();
01037 
01038 #ifndef U_HIDE_DEPRECATED_API
01039 
01050     Collator(UCollationStrength collationStrength,
01051              UNormalizationMode decompositionMode);
01052 #endif  /* U_HIDE_DEPRECATED_API */
01053 
01059     Collator(const Collator& other);
01060 
01061     // Collator protected methods -----------------------------------------
01062 
01063 
01071     virtual void setLocales(const Locale& requestedLocale, const Locale& validLocale, const Locale& actualLocale);
01072 
01073 public:
01074 #if !UCONFIG_NO_SERVICE
01075 #ifndef U_HIDE_INTERNAL_API
01076 
01080     static UCollator* createUCollator(const char* loc, UErrorCode* status);
01081 #endif  /* U_HIDE_INTERNAL_API */
01082 #endif
01083 
01107     virtual int32_t internalGetShortDefinitionString(const char *locale,
01108                                                      char *buffer,
01109                                                      int32_t capacity,
01110                                                      UErrorCode &status) const;
01111 private:
01116     Collator& operator=(const Collator& other);
01117 
01118     friend class CFactory;
01119     friend class SimpleCFactory;
01120     friend class ICUCollatorFactory;
01121     friend class ICUCollatorService;
01122     static Collator* makeInstance(const Locale& desiredLocale,
01123                                   UErrorCode& status);
01124 
01125     // Collator private data members ---------------------------------------
01126 
01127     /*
01128     synwee : removed as attributes to be handled by child class
01129     UCollationStrength  strength;
01130     Normalizer::EMode  decmp;
01131     */
01132     /* This is useless information */
01133 /*  static const UVersionInfo fVersion;*/
01134 };
01135 
01136 #if !UCONFIG_NO_SERVICE
01137 
01153 class U_I18N_API CollatorFactory : public UObject {
01154 public:
01155 
01160     virtual ~CollatorFactory();
01161 
01169     virtual UBool visible(void) const;
01170 
01178     virtual Collator* createCollator(const Locale& loc) = 0;
01179 
01190     virtual  UnicodeString& getDisplayName(const Locale& objectLocale,
01191                                            const Locale& displayLocale,
01192                                            UnicodeString& result);
01193 
01203     virtual const UnicodeString * getSupportedIDs(int32_t &count, UErrorCode& status) = 0;
01204 };
01205 #endif /* UCONFIG_NO_SERVICE */
01206 
01207 // Collator inline methods -----------------------------------------------
01208 
01209 U_NAMESPACE_END
01210 
01211 #endif /* #if !UCONFIG_NO_COLLATION */
01212 
01213 #endif

Generated on 27 Oct 2013 for ICU 50.1.2 by  doxygen 1.4.7