Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
widetext_buffer.cpp
Go to the documentation of this file.
1// Copyright 2017 The PDFium Authors
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6
7#include "core/fxcrt/widetext_buffer.h"
8
9#include "core/fxcrt/fx_safe_types.h"
10#include "core/fxcrt/span_util.h"
11
12namespace fxcrt {
13
14size_t WideTextBuffer::GetLength() const {
15 return GetSize() / sizeof(wchar_t);
16}
17
18pdfium::span<wchar_t> WideTextBuffer::GetWideSpan() {
19 return reinterpret_span<wchar_t>(GetMutableSpan());
20}
21
22pdfium::span<const wchar_t> WideTextBuffer::GetWideSpan() const {
23 return reinterpret_span<const wchar_t>(GetSpan());
24}
25
26WideStringView WideTextBuffer::AsStringView() const {
27 return WideStringView(GetWideSpan());
28}
29
30WideString WideTextBuffer::MakeString() const {
31 return WideString(AsStringView());
32}
33
34void WideTextBuffer::AppendChar(wchar_t ch) {
35 pdfium::span<wchar_t> new_span = ExpandWideBuf(1);
36 new_span[0] = ch;
37}
38
39void WideTextBuffer::Delete(size_t start_index, size_t count) {
40 DeleteBuf(start_index * sizeof(wchar_t), count * sizeof(wchar_t));
41}
42
43void WideTextBuffer::AppendWideString(WideStringView str) {
44 AppendSpan(pdfium::as_bytes(str.span()));
45}
46
47WideTextBuffer& WideTextBuffer::operator<<(ByteStringView ascii) {
48 pdfium::span<wchar_t> new_span = ExpandWideBuf(ascii.GetLength());
49 for (size_t i = 0; i < ascii.GetLength(); ++i)
50 new_span[i] = ascii[i];
51 return *this;
52}
53
54WideTextBuffer& WideTextBuffer::operator<<(WideStringView str) {
55 AppendWideString(str);
56 return *this;
57}
58
59WideTextBuffer& WideTextBuffer::operator<<(const WideString& str) {
60 AppendWideString(str.AsStringView());
61 return *this;
62}
63
64WideTextBuffer& WideTextBuffer::operator<<(const wchar_t* lpsz) {
65 AppendWideString(WideStringView(lpsz));
66 return *this;
67}
68
69WideTextBuffer& WideTextBuffer::operator<<(const WideTextBuffer& buf) {
70 AppendWideString(buf.AsStringView());
71 return *this;
72}
73
74pdfium::span<wchar_t> WideTextBuffer::ExpandWideBuf(size_t char_count) {
75 size_t original_count = GetLength();
76 FX_SAFE_SIZE_T safe_bytes = char_count;
77 safe_bytes *= sizeof(wchar_t);
78 size_t bytes = safe_bytes.ValueOrDie();
79 ExpandBuf(bytes);
80 m_DataSize += bytes;
81 return GetWideSpan().subspan(original_count);
82}
83
84} // namespace fxcrt
pdfium::span< wchar_t > GetWideSpan()
void AppendChar(wchar_t wch)
void Delete(size_t start_index, size_t count)
pdfium::span< const wchar_t > GetWideSpan() const
WideString MakeString() const
WideStringView AsStringView() const
size_t GetLength() const override
StringViewTemplate< wchar_t > WideStringView
StringViewTemplate< char > ByteStringView