Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
Loading...
Searching...
No Matches
fx_string_testhelpers.cpp
Go to the documentation of this file.
1
// Copyright 2014 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
#
include
"testing/fx_string_testhelpers.h"
6
7
#
include
<
iomanip
>
8
#
include
<
ios
>
9
#
include
<
ostream
>
10
11
#
include
"core/fxcrt/cfx_datetime.h"
12
#
include
"core/fxcrt/check_op.h"
13
#
include
"core/fxcrt/compiler_specific.h"
14
#
include
"core/fxcrt/fx_string.h"
15
#
include
"core/fxcrt/span.h"
16
#
include
"fpdfsdk/cpdfsdk_helpers.h"
17
18
std
::ostream& operator<<(
std
::ostream& os,
const
CFX_DateTime
& dt) {
19
os << dt
.
GetYear
(
)
<<
"-"
<< std::to_string(dt
.
GetMonth
(
)
) <<
"-"
20
<< std::to_string(dt
.
GetDay
(
)
) <<
" "
<< std::to_string(dt
.
GetHour
(
)
)
21
<<
":"
<< std::to_string(dt
.
GetMinute
(
)
) <<
":"
22
<< std::to_string(dt
.
GetSecond
(
)
) <<
"."
23
<< std::to_string(dt
.
GetMillisecond
(
)
);
24
return
os;
25
}
26
27
std
::
vector
<
std
::
string
>
StringSplit
(
const
std
::string& str,
char
delimiter) {
28
std::vector<std::string> result;
29
size_t pos = 0;
30
while
(
true
) {
31
size_t found = str.find(delimiter, pos);
32
if
(found == std::string::npos)
33
break
;
34
35
result.push_back(str.substr(pos, found - pos));
36
pos = found + 1;
37
}
38
result.push_back(str.substr(pos));
39
return
result;
40
}
41
42
std
::string
GetPlatformString
(FPDF_WIDESTRING wstr) {
43
WideString
wide_string =
WideStringFromFPDFWideString
(
wstr
)
;
44
return
std
::string(wide_string
.
ToUTF8
(
)
.c_str());
45
}
46
47
std
::wstring
GetPlatformWString
(FPDF_WIDESTRING wstr) {
48
if
(!wstr)
49
return
std::wstring();
50
51
size_t characters = 0;
52
while
(wstr[characters])
53
++characters;
54
55
std
::wstring platform_string;
56
platform_string.reserve(characters);
57
for
(size_t i = 0; i < characters; ++i) {
58
const
unsigned
char
* ptr =
reinterpret_cast
<
const
unsigned
char
*>(&wstr[i]);
59
platform_string.push_back(ptr[0] + 256 * ptr[1]);
60
}
61
return
platform_string;
62
}
63
64
ScopedFPDFWideString
GetFPDFWideString
(
const
std
::wstring& wstr) {
65
size_t length =
sizeof
(uint16_t) * (wstr.size() + 1);
66
ScopedFPDFWideString
result(
static_cast
<FPDF_WCHAR*>(malloc(length)));
67
68
// SAFETY: length was argument to malloc above.
69
pdfium::span<uint8_t> result_span =
UNSAFE_BUFFERS
(
70
pdfium
::make_span(
reinterpret_cast
<uint8_t*>(result.get()), length));
71
72
size_t i = 0;
73
for
(
wchar_t
w : wstr) {
74
result_span[i++] = w & 0xff;
75
result_span[i++] = (w >> 8) & 0xff;
76
}
77
result_span[i++] = 0;
78
result_span[i] = 0;
79
return
result;
80
}
81
82
std
::
vector
<
FPDF_WCHAR
>
GetFPDFWideStringBuffer
(size_t length_bytes) {
83
DCHECK_EQ
(length_bytes %
sizeof
(FPDF_WCHAR), 0u);
84
return
std::vector<FPDF_WCHAR>(length_bytes /
sizeof
(FPDF_WCHAR));
85
}
DCHECK_EQ
#define DCHECK_EQ(x, y)
Definition
check_op.h:17
CFX_DateTime
Definition
cfx_datetime.h:15
CFX_DateTime::GetYear
int32_t GetYear() const
Definition
cfx_datetime.h:66
CFX_DateTime::GetSecond
uint8_t GetSecond() const
Definition
cfx_datetime.h:71
CFX_DateTime::GetHour
uint8_t GetHour() const
Definition
cfx_datetime.h:69
CFX_DateTime::GetDay
uint8_t GetDay() const
Definition
cfx_datetime.h:68
CFX_DateTime::GetMinute
uint8_t GetMinute() const
Definition
cfx_datetime.h:70
CFX_DateTime::GetMillisecond
uint16_t GetMillisecond() const
Definition
cfx_datetime.h:72
CFX_DateTime::GetMonth
uint8_t GetMonth() const
Definition
cfx_datetime.h:67
fxcrt::WideString::ToUTF8
ByteString ToUTF8() const
Definition
widestring.cpp:605
pdfium::CFDETextOutLargeBitmapTest
Definition
cfde_textout_unittest.cpp:117
UNSAFE_BUFFERS
#define UNSAFE_BUFFERS(...)
Definition
compiler_specific.h:95
WideStringFromFPDFWideString
UNSAFE_BUFFER_USAGE WideString WideStringFromFPDFWideString(FPDF_WIDESTRING wide_string)
Definition
cpdfsdk_helpers.cpp:244
ScopedFPDFWideString
std::unique_ptr< FPDF_WCHAR, pdfium::FreeDeleter > ScopedFPDFWideString
Definition
fx_string_testhelpers.h:31
GetFPDFWideStringBuffer
std::vector< FPDF_WCHAR > GetFPDFWideStringBuffer(size_t length_bytes)
Definition
fx_string_testhelpers.cpp:82
StringSplit
std::vector< std::string > StringSplit(const std::string &str, char delimiter)
Definition
fx_string_testhelpers.cpp:27
GetFPDFWideString
ScopedFPDFWideString GetFPDFWideString(const std::wstring &wstr)
Definition
fx_string_testhelpers.cpp:64
GetPlatformString
std::string GetPlatformString(FPDF_WIDESTRING wstr)
Definition
fx_string_testhelpers.cpp:42
GetPlatformWString
std::wstring GetPlatformWString(FPDF_WIDESTRING wstr)
Definition
fx_string_testhelpers.cpp:47
std
[33]
Definition
src_corelib_tools_qhash.cpp:421
WideString
fxcrt::WideString WideString
Definition
widestring.h:207
qtwebengine
src
3rdparty
chromium
third_party
pdfium
testing
fx_string_testhelpers.cpp
Generated on
for Qt by
1.18.0