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

Unified Diff: Source/wtf/text/TextCodecReplacement.cpp

Issue 265973003: Implement "replacement" text encoding. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Request rebaseline the temporary chaset-replacement output Created 6 years, 7 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 | « Source/wtf/text/TextCodecReplacement.h ('k') | Source/wtf/text/TextCodecReplacementTest.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/wtf/text/TextCodecReplacement.cpp
diff --git a/Source/wtf/text/TextCodecReplacement.cpp b/Source/wtf/text/TextCodecReplacement.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..ca9373abd77b70b99b9aca968be458fecab1ad36
--- /dev/null
+++ b/Source/wtf/text/TextCodecReplacement.cpp
@@ -0,0 +1,54 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "config.h"
+#include "wtf/text/TextCodecReplacement.h"
+
+#include "wtf/PassOwnPtr.h"
+#include "wtf/text/WTFString.h"
+#include "wtf/unicode/CharacterNames.h"
+
+namespace WTF {
+
+TextCodecReplacement::TextCodecReplacement()
+ : m_sentEOF(false)
+{
+}
+
+void TextCodecReplacement::registerEncodingNames(EncodingNameRegistrar registrar)
+{
+ // FIXME: The 'replacement' label itself should not be referenceable by
+ // resources or script - it's a specification convenience - but much of
+ // the wtf/text API asserts that an encoding name is a label for itself.
+ // crbug.com/277037
+ registrar("replacement", "replacement");
+
+ registrar("csiso2022kr", "replacement");
+ registrar("hz-gb-2312", "replacement");
+ registrar("iso-2022-cn", "replacement");
+ registrar("iso-2022-cn-ext", "replacement");
+ registrar("iso-2022-kr", "replacement");
+}
+
+static PassOwnPtr<TextCodec> newStreamingTextDecoderReplacement(const TextEncoding&, const void*)
+{
+ return adoptPtr(new TextCodecReplacement);
+}
+
+void TextCodecReplacement::registerCodecs(TextCodecRegistrar registrar)
+{
+ registrar("replacement", newStreamingTextDecoderReplacement, 0);
+}
+
+String TextCodecReplacement::decode(const char*, size_t, FlushBehavior, bool, bool& sawError)
+{
+ sawError = true;
+ if (m_sentEOF)
+ return String();
+
+ m_sentEOF = true;
+ return String(&Unicode::replacementCharacter, 1);
+}
+
+} // namespace WTF
« no previous file with comments | « Source/wtf/text/TextCodecReplacement.h ('k') | Source/wtf/text/TextCodecReplacementTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698