Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(362)

Side by Side Diff: source/i18n/uspoof_impl.cpp

Issue 845603002: Update ICU to 54.1 step 1 (Closed) Base URL: https://chromium.googlesource.com/chromium/deps/icu.git@master
Patch Set: remove unusued directories Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « source/i18n/uspoof.cpp ('k') | source/i18n/usrchimp.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 ********************************************************************** 2 **********************************************************************
3 * Copyright (C) 2008-2013, International Business Machines 3 * Copyright (C) 2008-2014, International Business Machines
4 * Corporation and others. All Rights Reserved. 4 * Corporation and others. All Rights Reserved.
5 ********************************************************************** 5 **********************************************************************
6 */ 6 */
7 7
8 #include "unicode/utypes.h" 8 #include "unicode/utypes.h"
9 #include "unicode/uspoof.h" 9 #include "unicode/uspoof.h"
10 #include "unicode/uchar.h" 10 #include "unicode/uchar.h"
11 #include "unicode/uniset.h" 11 #include "unicode/uniset.h"
12 #include "unicode/utf16.h" 12 #include "unicode/utf16.h"
13 #include "utrie2.h" 13 #include "utrie2.h"
14 #include "cmemory.h" 14 #include "cmemory.h"
15 #include "cstring.h" 15 #include "cstring.h"
16 #include "identifier_info.h" 16 #include "identifier_info.h"
17 #include "scriptset.h" 17 #include "scriptset.h"
18 #include "udatamem.h"
19 #include "umutex.h" 18 #include "umutex.h"
20 #include "udataswp.h" 19 #include "udataswp.h"
21 #include "uassert.h" 20 #include "uassert.h"
22 #include "uspoof_impl.h" 21 #include "uspoof_impl.h"
23 22
24 #if !UCONFIG_NO_NORMALIZATION 23 #if !UCONFIG_NO_NORMALIZATION
25 24
26 25
27 U_NAMESPACE_BEGIN 26 U_NAMESPACE_BEGIN
28 27
(...skipping 439 matching lines...) Expand 10 before | Expand all | Expand 10 after
468 rawData == NULL || 467 rawData == NULL ||
469 rawData->fMagic != USPOOF_MAGIC || 468 rawData->fMagic != USPOOF_MAGIC ||
470 rawData->fFormatVersion[0] > 1 || 469 rawData->fFormatVersion[0] > 1 ||
471 rawData->fFormatVersion[1] > 0) { 470 rawData->fFormatVersion[1] > 0) {
472 status = U_INVALID_FORMAT_ERROR; 471 status = U_INVALID_FORMAT_ERROR;
473 return FALSE; 472 return FALSE;
474 } 473 }
475 return TRUE; 474 return TRUE;
476 } 475 }
477 476
477 static UBool U_CALLCONV
478 spoofDataIsAcceptable(void *context,
479 const char * /* type */, const char * /*name*/,
480 const UDataInfo *pInfo) {
481 if(
482 pInfo->size >= 20 &&
483 pInfo->isBigEndian == U_IS_BIG_ENDIAN &&
484 pInfo->charsetFamily == U_CHARSET_FAMILY &&
485 pInfo->dataFormat[0] == 0x43 && // dataFormat="Cfu "
486 pInfo->dataFormat[1] == 0x66 &&
487 pInfo->dataFormat[2] == 0x75 &&
488 pInfo->dataFormat[3] == 0x20 &&
489 pInfo->formatVersion[0] == 1
490 ) {
491 UVersionInfo *version = static_cast<UVersionInfo *>(context);
492 if(version != NULL) {
493 uprv_memcpy(version, pInfo->dataVersion, 4);
494 }
495 return TRUE;
496 } else {
497 return FALSE;
498 }
499 }
500
478 // 501 //
479 // SpoofData::getDefault() - return a wrapper around the spoof data that is 502 // SpoofData::getDefault() - return a wrapper around the spoof data that is
480 // baked into the default ICU data. 503 // baked into the default ICU data.
481 // 504 //
482 SpoofData *SpoofData::getDefault(UErrorCode &status) { 505 SpoofData *SpoofData::getDefault(UErrorCode &status) {
483 // TODO: Cache it. Lazy create, keep until cleanup. 506 // TODO: Cache it. Lazy create, keep until cleanup.
484 507
485 UDataMemory *udm = udata_open(NULL, "cfu", "confusables", &status); 508 UDataMemory *udm = udata_openChoice(NULL, "cfu", "confusables",
509 spoofDataIsAcceptable,
510 NULL, // context, would receive da taVersion if supplied.
511 &status);
486 if (U_FAILURE(status)) { 512 if (U_FAILURE(status)) {
487 return NULL; 513 return NULL;
488 } 514 }
489 SpoofData *This = new SpoofData(udm, status); 515 SpoofData *This = new SpoofData(udm, status);
490 if (U_FAILURE(status)) { 516 if (U_FAILURE(status)) {
491 delete This; 517 delete This;
492 return NULL; 518 return NULL;
493 } 519 }
494 if (This == NULL) { 520 if (This == NULL) {
495 status = U_MEMORY_ALLOCATION_ERROR; 521 status = U_MEMORY_ALLOCATION_ERROR;
496 } 522 }
497 return This; 523 return This;
498 } 524 }
499 525
500
501 SpoofData::SpoofData(UDataMemory *udm, UErrorCode &status) 526 SpoofData::SpoofData(UDataMemory *udm, UErrorCode &status)
502 { 527 {
503 reset(); 528 reset();
504 if (U_FAILURE(status)) { 529 if (U_FAILURE(status)) {
505 return; 530 return;
506 } 531 }
507 fRawData = reinterpret_cast<SpoofDataHeader *>
508 ((char *)(udm->pHeader) + udm->pHeader->dataHeader.headerSize );
509 fUDM = udm; 532 fUDM = udm;
533 // fRawData is non-const because it may be constructed by the data builder.
534 fRawData = reinterpret_cast<SpoofDataHeader *>(
535 const_cast<void *>(udata_getMemory(udm)));
510 validateDataVersion(fRawData, status); 536 validateDataVersion(fRawData, status);
511 initPtrs(status); 537 initPtrs(status);
512 } 538 }
513 539
514 540
515 SpoofData::SpoofData(const void *data, int32_t length, UErrorCode &status) 541 SpoofData::SpoofData(const void *data, int32_t length, UErrorCode &status)
516 { 542 {
517 reset(); 543 reset();
518 if (U_FAILURE(status)) { 544 if (U_FAILURE(status)) {
519 return; 545 return;
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after
836 } 862 }
837 // swap starting at fLength 863 // swap starting at fLength
838 ds->swapArray32(ds, &spoofDH->fLength, sizeof(SpoofDataHeader)-8 /* minus ma gic and fFormatVersion[4] */, &outputDH->fLength, status); 864 ds->swapArray32(ds, &spoofDH->fLength, sizeof(SpoofDataHeader)-8 /* minus ma gic and fFormatVersion[4] */, &outputDH->fLength, status);
839 865
840 return totalSize; 866 return totalSize;
841 } 867 }
842 868
843 #endif 869 #endif
844 870
845 871
OLDNEW
« no previous file with comments | « source/i18n/uspoof.cpp ('k') | source/i18n/usrchimp.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698