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

Side by Side Diff: third_party/WebKit/Source/wtf/text/TextCodecReplacement.cpp

Issue 2050123002: Remove OwnPtr from Blink. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: First attempt to land. Created 4 years, 6 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 unified diff | Download patch
OLDNEW
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/PtrUtil.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 #include <memory>
10 11
11 namespace WTF { 12 namespace WTF {
12 13
13 TextCodecReplacement::TextCodecReplacement() 14 TextCodecReplacement::TextCodecReplacement()
14 : m_replacementErrorReturned(false) 15 : m_replacementErrorReturned(false)
15 { 16 {
16 } 17 }
17 18
18 void TextCodecReplacement::registerEncodingNames(EncodingNameRegistrar registrar ) 19 void TextCodecReplacement::registerEncodingNames(EncodingNameRegistrar registrar )
19 { 20 {
20 // The 'replacement' label itself should not be referenceable by 21 // The 'replacement' label itself should not be referenceable by
21 // resources or script - it's a specification convenience - but much of 22 // resources or script - it's a specification convenience - but much of
22 // the wtf/text API asserts that an encoding name is a label for itself. 23 // 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 // This is handled in TextEncoding by marking it as not valid.
24 registrar("replacement", "replacement"); 25 registrar("replacement", "replacement");
25 26
26 registrar("csiso2022kr", "replacement"); 27 registrar("csiso2022kr", "replacement");
27 registrar("hz-gb-2312", "replacement"); 28 registrar("hz-gb-2312", "replacement");
28 registrar("iso-2022-cn", "replacement"); 29 registrar("iso-2022-cn", "replacement");
29 registrar("iso-2022-cn-ext", "replacement"); 30 registrar("iso-2022-cn-ext", "replacement");
30 registrar("iso-2022-kr", "replacement"); 31 registrar("iso-2022-kr", "replacement");
31 } 32 }
32 33
33 static PassOwnPtr<TextCodec> newStreamingTextDecoderReplacement(const TextEncodi ng&, const void*) 34 static std::unique_ptr<TextCodec> newStreamingTextDecoderReplacement(const TextE ncoding&, const void*)
34 { 35 {
35 return adoptPtr(new TextCodecReplacement); 36 return wrapUnique(new TextCodecReplacement);
36 } 37 }
37 38
38 void TextCodecReplacement::registerCodecs(TextCodecRegistrar registrar) 39 void TextCodecReplacement::registerCodecs(TextCodecRegistrar registrar)
39 { 40 {
40 registrar("replacement", newStreamingTextDecoderReplacement, 0); 41 registrar("replacement", newStreamingTextDecoderReplacement, 0);
41 } 42 }
42 43
43 String TextCodecReplacement::decode(const char*, size_t length, FlushBehavior, b ool, bool& sawError) 44 String TextCodecReplacement::decode(const char*, size_t length, FlushBehavior, b ool, bool& sawError)
44 { 45 {
45 // https://encoding.spec.whatwg.org/#replacement-decoder 46 // https://encoding.spec.whatwg.org/#replacement-decoder
46 47
47 // 1. If byte is end-of-stream, return finished. 48 // 1. If byte is end-of-stream, return finished.
48 if (!length) 49 if (!length)
49 return String(); 50 return String();
50 51
51 // 2. If replacement error returned flag is unset, set the replacement 52 // 2. If replacement error returned flag is unset, set the replacement
52 // error returned flag and return error. 53 // error returned flag and return error.
53 if (!m_replacementErrorReturned) { 54 if (!m_replacementErrorReturned) {
54 m_replacementErrorReturned = true; 55 m_replacementErrorReturned = true;
55 sawError = true; 56 sawError = true;
56 return String(&replacementCharacter, 1); 57 return String(&replacementCharacter, 1);
57 } 58 }
58 59
59 // 3. Return finished. 60 // 3. Return finished.
60 return String(); 61 return String();
61 } 62 }
62 63
63 } // namespace WTF 64 } // namespace WTF
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698