ICU-10282 deprecate bad API RuleBasedCollator::cloneRuleData(), call cloneBinary()

X-SVN-Rev: 34314
This commit is contained in:
Markus Scherer 2013-09-13 19:25:01 +00:00
parent bac694742e
commit b20a9793f9
5 changed files with 27 additions and 83 deletions

View file

@ -1,6 +1,6 @@
/*
******************************************************************************
* Copyright (C) 1996-2012, International Business Machines Corporation and
* Copyright (C) 1996-2013, International Business Machines Corporation and
* others. All Rights Reserved.
******************************************************************************
*/
@ -456,7 +456,23 @@ int32_t RuleBasedCollator::getMaxExpansion(int32_t order) const
uint8_t* RuleBasedCollator::cloneRuleData(int32_t &length,
UErrorCode &status)
{
return ucol_cloneRuleData(ucollator, &length, &status);
if (U_FAILURE(status)) { return NULL; }
LocalMemory<uint8_t> buffer((uint8_t *)uprv_malloc(20000));
if (buffer.isNull()) {
status = U_MEMORY_ALLOCATION_ERROR;
return NULL;
}
length = cloneBinary(buffer.getAlias(), 20000, status);
if (status == U_BUFFER_OVERFLOW_ERROR) {
if (buffer.allocateInsteadAndCopy(length, 0) == NULL) {
status = U_MEMORY_ALLOCATION_ERROR;
return NULL;
}
status = U_ZERO_ERROR;
length = cloneBinary(buffer.getAlias(), length, status);
}
if (U_FAILURE(status)) { return NULL; }
return buffer.orphan();
}

View file

@ -764,68 +764,6 @@ ucol_close(UCollator *coll)
UTRACE_EXIT();
}
/* This one is currently used by genrb & tests. After constructing from rules (tailoring),*/
/* you should be able to get the binary chunk to write out... Doesn't look very full now */
U_CFUNC uint8_t* U_EXPORT2
ucol_cloneRuleData(const UCollator *coll, int32_t *length, UErrorCode *status)
{
uint8_t *result = NULL;
if(U_FAILURE(*status)) {
return NULL;
}
if(coll->hasRealData == TRUE) {
*length = coll->image->size;
result = (uint8_t *)uprv_malloc(*length);
/* test for NULL */
if (result == NULL) {
*status = U_MEMORY_ALLOCATION_ERROR;
return NULL;
}
uprv_memcpy(result, coll->image, *length);
} else {
*length = (int32_t)(paddedsize(sizeof(UCATableHeader))+paddedsize(sizeof(UColOptionSet)));
result = (uint8_t *)uprv_malloc(*length);
/* test for NULL */
if (result == NULL) {
*status = U_MEMORY_ALLOCATION_ERROR;
return NULL;
}
/* build the UCATableHeader with minimal entries */
/* do not copy the header from the UCA file because its values are wrong! */
/* uprv_memcpy(result, UCA->image, sizeof(UCATableHeader)); */
/* reset everything */
uprv_memset(result, 0, *length);
/* set the tailoring-specific values */
UCATableHeader *myData = (UCATableHeader *)result;
myData->size = *length;
/* offset for the options, the only part of the data that is present after the header */
myData->options = sizeof(UCATableHeader);
/* need to always set the expansion value for an upper bound of the options */
myData->expansion = myData->options + sizeof(UColOptionSet);
myData->magic = UCOL_HEADER_MAGIC;
myData->isBigEndian = U_IS_BIG_ENDIAN;
myData->charSetFamily = U_CHARSET_FAMILY;
/* copy UCA's version; genrb will override all but the builder version with tailoring data */
uprv_memcpy(myData->version, coll->image->version, sizeof(UVersionInfo));
uprv_memcpy(myData->UCAVersion, coll->image->UCAVersion, sizeof(UVersionInfo));
uprv_memcpy(myData->UCDVersion, coll->image->UCDVersion, sizeof(UVersionInfo));
uprv_memcpy(myData->formatVersion, coll->image->formatVersion, sizeof(UVersionInfo));
myData->jamoSpecial = coll->image->jamoSpecial;
/* copy the collator options */
uprv_memcpy(result+paddedsize(sizeof(UCATableHeader)), coll->options, sizeof(UColOptionSet));
}
return result;
}
void ucol_setOptionsFromHeader(UCollator* result, UColOptionSet * opts, UErrorCode *status) {
if(U_FAILURE(*status)) {
return;

View file

@ -1,7 +1,7 @@
/*
*******************************************************************************
*
* Copyright (C) 1998-2012, International Business Machines
* Copyright (C) 1998-2013, International Business Machines
* Corporation and others. All Rights Reserved.
*
*******************************************************************************
@ -578,18 +578,6 @@ SortKeyGenerator(const UCollator *coll,
#endif
/**
* Makes a copy of the Collator's rule data. The format is
* that of .col files.
*
* @param length returns the length of the data, in bytes.
* @param status the error status
* @return memory, owned by the caller, of size 'length' bytes.
* @internal INTERNAL USE ONLY
*/
U_CFUNC uint8_t* U_EXPORT2
ucol_cloneRuleData(const UCollator *coll, int32_t *length, UErrorCode *status);
/**
* Used to set requested and valid locales on a collator returned by the collator
* service.

View file

@ -439,16 +439,19 @@ public:
*/
static UClassID U_EXPORT2 getStaticClassID(void);
#ifndef U_HIDE_DEPRECATED_API
/**
* Returns the binary format of the class's rules. The format is that of
* .col files.
* Do not use this method: The caller and the ICU library might use different heaps.
* Use cloneBinary() instead which writes to caller-provided memory.
*
* Returns a binary format of this collator.
* @param length Returns the length of the data, in bytes
* @param status the error code status.
* @return memory, owned by the caller, of size 'length' bytes.
* @stable ICU 2.2
* @deprecated ICU 52. Use cloneBinary() instead.
*/
uint8_t *cloneRuleData(int32_t &length, UErrorCode &status);
#endif /* U_HIDE_DEPRECATED_API */
/** Creates a binary image of a collator. This binary image can be stored and
* later used to instantiate a collator using ucol_openBinary.

View file

@ -1,7 +1,7 @@
/*
*******************************************************************************
*
* Copyright (C) 1998-2012, International Business Machines
* Copyright (C) 1998-2013, International Business Machines
* Corporation and others. All Rights Reserved.
*
*******************************************************************************
@ -937,7 +937,6 @@ addCollation(ParseState* state, struct SResource *result, uint32_t startline, U
data = (uint8_t *)uprv_malloc(len);
intStatus = U_ZERO_ERROR;
len = ucol_cloneBinary(coll, data, len, &intStatus);
/*data = ucol_cloneRuleData(coll, &len, &intStatus);*/
/* tailoring rules version */
/* This is wrong! */