ICU-11032 Incorporate review comments, use isAcceptable call-back with udata_open
X-SVN-Rev: 36466
This commit is contained in:
parent
02f78e8bbb
commit
84d1d936ab
@ -329,7 +329,7 @@ uspoof_open(UErrorCode *status);
|
||||
|
||||
|
||||
/**
|
||||
* Open a Spoof checker from its serialized from, stored in 32-bit-aligned memory.
|
||||
* Open a Spoof checker from its serialized form, stored in 32-bit-aligned memory.
|
||||
* Inverse of uspoof_serialize().
|
||||
* The memory containing the serialized data must remain valid and unchanged
|
||||
* as long as the spoof checker, or any cloned copies of the spoof checker,
|
||||
@ -355,9 +355,9 @@ uspoof_openFromSerialized(const void *data, int32_t length, int32_t *pActualLeng
|
||||
|
||||
/**
|
||||
* Open a Spoof Checker from the source form of the spoof data.
|
||||
* The Three inputs correspond to the Unicode data files confusables.txt
|
||||
* confusablesWholeScript.txt and xidmdifications.txt as described in
|
||||
* Unicode UAX #39. The syntax of the source data is as described in UAX #39 for
|
||||
* The two inputs correspond to the Unicode data files confusables.txt
|
||||
* and confusablesWholeScript.txt as described in Unicode UAX #39.
|
||||
* The syntax of the source data is as described in UAX #39 for
|
||||
* these files, and the content of these files is acceptable input.
|
||||
*
|
||||
* The character encoding of the (char *) input text is UTF-8.
|
||||
|
@ -475,6 +475,30 @@ UBool SpoofData::validateDataVersion(const SpoofDataHeader *rawData, UErrorCode
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static UBool U_CALLCONV
|
||||
spoofDataIsAcceptable(void *context,
|
||||
const char * /* type */, const char * /*name*/,
|
||||
const UDataInfo *pInfo) {
|
||||
if(
|
||||
pInfo->size >= 20 &&
|
||||
pInfo->isBigEndian == U_IS_BIG_ENDIAN &&
|
||||
pInfo->charsetFamily == U_CHARSET_FAMILY &&
|
||||
pInfo->dataFormat[0] == 0x43 && // dataFormat="Cfu "
|
||||
pInfo->dataFormat[1] == 0x66 &&
|
||||
pInfo->dataFormat[2] == 0x75 &&
|
||||
pInfo->dataFormat[3] == 0x20 &&
|
||||
pInfo->formatVersion[0] == 1
|
||||
) {
|
||||
UVersionInfo *version = static_cast<UVersionInfo *>(context);
|
||||
if(version != NULL) {
|
||||
uprv_memcpy(version, pInfo->dataVersion, 4);
|
||||
}
|
||||
return TRUE;
|
||||
} else {
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// SpoofData::getDefault() - return a wrapper around the spoof data that is
|
||||
// baked into the default ICU data.
|
||||
@ -482,7 +506,10 @@ UBool SpoofData::validateDataVersion(const SpoofDataHeader *rawData, UErrorCode
|
||||
SpoofData *SpoofData::getDefault(UErrorCode &status) {
|
||||
// TODO: Cache it. Lazy create, keep until cleanup.
|
||||
|
||||
UDataMemory *udm = udata_open(NULL, "cfu", "confusables", &status);
|
||||
UDataMemory *udm = udata_openChoice(NULL, "cfu", "confusables",
|
||||
spoofDataIsAcceptable,
|
||||
NULL, // context, would receive dataVersion if supplied.
|
||||
&status);
|
||||
if (U_FAILURE(status)) {
|
||||
return NULL;
|
||||
}
|
||||
@ -497,30 +524,17 @@ SpoofData *SpoofData::getDefault(UErrorCode &status) {
|
||||
return This;
|
||||
}
|
||||
|
||||
|
||||
SpoofData::SpoofData(UDataMemory *udm, UErrorCode &status)
|
||||
{
|
||||
reset();
|
||||
if (U_FAILURE(status)) {
|
||||
return;
|
||||
}
|
||||
fUDM = udm;
|
||||
const DataHeader *dh = udm->pHeader;
|
||||
int32_t headerSize = dh->dataHeader.headerSize;
|
||||
if ( !(headerSize >= 20 &&
|
||||
dh->info.isBigEndian == U_IS_BIG_ENDIAN &&
|
||||
dh->info.charsetFamily == U_CHARSET_FAMILY &&
|
||||
dh->info.dataFormat[0] == 0x43 && // dataFormat="Cfu "
|
||||
dh->info.dataFormat[1] == 0x66 &&
|
||||
dh->info.dataFormat[2] == 0x75 &&
|
||||
dh->info.dataFormat[3] == 0x20)
|
||||
) {
|
||||
status = U_INVALID_FORMAT_ERROR;
|
||||
return;
|
||||
}
|
||||
|
||||
fRawData = reinterpret_cast<SpoofDataHeader *>
|
||||
((char *)(udm->pHeader) + headerSize);
|
||||
fUDM = udm;
|
||||
((char *)dh + headerSize);
|
||||
validateDataVersion(fRawData, status);
|
||||
initPtrs(status);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user