Line data Source code
1 : // SPDX-FileCopyrightText: 2022-2025 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_USE_STRINGLITERALS
19 : *
20 : * Internal macro for using either official Qt string literals (added in Qt 6.4), or our own equivalent ones for older Qt
21 : * versions. This macro can, and will, be removed entirely when Dokit no longer supports Qt versions earlier than 6.4.
22 : */
23 :
24 : #include <QtGlobal>
25 : #if (QT_VERSION < QT_VERSION_CHECK(6, 4, 0))
26 :
27 : #if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
28 124430 : #define __DOKIT_DEST_SIZE_TYPE int
29 : #else
30 31682 : #define __DOKIT_DEST_SIZE_TYPE qsizetype
31 : #endif
32 :
33 : namespace _dokit {
34 : inline namespace Literals {
35 : inline namespace StringLiterals {
36 :
37 : constexpr inline QLatin1Char operator"" _L1(char ch) noexcept
38 12163 : {
39 12163 : return QLatin1Char(ch);
40 12163 : }
41 :
42 : constexpr inline QLatin1String/*View*/ operator"" _L1(const char *str, size_t size) noexcept
43 0 : {
44 0 : //return {str, qsizetype(size)};
45 0 : return QLatin1String(str, __DOKIT_DEST_SIZE_TYPE(size));
46 0 : }
47 :
48 : inline QString operator"" _s(const char16_t *str, size_t size) noexcept
49 156112 : {
50 : //return QString(QStringPrivate(nullptr, const_cast<char16_t *>(str), qsizetype(size)));
51 201564 : return QString::fromUtf16(str, __DOKIT_DEST_SIZE_TYPE(size));
52 156112 : }
53 :
54 : } } } // _dokit::Literals::StringLiterals
55 :
56 : #undef __DOKIT_DEST_SIZE_TYPE
57 :
58 : #define DOKIT_USE_STRINGLITERALS using namespace _dokit::Literals::StringLiterals;
59 : #else
60 : #define DOKIT_USE_STRINGLITERALS using namespace Qt::Literals::StringLiterals;
61 : #endif
62 :
63 : /// \endcond
64 :
65 : #endif // DOKIT_STRINGLITERALS_P_H
|