+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
/*
**********************************************************************
- * Copyright (C) 1999-2005, International Business Machines
+ * Copyright (C) 1999-2011, International Business Machines
* Corporation and others. All Rights Reserved.
**********************************************************************
* Date Name Description
#include "unicode/unistr.h"
#include "unicode/uniset.h"
+#include "unicode/utf16.h"
#include "rbt_set.h"
#include "rbt_rule.h"
#include "cmemory.h"
U_CDECL_BEGIN
static void U_CALLCONV _deleteRule(void *rule) {
- delete (U_NAMESPACE_QUALIFIER TransliterationRule *)rule;
+ delete (icu::TransliterationRule *)rule;
}
U_CDECL_END
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";
// 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;
*/
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;
}
/**
if (other.ruleVector != 0 && ruleVector != 0 && U_SUCCESS(status)) {
len = other.ruleVector->size();
for (i=0; i<len && U_SUCCESS(status); ++i) {
- ruleVector->addElement(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);
}
}
}
// 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;
}
* (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; i<count; ++i) {
- TransliterationRule* r =
- (TransliterationRule*) ruleVector->elementAt(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;
}