Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(311)

Unified Diff: third_party/WebKit/Source/wtf/text/TextCodecICU.cpp

Issue 1709293002: Add support for CSS unicod encoding to the text codec. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/WebKit/Source/wtf/text/TextCodec.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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));
« no previous file with comments | « third_party/WebKit/Source/wtf/text/TextCodec.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698