57 #if U_SHOW_CPLUSPLUS_API
59 #if !UCONFIG_NO_COLLATION
62 #include <string_view>
63 #include <type_traits>
78 class StringEnumeration;
80 #if !UCONFIG_NO_SERVICE
84 class CollatorFactory;
215 #ifndef U_FORCE_HIDE_DEPRECATED_API
336 #ifndef U_FORCE_HIDE_DEPRECATED_API
368 #ifndef U_FORCE_HIDE_DEPRECATED_API
383 int32_t length)
const;
404 #ifndef U_FORCE_HIDE_DEPRECATED_API
439 const char16_t* target, int32_t targetLength)
460 const char16_t* target, int32_t targetLength,
537 int32_t sourceLength,
546 #ifndef U_FORCE_HIDE_DEPRECATED_API
597 #ifndef U_HIDE_DRAFT_API
604 inline auto equal_to()
const {
return Predicate<std::equal_to, UCOL_EQUAL>(*
this); }
611 inline auto greater()
const {
return Predicate<std::equal_to, UCOL_GREATER>(*
this); }
618 inline auto less()
const {
return Predicate<std::equal_to, UCOL_LESS>(*
this); }
625 inline auto not_equal_to()
const {
return Predicate<std::not_equal_to, UCOL_EQUAL>(*
this); }
632 inline auto greater_equal()
const {
return Predicate<std::not_equal_to, UCOL_LESS>(*
this); }
639 inline auto less_equal()
const {
return Predicate<std::not_equal_to, UCOL_GREATER>(*
this); }
643 #ifndef U_FORCE_HIDE_DEPRECATED_API
693 int32_t destCapacity,
712 int32_t reorderCodesLength,
737 int32_t destCapacity,
750 const Locale& displayLocale,
860 #if !UCONFIG_NO_SERVICE
973 #ifndef U_FORCE_HIDE_DEPRECATED_API
1043 #ifndef U_FORCE_HIDE_DEPRECATED_API
1072 int32_t resultLength)
const = 0;
1093 virtual int32_t
getSortKey(
const char16_t*source, int32_t sourceLength,
1094 uint8_t*result, int32_t resultLength)
const = 0;
1133 static int32_t U_EXPORT2
getBound(
const uint8_t *source,
1134 int32_t sourceLength,
1136 uint32_t noOfLevels,
1138 int32_t resultLength,
1155 #ifndef U_HIDE_DEPRECATED_API
1221 const char *left, int32_t leftLength,
1222 const char *right, int32_t rightLength,
1232 uint8_t *dest, int32_t count,
UErrorCode &errorCode)
const;
1234 #ifndef U_HIDE_INTERNAL_API
1237 return reinterpret_cast<Collator *
>(uc);
1241 return reinterpret_cast<const Collator *
>(uc);
1245 return reinterpret_cast<UCollator *
>(
this);
1249 return reinterpret_cast<const UCollator *
>(
this);
1259 friend class CFactory;
1260 friend class SimpleCFactory;
1261 friend class ICUCollatorFactory;
1262 friend class ICUCollatorService;
1266 #ifndef U_HIDE_DRAFT_API
1271 template <
template <
typename...>
typename Compare,
UCollationResult result>
1274 explicit Predicate(
const Collator& parent) : collator(parent) {}
1277 typename T,
typename U,
1278 typename = std::enable_if_t<ConvertibleToU16StringView<T> && ConvertibleToU16StringView<U>>>
1279 bool operator()(
const T& lhs,
const U& rhs)
const {
1283 UnicodeString::readOnlyAlias(lhs),
1284 UnicodeString::readOnlyAlias(rhs),
1289 bool operator()(std::string_view lhs, std::string_view rhs)
const {
1291 return compare(collator.compareUTF8(lhs, rhs, status), result);
1294 #if defined(__cpp_char8_t)
1295 bool operator()(std::u8string_view lhs, std::u8string_view rhs)
const {
1297 return compare(collator.compareUTF8(lhs, rhs, status), result);
1302 const Collator& collator;
1303 static constexpr Compare<UCollationResult> compare{};
1308 #if !UCONFIG_NO_SERVICE
1363 const Locale& displayLocale,
C++ API: char16_t pointer wrappers with implicit conversion from bit-compatible raw pointer types.
Collation keys are generated by the Collator class.
A factory, used with registerFactory, the creates multiple collators and provides display names for t...
virtual const UnicodeString * getSupportedIDs(int32_t &count, UErrorCode &status)=0
Return an array of all the locale names directly supported by this factory.
virtual UnicodeString & getDisplayName(const Locale &objectLocale, const Locale &displayLocale, UnicodeString &result)
Return the name of the collator for the objectLocale, localized for the displayLocale.
virtual UBool visible() const
Return true if this factory is visible.
virtual Collator * createCollator(const Locale &loc)=0
Return a collator for the provided locale.
virtual ~CollatorFactory()
Destructor.
The Collator class performs locale-sensitive string comparison.
virtual UCollationResult internalCompareUTF8(const char *left, int32_t leftLength, const char *right, int32_t rightLength, UErrorCode &errorCode) const
Implements ucol_strcollUTF8().
static URegistryKey registerInstance(Collator *toAdopt, const Locale &locale, UErrorCode &status)
Register a new Collator.
virtual Collator * clone() const =0
Makes a copy of this object.
static UnicodeString & getDisplayName(const Locale &objectLocale, UnicodeString &name)
Get name of the object for the desired Locale, in the language of the default locale.
virtual ECollationStrength getStrength() const
Determines the minimum strength that will be used in comparison or transformation.
static StringEnumeration * getAvailableLocales()
Return a StringEnumeration over the locales available at the time of the call, including registered l...
UBool equals(const UnicodeString &source, const UnicodeString &target) const
Convenience method for comparing two strings based on the collation rules.
static StringEnumeration * getKeywords(UErrorCode &status)
Create a string enumerator of all possible keywords that are relevant to collation.
const UCollator * toUCollator() const
virtual void getVersion(UVersionInfo info) const =0
Gets the version information for a Collator.
virtual Collator * safeClone() const
Same as clone().
virtual bool operator==(const Collator &other) const
Returns true if "other" is the same as "this".
auto less() const
Creates a comparison function object that uses this collator.
virtual CollationKey & getCollationKey(const char16_t *source, int32_t sourceLength, CollationKey &key, UErrorCode &status) const =0
Transforms the string into a series of characters that can be compared with CollationKey::compareTo.
static Locale getFunctionalEquivalent(const char *keyword, const Locale &locale, UBool &isAvailable, UErrorCode &status)
Return the functionally equivalent locale for the given requested locale, with respect to given keywo...
Collator()
Default constructor.
virtual EComparisonResult compare(const UnicodeString &source, const UnicodeString &target) const
The comparison function compares the character data stored in two different strings.
virtual void setLocales(const Locale &requestedLocale, const Locale &validLocale, const Locale &actualLocale)
Used internally by registration to define the requested and valid locales.
auto less_equal() const
Creates a comparison function object that uses this collator.
static StringEnumeration * getKeywordValues(const char *keyword, UErrorCode &status)
Given a keyword, create a string enumeration of all values for that keyword that are currently in use...
virtual void setAttribute(UColAttribute attr, UColAttributeValue value, UErrorCode &status)=0
Universal attribute setter.
virtual UClassID getDynamicClassID() const override=0
Returns a unique class ID POLYMORPHICALLY.
static Collator * createInstance(UErrorCode &err)
Creates the Collator object for the current default locale.
UBool greaterOrEqual(const UnicodeString &source, const UnicodeString &target) const
Convenience method for comparing two strings based on the collation rules.
virtual int32_t getSortKey(const UnicodeString &source, uint8_t *result, int32_t resultLength) const =0
Get the sort key as an array of bytes from a UnicodeString.
virtual UnicodeSet * getTailoredSet(UErrorCode &status) const
Get a UnicodeSet that contains all the characters and sequences tailored in this collator.
virtual UCollationResult compareUTF8(const StringPiece &source, const StringPiece &target, UErrorCode &status) const
Compares two UTF-8 strings using the Collator.
UBool greater(const UnicodeString &source, const UnicodeString &target) const
Convenience method for comparing two strings based on the collation rules.
virtual uint32_t getVariableTop(UErrorCode &status) const =0
Gets the variable top value of a Collator.
virtual void setStrength(ECollationStrength newStrength)
Sets the minimum strength to be used in comparison or transformation.
static int32_t getBound(const uint8_t *source, int32_t sourceLength, UColBoundMode boundType, uint32_t noOfLevels, uint8_t *result, int32_t resultLength, UErrorCode &status)
Produce a bound for a given sortkey and a number of levels.
virtual UCollationResult compare(const char16_t *source, int32_t sourceLength, const char16_t *target, int32_t targetLength, UErrorCode &status) const =0
The comparison function compares the character data stored in two different string arrays.
auto equal_to() const
Creates a comparison function object that uses this collator.
static Collator * fromUCollator(UCollator *uc)
virtual int32_t getReorderCodes(int32_t *dest, int32_t destCapacity, UErrorCode &status) const
Retrieves the reordering codes for this collator.
UCollator * toUCollator()
virtual uint32_t setVariableTop(const UnicodeString &varTop, UErrorCode &status)=0
Sets the variable top to the primary weight of the specified string.
ECollationStrength
Base letter represents a primary difference.
virtual UCollationResult compare(const UnicodeString &source, const UnicodeString &target, UErrorCode &status) const =0
The comparison function compares the character data stored in two different strings.
virtual UCollationResult compare(UCharIterator &sIter, UCharIterator &tIter, UErrorCode &status) const
Compares two strings using the Collator.
static StringEnumeration * getKeywordValuesForLocale(const char *keyword, const Locale &locale, UBool commonlyUsed, UErrorCode &status)
Given a key and a locale, returns an array of string values in a preferred order that would make a di...
auto greater_equal() const
Creates a comparison function object that uses this collator.
auto not_equal_to() const
Creates a comparison function object that uses this collator.
virtual int32_t hashCode() const =0
Generates the hash code for the collation object.
static URegistryKey registerFactory(CollatorFactory *toAdopt, UErrorCode &status)
Register a new CollatorFactory.
Collator(UCollationStrength collationStrength, UNormalizationMode decompositionMode)
Constructor.
static const Collator * fromUCollator(const UCollator *uc)
virtual ~Collator()
Destructor.
virtual int32_t internalNextSortKeyPart(UCharIterator *iter, uint32_t state[2], uint8_t *dest, int32_t count, UErrorCode &errorCode) const
Implements ucol_nextSortKeyPart().
virtual Locale getLocale(ULocDataLocaleType type, UErrorCode &status) const =0
Gets the locale of the Collator.
virtual UColAttributeValue getAttribute(UColAttribute attr, UErrorCode &status) const =0
Universal attribute getter.
virtual EComparisonResult compare(const char16_t *source, int32_t sourceLength, const char16_t *target, int32_t targetLength) const
The comparison function compares the character data stored in two different string arrays.
virtual UColReorderCode getMaxVariable() const
Returns the maximum reordering group whose characters are affected by UCOL_ALTERNATE_HANDLING.
auto greater() const
Creates a comparison function object that uses this collator.
virtual Collator & setMaxVariable(UColReorderCode group, UErrorCode &errorCode)
Sets the variable top to the top of the specified reordering group.
virtual int32_t getSortKey(const char16_t *source, int32_t sourceLength, uint8_t *result, int32_t resultLength) const =0
Get the sort key as an array of bytes from a char16_t buffer.
EComparisonResult
LESS is returned if source string is compared to be less than target string in the compare() method.
virtual bool operator!=(const Collator &other) const
Returns true if "other" is not the same as "this".
virtual void setReorderCodes(const int32_t *reorderCodes, int32_t reorderCodesLength, UErrorCode &status)
Sets the ordering of scripts for this collator.
virtual CollationKey & getCollationKey(const UnicodeString &source, CollationKey &key, UErrorCode &status) const =0
Transforms the string into a series of characters that can be compared with CollationKey::compareTo.
virtual void setVariableTop(uint32_t varTop, UErrorCode &status)=0
Sets the variable top to the specified primary weight.
virtual uint32_t setVariableTop(const char16_t *varTop, int32_t len, UErrorCode &status)=0
Sets the variable top to the primary weight of the specified string.
virtual UCollationResult compare(const UnicodeString &source, const UnicodeString &target, int32_t length, UErrorCode &status) const =0
Does the same thing as compare but limits the comparison to a specified length.
static UBool unregister(URegistryKey key, UErrorCode &status)
Unregister a previously-registered Collator or CollatorFactory using the key returned from the regist...
Collator(const Collator &other)
Copy constructor.
virtual EComparisonResult compare(const UnicodeString &source, const UnicodeString &target, int32_t length) const
Does the same thing as compare but limits the comparison to a specified length.
static Collator * createInstance(const Locale &loc, UErrorCode &err)
Gets the collation object for the desired locale.
static int32_t getEquivalentReorderCodes(int32_t reorderCode, int32_t *dest, int32_t destCapacity, UErrorCode &status)
Retrieves the reorder codes that are grouped with the given reorder code.
static const Locale * getAvailableLocales(int32_t &count)
Get the set of Locales for which Collations are installed.
static UnicodeString & getDisplayName(const Locale &objectLocale, const Locale &displayLocale, UnicodeString &name)
Get name of the object for the desired Locale, in the desired language.
virtual int32_t internalGetShortDefinitionString(const char *locale, char *buffer, int32_t capacity, UErrorCode &status) const
Get the short definition string for a collator.
A Locale object represents a specific geographical, political, or cultural region.
Base class for 'pure' C++ implementations of uenum api.
A string-like object that points to a sized piece of memory.
UObject is the common ICU "boilerplate" class.
A mutable set of Unicode characters and multicharacter strings.
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
C++ API: Locale ID object.
C++ API: StringPiece: Read-only byte string wrapper class.
C API for code unit iteration.
struct UCollator UCollator
structure representing a collator object instance
UColAttribute
Attributes that collation service understands.
UCollationResult
UCOL_LESS is returned if source string is compared to be less than target string in the ucol_strcoll(...
@ UCOL_LESS
string a < string b
@ UCOL_GREATER
string a > string b
@ UCOL_EQUAL
string a == string b
UColBoundMode
enum that is taken by ucol_getBound API See below for explanation do not change the values assigned...
UColAttributeValue
Enum containing attribute values for controlling collation behavior.
@ UCOL_TERTIARY
Tertiary collation strength.
@ UCOL_IDENTICAL
Identical collation strength.
@ UCOL_QUATERNARY
Quaternary collation strength.
@ UCOL_PRIMARY
Primary collation strength.
@ UCOL_SECONDARY
Secondary collation strength.
UColReorderCode
Enum containing the codes for reordering segments of the collation table that are not script codes.
C API: Unicode Character Iteration.
ULocDataLocaleType
Constants for *_getLocale() Allow user to select whether she wants information on requested,...
int8_t UBool
The ICU boolean type, a signed-byte integer.
C API: Miscellaneous definitions.
const void * URegistryKey
Opaque type returned by registerInstance, registerFactory and unregister for service registration.
C API: Unicode Normalization.
UNormalizationMode
Constants for normalization modes.
C++ API: Common ICU base class UObject.
void * UClassID
UClassID is used to identify classes without using the compiler's RTTI.
Basic definitions for ICU, for both C and C++ APIs.
UErrorCode
Standard ICU4C error code type, a substitute for exceptions.
@ U_ZERO_ERROR
No error, no warning.
#define U_I18N_API
Set to export library symbols from inside the i18n library, and to import them from outside.
uint8_t UVersionInfo[U_MAX_VERSION_LENGTH]
The binary form of a version on ICU APIs is an array of 4 uint8_t.