It is not recommended for production use.
</p>
- <p>Last updated: 2012-Jun-25<br />
+ <p>Last updated: 2012-Aug-03<br />
Copyright © 1997-2012 International Business Machines Corporation and
others. All Rights Reserved.</p>
<!-- Remember that there is a copyright at the end too -->
<code>u_setMutexFunctions()</code> and <code>u_setAtomicIncDecFunctions()</code>
with empty implementation functions.</p>
+ <h3>C++ Collator subclassing-API breaking changes</h3>
+ <p>We have made some changes to the C++ Collator API for ICU 50
+ that will make it easier to use and implement the Collator but
+ which are incompatible for subclasses.
+ If there are subclasses, they will have to be modified as well.
+ It will be easy to adapt subclass source code, if there is any.
+ We think it is unlikely (or at least rare) that users write subclasses of the C++ Collator,
+ given the number of virtual methods and the complexities of a collation implementation.</p>
+
+ <p>For details see the email "ICU4C C++ Collator subclassing-API breaking changes"
+ sent on 2012-jul-25 to the icu-design and icu-support
+ <a href="http://site.icu-project.org/contacts">mailing lists</a>,
+ and <a href="http://bugs.icu-project.org/trac/ticket/9346">ICU ticket #9346</a>,
+ including the <a href="http://bugs.icu-project.org/trac/review/9346">changes for that ticket</a>.</p>
+
+ <p>In particular, the <code>class TestCollator</code> in
+ <a href="http://bugs.icu-project.org/trac/browser/icu/trunk/source/test/intltest/apicoll.cpp"><code>source/test/intltest/apicoll.cpp</code></a>
+ illustrates how a subclass needs to be changed.
+ However, note that the TestCollator was also simplified slightly;
+ not all changes made there were strictly required for the API signature changes.</p>
+
<h2><a name="Download" href="#Download" id="Download">How To Download the
Source Code</a></h2>
* 01/29/01 synwee Modified into a C++ wrapper calling C APIs (ucol.h)
*/
+#include "utypeinfo.h" // for 'typeid' to work
+
#include "unicode/utypes.h"
#if !UCONFIG_NO_COLLATION
const UnicodeString& target) const
{
UErrorCode ec = U_ZERO_ERROR;
- return (Collator::EComparisonResult)compare(source, target, ec);
+ return (EComparisonResult)compare(source, target, ec);
}
// implement deprecated, previously abstract method
int32_t length) const
{
UErrorCode ec = U_ZERO_ERROR;
- return (Collator::EComparisonResult)compare(source, target, length, ec);
+ return (EComparisonResult)compare(source, target, length, ec);
}
// implement deprecated, previously abstract method
const
{
UErrorCode ec = U_ZERO_ERROR;
- return (Collator::EComparisonResult)compare(source, sourceLength, target, targetLength, ec);
+ return (EComparisonResult)compare(source, sourceLength, target, targetLength, ec);
}
UCollationResult Collator::compare(UCharIterator &/*sIter*/,
UBool Collator::operator==(const Collator& other) const
{
- return (UBool)(this == &other);
+ // Subclasses: Call this method and then add more specific checks.
+ return typeid(*this) == typeid(other);
}
UBool Collator::operator!=(const Collator& other) const
return Locale::createFromName(loc);
}
+Collator::ECollationStrength
+Collator::getStrength(void) const {
+ UErrorCode intStatus = U_ZERO_ERROR;
+ return (ECollationStrength)getAttribute(UCOL_STRENGTH, intStatus);
+}
+
+void
+Collator::setStrength(ECollationStrength newStrength) {
+ UErrorCode intStatus = U_ZERO_ERROR;
+ setAttribute(UCOL_STRENGTH, (UColAttributeValue)newStrength, intStatus);
+}
+
int32_t U_EXPORT2
Collator::getReorderCodes(int32_t* /* dest*/,
int32_t /* destCapacity*/,
* 01/29/01 synwee Modified into a C++ wrapper calling C APIs (ucol.h)
*/
-#include "utypeinfo.h" // for 'typeid' to work
-
#include "unicode/utypes.h"
#if !UCONFIG_NO_COLLATION
UErrorCode& status) : dataIsOwned(FALSE)
{
construct(rules,
- getUCollationStrength(collationStrength),
+ (UColAttributeValue)collationStrength,
UCOL_DEFAULT,
status);
}
UErrorCode& status) : dataIsOwned(FALSE)
{
construct(rules,
- getUCollationStrength(collationStrength),
+ (UColAttributeValue)collationStrength,
decompositionMode,
status);
}
UBool RuleBasedCollator::operator==(const Collator& that) const
{
/* only checks for address equals here */
- if (Collator::operator==(that))
+ if (this == &that) {
return TRUE;
-
- if (typeid(*this) != typeid(that))
+ }
+ if (!Collator::operator==(that)) {
return FALSE; /* not the same class */
+ }
RuleBasedCollator& thatAlias = (RuleBasedCollator&)that;
- // weiv: use C function, commented code below is wrong
return ucol_equals(this->ucollator, thatAlias.ucollator);
- /*
- synwee : orginal code does not check for data compatibility
- */
- /*
- if (ucollator != thatAlias.ucollator)
- return FALSE;
-
- return TRUE;
- */
-}
-
-UBool RuleBasedCollator::operator!=(const Collator& other) const
-{
- return !(*this == other);
}
// aliasing, not write-through
}
}
-Collator::EComparisonResult RuleBasedCollator::compare(
- const UnicodeString& source,
- const UnicodeString& target,
- int32_t length) const
-{
- UErrorCode status = U_ZERO_ERROR;
- return getEComparisonResult(compare(source.getBuffer(), uprv_min(length,source.length()), target.getBuffer(), uprv_min(length,target.length()), status));
-}
-
+/**
+* Compare two strings using this collator
+*/
UCollationResult RuleBasedCollator::compare(
const UnicodeString& source,
const UnicodeString& target,
return compare(source.getBuffer(), uprv_min(length,source.length()), target.getBuffer(), uprv_min(length,target.length()), status);
}
-Collator::EComparisonResult RuleBasedCollator::compare(const UChar* source,
- int32_t sourceLength,
- const UChar* target,
- int32_t targetLength)
- const
-{
- return getEComparisonResult(ucol_strcoll(ucollator, source, sourceLength,
- target, targetLength));
-}
-
UCollationResult RuleBasedCollator::compare(const UChar* source,
int32_t sourceLength,
const UChar* target,
}
}
-/**
-* Compare two strings using this collator
-*/
-Collator::EComparisonResult RuleBasedCollator::compare(
- const UnicodeString& source,
- const UnicodeString& target) const
-{
- return getEComparisonResult(ucol_strcoll(ucollator, source.getBuffer(), source.length(),
- target.getBuffer(), target.length()));
-}
-
UCollationResult RuleBasedCollator::compare(
const UnicodeString& source,
const UnicodeString& target,
}
UColAttributeValue RuleBasedCollator::getAttribute(UColAttribute attr,
- UErrorCode &status)
+ UErrorCode &status) const
{
if (U_FAILURE(status))
return UCOL_DEFAULT;
return ucol_setVariableTop(ucollator, varTop, len, &status);
}
-uint32_t RuleBasedCollator::setVariableTop(const UnicodeString varTop, UErrorCode &status) {
+uint32_t RuleBasedCollator::setVariableTop(const UnicodeString &varTop, UErrorCode &status) {
checkOwned();
return ucol_setVariableTop(ucollator, varTop.getBuffer(), varTop.length(), &status);
}
-void RuleBasedCollator::setVariableTop(const uint32_t varTop, UErrorCode &status) {
+void RuleBasedCollator::setVariableTop(uint32_t varTop, UErrorCode &status) {
checkOwned();
ucol_restoreVariableTop(ucollator, varTop, &status);
}
return ucol_getVariableTop(ucollator, &status);
}
-Collator* RuleBasedCollator::safeClone(void)
+Collator* RuleBasedCollator::safeClone(void) const
{
UErrorCode intStatus = U_ZERO_ERROR;
int32_t buffersize = U_COL_SAFECLONE_BUFFERSIZE;
RuleBasedCollator *result = new RuleBasedCollator();
// Null pointer check
if (result != NULL) {
- result->ucollator = ucol;
- result->dataIsOwned = TRUE;
- result->isWriteThroughAlias = FALSE;
- setRuleStringFromCollator();
+ result->ucollator = ucol;
+ result->dataIsOwned = TRUE;
+ result->isWriteThroughAlias = FALSE;
+ result->setRuleStringFromCollator();
}
return result;
return ucol_getSortKey(ucollator, source, sourceLength, result, resultLength);
}
-Collator::ECollationStrength RuleBasedCollator::getStrength(void) const
-{
- UErrorCode intStatus = U_ZERO_ERROR;
- return getECollationStrength(ucol_getAttribute(ucollator, UCOL_STRENGTH,
- &intStatus));
-}
-
-void RuleBasedCollator::setStrength(ECollationStrength newStrength)
-{
- checkOwned();
- UErrorCode intStatus = U_ZERO_ERROR;
- UCollationStrength strength = getUCollationStrength(newStrength);
- ucol_setAttribute(ucollator, UCOL_STRENGTH, strength, &intStatus);
-}
-
int32_t RuleBasedCollator::getReorderCodes(int32_t *dest,
int32_t destCapacity,
UErrorCode& status) const
/**
* return the locale of this collator
*/
-const Locale RuleBasedCollator::getLocale(ULocDataLocaleType type, UErrorCode &status) const {
+Locale RuleBasedCollator::getLocale(ULocDataLocaleType type, UErrorCode &status) const {
const char *result = ucol_getLocaleByType(ucollator, type, &status);
if(result == NULL) {
Locale res("");
*/
enum ECollationStrength
{
- PRIMARY = 0,
- SECONDARY = 1,
- TERTIARY = 2,
- QUATERNARY = 3,
- IDENTICAL = 15
+ PRIMARY = UCOL_PRIMARY, // 0
+ SECONDARY = UCOL_SECONDARY, // 1
+ TERTIARY = UCOL_TERTIARY, // 2
+ QUATERNARY = UCOL_QUATERNARY, // 3
+ IDENTICAL = UCOL_IDENTICAL // 15
};
/**
*/
enum EComparisonResult
{
- LESS = -1,
- EQUAL = 0,
- GREATER = 1
+ LESS = UCOL_LESS, // -1
+ EQUAL = UCOL_EQUAL, // 0
+ GREATER = UCOL_GREATER // 1
};
// Collator public destructor -----------------------------------------
// Collator public methods --------------------------------------------
/**
- * Returns true if "other" is the same as "this"
+ * Returns TRUE if "other" is the same as "this".
+ *
+ * The base class implementation returns TRUE if "other" has the same type/class as "this":
+ * <code>typeid(*this) == typeid(other)</code>.
+ *
+ * Subclass implementations should do something like the following:
+ * <pre>
+ * if (this == &other) { return TRUE; }
+ * if (!Collator::operator==(other)) { return FALSE; } // not the same class
+ *
+ * const MyCollator &o = (const MyCollator&)other;
+ * (compare this vs. o's subclass fields)
+ * </pre>
* @param other Collator object to be compared
- * @return true if other is the same as this.
+ * @return TRUE if other is the same as this.
* @stable ICU 2.0
*/
virtual UBool operator==(const Collator& other) const;
/**
* Returns true if "other" is not the same as "this".
+ * Calls !Collator::operator==(other) which works for all subclasses.
* @param other Collator object to be compared
- * @return true if other is not the same as this.
+ * @return TRUE if other is not the same as this.
* @stable ICU 2.0
*/
virtual UBool operator!=(const Collator& other) const;
* The comparison function compares the character data stored in two
* different string arrays. Returns information about whether a string array
* is less than, greater than or equal to another string array.
+ * <p>Example of use:
+ * <pre>
+ * . UChar ABC[] = {0x41, 0x42, 0x43, 0}; // = "ABC"
+ * . UChar abc[] = {0x61, 0x62, 0x63, 0}; // = "abc"
+ * . UErrorCode status = U_ZERO_ERROR;
+ * . Collator *myCollation =
+ * . Collator::createInstance(Locale::US, status);
+ * . if (U_FAILURE(status)) return;
+ * . myCollation->setStrength(Collator::PRIMARY);
+ * . // result would be Collator::EQUAL ("abc" == "ABC")
+ * . // (no primary difference between "abc" and "ABC")
+ * . Collator::EComparisonResult result =
+ * . myCollation->compare(abc, 3, ABC, 3);
+ * . myCollation->setStrength(Collator::TERTIARY);
+ * . // result would be Collator::LESS ("abc" <<< "ABC")
+ * . // (with tertiary difference between "abc" and "ABC")
+ * . result = myCollation->compare(abc, 3, ABC, 3);
+ * </pre>
* @param source the source string array to be compared with.
* @param sourceLength the length of the source string array. If this value
* is equal to -1, the string array is null-terminated.
* @deprecated ICU 2.8 This API is under consideration for revision
* in ICU 3.0.
*/
- virtual const Locale getLocale(ULocDataLocaleType type, UErrorCode& status) const = 0;
+ virtual Locale getLocale(ULocDataLocaleType type, UErrorCode& status) const = 0;
/**
* Convenience method for comparing two strings based on the collation rules.
UBool equals(const UnicodeString& source, const UnicodeString& target) const;
/**
- * Determines the minimum strength that will be use in comparison or
+ * Determines the minimum strength that will be used in comparison or
* transformation.
* <p>E.g. with strength == SECONDARY, the tertiary difference is ignored
* <p>E.g. with strength == PRIMARY, the secondary and tertiary difference
* @see Collator#setStrength
* @deprecated ICU 2.6 Use getAttribute(UCOL_STRENGTH...) instead
*/
- virtual ECollationStrength getStrength(void) const = 0;
+ virtual ECollationStrength getStrength(void) const;
/**
* Sets the minimum strength to be used in comparison or transformation.
* @param newStrength the new comparison level.
* @deprecated ICU 2.6 Use setAttribute(UCOL_STRENGTH...) instead
*/
- virtual void setStrength(ECollationStrength newStrength) = 0;
+ virtual void setStrength(ECollationStrength newStrength);
/**
* Retrieves the reordering codes for this collator.
* @see UColReorderCode
* @stable ICU 4.8
*/
- virtual int32_t U_EXPORT2 getReorderCodes(int32_t *dest,
- int32_t destCapacity,
- UErrorCode& status) const;
+ virtual int32_t getReorderCodes(int32_t *dest,
+ int32_t destCapacity,
+ UErrorCode& status) const;
/**
* Sets the ordering of scripts for this collator.
* @see UColReorderCode
* @stable ICU 4.8
*/
- virtual void U_EXPORT2 setReorderCodes(const int32_t* reorderCodes,
- int32_t reorderCodesLength,
- UErrorCode& status) ;
+ virtual void setReorderCodes(const int32_t* reorderCodes,
+ int32_t reorderCodesLength,
+ UErrorCode& status) ;
/**
* Retrieves the reorder codes that are grouped with the given reorder code. Some reorder
* @stable ICU 2.2
*/
virtual UColAttributeValue getAttribute(UColAttribute attr,
- UErrorCode &status) = 0;
+ UErrorCode &status) const = 0;
/**
* Sets the variable top to a collation element value of a string supplied.
* @return a 32 bit value containing the value of the variable top in upper 16 bits. Lower 16 bits are undefined
* @stable ICU 2.0
*/
- virtual uint32_t setVariableTop(const UnicodeString varTop, UErrorCode &status) = 0;
+ virtual uint32_t setVariableTop(const UnicodeString &varTop, UErrorCode &status) = 0;
/**
* Sets the variable top to a collation element value supplied. Variable top is set to the upper 16 bits.
* @param status error code (not changed by function)
* @stable ICU 2.0
*/
- virtual void setVariableTop(const uint32_t varTop, UErrorCode &status) = 0;
+ virtual void setVariableTop(uint32_t varTop, UErrorCode &status) = 0;
/**
* Gets the variable top value of a Collator.
* @return pointer to the new clone, user should remove it.
* @stable ICU 2.2
*/
- virtual Collator* safeClone(void) = 0;
+ virtual Collator* safeClone(void) const = 0;
/**
* Get the sort key as an array of bytes from an UnicodeString.
*/
virtual UBool operator==(const Collator& other) const;
- /**
- * Returns true if argument is not the same as this object.
- * @param other Collator object to be compared
- * @return returns true if argument is not the same as this object.
- * @stable ICU 2.0
- */
- virtual UBool operator!=(const Collator& other) const;
-
/**
* Makes a deep copy of the object.
* The caller owns the returned object.
virtual CollationElementIterator* createCollationElementIterator(
const CharacterIterator& source) const;
- /**
- * Compares a range of character data stored in two different strings based
- * on the collation rules. Returns information about whether a string is
- * less than, greater than or equal to another string in a language.
- * This can be overriden in a subclass.
- * @param source the source string.
- * @param target the target string to be compared with the source string.
- * @return the comparison result. GREATER if the source string is greater
- * than the target string, LESS if the source is less than the
- * target. Otherwise, returns EQUAL.
- * @deprecated ICU 2.6 Use overload with UErrorCode&
- */
- virtual EComparisonResult compare(const UnicodeString& source,
- const UnicodeString& target) const;
-
+ // Make deprecated versions of Collator::compare() visible.
+ using Collator::compare;
/**
* The comparison function compares the character data stored in two
const UnicodeString& target,
UErrorCode &status) const;
- /**
- * Compares a range of character data stored in two different strings based
- * on the collation rules up to the specified length. Returns information
- * about whether a string is less than, greater than or equal to another
- * string in a language. This can be overriden in a subclass.
- * @param source the source string.
- * @param target the target string to be compared with the source string.
- * @param length compares up to the specified length
- * @return the comparison result. GREATER if the source string is greater
- * than the target string, LESS if the source is less than the
- * target. Otherwise, returns EQUAL.
- * @deprecated ICU 2.6 Use overload with UErrorCode&
- */
- 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
int32_t length,
UErrorCode &status) const;
- /**
- * The comparison function compares the character data stored in two
- * different string arrays. Returns information about whether a string array
- * is less than, greater than or equal to another string array.
- * <p>Example of use:
- * <pre>
- * . UChar ABC[] = {0x41, 0x42, 0x43, 0}; // = "ABC"
- * . UChar abc[] = {0x61, 0x62, 0x63, 0}; // = "abc"
- * . UErrorCode status = U_ZERO_ERROR;
- * . Collator *myCollation =
- * . Collator::createInstance(Locale::US, status);
- * . if (U_FAILURE(status)) return;
- * . myCollation->setStrength(Collator::PRIMARY);
- * . // result would be Collator::EQUAL ("abc" == "ABC")
- * . // (no primary difference between "abc" and "ABC")
- * . Collator::EComparisonResult result =
- * . myCollation->compare(abc, 3, ABC, 3);
- * . myCollation->setStrength(Collator::TERTIARY);
- * . // result would be Collator::LESS ("abc" <<< "ABC")
- * . // (with tertiary difference between "abc" and "ABC")
- * . result = myCollation->compare(abc, 3, ABC, 3);
- * </pre>
- * @param source the source string array to be compared with.
- * @param sourceLength the length of the source string array. If this value
- * is equal to -1, the string array is null-terminated.
- * @param target the string that is to be compared with the source string.
- * @param targetLength the length of the target string array. If this value
- * is equal to -1, the string array is null-terminated.
- * @return Returns a byte value. GREATER if source is greater than target;
- * EQUAL if source is equal to target; LESS if source is less than
- * target
- * @deprecated ICU 2.6 Use overload with UErrorCode&
- */
- virtual EComparisonResult compare(const UChar* source, int32_t sourceLength,
- const UChar* target, int32_t targetLength)
- const;
-
/**
* The comparison function compares the character data stored in two
* different string arrays. Returns information about whether a string array
* was instantiated from rules, locale is empty.
* @deprecated ICU 2.8 likely to change in ICU 3.0, based on feedback
*/
- virtual const Locale getLocale(ULocDataLocaleType type, UErrorCode& status) const;
+ virtual Locale getLocale(ULocDataLocaleType type, UErrorCode& status) const;
/**
* Gets the table-based rules for the collation object.
* @stable ICU 2.2
*/
virtual UColAttributeValue getAttribute(UColAttribute attr,
- UErrorCode &status);
+ UErrorCode &status) const;
/**
* Sets the variable top to a collation element value of a string supplied.
* @return a 32 bit value containing the value of the variable top in upper 16 bits. Lower 16 bits are undefined
* @stable ICU 2.0
*/
- virtual uint32_t setVariableTop(const UnicodeString varTop, UErrorCode &status);
+ virtual uint32_t setVariableTop(const UnicodeString &varTop, UErrorCode &status);
/**
* Sets the variable top to a collation element value supplied. Variable top is set to the upper 16 bits.
* @param status error code (not changed by function)
* @stable ICU 2.0
*/
- virtual void setVariableTop(const uint32_t varTop, UErrorCode &status);
+ virtual void setVariableTop(uint32_t varTop, UErrorCode &status);
/**
* Gets the variable top value of a Collator.
* @return pointer to the new clone, user should remove it.
* @stable ICU 2.2
*/
- virtual Collator* safeClone(void);
+ virtual Collator* safeClone(void) const;
/**
* Get the sort key as an array of bytes from an UnicodeString.
virtual int32_t getSortKey(const UChar *source, int32_t sourceLength,
uint8_t *result, int32_t resultLength) const;
- /**
- * Determines the minimum strength that will be use in comparison or
- * transformation.
- * <p>E.g. with strength == SECONDARY, the tertiary difference is ignored
- * <p>E.g. with strength == PRIMARY, the secondary and tertiary difference
- * are ignored.
- * @return the current comparison level.
- * @see RuleBasedCollator#setStrength
- * @deprecated ICU 2.6 Use getAttribute(UCOL_STRENGTH...) instead
- */
- virtual ECollationStrength getStrength(void) const;
-
- /**
- * Sets the minimum strength to be used in comparison or transformation.
- * @see RuleBasedCollator#getStrength
- * @param newStrength the new comparison level.
- * @deprecated ICU 2.6 Use setAttribute(UCOL_STRENGTH...) instead
- */
- virtual void setStrength(ECollationStrength newStrength);
-
/**
* Retrieves the reordering codes for this collator.
* @param dest The array to fill with the script ordering.
* @see Collator#setReorderCodes
* @stable ICU 4.8
*/
- virtual int32_t U_EXPORT2 getReorderCodes(int32_t *dest,
- int32_t destCapacity,
- UErrorCode& status) const;
+ virtual int32_t getReorderCodes(int32_t *dest,
+ int32_t destCapacity,
+ UErrorCode& status) const;
/**
* Sets the ordering of scripts for this collator.
* @see Collator#getEquivalentReorderCodes
* @stable ICU 4.8
*/
- virtual void U_EXPORT2 setReorderCodes(const int32_t* reorderCodes,
- int32_t reorderCodesLength,
- UErrorCode& status) ;
+ virtual void setReorderCodes(const int32_t* reorderCodes,
+ int32_t reorderCodesLength,
+ UErrorCode& status) ;
/**
* Retrieves the reorder codes that are grouped with the given reorder code. Some reorder
virtual void setLocales(const Locale& requestedLocale, const Locale& validLocale, const Locale& actualLocale);
private:
-
// if not owned and not a write through alias, copy the ucollator
void checkOwned(void);
// utility to init rule string used by checkOwned and construct
void setRuleStringFromCollator();
- /**
- * Converts C's UCollationResult to EComparisonResult
- * @param result member of the enum UComparisonResult
- * @return EComparisonResult equivalent of UCollationResult
- * @deprecated ICU 2.6. We will not need it.
- */
- Collator::EComparisonResult getEComparisonResult(
- const UCollationResult &result) const;
-
- /**
- * Converts C's UCollationStrength to ECollationStrength
- * @param strength member of the enum UCollationStrength
- * @return ECollationStrength equivalent of UCollationStrength
- */
- Collator::ECollationStrength getECollationStrength(
- const UCollationStrength &strength) const;
-
- /**
- * Converts C++'s ECollationStrength to UCollationStrength
- * @param strength member of the enum ECollationStrength
- * @return UCollationStrength equivalent of ECollationStrength
- */
- UCollationStrength getUCollationStrength(
- const Collator::ECollationStrength &strength) const;
- public:
+public:
/** Get the short definition string for a collator. This internal API harvests the collator's
* locale and the attribute set and produces a string that can be used for opening
* a collator with the same properties using the ucol_openFromShortString API.
}
#endif
-inline Collator::EComparisonResult RuleBasedCollator::getEComparisonResult(
- const UCollationResult &result) const
-{
- switch (result)
- {
- case UCOL_LESS :
- return Collator::LESS;
- case UCOL_EQUAL :
- return Collator::EQUAL;
- default :
- return Collator::GREATER;
- }
-}
-
-inline Collator::ECollationStrength RuleBasedCollator::getECollationStrength(
- const UCollationStrength &strength) const
-{
- switch (strength)
- {
- case UCOL_PRIMARY :
- return Collator::PRIMARY;
- case UCOL_SECONDARY :
- return Collator::SECONDARY;
- case UCOL_TERTIARY :
- return Collator::TERTIARY;
- case UCOL_QUATERNARY :
- return Collator::QUATERNARY;
- default :
- return Collator::IDENTICAL;
- }
-}
-
-inline UCollationStrength RuleBasedCollator::getUCollationStrength(
- const Collator::ECollationStrength &strength) const
-{
- switch (strength)
- {
- case Collator::PRIMARY :
- return UCOL_PRIMARY;
- case Collator::SECONDARY :
- return UCOL_SECONDARY;
- case Collator::TERTIARY :
- return UCOL_TERTIARY;
- case Collator::QUATERNARY :
- return UCOL_QUATERNARY;
- default :
- return UCOL_IDENTICAL;
- }
-}
-
U_NAMESPACE_END
#endif /* #if !UCONFIG_NO_COLLATION */
/********************************************************************
* COPYRIGHT:
- * Copyright (c) 1997-2011, International Business Machines Corporation and
+ * Copyright (c) 1997-2012, International Business Machines Corporation and
* others. All Rights Reserved.
********************************************************************/
//===============================================================================
public:
virtual Collator* clone(void) const;
- // dang, markus says we can't use 'using' in ICU. I hate doing this for
- // deprecated methods...
-
- // using Collator::compare;
-
- virtual EComparisonResult compare(const UnicodeString& source,
- const UnicodeString& target) const
- {
- return Collator::compare(source, target);
- }
-
- virtual EComparisonResult compare(const UnicodeString& source,
- const UnicodeString& target,
- int32_t length) const
- {
- return Collator::compare(source, target, length);
- }
-
- virtual EComparisonResult compare(const UChar* source,
- int32_t sourceLength,
- const UChar* target,
- int32_t targetLength) const
- {
- return Collator::compare(source, sourceLength, target, targetLength);
- }
-
+ using Collator::compare;
virtual UCollationResult compare(const UnicodeString& source,
const UnicodeString& target,
CollationKey& key,
UErrorCode& status) const;
virtual int32_t hashCode(void) const;
- virtual const Locale getLocale(ULocDataLocaleType type,
- UErrorCode& status) const;
+ virtual Locale getLocale(ULocDataLocaleType type, UErrorCode& status) const;
virtual ECollationStrength getStrength(void) const;
virtual void setStrength(ECollationStrength newStrength);
virtual UClassID getDynamicClassID(void) const;
virtual void setAttribute(UColAttribute attr, UColAttributeValue value,
UErrorCode &status);
virtual UColAttributeValue getAttribute(UColAttribute attr,
- UErrorCode &status);
+ UErrorCode &status) const;
virtual uint32_t setVariableTop(const UChar *varTop, int32_t len,
UErrorCode &status);
- virtual uint32_t setVariableTop(const UnicodeString varTop,
+ virtual uint32_t setVariableTop(const UnicodeString &varTop,
UErrorCode &status);
- virtual void setVariableTop(const uint32_t varTop, UErrorCode &status);
+ virtual void setVariableTop(uint32_t varTop, UErrorCode &status);
virtual uint32_t getVariableTop(UErrorCode &status) const;
- virtual Collator* safeClone(void);
+ virtual Collator* safeClone(void) 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 UnicodeSet *getTailoredSet(UErrorCode &status) const;
- virtual UBool operator!=(const Collator& other) const;
+ virtual UBool operator==(const Collator& other) const;
+ // Collator::operator!= calls !Collator::operator== which works for all subclasses.
virtual void setLocales(const Locale& requestedLocale, const Locale& validLocale, const Locale& actualLocale);
TestCollator() : Collator() {};
TestCollator(UCollationStrength collationStrength,
UNormalizationMode decompositionMode) : Collator(collationStrength, decompositionMode) {};
};
-inline UBool TestCollator::operator!=(const Collator& other) const {
- return Collator::operator!=(other);
-}
+inline UBool TestCollator::operator==(const Collator& other) const {
+ // TestCollator has no fields, so we test for identity.
+ return this == &other;
-#define returnEComparisonResult(data) \
- if (data < 0) return Collator::LESS;\
- if (data > 0) return Collator::GREATER;\
- return Collator::EQUAL;
+ // Normally, subclasses should do something like the following:
+ // if (this == &other) { return TRUE; }
+ // if (!Collator::operator==(other)) { return FALSE; } // not the same class
+ //
+ // const TestCollator &o = (const TestCollator&)other;
+ // (compare this vs. o's subclass fields)
+}
Collator* TestCollator::clone() const
{
return 0;
}
-const Locale TestCollator::getLocale(ULocDataLocaleType type,
- UErrorCode& status) const
+Locale TestCollator::getLocale(ULocDataLocaleType type, UErrorCode& status) const
{
// api not used, this is to make the compiler happy
if (U_FAILURE(status)) {
}
UColAttributeValue TestCollator::getAttribute(UColAttribute attr,
- UErrorCode &status)
+ UErrorCode &status) const
{
// api not used, this is to make the compiler happy
if (U_FAILURE(status) || attr == UCOL_ATTRIBUTE_COUNT) {
return 0;
}
-uint32_t TestCollator::setVariableTop(const UnicodeString varTop,
+uint32_t TestCollator::setVariableTop(const UnicodeString &varTop,
UErrorCode &status)
{
// api not used, this is to make the compiler happy
return 0;
}
-void TestCollator::setVariableTop(const uint32_t varTop, UErrorCode &status)
+void TestCollator::setVariableTop(uint32_t varTop, UErrorCode &status)
{
// api not used, this is to make the compiler happy
if (U_SUCCESS(status) && varTop == 0) {
return (uint32_t)(0xFFFFFFFFu);
}
-Collator* TestCollator::safeClone(void)
+Collator* TestCollator::safeClone(void) const
{
return new TestCollator();
}
{
TestCollator col1;
TestCollator col2;
- doAssert(col1 != col2, "2 instance of TestCollator should be different");
+ doAssert(col1 != col2, "2 instances of TestCollator should be different");
if (col1.hashCode() != col2.hashCode()) {
errln("Every TestCollator has the same hashcode");
}