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
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#include <chrono>
22#include <limits.h>
23#include <time.h>
24
25QT_BEGIN_NAMESPACE
26
27namespace QtMiscUtils {
28[[nodiscard]] constexpr inline char toHexUpper(char32_t value) noexcept
29{
30 return "0123456789ABCDEF"[value & 0xF];
31}
32
33[[nodiscard]] constexpr inline char toHexLower(char32_t value) noexcept
34{
35 return "0123456789abcdef"[value & 0xF];
36}
37
38[[nodiscard]] constexpr inline bool isHexDigit(char32_t c) noexcept
39{
40 return (c >= '0' && c <= '9')
41 || (c >= 'A' && c <= 'F')
42 || (c >= 'a' && c <= 'f');
43}
44
45[[nodiscard]] constexpr inline int fromHex(char32_t c) noexcept
46{
47 return ((c >= '0') && (c <= '9')) ? int(c - '0') :
48 ((c >= 'A') && (c <= 'F')) ? int(c - 'A' + 10) :
49 ((c >= 'a') && (c <= 'f')) ? int(c - 'a' + 10) :
50 /* otherwise */ -1;
51}
52
53[[nodiscard]] constexpr inline char toOct(char32_t value) noexcept
54{
55 return char('0' + (value & 0x7));
56}
57
58[[nodiscard]] constexpr inline bool isOctalDigit(char32_t c) noexcept
59{
60 return c >= '0' && c <= '7';
61}
62
63[[nodiscard]] constexpr inline int fromOct(char32_t c) noexcept
64{
65 return isOctalDigit(c) ? int(c - '0') : -1;
66}
67
68[[nodiscard]] constexpr inline bool isAsciiDigit(char32_t c) noexcept
69{
70 return c >= '0' && c <= '9';
71}
72
73[[nodiscard]] constexpr inline bool isAsciiUpper(char32_t c) noexcept
74{
75 return c >= 'A' && c <= 'Z';
76}
77
78[[nodiscard]] constexpr inline bool isAsciiLower(char32_t c) noexcept
79{
80 return c >= 'a' && c <= 'z';
81}
82
83[[nodiscard]] constexpr inline bool isAsciiLetterOrNumber(char32_t c) noexcept
84{
86}
87
88[[nodiscard]] constexpr inline char toAsciiLower(char ch) noexcept
89{
90 return isAsciiUpper(ch) ? ch - 'A' + 'a' : ch;
91}
92
93[[nodiscard]] constexpr inline char toAsciiUpper(char ch) noexcept
94{
95 return isAsciiLower(ch) ? ch - 'a' + 'A' : ch;
96}
97
98[[nodiscard]] constexpr inline int caseCompareAscii(char lhs, char rhs) noexcept
99{
100 const char lhsLower = QtMiscUtils::toAsciiLower(lhs);
101 const char rhsLower = QtMiscUtils::toAsciiLower(rhs);
102 return int(uchar(lhsLower)) - int(uchar(rhsLower));
103}
104
105[[nodiscard]] constexpr inline int isAsciiPrintable(char32_t ch) noexcept
106{
107 return ch >= ' ' && ch < 0x7f;
108}
109
110[[nodiscard]] constexpr inline int qt_lencmp(qsizetype lhs, qsizetype rhs) noexcept
111{
112 return lhs == rhs ? 0 :
113 lhs > rhs ? 1 :
114 /* else */ -1 ;
115}
116
117} // namespace QtMiscUtils
118
124
125// Implemented in qarraydata.cpp:
126qsizetype Q_CORE_EXPORT Q_DECL_CONST_FUNCTION
127qCalculateBlockSize(qsizetype elementCount, qsizetype elementSize, qsizetype headerSize = 0) noexcept;
128CalculateGrowingBlockSizeResult Q_CORE_EXPORT Q_DECL_CONST_FUNCTION
129qCalculateGrowingBlockSize(qsizetype elementCount, qsizetype elementSize, qsizetype headerSize = 0) noexcept ;
130
131QT_END_NAMESPACE
132
133#endif // QTOOLS_P_H
constexpr char toOct(char32_t value) noexcept
Definition qtools_p.h:53
constexpr bool isAsciiDigit(char32_t c) noexcept
Definition qtools_p.h:68
constexpr int fromOct(char32_t c) noexcept
Definition qtools_p.h:63
constexpr int caseCompareAscii(char lhs, char rhs) noexcept
Definition qtools_p.h:98
constexpr bool isAsciiLower(char32_t c) noexcept
Definition qtools_p.h:78
constexpr bool isAsciiLetterOrNumber(char32_t c) noexcept
Definition qtools_p.h:83
constexpr bool isAsciiUpper(char32_t c) noexcept
Definition qtools_p.h:73
constexpr int isAsciiPrintable(char32_t ch) noexcept
Definition qtools_p.h:105
constexpr char toHexUpper(char32_t value) noexcept
Definition qtools_p.h:28
constexpr int qt_lencmp(qsizetype lhs, qsizetype rhs) noexcept
Definition qtools_p.h:110
constexpr char toHexLower(char32_t value) noexcept
Definition qtools_p.h:33
constexpr bool isOctalDigit(char32_t c) noexcept
Definition qtools_p.h:58
constexpr bool isHexDigit(char32_t c) noexcept
Definition qtools_p.h:38
constexpr int fromHex(char32_t c) noexcept
Definition qtools_p.h:45
constexpr char toAsciiUpper(char ch) noexcept
Definition qtools_p.h:93
constexpr char toAsciiLower(char ch) noexcept
Definition qtools_p.h:88