// © 2016 and later: Unicode, Inc. and others. // License & terms of use: http://www.unicode.org/copyright.html /* ******************************************************************************* * * Copyright (C) 2003-2014, International Business Machines * Corporation and others. All Rights Reserved. * ******************************************************************************* * file name: nptrans.h * encoding: UTF-8 * tab size: 8 (not used) * indentation:4 * * created on: 2003feb1 * created by: Ram Viswanadha */ #include "unicode/utypes.h" #if !UCONFIG_NO_TRANSLITERATION #if !UCONFIG_NO_IDNA #include "nptrans.h" #include "unicode/resbund.h" #include "unicode/uniset.h" #include "sprpimpl.h" #include "cmemory.h" #include "ustr_imp.h" #include "intltest.h" #ifdef NPTRANS_DEBUG #include #endif const char NamePrepTransform::fgClassID=0; //Factory method NamePrepTransform* NamePrepTransform::createInstance(UParseError& parseError, UErrorCode& status){ NamePrepTransform* transform = new NamePrepTransform(parseError, status); if(U_FAILURE(status)){ delete transform; return NULL; } return transform; } //constructor NamePrepTransform::NamePrepTransform(UParseError& parseError, UErrorCode& status) : unassigned(), prohibited(), labelSeparatorSet(){ mapping = NULL; bundle = NULL; const char* testDataName = IntlTest::loadTestData(status); if(U_FAILURE(status)){ return; } bundle = ures_openDirect(testDataName,"idna_rules",&status); if(bundle != NULL && U_SUCCESS(status)){ // create the mapping transliterator int32_t ruleLen = 0; const UChar* ruleUChar = ures_getStringByKey(bundle, "MapNFKC",&ruleLen, &status); int32_t mapRuleLen = 0; const UChar *mapRuleUChar = ures_getStringByKey(bundle, "MapNoNormalization", &mapRuleLen, &status); UnicodeString rule(mapRuleUChar, mapRuleLen); rule.append(ruleUChar, ruleLen); mapping = Transliterator::createFromRules(UnicodeString("NamePrepTransform", ""), rule, UTRANS_FORWARD, parseError,status); if(U_FAILURE(status)) { return; } //create the unassigned set int32_t patternLen =0; const UChar* pattern = ures_getStringByKey(bundle,"UnassignedSet",&patternLen, &status); unassigned.applyPattern(UnicodeString(pattern, patternLen), status); //create prohibited set patternLen=0; pattern = ures_getStringByKey(bundle,"ProhibitedSet",&patternLen, &status); UnicodeString test(pattern,patternLen); prohibited.applyPattern(test,status); #ifdef NPTRANS_DEBUG if(U_FAILURE(status)){ printf("Construction of Unicode set failed\n"); } if(U_SUCCESS(status)){ if(prohibited.contains((UChar) 0x644)){ printf("The string contains 0x644 ... !!\n"); } UnicodeString temp; prohibited.toPattern(temp,TRUE); for(int32_t i=0;itransliterate(rsource); const UChar* buffer = rsource.getBuffer(); int32_t bufLen = rsource.length(); // check if unassigned if(allowUnassigned == FALSE){ int32_t bufIndex=0; UChar32 ch =0 ; for(;bufIndex