ICU-1229 in ucol_openRules: use UColAttributeValue instead of UNormalizationMode

X-SVN-Rev: 5891
This commit is contained in:
Markus Scherer 2001-09-22 01:10:41 +00:00
parent 8b7793a7ff
commit ea6f9c6c3c
2 changed files with 95 additions and 121 deletions

View file

@ -115,143 +115,80 @@ RuleBasedCollator::RuleBasedCollator(const UnicodeString& rules,
UErrorCode& status) :
dataIsOwned(FALSE)
{
if (U_FAILURE(status))
return;
int32_t length = rules.length();
UChar ucharrules[STACK_BUFFER_LENGTH_];
UChar *pucharrules = ucharrules;
if (length >= STACK_BUFFER_LENGTH_)
pucharrules = new UChar[length + 1];
rules.extract(0, length, pucharrules);
pucharrules[length] = 0;
ucollator = ucol_openRules(pucharrules, length, UCOL_DEFAULT_NORMALIZATION,
UCOL_DEFAULT_STRENGTH, NULL, &status);
if (U_SUCCESS(status))
{
const UChar *r = ucol_getRules(ucollator, &length);
if (length > 0) {
urulestring = new UnicodeString(r, length);
}
else {
urulestring = new UnicodeString();
}
dataIsOwned = TRUE;
}
if (pucharrules != ucharrules)
delete[] pucharrules;
construct(rules,
UCOL_DEFAULT_STRENGTH,
UCOL_DEFAULT,
status);
}
RuleBasedCollator::RuleBasedCollator(const UnicodeString& rules,
ECollationStrength collationStrength,
UErrorCode& status) : dataIsOwned(FALSE)
{
if (U_FAILURE(status))
return;
int32_t length = rules.length();
UChar ucharrules[STACK_BUFFER_LENGTH_];
UChar *pucharrules = ucharrules;
if (length >= STACK_BUFFER_LENGTH_)
pucharrules = new UChar[length + 1];
rules.extract(0, length, pucharrules);
pucharrules[length] = 0;
UCollationStrength strength = getUCollationStrength(collationStrength);
ucollator = ucol_openRules(pucharrules, length, UCOL_DEFAULT_NORMALIZATION,
strength, NULL,&status);
if (U_SUCCESS(status))
{
const UChar *r = ucol_getRules(ucollator, &length);
if (length > 0) {
urulestring = new UnicodeString(r, length);
}
else {
urulestring = new UnicodeString();
}
dataIsOwned = TRUE;
}
if (pucharrules != ucharrules)
delete[] pucharrules;
construct(rules,
getUCollationStrength(collationStrength),
UCOL_DEFAULT,
status);
}
// TODO this is a deprecated constructor, remove >2002-sep-30
RuleBasedCollator::RuleBasedCollator(const UnicodeString& rules,
Normalizer::EMode decompositionMode,
UErrorCode& status) :
dataIsOwned(FALSE)
{
if (U_FAILURE(status))
return;
int32_t length = rules.length();
UChar ucharrules[STACK_BUFFER_LENGTH_];
UChar *pucharrules = ucharrules;
if (length >= STACK_BUFFER_LENGTH_)
pucharrules = new UChar[length + 1];
rules.extract(0, length, pucharrules);
pucharrules[length] = 0;
UNormalizationMode mode = Normalizer::getUNormalizationMode(
decompositionMode, status);
ucollator = ucol_openRules(pucharrules, length, mode,
UCOL_DEFAULT_STRENGTH, NULL, &status);
if (U_SUCCESS(status))
{
const UChar *r = ucol_getRules(ucollator, &length);
if (length > 0) {
urulestring = new UnicodeString(r, length);
}
else {
urulestring = new UnicodeString();
}
dataIsOwned = TRUE;
}
if (pucharrules != ucharrules)
delete[] pucharrules;
construct(rules,
UCOL_DEFAULT_STRENGTH,
(UColAttributeValue)Normalizer::getUNormalizationMode(decompositionMode, status),
status);
}
RuleBasedCollator::RuleBasedCollator(const UnicodeString& rules,
UColAttributeValue decompositionMode,
UErrorCode& status) :
dataIsOwned(FALSE)
{
construct(rules,
UCOL_DEFAULT_STRENGTH,
decompositionMode,
status);
}
// TODO this is a deprecated constructor, remove >2002-sep-30
RuleBasedCollator::RuleBasedCollator(const UnicodeString& rules,
ECollationStrength collationStrength,
Normalizer::EMode decompositionMode,
UErrorCode& status) : dataIsOwned(FALSE)
{
if (U_FAILURE(status))
return;
construct(rules,
getUCollationStrength(collationStrength),
(UColAttributeValue)Normalizer::getUNormalizationMode(decompositionMode, status),
status);
}
int32_t length = rules.length();
RuleBasedCollator::RuleBasedCollator(const UnicodeString& rules,
ECollationStrength collationStrength,
UColAttributeValue decompositionMode,
UErrorCode& status) : dataIsOwned(FALSE)
{
construct(rules,
getUCollationStrength(collationStrength),
decompositionMode,
status);
}
UChar ucharrules[STACK_BUFFER_LENGTH_];
UChar *pucharrules = ucharrules;
if (length >= STACK_BUFFER_LENGTH_)
pucharrules = new UChar[length + 1];
rules.extract(0, length, pucharrules);
pucharrules[length] = 0;
UCollationStrength strength = getUCollationStrength(collationStrength);
UNormalizationMode mode = Normalizer::getUNormalizationMode(
decompositionMode, status);
ucollator = ucol_openRules(pucharrules, length, mode, strength,NULL, &status);
void
RuleBasedCollator::construct(const UnicodeString& rules,
UColAttributeValue collationStrength,
UColAttributeValue decompositionMode,
UErrorCode& status)
{
ucollator = ucol_openRules(rules.getBuffer(), rules.length(),
decompositionMode, collationStrength,
NULL, &status);
if (U_SUCCESS(status))
{
int32_t length;
const UChar *r = ucol_getRules(ucollator, &length);
if (length > 0) {
urulestring = new UnicodeString(r, length);
@ -261,13 +198,8 @@ RuleBasedCollator::RuleBasedCollator(const UnicodeString& rules,
}
dataIsOwned = TRUE;
}
if (pucharrules != ucharrules)
delete[] pucharrules;
}
/* RuleBasedCollator public destructor ----------------------------------- */
RuleBasedCollator::~RuleBasedCollator()
@ -277,7 +209,8 @@ RuleBasedCollator::~RuleBasedCollator()
ucol_close(ucollator);
delete urulestring;
}
ucollator = NULL;
ucollator = 0;
urulestring = 0;
}
/* RuleBaseCollator public methods --------------------------------------- */

View file

@ -391,7 +391,7 @@ public:
* @see Locale
*/
RuleBasedCollator(const UnicodeString& rules,
Normalizer::EMode decompositionMode,
UColAttributeValue decompositionMode,
UErrorCode& status);
/**
@ -406,7 +406,7 @@ public:
*/
RuleBasedCollator(const UnicodeString& rules,
ECollationStrength collationStrength,
Normalizer::EMode decompositionMode,
UColAttributeValue decompositionMode,
UErrorCode& status);
/**
@ -763,11 +763,44 @@ public:
*/
virtual void setStrength(ECollationStrength newStrength);
// deprecated functions ---------------------------------------------------
/**
* RuleBasedCollator constructor. This takes the table rules and builds a
* collation table out of them. Please see RuleBasedCollator class
* description for more details on the collation rule syntax.
* @param rules the collation rules to build the collation table from.
* @param decompositionMode the normalisation mode
* @param status reporting a success or an error.
* @see Locale
* @deprecated To be removed after 2002-sep-30, specify the decomposition mode with a UColAttributeValue.
*/
RuleBasedCollator(const UnicodeString& rules,
Normalizer::EMode decompositionMode,
UErrorCode& status);
/**
* RuleBasedCollator constructor. This takes the table rules and builds a
* collation table out of them. Please see RuleBasedCollator class
* description for more details on the collation rule syntax.
* @param rules the collation rules to build the collation table from.
* @param collationStrength default strength for comparison
* @param decompositionMode the normalisation mode
* @param status reporting a success or an error.
* @see Locale
* @deprecated To be removed after 2002-sep-30, specify the decomposition mode with a UColAttributeValue.
*/
RuleBasedCollator(const UnicodeString& rules,
ECollationStrength collationStrength,
Normalizer::EMode decompositionMode,
UErrorCode& status);
/**
* Set the decomposition mode of the Collator object. success is equal to
* U_ILLEGAL_ARGUMENT_ERROR if error occurs.
* @param the new decomposition mode
* @see Collator#getDecomposition
* @deprecated To be removed after 2002-sep-30; use setAttribute().
*/
virtual void setDecomposition(Normalizer::EMode mode);
@ -775,6 +808,7 @@ public:
* Get the decomposition mode of the Collator object.
* @return the decomposition mode
* @see Collator#setDecomposition
* @deprecated To be removed after 2002-sep-30; use getAttribute().
*/
virtual Normalizer::EMode getDecomposition(void) const;
@ -879,6 +913,13 @@ private:
*/
RuleBasedCollator(const Locale& desiredLocale, UErrorCode& status);
/** common constructor implementation */
void
construct(const UnicodeString& rules,
UColAttributeValue collationStrength,
UColAttributeValue decompositionMode,
UErrorCode& status);
// private methods -------------------------------------------------------
/**