]> git.saurik.com Git - apple/icu.git/blobdiff - icuSources/i18n/rbt_rule.cpp
ICU-62141.0.1.tar.gz
[apple/icu.git] / icuSources / i18n / rbt_rule.cpp
index bf16248c90e54dc18f222c693a6bafa7a4a4b29d..3569e42fa4f137f903264dc11428b17ba5a52a70 100644 (file)
@@ -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
@@ -15,6 +17,7 @@
 #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"
@@ -173,7 +176,7 @@ TransliterationRule::TransliterationRule(TransliterationRule& other) :
     segmentsCount = 0;
     if (other.segmentsCount > 0) {
         segments = (UnicodeFunctor **)uprv_malloc(other.segmentsCount * sizeof(UnicodeFunctor *));
-        uprv_memcpy(segments, other.segments, other.segmentsCount*sizeof(segments[0]));
+        uprv_memcpy(segments, other.segments, (size_t)other.segmentsCount*sizeof(segments[0]));
     }
 
     if (other.anteContext != NULL) {
@@ -292,6 +295,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.
@@ -299,7 +303,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)) ||
@@ -309,18 +313,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;
 }
 
@@ -500,7 +504,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
 
@@ -529,14 +533,14 @@ void TransliterationRule::setData(const TransliterationRuleData* d) {
 void TransliterationRule::addSourceSetTo(UnicodeSet& toUnionTo) const {
     int32_t limit = anteContextLength + keyLength;
     for (int32_t i=anteContextLength; i<limit; ) {
-    UChar32 ch = pattern.char32At(i);
-    i += UTF_CHAR_LENGTH(ch);
-    const UnicodeMatcher* matcher = data->lookupMatcher(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);
+        }
     }
 }