X-Git-Url: https://git.saurik.com/apple/icu.git/blobdiff_plain/b75a7d8f3b4adbae880cab104ce2c6a50eee4db2..ba516feee23ef0c2b810ac6365e88f33807caaa8:/icuSources/i18n/rbt_rule.cpp diff --git a/icuSources/i18n/rbt_rule.cpp b/icuSources/i18n/rbt_rule.cpp index cf1c06af..b21e37c9 100644 --- a/icuSources/i18n/rbt_rule.cpp +++ b/icuSources/i18n/rbt_rule.cpp @@ -1,12 +1,12 @@ /* -********************************************************************** -* Copyright (C) 1999-2001, International Business Machines -* Corporation and others. All Rights Reserved. -********************************************************************** -* Date Name Description -* 11/17/99 aliu Creation. -********************************************************************** -*/ + ********************************************************************** + * Copyright (C) 1999-2011, International Business Machines + * Corporation and others. All Rights Reserved. + ********************************************************************** + * Date Name Description + * 11/17/99 aliu Creation. + ********************************************************************** + */ #include "unicode/utypes.h" @@ -15,12 +15,14 @@ #include "unicode/rep.h" #include "unicode/unifilt.h" #include "unicode/uniset.h" +#include "unicode/utf16.h" #include "rbt_rule.h" #include "rbt_data.h" #include "cmemory.h" #include "strmatch.h" #include "strrepl.h" #include "util.h" +#include "putilimp.h" static const UChar FORWARD_OP[] = {32,62,32,0}; // " > " @@ -291,6 +293,7 @@ UBool TransliterationRule::masks(const TransliterationRule& r2) const { int32_t left2 = r2.anteContextLength; int32_t right = len - left; int32_t right2 = r2.pattern.length() - left2; + int32_t cachedCompare = r2.pattern.compare(left2 - left, len, pattern); // TODO Clean this up -- some logic might be combinable with the // next statement. @@ -298,7 +301,7 @@ UBool TransliterationRule::masks(const TransliterationRule& r2) const { // Test for anchor masking if (left == left2 && right == right2 && keyLength <= r2.keyLength && - 0 == r2.pattern.compare(0, len, pattern)) { + 0 == cachedCompare) { // The following boolean logic implements the table above return (flags == r2.flags) || (!(flags & ANCHOR_START) && !(flags & ANCHOR_END)) || @@ -308,18 +311,18 @@ UBool TransliterationRule::masks(const TransliterationRule& r2) const { return left <= left2 && (right < right2 || (right == right2 && keyLength <= r2.keyLength)) && - 0 == r2.pattern.compare(left2 - left, len, pattern); + (0 == cachedCompare); } static inline int32_t posBefore(const Replaceable& str, int32_t pos) { return (pos > 0) ? - pos - UTF_CHAR_LENGTH(str.char32At(pos-1)) : + pos - U16_LENGTH(str.char32At(pos-1)) : pos - 1; } static inline int32_t posAfter(const Replaceable& str, int32_t pos) { return (pos >= 0 && pos < str.length()) ? - pos + UTF_CHAR_LENGTH(str.char32At(pos)) : + pos + U16_LENGTH(str.char32At(pos)) : pos + 1; } @@ -499,7 +502,7 @@ UnicodeString& TransliterationRule::toRule(UnicodeString& rule, rule.append((UChar)36/*$*/); } - ICU_Utility::appendToRule(rule, FORWARD_OP, TRUE, escapeUnprintable, quoteBuf); + ICU_Utility::appendToRule(rule, UnicodeString(TRUE, FORWARD_OP, 3), TRUE, escapeUnprintable, quoteBuf); // Emit the output pattern @@ -528,14 +531,14 @@ void TransliterationRule::setData(const TransliterationRuleData* d) { void TransliterationRule::addSourceSetTo(UnicodeSet& toUnionTo) const { int32_t limit = anteContextLength + keyLength; for (int32_t i=anteContextLength; ilookupMatcher(ch); - if (matcher == NULL) { - toUnionTo.add(ch); - } else { - matcher->addMatchSetTo(toUnionTo); - } + UChar32 ch = pattern.char32At(i); + i += U16_LENGTH(ch); + const UnicodeMatcher* matcher = data->lookupMatcher(ch); + if (matcher == NULL) { + toUnionTo.add(ch); + } else { + matcher->addMatchSetTo(toUnionTo); + } } }