+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
/*
**********************************************************************
-* Copyright (C) 2001-2004, International Business Machines
+* Copyright (C) 2001-2011, International Business Machines
* Corporation and others. All Rights Reserved.
**********************************************************************
* Date Name Description
#include "unicode/unifilt.h"
#include "unicode/uchar.h"
#include "unicode/uniset.h"
-#include "name2uni.h"
+#include "unicode/utf16.h"
#include "cmemory.h"
+#include "name2uni.h"
+#include "patternprops.h"
#include "uprops.h"
+#include "uinvchar.h"
#include "util.h"
U_NAMESPACE_BEGIN
// Does not use uset.h to reduce code dependencies
static void U_CALLCONV
_set_add(USet *set, UChar32 c) {
- ((UnicodeSet *)set)->add(c);
+ uset_add(set, c);
}
-static void U_CALLCONV
+// These functions aren't used.
+/*static void U_CALLCONV
_set_addRange(USet *set, UChar32 start, UChar32 end) {
((UnicodeSet *)set)->add(start, end);
}
static void U_CALLCONV
_set_addString(USet *set, const UChar *str, int32_t length) {
((UnicodeSet *)set)->add(UnicodeString((UBool)(length<0), str, length));
-}
+}*/
U_CDECL_END
NameUnicodeTransliterator::NameUnicodeTransliterator(UnicodeFilter* adoptedFilter) :
Transliterator(UNICODE_STRING("Name-Any", 8), adoptedFilter) {
+ UnicodeSet *legalPtr = &legal;
// Get the legal character set
USetAdder sa = {
- (USet *)&legal, // USet* == UnicodeSet*
+ (USet *)legalPtr, // USet* == UnicodeSet*
_set_add,
- _set_addRange,
- _set_addString
+ NULL, // Don't need _set_addRange
+ NULL, // Don't need _set_addString
+ NULL, // Don't need remove()
+ NULL
};
uprv_getCharNameCharacters(&sa);
}
/**
* Assignment operator.
*/
-NameUnicodeTransliterator& NameUnicodeTransliterator::operator=(
+/*NameUnicodeTransliterator& NameUnicodeTransliterator::operator=(
const NameUnicodeTransliterator& o) {
Transliterator::operator=(o);
// not necessary: the legal sets should all be the same -- legal=o.legal;
return *this;
-}
+}*/
/**
* Transliterator API.
// Convert \s+ => SPACE. This assumes there are no
// runs of >1 space characters in names.
- if (uprv_isRuleWhiteSpace(c)) {
+ if (PatternProps::isWhiteSpace(c)) {
// Ignore leading whitespace
if (name.length() > 0 &&
name.charAt(name.length()-1) != SPACE) {
}
if (c == CLOSE_DELIM) {
-
int32_t len = name.length();
// Delete trailing space, if any
--len;
}
- name.extract(0, len, cbuf, "");
+ if (uprv_isInvariantUString(name.getBuffer(), len)) {
+ name.extract(0, len, cbuf, maxLen, US_INV);
- UErrorCode status = U_ZERO_ERROR;
- c = u_charFromName(U_EXTENDED_CHAR_NAME, cbuf, &status);
- if (U_SUCCESS(status)) {
- // Lookup succeeded
+ UErrorCode status = U_ZERO_ERROR;
+ c = u_charFromName(U_EXTENDED_CHAR_NAME, cbuf, &status);
+ if (U_SUCCESS(status)) {
+ // Lookup succeeded
- // assert(UTF_CHAR_LENGTH(CLOSE_DELIM) == 1);
- cursor++; // advance over CLOSE_DELIM
+ // assert(U16_LENGTH(CLOSE_DELIM) == 1);
+ cursor++; // advance over CLOSE_DELIM
- str.truncate(0);
- str.append(c);
- text.handleReplaceBetween(openPos, cursor, str);
+ str.truncate(0);
+ str.append(c);
+ text.handleReplaceBetween(openPos, cursor, str);
- // Adjust indices for the change in the length of
- // the string. Do not assume that str.length() ==
- // 1, in case of surrogates.
- int32_t delta = cursor - openPos - str.length();
- cursor -= delta;
- limit -= delta;
- // assert(cursor == openPos + str.length());
+ // Adjust indices for the change in the length of
+ // the string. Do not assume that str.length() ==
+ // 1, in case of surrogates.
+ int32_t delta = cursor - openPos - str.length();
+ cursor -= delta;
+ limit -= delta;
+ // assert(cursor == openPos + str.length());
+ }
}
// If the lookup failed, we leave things as-is and
// still switch to mode 0 and continue.
break;
}
- cursor += UTF_CHAR_LENGTH(c);
+ cursor += U16_LENGTH(c);
}
offsets.contextLimit += limit - offsets.limit;