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
qtools_p.h
Go to the documentation of this file.
1
// Copyright (C) 2019 The Qt Company Ltd.
2
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
// Qt-Security score:critical reason:data-parser
4
5
#
ifndef
QTOOLS_P_H
6
#
define
QTOOLS_P_H
7
8
//
9
// W A R N I N G
10
// -------------
11
//
12
// This file is not part of the Qt API. It exists for the convenience
13
// of other Qt classes. This header file may change from version to
14
// version without notice, or even be removed.
15
//
16
// We mean it.
17
//
18
19
#
include
"QtCore/private/qglobal_p.h"
20
21
// toAsciiLower, isAsciiUpper and caseCompareAscii are now moved here:
22
#
include
<
QtCore
/
qbytearrayalgorithms
.
h
>
23
#
include
<
QtCore
/
private
/
qnumeric_p
.
h
>
24
25
#
include
<
cerrno
>
26
#
include
<
cstdlib
>
27
28
QT_BEGIN_NAMESPACE
29
30
namespace
QtMiscUtils
{
31
[[
nodiscard
]]
constexpr
inline
char
toHexUpper
(
char32_t
value)
noexcept
32
{
33
return
"0123456789ABCDEF"
[value & 0xF];
34
}
35
36
[[
nodiscard
]]
constexpr
inline
char
toHexLower
(
char32_t
value)
noexcept
37
{
38
return
"0123456789abcdef"
[value & 0xF];
39
}
40
41
[[
nodiscard
]]
constexpr
inline
bool
isHexDigit
(
char32_t
c)
noexcept
42
{
43
return
(c >=
'0'
&& c <=
'9'
)
44
|| (c >=
'A'
&& c <=
'F'
)
45
|| (c >=
'a'
&& c <=
'f'
);
46
}
47
48
[[
nodiscard
]]
constexpr
inline
int
fromHex
(
char32_t
c)
noexcept
49
{
50
return
((c >=
'0'
) && (c <=
'9'
)) ?
int
(c -
'0'
) :
51
((c >=
'A'
) && (c <=
'F'
)) ?
int
(c -
'A'
+ 10) :
52
((c >=
'a'
) && (c <=
'f'
)) ?
int
(c -
'a'
+ 10) :
53
/* otherwise */
-1;
54
}
55
56
[[
nodiscard
]]
constexpr
inline
char
toOct
(
char32_t
value)
noexcept
57
{
58
return
char
(
'0'
+ (value & 0x7));
59
}
60
61
[[
nodiscard
]]
constexpr
inline
bool
isOctalDigit
(
char32_t
c)
noexcept
62
{
63
return
c >=
'0'
&& c <=
'7'
;
64
}
65
66
[[
nodiscard
]]
constexpr
inline
int
fromOct
(
char32_t
c)
noexcept
67
{
68
return
isOctalDigit
(
c
)
?
int
(c -
'0'
) : -1;
69
}
70
71
[[
nodiscard
]]
constexpr
inline
bool
isAsciiDigit
(
char32_t
c)
noexcept
72
{
73
return
c >=
'0'
&& c <=
'9'
;
74
}
75
76
[[
nodiscard
]]
constexpr
inline
bool
isAsciiLower
(
char32_t
c)
noexcept
77
{
78
return
c >=
'a'
&& c <=
'z'
;
79
}
80
81
using
QtPrivate
::
isAsciiUpper
;
82
using
QtPrivate
::
toAsciiLower
;
83
using
QtPrivate
::
caseCompareAscii
;
84
85
[[
nodiscard
]]
constexpr
inline
bool
isAsciiLetterOrNumber
(
char32_t
c)
noexcept
86
{
87
return
isAsciiDigit
(
c
)
||
isAsciiLower
(
c
)
|| isAsciiUpper(c);
88
}
89
90
[[
nodiscard
]]
constexpr
inline
char
toAsciiUpper
(
char
ch)
noexcept
91
{
92
return
isAsciiLower
(
ch
)
? ch -
'a'
+
'A'
: ch;
93
}
94
95
[[
nodiscard
]]
constexpr
inline
int
isAsciiPrintable
(
char32_t
ch)
noexcept
96
{
97
return
ch >=
' '
&& ch < 0x7f;
98
}
99
100
[[
nodiscard
]]
constexpr
inline
int
qt_lencmp
(qsizetype lhs, qsizetype rhs)
noexcept
101
{
102
return
lhs == rhs ? 0 :
103
lhs > rhs ? 1 :
104
/* else */
-1 ;
105
}
106
}
// namespace QtMiscUtils
107
108
// Like POSIX 2024 reallocarray()
109
// https://pubs.opengroup.org/onlinepubs/9799919799/functions/realloc.html
110
inline
void
*
qt_reallocarray
(
void
*p, size_t n, size_t s)
111
{
112
if
(Q_UNLIKELY(mul_overflow(n, s, &n))) {
113
errno = ENOMEM;
114
return
nullptr
;
115
}
116
return
std::realloc(p, n);
117
}
118
119
struct
CalculateGrowingBlockSizeResult
120
{
121
qsizetype
size
;
122
qsizetype
elementCount
;
123
};
124
125
// Implemented in qarraydata.cpp:
126
qsizetype Q_CORE_EXPORT Q_DECL_CONST_FUNCTION
127
qCalculateBlockSize(qsizetype elementCount, qsizetype elementSize, qsizetype headerSize = 0)
noexcept
;
128
CalculateGrowingBlockSizeResult
Q_CORE_EXPORT Q_DECL_CONST_FUNCTION
129
qCalculateGrowingBlockSize(qsizetype elementCount, qsizetype elementSize, qsizetype headerSize = 0)
noexcept
;
130
131
QT_END_NAMESPACE
132
133
#
endif
// QTOOLS_P_H
QtMiscUtils
Definition
qtools_p.h:30
QtMiscUtils::toOct
constexpr char toOct(char32_t value) noexcept
Definition
qtools_p.h:56
QtMiscUtils::isAsciiDigit
constexpr bool isAsciiDigit(char32_t c) noexcept
Definition
qtools_p.h:71
QtMiscUtils::fromOct
constexpr int fromOct(char32_t c) noexcept
Definition
qtools_p.h:66
QtMiscUtils::isAsciiLower
constexpr bool isAsciiLower(char32_t c) noexcept
Definition
qtools_p.h:76
QtMiscUtils::isAsciiLetterOrNumber
constexpr bool isAsciiLetterOrNumber(char32_t c) noexcept
Definition
qtools_p.h:85
QtMiscUtils::isAsciiPrintable
constexpr int isAsciiPrintable(char32_t ch) noexcept
Definition
qtools_p.h:95
QtMiscUtils::toHexUpper
constexpr char toHexUpper(char32_t value) noexcept
Definition
qtools_p.h:31
QtMiscUtils::qt_lencmp
constexpr int qt_lencmp(qsizetype lhs, qsizetype rhs) noexcept
Definition
qtools_p.h:100
QtMiscUtils::toHexLower
constexpr char toHexLower(char32_t value) noexcept
Definition
qtools_p.h:36
QtMiscUtils::isOctalDigit
constexpr bool isOctalDigit(char32_t c) noexcept
Definition
qtools_p.h:61
QtMiscUtils::isHexDigit
constexpr bool isHexDigit(char32_t c) noexcept
Definition
qtools_p.h:41
QtMiscUtils::fromHex
constexpr int fromHex(char32_t c) noexcept
Definition
qtools_p.h:48
QtMiscUtils::toAsciiUpper
constexpr char toAsciiUpper(char ch) noexcept
Definition
qtools_p.h:90
qt_reallocarray
void * qt_reallocarray(void *p, size_t n, size_t s)
Definition
qtools_p.h:110
CalculateGrowingBlockSizeResult
Definition
qtools_p.h:120
CalculateGrowingBlockSizeResult::size
qsizetype size
Definition
qtools_p.h:121
CalculateGrowingBlockSizeResult::elementCount
qsizetype elementCount
Definition
qtools_p.h:122
qtbase
src
corelib
tools
qtools_p.h
Generated on
for Qt by
1.18.0