X-Git-Url: https://git.saurik.com/apple/icu.git/blobdiff_plain/374ca955a76ecab1204ca8bfa63ff9238d998416..a01113dcd0f39d5da295ef82785beff9ed86fe38:/icuSources/i18n/rbt_set.cpp diff --git a/icuSources/i18n/rbt_set.cpp b/icuSources/i18n/rbt_set.cpp index 0999cc21..d8d0384d 100644 --- a/icuSources/i18n/rbt_set.cpp +++ b/icuSources/i18n/rbt_set.cpp @@ -1,6 +1,8 @@ +// © 2016 and later: Unicode, Inc. and others. +// License & terms of use: http://www.unicode.org/copyright.html /* ********************************************************************** - * Copyright (C) 1999-2004, International Business Machines + * Copyright (C) 1999-2011, International Business Machines * Corporation and others. All Rights Reserved. ********************************************************************** * Date Name Description @@ -14,14 +16,15 @@ #include "unicode/unistr.h" #include "unicode/uniset.h" +#include "unicode/utf16.h" #include "rbt_set.h" #include "rbt_rule.h" #include "cmemory.h" #include "putilimp.h" U_CDECL_BEGIN -static void U_EXPORT2 U_CALLCONV _deleteRule(void *rule) { - delete (U_NAMESPACE_QUALIFIER TransliterationRule *)rule; +static void U_CALLCONV _deleteRule(void *rule) { + delete (icu::TransliterationRule *)rule; } U_CDECL_END @@ -90,7 +93,7 @@ UnicodeString& _escape(const UnicodeString &source, UnicodeString &target) { for (int32_t i = 0; i < source.length(); ) { UChar32 ch = source.char32At(i); - i += UTF_CHAR_LENGTH(ch); + i += U16_LENGTH(ch); if (ch < 0x09 || (ch > 0x0A && ch < 0x20)|| ch > 0x7E) { if (ch <= 0xFFFF) { target += "\\u"; @@ -120,7 +123,7 @@ inline void _debugOut(const char* msg, TransliterationRule* rule, UnicodeString esc; _escape(buf, esc); CharString cbuf(esc); - printf("%s\n", (char*) cbuf); + printf("%s\n", (const char*) cbuf); } #else @@ -133,10 +136,10 @@ inline void _debugOut(const char* msg, TransliterationRule* rule, // Fill the precontext and postcontext with the patterns of the rules // that are masking one another. -static void maskingError(const U_NAMESPACE_QUALIFIER TransliterationRule& rule1, - const U_NAMESPACE_QUALIFIER TransliterationRule& rule2, +static void maskingError(const icu::TransliterationRule& rule1, + const icu::TransliterationRule& rule2, UParseError& parseError) { - U_NAMESPACE_QUALIFIER UnicodeString r; + icu::UnicodeString r; int32_t len; parseError.line = parseError.offset = -1; @@ -162,11 +165,14 @@ U_NAMESPACE_BEGIN */ TransliterationRuleSet::TransliterationRuleSet(UErrorCode& status) : UMemory() { ruleVector = new UVector(&_deleteRule, NULL, status); - rules = NULL; - maxContextLength = 0; + if (U_FAILURE(status)) { + return; + } if (ruleVector == NULL) { status = U_MEMORY_ALLOCATION_ERROR; } + rules = NULL; + maxContextLength = 0; } /** @@ -185,11 +191,19 @@ TransliterationRuleSet::TransliterationRuleSet(const TransliterationRuleSet& oth if (other.ruleVector != 0 && ruleVector != 0 && U_SUCCESS(status)) { len = other.ruleVector->size(); for (i=0; iaddElement(new TransliterationRule( - *(TransliterationRule*)other.ruleVector->elementAt(i)), status); + TransliterationRule *tempTranslitRule = new TransliterationRule(*(TransliterationRule*)other.ruleVector->elementAt(i)); + // Null pointer test + if (tempTranslitRule == NULL) { + status = U_MEMORY_ALLOCATION_ERROR; + break; + } + ruleVector->addElement(tempTranslitRule, status); + if (U_FAILURE(status)) { + break; + } } } - if (other.rules != 0) { + if (other.rules != 0 && U_SUCCESS(status)) { UParseError p; freeze(p, status); } @@ -405,7 +419,7 @@ UBool TransliterationRuleSet::transliterate(Replaceable& text, } } // No match or partial match from any rule - pos.start += UTF_CHAR_LENGTH(text.char32At(pos.start)); + pos.start += U16_LENGTH(text.char32At(pos.start)); _debugOut("no match", NULL, text, pos); return TRUE; } @@ -434,17 +448,18 @@ UnicodeString& TransliterationRuleSet::toRules(UnicodeString& ruleSource, * (getTarget=false) or emitted (getTarget=true) by this set. */ UnicodeSet& TransliterationRuleSet::getSourceTargetSet(UnicodeSet& result, - UBool getTarget) const { + UBool getTarget) const +{ result.clear(); int32_t count = ruleVector->size(); for (int32_t i=0; ielementAt(i); - if (getTarget) { - r->addTargetSetTo(result); - } else { - r->addSourceSetTo(result); - } + TransliterationRule* r = + (TransliterationRule*) ruleVector->elementAt(i); + if (getTarget) { + r->addTargetSetTo(result); + } else { + r->addSourceSetTo(result); + } } return result; }