X-Git-Url: https://git.saurik.com/apple/icu.git/blobdiff_plain/374ca955a76ecab1204ca8bfa63ff9238d998416..a01113dcd0f39d5da295ef82785beff9ed86fe38:/icuSources/i18n/name2uni.cpp?ds=sidebyside diff --git a/icuSources/i18n/name2uni.cpp b/icuSources/i18n/name2uni.cpp index 255a4bc6..69e92b8c 100644 --- a/icuSources/i18n/name2uni.cpp +++ b/icuSources/i18n/name2uni.cpp @@ -1,6 +1,8 @@ +// © 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 @@ -15,9 +17,12 @@ #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 @@ -35,10 +40,11 @@ U_CDECL_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); } @@ -46,7 +52,7 @@ _set_addRange(USet *set, UChar32 start, UChar32 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 @@ -57,12 +63,15 @@ 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); } @@ -81,12 +90,12 @@ NameUnicodeTransliterator::NameUnicodeTransliterator(const NameUnicodeTransliter /** * 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. @@ -157,7 +166,7 @@ void NameUnicodeTransliterator::handleTransliterate(Replaceable& text, UTransPos // 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) { @@ -172,7 +181,6 @@ void NameUnicodeTransliterator::handleTransliterate(Replaceable& text, UTransPos } if (c == CLOSE_DELIM) { - int32_t len = name.length(); // Delete trailing space, if any @@ -181,27 +189,29 @@ void NameUnicodeTransliterator::handleTransliterate(Replaceable& text, UTransPos --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. @@ -231,7 +241,7 @@ void NameUnicodeTransliterator::handleTransliterate(Replaceable& text, UTransPos break; } - cursor += UTF_CHAR_LENGTH(c); + cursor += U16_LENGTH(c); } offsets.contextLimit += limit - offsets.limit;