From: Andy Heninger Date: Thu, 11 Sep 2014 18:28:05 +0000 (+0000) Subject: ICU-11032 Incorporate review comments, use isAcceptable call-back with udata_open X-Git-Tag: milestone-59-0-1~1548 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=84d1d936abd7ecb1366214878163548a37eba8f4;p=icu ICU-11032 Incorporate review comments, use isAcceptable call-back with udata_open X-SVN-Rev: 36466 --- diff --git a/icu4c/source/i18n/unicode/uspoof.h b/icu4c/source/i18n/unicode/uspoof.h index c766f3fcabf..83dea3702a2 100644 --- a/icu4c/source/i18n/unicode/uspoof.h +++ b/icu4c/source/i18n/unicode/uspoof.h @@ -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. diff --git a/icu4c/source/i18n/uspoof_impl.cpp b/icu4c/source/i18n/uspoof_impl.cpp index b53af83c4de..ffb986cb624 100644 --- a/icu4c/source/i18n/uspoof_impl.cpp +++ b/icu4c/source/i18n/uspoof_impl.cpp @@ -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(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 - ((char *)(udm->pHeader) + headerSize); - fUDM = udm; + ((char *)dh + headerSize); validateDataVersion(fRawData, status); initPtrs(status); }