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// toAsciiLower, isAsciiUpper and caseCompareAscii are now moved here:
22#include <QtCore/qbytearrayalgorithms.h>
23
24#include <chrono>
25#include <limits.h>
26#include <time.h>
27
28QT_BEGIN_NAMESPACE
29
30namespace 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
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
113
114// Implemented in qarraydata.cpp:
115qsizetype Q_CORE_EXPORT Q_DECL_CONST_FUNCTION
116qCalculateBlockSize(qsizetype elementCount, qsizetype elementSize, qsizetype headerSize = 0) noexcept;
117CalculateGrowingBlockSizeResult Q_CORE_EXPORT Q_DECL_CONST_FUNCTION
118qCalculateGrowingBlockSize(qsizetype elementCount, qsizetype elementSize, qsizetype headerSize = 0) noexcept ;
119
120QT_END_NAMESPACE
121
122#endif // QTOOLS_P_H
constexpr char toOct(char32_t value) noexcept
Definition qtools_p.h:56
constexpr bool isAsciiDigit(char32_t c) noexcept
Definition qtools_p.h:71
constexpr int fromOct(char32_t c) noexcept
Definition qtools_p.h:66
constexpr bool isAsciiLower(char32_t c) noexcept
Definition qtools_p.h:76
constexpr bool isAsciiLetterOrNumber(char32_t c) noexcept
Definition qtools_p.h:85
constexpr int isAsciiPrintable(char32_t ch) noexcept
Definition qtools_p.h:95
constexpr char toHexUpper(char32_t value) noexcept
Definition qtools_p.h:31
constexpr int qt_lencmp(qsizetype lhs, qsizetype rhs) noexcept
Definition qtools_p.h:100
constexpr char toHexLower(char32_t value) noexcept
Definition qtools_p.h:36
constexpr bool isOctalDigit(char32_t c) noexcept
Definition qtools_p.h:61
constexpr bool isHexDigit(char32_t c) noexcept
Definition qtools_p.h:41
constexpr int fromHex(char32_t c) noexcept
Definition qtools_p.h:48
constexpr char toAsciiUpper(char ch) noexcept
Definition qtools_p.h:90