/*
-**********************************************************************
-* 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"
#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}; // " > "
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.
// 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)) ||
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;
}
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
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);
+ }
}
}