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/fx_system.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 pdfium::make_span(reinterpret_cast<wchar_t*>(m_buffer.data()),
20 GetLength());
21}
22
23pdfium::span<const wchar_t> WideTextBuffer::GetWideSpan() const {
24 return pdfium::make_span(reinterpret_cast<const wchar_t*>(m_buffer.data()),
25 GetLength());
26}
27
28WideStringView WideTextBuffer::AsStringView() const {
29 return WideStringView(GetWideSpan());
30}
31
32WideString WideTextBuffer::MakeString() const {
33 return WideString(AsStringView());
34}
35
36void WideTextBuffer::AppendChar(wchar_t ch) {
37 pdfium::span<wchar_t> new_span = ExpandWideBuf(1);
38 new_span[0] = ch;
39}
40
41void WideTextBuffer::Delete(size_t start_index, size_t count) {
42 DeleteBuf(start_index * sizeof(wchar_t), count * sizeof(wchar_t));
43}
44
45void WideTextBuffer::AppendWideString(WideStringView str) {
46 AppendSpan(pdfium::as_bytes(str.span()));
47}
48
49WideTextBuffer& WideTextBuffer::operator<<(ByteStringView ascii) {
50 pdfium::span<wchar_t> new_span = ExpandWideBuf(ascii.GetLength());
51 for (size_t i = 0; i < ascii.GetLength(); ++i)
52 new_span[i] = ascii[i];
53 return *this;
54}
55
56WideTextBuffer& WideTextBuffer::operator<<(WideStringView str) {
57 AppendWideString(str);
58 return *this;
59}
60
61WideTextBuffer& WideTextBuffer::operator<<(const WideString& str) {
62 AppendWideString(str.AsStringView());
63 return *this;
64}
65
66WideTextBuffer& WideTextBuffer::operator<<(const wchar_t* lpsz) {
67 AppendWideString(WideStringView(lpsz));
68 return *this;
69}
70
71WideTextBuffer& WideTextBuffer::operator<<(const WideTextBuffer& buf) {
72 AppendWideString(buf.AsStringView());
73 return *this;
74}
75
76pdfium::span<wchar_t> WideTextBuffer::ExpandWideBuf(size_t char_count) {
77 size_t original_count = GetLength();
78 FX_SAFE_SIZE_T safe_bytes = char_count;
79 safe_bytes *= sizeof(wchar_t);
80 size_t bytes = safe_bytes.ValueOrDie();
81 ExpandBuf(bytes);
82 m_DataSize += bytes;
83 return GetWideSpan().subspan(original_count);
84}
85
86} // namespace fxcrt
void AppendSpan(pdfium::span< const uint8_t > span)
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