ICU-9460 deprecate Collator::safeClone() and default-implement it in the base class

X-SVN-Rev: 32127
This commit is contained in:
Markus Scherer 2012-08-08 21:03:52 +00:00
parent eb0347f25f
commit ca65e1c41e
4 changed files with 33 additions and 57 deletions

View File

@ -425,6 +425,11 @@ Collator::createInstance(const Locale &loc,
}
#endif
Collator *
Collator::safeClone() const {
return clone();
}
// implement deprecated, previously abstract method
Collator::EComparisonResult Collator::compare(const UnicodeString& source,
const UnicodeString& target) const

View File

@ -206,32 +206,33 @@ UBool RuleBasedCollator::operator==(const Collator& that) const
// aliasing, not write-through
RuleBasedCollator& RuleBasedCollator::operator=(const RuleBasedCollator& that)
{
if (this != &that)
{
if (dataIsOwned)
{
ucol_close(ucollator);
}
if (this == &that) { return *this; }
urulestring.truncate(0); // empty the rule string
dataIsOwned = TRUE;
isWriteThroughAlias = FALSE;
UErrorCode intStatus = U_ZERO_ERROR;
int32_t buffersize = U_COL_SAFECLONE_BUFFERSIZE;
UCollator *ucol = ucol_safeClone(that.ucollator, NULL, &buffersize, &intStatus);
if (U_FAILURE(intStatus)) { return *this; }
UErrorCode intStatus = U_ZERO_ERROR;
int32_t buffersize = U_COL_SAFECLONE_BUFFERSIZE;
ucollator = ucol_safeClone(that.ucollator, NULL, &buffersize,
&intStatus);
if (U_SUCCESS(intStatus)) {
setRuleStringFromCollator();
}
if (dataIsOwned) {
ucol_close(ucollator);
}
ucollator = ucol;
dataIsOwned = TRUE;
isWriteThroughAlias = FALSE;
setRuleStringFromCollator();
return *this;
}
// aliasing, not write-through
Collator* RuleBasedCollator::clone() const
{
return new RuleBasedCollator(*this);
RuleBasedCollator* coll = new RuleBasedCollator(*this);
// There is a small chance that the internal ucol_safeClone() call fails.
if (coll != NULL && coll->ucollator == NULL) {
delete coll;
return NULL;
}
return coll;
}
@ -519,29 +520,6 @@ uint32_t RuleBasedCollator::getVariableTop(UErrorCode &status) const {
return ucol_getVariableTop(ucollator, &status);
}
Collator* RuleBasedCollator::safeClone(void) const
{
UErrorCode intStatus = U_ZERO_ERROR;
int32_t buffersize = U_COL_SAFECLONE_BUFFERSIZE;
UCollator *ucol = ucol_safeClone(ucollator, NULL, &buffersize,
&intStatus);
if (U_FAILURE(intStatus)) {
return NULL;
}
RuleBasedCollator *result = new RuleBasedCollator();
// Null pointer check
if (result != NULL) {
result->ucollator = ucol;
result->dataIsOwned = TRUE;
result->isWriteThroughAlias = FALSE;
result->setRuleStringFromCollator();
}
return result;
}
int32_t RuleBasedCollator::getSortKey(const UnicodeString& source,
uint8_t *result, int32_t resultLength)
const

View File

@ -270,8 +270,8 @@ public:
virtual UBool operator!=(const Collator& other) const;
/**
* Makes a shallow copy of the current object.
* @return a copy of this object
* Makes a copy of this object.
* @return a copy of this object, owned by the caller
* @stable ICU 2.0
*/
virtual Collator* clone(void) const = 0;
@ -933,13 +933,14 @@ public:
*/
virtual UnicodeSet *getTailoredSet(UErrorCode &status) const;
/**
* Thread safe cloning operation
* @return pointer to the new clone, user should remove it.
* @stable ICU 2.2
* Same as clone().
* The base class implementation simply calls clone().
* @return a copy of this object, owned by the caller
* @see clone()
* @deprecated ICU 50 no need to have two methods for cloning
*/
virtual Collator* safeClone(void) const = 0;
virtual Collator* safeClone(void) const;
/**
* Get the sort key as an array of bytes from an UnicodeString.

View File

@ -224,9 +224,8 @@ public:
virtual UBool operator==(const Collator& other) const;
/**
* Makes a deep copy of the object.
* The caller owns the returned object.
* @return the cloned object.
* Makes a copy of this object.
* @return a copy of this object, owned by the caller
* @stable ICU 2.0
*/
virtual Collator* clone(void) const;
@ -536,13 +535,6 @@ public:
*/
virtual UnicodeSet *getTailoredSet(UErrorCode &status) const;
/**
* Thread safe cloning operation.
* @return pointer to the new clone, user should remove it.
* @stable ICU 2.2
*/
virtual Collator* safeClone(void) const;
/**
* Get the sort key as an array of bytes from an UnicodeString.
* @param source string to be processed.