Dokit
dev
v0.6.0
v0.5.8
v0.5.7
v0.5.6
v0.5.5
v0.5.4
v0.5.3
v0.5.2
v0.5.1
v0.5.0
v0.4.0
v0.3.0
v0.2.0
v0.1.2
v0.1.1
v0.1.0
User docs
Internal
Coverage
Internal development documentation
Toggle main menu visibility
Loading...
Searching...
No Matches
stringliterals_p.h
Go to the documentation of this file.
1
// SPDX-FileCopyrightText: 2022-2026 Paul Colby <git@colby.id.au>
2
// SPDX-License-Identifier: LGPL-3.0-or-later
3
4
/*!
5
* \file
6
* Declares the DOKIT_USE_STRINGLITERALS macro, and related functions.
7
*
8
* This is only required to support Qt versions earlier than 6.4, since Qt added string literal operators in that
9
* versions. This header can, and will, be removed entirely when Dokit no longer supports Qt versions earlier than 6.4.
10
*/
11
12
#ifndef DOKIT_STRINGLITERALS_P_H
13
#define DOKIT_STRINGLITERALS_P_H
14
15
/// \cond internal
16
17
/*!
18
* \def DOKIT_STRING_INDEX_TYPE
19
*
20
* Internal macro for matching the index type used by QString methods. Specifically, from Qt 6.0.0 onwards, QString
21
* (and related classes, and methods) use qsizetype for index positions, while Qt5 used int instead.
22
*
23
* \todo Remove this macro when Dokit no longer supports Qt5.
24
*/
25
26
/*!
27
* \def DOKIT_USE_STRINGLITERALS
28
*
29
* Internal macro for using either official Qt string literals (added in Qt 6.4), or our own equivalent ones for older
30
* Qt versions.
31
*
32
* \todo Remove this macro when Dokit no longer supports Qt versions earlier than 6.4.
33
*/
34
35
#include <QtGlobal>
36
37
// Although qsizetype was added in Qt 5.10.0, it wasn't used for QString indexes until 6.0.
38
#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
39
#define DOKIT_STRING_INDEX_TYPE int
40
#else
41
#define DOKIT_STRING_INDEX_TYPE qsizetype
42
#endif
43
44
#if (QT_VERSION < QT_VERSION_CHECK(6, 4, 0))
// String literals added in Qt 6.4.0.
45
46
namespace
_dokit {
47
inline
namespace
Literals {
48
inline
namespace
StringLiterals {
49
50
constexpr
inline
QLatin1Char
operator
""
_L1(
char
ch)
noexcept
51
{
52
return
QLatin1Char
(ch);
53
}
54
55
constexpr
inline
QLatin1String
/*View*/
operator
""
_L1(
const
char
*str,
size_t
size)
noexcept
56
{
57
//return {str, qsizetype(size)};
58
return
QLatin1String
(str,
DOKIT_STRING_INDEX_TYPE
(size));
59
}
60
61
inline
QString
operator
""
_s(
const
char16_t
*str,
size_t
size)
noexcept
62
{
63
//return QString(QStringPrivate(nullptr, const_cast<char16_t *>(str), qsizetype(size)));
64
return
QString::fromUtf16
(str,
DOKIT_STRING_INDEX_TYPE
(size));
65
}
66
67
} } }
// _dokit::Literals::StringLiterals
68
69
#define DOKIT_USE_STRINGLITERALS using namespace _dokit::Literals::StringLiterals;
70
#else
71
#define DOKIT_USE_STRINGLITERALS using namespace Qt::Literals::StringLiterals;
72
#endif
73
74
/// \endcond
75
76
#endif
// DOKIT_STRINGLITERALS_P_H
QLatin1Char
QLatin1Char::QLatin1Char
QLatin1Char(char c)
QLatin1String
QLatin1String::QLatin1String
QLatin1String()
QString
QString::fromUtf16
QString fromUtf16(const ushort *unicode, int size)
DOKIT_STRING_INDEX_TYPE
#define DOKIT_STRING_INDEX_TYPE
Internal macro for matching the index type used by QString methods.
Definition
stringliterals_p.h:41
dokit
dokit
src
stringliterals_p.h
Generated by
1.18.0