/**
- * 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,
/**
* 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.
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.
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;
}
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);
}