Chromium Code Reviews| Index: third_party/WebKit/Source/wtf/text/TextCodecICU.cpp |
| diff --git a/third_party/WebKit/Source/wtf/text/TextCodecICU.cpp b/third_party/WebKit/Source/wtf/text/TextCodecICU.cpp |
| index f90d447cebabc06f48162bf5f8de83b677797a5f..d3762707d253179feb5f27f43f8fa2ddae345683 100644 |
| --- a/third_party/WebKit/Source/wtf/text/TextCodecICU.cpp |
| +++ b/third_party/WebKit/Source/wtf/text/TextCodecICU.cpp |
| @@ -414,6 +414,22 @@ static UChar fallbackForGBK(UChar32 character) |
| // Invalid character handler when writing escaped entities for unrepresentable |
| // characters. See the declaration of TextCodec::encode for more. |
| +static void cssEscapedEntityCallback(const void* context, UConverterFromUnicodeArgs* fromUArgs, const UChar* codeUnits, int32_t length, |
|
Dmitry Titov
2016/02/18 21:26:48
These two new functions are not really trivial cop
|
| + UChar32 codePoint, UConverterCallbackReason reason, UErrorCode* err) |
| +{ |
| + if (reason == UCNV_UNASSIGNED) { |
| + *err = U_ZERO_ERROR; |
| + |
| + UnencodableReplacementArray entity; |
| + int entityLen = TextCodec::getUnencodableReplacement(codePoint, CSSEncodedEntitiesForUnencodables, entity); |
| + ucnv_cbFromUWriteBytes(fromUArgs, entity, entityLen, 0, err); |
| + } else { |
| + UCNV_FROM_U_CALLBACK_ESCAPE(context, fromUArgs, codeUnits, length, codePoint, reason, err); |
| + } |
| +} |
| + |
| +// Invalid character handler when writing escaped entities for unrepresentable |
| +// characters. See the declaration of TextCodec::encode for more. |
| static void urlEscapedEntityCallback(const void* context, UConverterFromUnicodeArgs* fromUArgs, const UChar* codeUnits, int32_t length, |
| UChar32 codePoint, UConverterCallbackReason reason, UErrorCode* err) |
| { |
| @@ -443,6 +459,23 @@ static void gbkCallbackEscape(const void* context, UConverterFromUnicodeArgs* fr |
| UCNV_FROM_U_CALLBACK_ESCAPE(context, fromUArgs, codeUnits, length, codePoint, reason, err); |
| } |
| +// Combines both gbkCssEscapedEntityCallback and GBK character substitution. |
| +static void gbkCssEscapedEntityCallack(const void* context, UConverterFromUnicodeArgs* fromUArgs, const UChar* codeUnits, int32_t length, |
| + UChar32 codePoint, UConverterCallbackReason reason, UErrorCode* err) |
| +{ |
| + if (reason == UCNV_UNASSIGNED) { |
| + if (UChar outChar = fallbackForGBK(codePoint)) { |
| + const UChar* source = &outChar; |
| + *err = U_ZERO_ERROR; |
| + ucnv_cbFromUWriteUChars(fromUArgs, &source, source + 1, 0, err); |
| + return; |
| + } |
| + cssEscapedEntityCallback(context, fromUArgs, codeUnits, length, codePoint, reason, err); |
| + return; |
| + } |
| + UCNV_FROM_U_CALLBACK_ESCAPE(context, fromUArgs, codeUnits, length, codePoint, reason, err); |
| +} |
| + |
| // Combines both gbkUrlEscapedEntityCallback and GBK character substitution. |
| static void gbkUrlEscapedEntityCallack(const void* context, UConverterFromUnicodeArgs* fromUArgs, const UChar* codeUnits, int32_t length, |
| UChar32 codePoint, UConverterCallbackReason reason, UErrorCode* err) |
| @@ -530,6 +563,13 @@ CString TextCodecICU::encodeInternal(const TextCodecInput& input, UnencodableHan |
| ucnv_setFromUCallBack(m_converterICU, m_needsGBKFallbacks ? gbkUrlEscapedEntityCallack : urlEscapedEntityCallback, 0, 0, 0, &err); |
| #endif |
| break; |
| + case CSSEncodedEntitiesForUnencodables: |
| +#if !defined(USING_SYSTEM_ICU) |
| + ucnv_setFromUCallBack(m_converterICU, cssEscapedEntityCallback, 0, 0, 0, &err); |
| +#else |
| + ucnv_setFromUCallBack(m_converterICU, m_needsGBKFallbacks ? gbkCssEscapedEntityCallack : cssEscapedEntityCallback, 0, 0, 0, &err); |
| +#endif |
| + break; |
| } |
| ASSERT(U_SUCCESS(err)); |