Dan Sinclair | 048afc6 | 2018-05-01 17:01:54 +0000 | [diff] [blame] | 1 | // Copyright 2018 PDFium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "testing/string_write_stream.h" |
Tom Sepez | 25f33d0 | 2021-01-29 01:58:51 +0000 | [diff] [blame] | 6 | |
Dan Sinclair | 048afc6 | 2018-05-01 17:01:54 +0000 | [diff] [blame] | 7 | #include "core/fxcrt/bytestring.h" |
| 8 | #include "core/fxcrt/widestring.h" |
Tom Sepez | 25f33d0 | 2021-01-29 01:58:51 +0000 | [diff] [blame] | 9 | #include "third_party/base/check.h" |
Dan Sinclair | 048afc6 | 2018-05-01 17:01:54 +0000 | [diff] [blame] | 10 | |
| 11 | StringWriteStream::StringWriteStream() = default; |
| 12 | |
| 13 | StringWriteStream::~StringWriteStream() = default; |
| 14 | |
| 15 | FX_FILESIZE StringWriteStream::GetSize() { |
| 16 | return stream_.tellp(); |
| 17 | } |
| 18 | |
| 19 | bool StringWriteStream::Flush() { |
| 20 | return true; |
| 21 | } |
| 22 | |
Lei Zhang | 59f7623 | 2018-11-15 20:22:59 +0000 | [diff] [blame] | 23 | bool StringWriteStream::WriteBlockAtOffset(const void* pData, |
| 24 | FX_FILESIZE offset, |
| 25 | size_t size) { |
Tom Sepez | 25f33d0 | 2021-01-29 01:58:51 +0000 | [diff] [blame] | 26 | DCHECK(offset == 0); |
Dan Sinclair | 048afc6 | 2018-05-01 17:01:54 +0000 | [diff] [blame] | 27 | stream_.write(static_cast<const char*>(pData), size); |
| 28 | return true; |
| 29 | } |
| 30 | |
Tom Sepez | c839ac7 | 2018-12-14 20:34:11 +0000 | [diff] [blame] | 31 | bool StringWriteStream::WriteString(ByteStringView str) { |
Dan Sinclair | 048afc6 | 2018-05-01 17:01:54 +0000 | [diff] [blame] | 32 | stream_.write(str.unterminated_c_str(), str.GetLength()); |
| 33 | return true; |
| 34 | } |