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

- Search for |

- File List
- Globals

# coll.h

Go to the documentation of this file.

    00001 /*
    00002 ******************************************************************************
    00003 *   Copyright (C) 1996-2009, 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    = 0,
    00210         SECONDARY  = 1,
    00211         TERTIARY   = 2,
    00212         QUATERNARY = 3,
    00213         IDENTICAL  = 15
    00214     };
    00215
    00226     enum EComparisonResult
    00227     {
    00228         LESS = -1,
    00229         EQUAL = 0,
    00230         GREATER = 1
    00231     };
    00232
    00233     // Collator public destructor -----------------------------------------
    00234
    00239     virtual ~Collator();
    00240
    00241     // Collator public methods --------------------------------------------
    00242
    00249     virtual UBool operator==(const Collator& other) const;
    00250
    00257     virtual UBool operator!=(const Collator& other) const;
    00258
    00264     virtual Collator* clone(void) const = 0;
    00265
    00285     static Collator* U_EXPORT2 createInstance(UErrorCode&  err);
    00286
    00310     static Collator* U_EXPORT2 createInstance(const Locale& loc, UErrorCode& err);
    00311
    00312 #ifdef U_USE_COLLATION_OBSOLETE_2_6
    00313
    00336     static Collator *createInstance(const Locale &loc, UVersionInfo version, UErrorCode &err);
    00337 #endif
    00338
    00350     virtual EComparisonResult compare(const UnicodeString& source,
    00351                                       const UnicodeString& target) const;
    00352
    00365     virtual UCollationResult compare(const UnicodeString& source,
    00366                                       const UnicodeString& target,
    00367                                       UErrorCode &status) const = 0;
    00368
    00381     virtual EComparisonResult compare(const UnicodeString& source,
    00382                                       const UnicodeString& target,
    00383                                       int32_t length) const;
    00384
    00398     virtual UCollationResult compare(const UnicodeString& source,
    00399                                       const UnicodeString& target,
    00400                                       int32_t length,
    00401                                       UErrorCode &status) const = 0;
    00402
    00418     virtual EComparisonResult compare(const UChar* source, int32_t sourceLength,
    00419                                       const UChar* target, int32_t targetLength)
    00420                                       const;
    00421
    00438     virtual UCollationResult compare(const UChar* source, int32_t sourceLength,
    00439                                       const UChar* target, int32_t targetLength,
    00440                                       UErrorCode &status) const = 0;
    00441
    00453     virtual UCollationResult compare(UCharIterator &sIter,
    00454                                      UCharIterator &tIter,
    00455                                      UErrorCode &status) const;
    00456
    00470     virtual UCollationResult compareUTF8(const StringPiece &source,
    00471                                          const StringPiece &target,
    00472                                          UErrorCode &status) const;
    00473
    00489     virtual CollationKey& getCollationKey(const UnicodeString&  source,
    00490                                           CollationKey& key,
    00491                                           UErrorCode& status) const = 0;
    00492
    00509     virtual CollationKey& getCollationKey(const UChar*source,
    00510                                           int32_t sourceLength,
    00511                                           CollationKey& key,
    00512                                           UErrorCode& status) const = 0;
    00517     virtual int32_t hashCode(void) const = 0;
    00518
    00531     virtual const Locale getLocale(ULocDataLocaleType type, UErrorCode& status) const = 0;
    00532
    00542     UBool greater(const UnicodeString& source, const UnicodeString& target)
    00543                   const;
    00544
    00554     UBool greaterOrEqual(const UnicodeString& source,
    00555                          const UnicodeString& target) const;
    00556
    00566     UBool equals(const UnicodeString& source, const UnicodeString& target) const;
    00567
    00578     virtual ECollationStrength getStrength(void) const = 0;
    00579
    00598     virtual void setStrength(ECollationStrength newStrength) = 0;
    00599
    00609     static UnicodeString& U_EXPORT2 getDisplayName(const Locale& objectLocale,
    00610                                          const Locale& displayLocale,
    00611                                          UnicodeString& name);
    00612
    00621     static UnicodeString& U_EXPORT2 getDisplayName(const Locale& objectLocale,
    00622                                          UnicodeString& name);
    00623
    00635     static const Locale* U_EXPORT2 getAvailableLocales(int32_t& count);
    00636
    00645     static StringEnumeration* U_EXPORT2 getAvailableLocales(void);
    00646
    00656     static StringEnumeration* U_EXPORT2 getKeywords(UErrorCode& status);
    00657
    00669     static StringEnumeration* U_EXPORT2 getKeywordValues(const char *keyword, UErrorCode& status);
    00670
    00687     static StringEnumeration* U_EXPORT2 getKeywordValuesForLocale(const char* keyword, const Locale& locale,
    00688                                                                     UBool commonlyUsed, UErrorCode& status);
    00689
    00717     static Locale U_EXPORT2 getFunctionalEquivalent(const char* keyword, const Locale& locale,
    00718                                           UBool& isAvailable, UErrorCode& status);
    00719
    00720 #if !UCONFIG_NO_SERVICE
    00721
    00729     static URegistryKey U_EXPORT2 registerInstance(Collator* toAdopt, const Locale& locale, UErrorCode& status);
    00730
    00738     static URegistryKey U_EXPORT2 registerFactory(CollatorFactory* toAdopt, UErrorCode& status);
    00739
    00750     static UBool U_EXPORT2 unregister(URegistryKey key, UErrorCode& status);
    00751 #endif /* UCONFIG_NO_SERVICE */
    00752
    00758     virtual void getVersion(UVersionInfo info) const = 0;
    00759
    00770     virtual UClassID getDynamicClassID(void) const = 0;
    00771
    00780     virtual void setAttribute(UColAttribute attr, UColAttributeValue value,
    00781                               UErrorCode &status) = 0;
    00782
    00791     virtual UColAttributeValue getAttribute(UColAttribute attr,
    00792                                             UErrorCode &status) = 0;
    00793
    00804     virtual uint32_t setVariableTop(const UChar *varTop, int32_t len, UErrorCode &status) = 0;
    00805
    00815     virtual uint32_t setVariableTop(const UnicodeString varTop, UErrorCode &status) = 0;
    00816
    00824     virtual void setVariableTop(const uint32_t varTop, UErrorCode &status) = 0;
    00825
    00832     virtual uint32_t getVariableTop(UErrorCode &status) const = 0;
    00833
    00843     virtual UnicodeSet *getTailoredSet(UErrorCode &status) const;
    00844
    00845
    00851     virtual Collator* safeClone(void) = 0;
    00852
    00865     virtual int32_t getSortKey(const UnicodeString& source,
    00866                               uint8_t* result,
    00867                               int32_t resultLength) const = 0;
    00868
    00884     virtual int32_t getSortKey(const UChar*source, int32_t sourceLength,
    00885                                uint8_t*result, int32_t resultLength) const = 0;
    00886
    00924     static int32_t U_EXPORT2 getBound(const uint8_t       *source,
    00925             int32_t             sourceLength,
    00926             UColBoundMode       boundType,
    00927             uint32_t            noOfLevels,
    00928             uint8_t             *result,
    00929             int32_t             resultLength,
    00930             UErrorCode          &status);
    00931
    00932
    00933 protected:
    00934
    00935     // Collator protected constructors -------------------------------------
    00936
    00944     Collator();
    00945
    00957     Collator(UCollationStrength collationStrength,
    00958              UNormalizationMode decompositionMode);
    00959
    00965     Collator(const Collator& other);
    00966
    00967     // Collator protected methods -----------------------------------------
    00968
    00969
    00977     virtual void setLocales(const Locale& requestedLocale, const Locale& validLocale, const Locale& actualLocale);
    00978
    00979 public:
    00980 #if !UCONFIG_NO_SERVICE
    00981
    00985     static UCollator* createUCollator(const char* loc, UErrorCode* status);
    00986 #endif
    00987 private:
    00992     Collator& operator=(const Collator& other);
    00993
    00994     friend class CFactory;
    00995     friend class SimpleCFactory;
    00996     friend class ICUCollatorFactory;
    00997     friend class ICUCollatorService;
    00998     static Collator* makeInstance(const Locale& desiredLocale,
    00999                                   UErrorCode& status);
    01000
    01001     // Collator private data members ---------------------------------------
    01002
    01003     /*
    01004     synwee : removed as attributes to be handled by child class
    01005     UCollationStrength  strength;
    01006     Normalizer::EMode  decmp;
    01007     */
    01008     /* This is useless information */
    01009 /*  static const UVersionInfo fVersion;*/
    01010 };
    01011
    01012 #if !UCONFIG_NO_SERVICE
    01013
    01029 class U_I18N_API CollatorFactory : public UObject {
    01030 public:
    01031
    01036     virtual ~CollatorFactory();
    01037
    01045     virtual UBool visible(void) const;
    01046
    01054     virtual Collator* createCollator(const Locale& loc) = 0;
    01055
    01066     virtual  UnicodeString& getDisplayName(const Locale& objectLocale,
    01067                                            const Locale& displayLocale,
    01068                                            UnicodeString& result);
    01069
    01079     virtual const UnicodeString * getSupportedIDs(int32_t &count, UErrorCode& status) = 0;
    01080 };
    01081 #endif /* UCONFIG_NO_SERVICE */
    01082
    01083 // Collator inline methods -----------------------------------------------
    01084
    01085 U_NAMESPACE_END
    01086
    01087 #endif /* #if !UCONFIG_NO_COLLATION */
    01088
    01089 #endif