| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "wtf/text/TextCodecReplacement.h" | 5 #include "wtf/text/TextCodecReplacement.h" |
| 6 | 6 |
| 7 #include "wtf/PassOwnPtr.h" | 7 #include "wtf/PassOwnPtr.h" |
| 8 #include "wtf/text/CharacterNames.h" | 8 #include "wtf/text/CharacterNames.h" |
| 9 #include "wtf/text/WTFString.h" | 9 #include "wtf/text/WTFString.h" |
| 10 | 10 |
| 11 namespace WTF { | 11 namespace WTF { |
| 12 | 12 |
| 13 TextCodecReplacement::TextCodecReplacement() | 13 TextCodecReplacement::TextCodecReplacement() : m_sentEOF(false) {} |
| 14 : m_sentEOF(false) | 14 |
| 15 { | 15 void TextCodecReplacement::registerEncodingNames( |
| 16 EncodingNameRegistrar registrar) { |
| 17 // The 'replacement' label itself should not be referenceable by |
| 18 // resources or script - it's a specification convenience - but much of |
| 19 // the wtf/text API asserts that an encoding name is a label for itself. |
| 20 // This is handled in TextEncoding by marking it as not valid. |
| 21 registrar("replacement", "replacement"); |
| 22 |
| 23 registrar("csiso2022kr", "replacement"); |
| 24 registrar("hz-gb-2312", "replacement"); |
| 25 registrar("iso-2022-cn", "replacement"); |
| 26 registrar("iso-2022-cn-ext", "replacement"); |
| 27 registrar("iso-2022-kr", "replacement"); |
| 16 } | 28 } |
| 17 | 29 |
| 18 void TextCodecReplacement::registerEncodingNames(EncodingNameRegistrar registrar
) | 30 static PassOwnPtr<TextCodec> newStreamingTextDecoderReplacement( |
| 19 { | 31 const TextEncoding&, |
| 20 // The 'replacement' label itself should not be referenceable by | 32 const void*) { |
| 21 // resources or script - it's a specification convenience - but much of | 33 return adoptPtr(new TextCodecReplacement); |
| 22 // the wtf/text API asserts that an encoding name is a label for itself. | |
| 23 // This is handled in TextEncoding by marking it as not valid. | |
| 24 registrar("replacement", "replacement"); | |
| 25 | |
| 26 registrar("csiso2022kr", "replacement"); | |
| 27 registrar("hz-gb-2312", "replacement"); | |
| 28 registrar("iso-2022-cn", "replacement"); | |
| 29 registrar("iso-2022-cn-ext", "replacement"); | |
| 30 registrar("iso-2022-kr", "replacement"); | |
| 31 } | 34 } |
| 32 | 35 |
| 33 static PassOwnPtr<TextCodec> newStreamingTextDecoderReplacement(const TextEncodi
ng&, const void*) | 36 void TextCodecReplacement::registerCodecs(TextCodecRegistrar registrar) { |
| 34 { | 37 registrar("replacement", newStreamingTextDecoderReplacement, 0); |
| 35 return adoptPtr(new TextCodecReplacement); | |
| 36 } | 38 } |
| 37 | 39 |
| 38 void TextCodecReplacement::registerCodecs(TextCodecRegistrar registrar) | 40 String TextCodecReplacement::decode(const char*, |
| 39 { | 41 size_t, |
| 40 registrar("replacement", newStreamingTextDecoderReplacement, 0); | 42 FlushBehavior, |
| 43 bool, |
| 44 bool& sawError) { |
| 45 sawError = true; |
| 46 if (m_sentEOF) |
| 47 return String(); |
| 48 |
| 49 m_sentEOF = true; |
| 50 return String(&replacementCharacter, 1); |
| 41 } | 51 } |
| 42 | 52 |
| 43 String TextCodecReplacement::decode(const char*, size_t, FlushBehavior, bool, bo
ol& sawError) | 53 } // namespace WTF |
| 44 { | |
| 45 sawError = true; | |
| 46 if (m_sentEOF) | |
| 47 return String(); | |
| 48 | |
| 49 m_sentEOF = true; | |
| 50 return String(&replacementCharacter, 1); | |
| 51 } | |
| 52 | |
| 53 } // namespace WTF | |
| OLD | NEW |