123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875 |
- #ifndef TBLCOLL_H
- #define TBLCOLL_H
- #include "unicode/utypes.h"
- #if !UCONFIG_NO_COLLATION
- #include "unicode/coll.h"
- #include "unicode/locid.h"
- #include "unicode/uiter.h"
- #include "unicode/ucol.h"
- U_NAMESPACE_BEGIN
- struct CollationCacheEntry;
- struct CollationData;
- struct CollationSettings;
- struct CollationTailoring;
- class StringSearch;
- /**
- * @stable ICU 2.0
- */
- class CollationElementIterator;
- class CollationKey;
- class SortKeyByteSink;
- class UnicodeSet;
- class UnicodeString;
- class UVector64;
- /**
- * The RuleBasedCollator class provides the implementation of
- * Collator, using data-driven tables. The user can create a customized
- * table-based collation.
- * <p>
- * For more information about the collation service see
- * <a href="http://userguide.icu-project.org/collation">the User Guide</a>.
- * <p>
- * Collation service provides correct sorting orders for most locales supported in ICU.
- * If specific data for a locale is not available, the orders eventually falls back
- * to the <a href="http://www.unicode.org/reports/tr35/tr35-collation.html#Root_Collation">CLDR root sort order</a>.
- * <p>
- * Sort ordering may be customized by providing your own set of rules. For more on
- * this subject see the <a href="http://userguide.icu-project.org/collation/customization">
- * Collation Customization</a> section of the User Guide.
- * <p>
- * Note, RuleBasedCollator is not to be subclassed.
- * @see Collator
- */
- class U_I18N_API RuleBasedCollator : public Collator {
- public:
-
- RuleBasedCollator(const UnicodeString& rules, UErrorCode& status);
-
- RuleBasedCollator(const UnicodeString& rules,
- ECollationStrength collationStrength,
- UErrorCode& status);
-
- RuleBasedCollator(const UnicodeString& rules,
- UColAttributeValue decompositionMode,
- UErrorCode& status);
-
- RuleBasedCollator(const UnicodeString& rules,
- ECollationStrength collationStrength,
- UColAttributeValue decompositionMode,
- UErrorCode& status);
- #ifndef U_HIDE_INTERNAL_API
-
- RuleBasedCollator(const UnicodeString &rules,
- UParseError &parseError, UnicodeString &reason,
- UErrorCode &errorCode);
- #endif
-
- RuleBasedCollator(const RuleBasedCollator& other);
-
- RuleBasedCollator(const uint8_t *bin, int32_t length,
- const RuleBasedCollator *base,
- UErrorCode &status);
-
- virtual ~RuleBasedCollator();
-
- RuleBasedCollator& operator=(const RuleBasedCollator& other);
-
- virtual UBool operator==(const Collator& other) const;
-
- virtual Collator* clone(void) const;
-
- virtual CollationElementIterator* createCollationElementIterator(
- const UnicodeString& source) const;
-
- virtual CollationElementIterator* createCollationElementIterator(
- const CharacterIterator& source) const;
-
- using Collator::compare;
-
- virtual UCollationResult compare(const UnicodeString& source,
- const UnicodeString& target,
- UErrorCode &status) const;
-
- virtual UCollationResult compare(const UnicodeString& source,
- const UnicodeString& target,
- int32_t length,
- UErrorCode &status) const;
-
- virtual UCollationResult compare(const UChar* source, int32_t sourceLength,
- const UChar* target, int32_t targetLength,
- UErrorCode &status) const;
-
- virtual UCollationResult compare(UCharIterator &sIter,
- UCharIterator &tIter,
- UErrorCode &status) const;
-
- virtual UCollationResult compareUTF8(const StringPiece &source,
- const StringPiece &target,
- UErrorCode &status) const;
-
- virtual CollationKey& getCollationKey(const UnicodeString& source,
- CollationKey& key,
- UErrorCode& status) const;
-
- virtual CollationKey& getCollationKey(const UChar *source,
- int32_t sourceLength,
- CollationKey& key,
- UErrorCode& status) const;
-
- virtual int32_t hashCode() const;
-
- virtual Locale getLocale(ULocDataLocaleType type, UErrorCode& status) const;
-
- const UnicodeString& getRules() const;
-
- virtual void getVersion(UVersionInfo info) const;
- #ifndef U_HIDE_DEPRECATED_API
-
- int32_t getMaxExpansion(int32_t order) const;
- #endif
-
- virtual UClassID getDynamicClassID(void) const;
-
- static UClassID U_EXPORT2 getStaticClassID(void);
- #ifndef U_HIDE_DEPRECATED_API
-
- uint8_t *cloneRuleData(int32_t &length, UErrorCode &status) const;
- #endif
-
- int32_t cloneBinary(uint8_t *buffer, int32_t capacity, UErrorCode &status) const;
-
- void getRules(UColRuleOption delta, UnicodeString &buffer) const;
-
- virtual void setAttribute(UColAttribute attr, UColAttributeValue value,
- UErrorCode &status);
-
- virtual UColAttributeValue getAttribute(UColAttribute attr,
- UErrorCode &status) const;
-
- virtual Collator &setMaxVariable(UColReorderCode group, UErrorCode &errorCode);
-
- virtual UColReorderCode getMaxVariable() const;
-
- virtual uint32_t setVariableTop(const UChar *varTop, int32_t len, UErrorCode &status);
-
- virtual uint32_t setVariableTop(const UnicodeString &varTop, UErrorCode &status);
-
- virtual void setVariableTop(uint32_t varTop, UErrorCode &status);
-
- virtual uint32_t getVariableTop(UErrorCode &status) const;
-
- virtual UnicodeSet *getTailoredSet(UErrorCode &status) const;
-
- virtual int32_t getSortKey(const UnicodeString& source, uint8_t *result,
- int32_t resultLength) const;
-
- virtual int32_t getSortKey(const UChar *source, int32_t sourceLength,
- uint8_t *result, int32_t resultLength) const;
-
- virtual int32_t getReorderCodes(int32_t *dest,
- int32_t destCapacity,
- UErrorCode& status) const;
-
- virtual void setReorderCodes(const int32_t* reorderCodes,
- int32_t reorderCodesLength,
- UErrorCode& status) ;
-
- virtual UCollationResult internalCompareUTF8(
- const char *left, int32_t leftLength,
- const char *right, int32_t rightLength,
- UErrorCode &errorCode) const;
-
- virtual int32_t internalGetShortDefinitionString(const char *locale,
- char *buffer,
- int32_t capacity,
- UErrorCode &status) const;
-
- virtual int32_t internalNextSortKeyPart(
- UCharIterator *iter, uint32_t state[2],
- uint8_t *dest, int32_t count, UErrorCode &errorCode) const;
-
-
- RuleBasedCollator();
- #ifndef U_HIDE_INTERNAL_API
-
- const char *internalGetLocaleID(ULocDataLocaleType type, UErrorCode &errorCode) const;
-
- void internalGetContractionsAndExpansions(
- UnicodeSet *contractions, UnicodeSet *expansions,
- UBool addPrefixes, UErrorCode &errorCode) const;
-
- void internalAddContractions(UChar32 c, UnicodeSet &set, UErrorCode &errorCode) const;
-
- void internalBuildTailoring(
- const UnicodeString &rules,
- int32_t strength,
- UColAttributeValue decompositionMode,
- UParseError *outParseError, UnicodeString *outReason,
- UErrorCode &errorCode);
-
- static inline RuleBasedCollator *rbcFromUCollator(UCollator *uc) {
- return dynamic_cast<RuleBasedCollator *>(fromUCollator(uc));
- }
-
- static inline const RuleBasedCollator *rbcFromUCollator(const UCollator *uc) {
- return dynamic_cast<const RuleBasedCollator *>(fromUCollator(uc));
- }
-
- void internalGetCEs(const UnicodeString &str, UVector64 &ces, UErrorCode &errorCode) const;
- #endif
- protected:
-
- virtual void setLocales(const Locale& requestedLocale, const Locale& validLocale, const Locale& actualLocale);
- private:
- friend class CollationElementIterator;
- friend class Collator;
- RuleBasedCollator(const CollationCacheEntry *entry);
- /**
- * Enumeration of attributes that are relevant for short definition strings
- * (e.g., ucol_getShortDefinitionString()).
- * Effectively extends UColAttribute.
- */
- enum Attributes {
- ATTR_VARIABLE_TOP = UCOL_ATTRIBUTE_COUNT,
- ATTR_LIMIT
- };
- void adoptTailoring(CollationTailoring *t, UErrorCode &errorCode);
-
- UCollationResult doCompare(const UChar *left, int32_t leftLength,
- const UChar *right, int32_t rightLength,
- UErrorCode &errorCode) const;
- UCollationResult doCompare(const uint8_t *left, int32_t leftLength,
- const uint8_t *right, int32_t rightLength,
- UErrorCode &errorCode) const;
- void writeSortKey(const UChar *s, int32_t length,
- SortKeyByteSink &sink, UErrorCode &errorCode) const;
- void writeIdenticalLevel(const UChar *s, const UChar *limit,
- SortKeyByteSink &sink, UErrorCode &errorCode) const;
- const CollationSettings &getDefaultSettings() const;
- void setAttributeDefault(int32_t attribute) {
- explicitlySetAttributes &= ~((uint32_t)1 << attribute);
- }
- void setAttributeExplicitly(int32_t attribute) {
- explicitlySetAttributes |= (uint32_t)1 << attribute;
- }
- UBool attributeHasBeenSetExplicitly(int32_t attribute) const {
-
- return (UBool)((explicitlySetAttributes & ((uint32_t)1 << attribute)) != 0);
- }
-
- UBool isUnsafe(UChar32 c) const;
- static void computeMaxExpansions(const CollationTailoring *t, UErrorCode &errorCode);
- UBool initMaxExpansions(UErrorCode &errorCode) const;
- void setFastLatinOptions(CollationSettings &ownedSettings) const;
- const CollationData *data;
- const CollationSettings *settings;
- const CollationTailoring *tailoring;
- const CollationCacheEntry *cacheEntry;
- Locale validLocale;
- uint32_t explicitlySetAttributes;
- UBool actualLocaleIsSameAsValid;
- };
- U_NAMESPACE_END
- #endif
- #endif
|