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

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

Issue 1621843002: ICU 56 update step 1 (Closed) Base URL: https://chromium.googlesource.com/chromium/deps/icu.git@561
Patch Set: Created 4 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_conf.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-2014, International Business Machines 3 * Copyright (C) 2008-2015, 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 "umutex.h" 18 #include "umutex.h"
19 #include "udataswp.h" 19 #include "udataswp.h"
20 #include "uassert.h" 20 #include "uassert.h"
21 #include "uspoof_impl.h" 21 #include "uspoof_impl.h"
22 22
23 #if !UCONFIG_NO_NORMALIZATION 23 #if !UCONFIG_NO_NORMALIZATION
24 24
25 25
26 U_NAMESPACE_BEGIN 26 U_NAMESPACE_BEGIN
27 27
28 UOBJECT_DEFINE_RTTI_IMPLEMENTATION(SpoofImpl) 28 UOBJECT_DEFINE_RTTI_IMPLEMENTATION(SpoofImpl)
29 29
30 SpoofImpl::SpoofImpl(SpoofData *data, UErrorCode &status) : 30 SpoofImpl::SpoofImpl(SpoofData *data, UErrorCode &status) :
31 fMagic(0), fChecks(USPOOF_ALL_CHECKS), fSpoofData(NULL), fAllowedCharsSe t(NULL) , 31 fMagic(0), fChecks(USPOOF_ALL_CHECKS), fSpoofData(data), fAllowedCharsSe t(NULL) ,
32 fAllowedLocales(NULL), fCachedIdentifierInfo(NULL) { 32 fAllowedLocales(NULL), fCachedIdentifierInfo(NULL) {
33 if (U_FAILURE(status)) { 33 if (U_FAILURE(status)) {
34 return; 34 return;
35 } 35 }
36 fSpoofData = data;
37 fRestrictionLevel = USPOOF_HIGHLY_RESTRICTIVE; 36 fRestrictionLevel = USPOOF_HIGHLY_RESTRICTIVE;
38 37
39 UnicodeSet *allowedCharsSet = new UnicodeSet(0, 0x10ffff); 38 UnicodeSet *allowedCharsSet = new UnicodeSet(0, 0x10ffff);
40 allowedCharsSet->freeze(); 39 allowedCharsSet->freeze();
41 fAllowedCharsSet = allowedCharsSet; 40 fAllowedCharsSet = allowedCharsSet;
42 fAllowedLocales = uprv_strdup(""); 41 fAllowedLocales = uprv_strdup("");
43 if (fAllowedCharsSet == NULL || fAllowedLocales == NULL) { 42 if (fAllowedCharsSet == NULL || fAllowedLocales == NULL) {
44 status = U_MEMORY_ALLOCATION_ERROR; 43 status = U_MEMORY_ALLOCATION_ERROR;
45 return; 44 return;
46 } 45 }
(...skipping 446 matching lines...) Expand 10 before | Expand all | Expand 10 after
493 uprv_memcpy(version, pInfo->dataVersion, 4); 492 uprv_memcpy(version, pInfo->dataVersion, 4);
494 } 493 }
495 return TRUE; 494 return TRUE;
496 } else { 495 } else {
497 return FALSE; 496 return FALSE;
498 } 497 }
499 } 498 }
500 499
501 // 500 //
502 // SpoofData::getDefault() - return a wrapper around the spoof data that is 501 // SpoofData::getDefault() - return a wrapper around the spoof data that is
503 // baked into the default ICU data. 502 // baked into the default ICU data.
503 //
504 // Called once, from the initOnce() function in uspoof_impl.cpp; t he resulting
505 // SpoofData is shared by all spoof checkers using the default dat a.
504 // 506 //
505 SpoofData *SpoofData::getDefault(UErrorCode &status) { 507 SpoofData *SpoofData::getDefault(UErrorCode &status) {
506 // TODO: Cache it. Lazy create, keep until cleanup.
507
508 UDataMemory *udm = udata_openChoice(NULL, "cfu", "confusables", 508 UDataMemory *udm = udata_openChoice(NULL, "cfu", "confusables",
509 spoofDataIsAcceptable, 509 spoofDataIsAcceptable,
510 NULL, // context, would receive da taVersion if supplied. 510 NULL, // context, would receive da taVersion if supplied.
511 &status); 511 &status);
512 if (U_FAILURE(status)) { 512 if (U_FAILURE(status)) {
513 return NULL; 513 return NULL;
514 } 514 }
515 SpoofData *This = new SpoofData(udm, status); 515 SpoofData *This = new SpoofData(udm, status);
516 if (U_FAILURE(status)) { 516 if (U_FAILURE(status)) {
517 delete This; 517 delete This;
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
560 560
561 561
562 // Spoof Data constructor for use from data builder. 562 // Spoof Data constructor for use from data builder.
563 // Initializes a new, empty data area that will be populated later. 563 // Initializes a new, empty data area that will be populated later.
564 SpoofData::SpoofData(UErrorCode &status) { 564 SpoofData::SpoofData(UErrorCode &status) {
565 reset(); 565 reset();
566 if (U_FAILURE(status)) { 566 if (U_FAILURE(status)) {
567 return; 567 return;
568 } 568 }
569 fDataOwned = true; 569 fDataOwned = true;
570 fRefCount = 1;
571 570
572 // The spoof header should already be sized to be a multiple of 16 bytes. 571 // The spoof header should already be sized to be a multiple of 16 bytes.
573 // Just in case it's not, round it up. 572 // Just in case it's not, round it up.
574 uint32_t initialSize = (sizeof(SpoofDataHeader) + 15) & ~15; 573 uint32_t initialSize = (sizeof(SpoofDataHeader) + 15) & ~15;
575 U_ASSERT(initialSize == sizeof(SpoofDataHeader)); 574 U_ASSERT(initialSize == sizeof(SpoofDataHeader));
576 575
577 fRawData = static_cast<SpoofDataHeader *>(uprv_malloc(initialSize)); 576 fRawData = static_cast<SpoofDataHeader *>(uprv_malloc(initialSize));
578 fMemLimit = initialSize; 577 fMemLimit = initialSize;
579 if (fRawData == NULL) { 578 if (fRawData == NULL) {
580 status = U_MEMORY_ALLOCATION_ERROR; 579 status = U_MEMORY_ALLOCATION_ERROR;
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after
862 } 861 }
863 // swap starting at fLength 862 // swap starting at fLength
864 ds->swapArray32(ds, &spoofDH->fLength, sizeof(SpoofDataHeader)-8 /* minus ma gic and fFormatVersion[4] */, &outputDH->fLength, status); 863 ds->swapArray32(ds, &spoofDH->fLength, sizeof(SpoofDataHeader)-8 /* minus ma gic and fFormatVersion[4] */, &outputDH->fLength, status);
865 864
866 return totalSize; 865 return totalSize;
867 } 866 }
868 867
869 #endif 868 #endif
870 869
871 870
OLDNEW
« no previous file with comments | « source/i18n/uspoof_conf.cpp ('k') | source/i18n/usrchimp.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698