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 "core/fetch/TextResource.h" | 5 #include "core/fetch/TextResource.h" |
6 | 6 |
7 #include "core/html/parser/TextResourceDecoder.h" | 7 #include "core/html/parser/TextResourceDecoder.h" |
8 #include "platform/SharedBuffer.h" | 8 #include "platform/SharedBuffer.h" |
9 #include "wtf/text/StringBuilder.h" | 9 #include "wtf/text/StringBuilder.h" |
10 | 10 |
(...skipping 14 matching lines...) Expand all Loading... | |
25 m_decoder->setEncoding(chs, TextResourceDecoder::EncodingFromHTTPHeader); | 25 m_decoder->setEncoding(chs, TextResourceDecoder::EncodingFromHTTPHeader); |
26 } | 26 } |
27 | 27 |
28 String TextResource::encoding() const | 28 String TextResource::encoding() const |
29 { | 29 { |
30 return m_decoder->encoding().name(); | 30 return m_decoder->encoding().name(); |
31 } | 31 } |
32 | 32 |
33 String TextResource::decodedText() const | 33 String TextResource::decodedText() const |
34 { | 34 { |
35 size_t position = 0; | |
36 return streamDecodedText(&position); | |
37 } | |
38 | |
39 String TextResource::streamDecodedText(size_t* position) const | |
40 { | |
35 ASSERT(m_data); | 41 ASSERT(m_data); |
Yoav Weiss
2016/03/30 21:38:31
ASSERT that position is not null
Charlie Harrison
2016/03/31 03:59:59
Done.
| |
36 | 42 |
37 StringBuilder builder; | 43 StringBuilder builder; |
38 const char* data; | 44 const char* data; |
39 size_t position = 0; | 45 while (size_t length = m_data->getSomeData(data, *position)) { |
40 while (size_t length = m_data->getSomeData(data, position)) { | |
41 builder.append(m_decoder->decode(data, length)); | 46 builder.append(m_decoder->decode(data, length)); |
42 position += length; | 47 *position += length; |
43 } | 48 } |
44 builder.append(m_decoder->flush()); | 49 builder.append(m_decoder->flush()); |
50 | |
45 return builder.toString(); | 51 return builder.toString(); |
46 } | 52 } |
47 | 53 |
48 } // namespace blink | 54 } // namespace blink |
OLD | NEW |