X-Git-Url: https://git.saurik.com/apple/icu.git/blobdiff_plain/374ca955a76ecab1204ca8bfa63ff9238d998416..249c4c5ea9376c24572daf9c2effa7484a282f14:/icuSources/i18n/esctrn.cpp?ds=sidebyside diff --git a/icuSources/i18n/esctrn.cpp b/icuSources/i18n/esctrn.cpp index 95c8a1dc..900bed7e 100644 --- a/icuSources/i18n/esctrn.cpp +++ b/icuSources/i18n/esctrn.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 @@ -12,6 +14,7 @@ #if !UCONFIG_NO_TRANSLITERATION +#include "unicode/utf16.h" #include "esctrn.h" #include "util.h" @@ -25,37 +28,36 @@ static const UChar XML10PRE[] = {38,35,0}; // "&#" static const UChar PERLPRE[] = {92,120,123,0}; // "\\x{" static const UChar SEMI[] = {59,0}; // ";" static const UChar RBRACE[] = {125,0}; // "}" -static const UChar EMPTY[] = {0}; // "" UOBJECT_DEFINE_RTTI_IMPLEMENTATION(EscapeTransliterator) /** * Factory methods */ -Transliterator* EscapeTransliterator::_createUnicode(const UnicodeString& ID, Token /*context*/) { +static Transliterator* _createEscUnicode(const UnicodeString& ID, Transliterator::Token /*context*/) { // Unicode: "U+10FFFF" hex, min=4, max=6 - return new EscapeTransliterator(ID, UNIPRE, EMPTY, 16, 4, TRUE, NULL); + return new EscapeTransliterator(ID, UnicodeString(TRUE, UNIPRE, 2), UnicodeString(), 16, 4, TRUE, NULL); } -Transliterator* EscapeTransliterator::_createJava(const UnicodeString& ID, Token /*context*/) { +static Transliterator* _createEscJava(const UnicodeString& ID, Transliterator::Token /*context*/) { // Java: "\\uFFFF" hex, min=4, max=4 - return new EscapeTransliterator(ID, BS_u, EMPTY, 16, 4, FALSE, NULL); + return new EscapeTransliterator(ID, UnicodeString(TRUE, BS_u, 2), UnicodeString(), 16, 4, FALSE, NULL); } -Transliterator* EscapeTransliterator::_createC(const UnicodeString& ID, Token /*context*/) { +static Transliterator* _createEscC(const UnicodeString& ID, Transliterator::Token /*context*/) { // C: "\\uFFFF" hex, min=4, max=4; \\U0010FFFF hex, min=8, max=8 - return new EscapeTransliterator(ID, BS_u, EMPTY, 16, 4, TRUE, - new EscapeTransliterator(EMPTY, BS_U, EMPTY, 16, 8, TRUE, NULL)); + return new EscapeTransliterator(ID, UnicodeString(TRUE, BS_u, 2), UnicodeString(), 16, 4, TRUE, + new EscapeTransliterator(UnicodeString(), UnicodeString(TRUE, BS_U, 2), UnicodeString(), 16, 8, TRUE, NULL)); } -Transliterator* EscapeTransliterator::_createXML(const UnicodeString& ID, Token /*context*/) { +static Transliterator* _createEscXML(const UnicodeString& ID, Transliterator::Token /*context*/) { // XML: "􏿿" hex, min=1, max=6 - return new EscapeTransliterator(ID, XMLPRE, SEMI, 16, 1, TRUE, NULL); + return new EscapeTransliterator(ID, UnicodeString(TRUE, XMLPRE, 3), UnicodeString(SEMI[0]), 16, 1, TRUE, NULL); } -Transliterator* EscapeTransliterator::_createXML10(const UnicodeString& ID, Token /*context*/) { +static Transliterator* _createEscXML10(const UnicodeString& ID, Transliterator::Token /*context*/) { // XML10: "&1114111;" dec, min=1, max=7 (not really "Any-Hex") - return new EscapeTransliterator(ID, XML10PRE, SEMI, 10, 1, TRUE, NULL); + return new EscapeTransliterator(ID, UnicodeString(TRUE, XML10PRE, 2), UnicodeString(SEMI[0]), 10, 1, TRUE, NULL); } -Transliterator* EscapeTransliterator::_createPerl(const UnicodeString& ID, Token /*context*/) { +static Transliterator* _createEscPerl(const UnicodeString& ID, Transliterator::Token /*context*/) { // Perl: "\\x{263A}" hex, min=1, max=6 - return new EscapeTransliterator(ID, PERLPRE, RBRACE, 16, 1, TRUE, NULL); + return new EscapeTransliterator(ID, UnicodeString(TRUE, PERLPRE, 3), UnicodeString(RBRACE[0]), 16, 1, TRUE, NULL); } /** @@ -65,19 +67,19 @@ Transliterator* EscapeTransliterator::_createPerl(const UnicodeString& ID, Token void EscapeTransliterator::registerIDs() { Token t = integerToken(0); - Transliterator::_registerFactory(UNICODE_STRING_SIMPLE("Any-Hex/Unicode"), _createUnicode, t); + Transliterator::_registerFactory(UNICODE_STRING_SIMPLE("Any-Hex/Unicode"), _createEscUnicode, t); - Transliterator::_registerFactory(UNICODE_STRING_SIMPLE("Any-Hex/Java"), _createJava, t); + Transliterator::_registerFactory(UNICODE_STRING_SIMPLE("Any-Hex/Java"), _createEscJava, t); - Transliterator::_registerFactory(UNICODE_STRING_SIMPLE("Any-Hex/C"), _createC, t); + Transliterator::_registerFactory(UNICODE_STRING_SIMPLE("Any-Hex/C"), _createEscC, t); - Transliterator::_registerFactory(UNICODE_STRING_SIMPLE("Any-Hex/XML"), _createXML, t); + Transliterator::_registerFactory(UNICODE_STRING_SIMPLE("Any-Hex/XML"), _createEscXML, t); - Transliterator::_registerFactory(UNICODE_STRING_SIMPLE("Any-Hex/XML10"), _createXML10, t); + Transliterator::_registerFactory(UNICODE_STRING_SIMPLE("Any-Hex/XML10"), _createEscXML10, t); - Transliterator::_registerFactory(UNICODE_STRING_SIMPLE("Any-Hex/Perl"), _createPerl, t); + Transliterator::_registerFactory(UNICODE_STRING_SIMPLE("Any-Hex/Perl"), _createEscPerl, t); - Transliterator::_registerFactory(UNICODE_STRING_SIMPLE("Any-Hex"), _createJava, t); + Transliterator::_registerFactory(UNICODE_STRING_SIMPLE("Any-Hex"), _createEscJava, t); } /** @@ -141,7 +143,7 @@ void EscapeTransliterator::handleTransliterate(Replaceable& text, while (start < limit) { int32_t c = grokSupplementals ? text.char32At(start) : text.charAt(start); - int32_t charLen = grokSupplementals ? UTF_CHAR_LENGTH(c) : 1; + int32_t charLen = grokSupplementals ? U16_LENGTH(c) : 1; if ((c & 0xFFFF0000) != 0 && supplementalHandler != NULL) { buf.truncate(0);