1// Copyright (C) 2016 The Qt Company Ltd.
2// Copyright (C) 2020 Intel Corporation.
3// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
4// Qt-Security score:significant reason:compile-time-only
5
6#ifndef QSTRINGLITERAL_H
7#define QSTRINGLITERAL_H
8
9#include <QtCore/qarraydata.h>
10#include <QtCore/qarraydatapointer.h>
11
12#if 0
13#pragma qt_class(QStringLiteral)
14#endif
15
16QT_BEGIN_NAMESPACE
17
18// all our supported compilers support Unicode string literals,
19// even if their Q_COMPILER_UNICODE_STRING has been revoked due
20// to lacking stdlib support. But QStringLiteral only needs the
21// core language feature, so just use u"" here unconditionally:
22
23#define QT_UNICODE_LITERAL(str) u"" str
24
25using QStringPrivate = QArrayDataPointer<char16_t>;
26
27namespace QtPrivate {
28template <qsizetype N>
29Q_ALWAYS_INLINE static QStringPrivate qMakeStringPrivate(const char16_t (&literal)[N])
30{
31 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-const-cast)
32 auto str = const_cast<char16_t *>(literal);
33 return { nullptr, str, N - 1 };
34}
35}
36
37#define QStringLiteral(str) \
38 (QString(QtPrivate::qMakeStringPrivate(QT_UNICODE_LITERAL(str)))) \
39 /**/
40
41
42QT_END_NAMESPACE
43
44#endif // QSTRINGLITERAL_H
45

source code of qtbase/src/corelib/text/qstringliteral.h