Chromium Code Reviews| 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..e2a8b0cb128d6f0d0f6bc68992ae4d3b14bbe051 |
| --- /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/CString.h" |
| +#include "wtf/text/StringBuffer.h" |
| +#include "wtf/text/StringBuilder.h" |
| +#include "wtf/text/WTFString.h" |
| +#include "wtf/unicode/CharacterNames.h" |
| + |
| +namespace WTF { |
| + |
| +TextCodecReplacement::TextCodecReplacement() |
| + : m_sentEOF(false) |
| +{ |
| +} |
| + |
| +void TextCodecReplacement::registerEncodingNames(EncodingNameRegistrar registrar) |
| +{ |
| + // The "replacement" encoding should not be available by name directly, |
| + // but is necessary during registration. It will be removed after the |
| + // labels are registered. |
| + registrar("replacement", "replacement"); |
| + registrar("csiso2022kr", "replacement"); |
|
eseidel
2014/04/01 23:12:16
36 out of 100M pages surveyed had this encoding.
|
| + registrar("iso-2022-cn", "replacement"); |
|
eseidel
2014/04/01 23:12:16
7 off 100M pages.
|
| + registrar("iso-2022-cn-ext", "replacement"); |
|
eseidel
2014/04/01 23:12:16
No data, presumably 0 pages.
|
| + registrar("iso-2022-kr", "replacement"); |
|
eseidel
2014/04/01 23:12:16
I suspect this is lumped in with the 36 above. :)
|
| +} |
| + |
| +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 |