diff options
Diffstat (limited to 'src/qmldom/qqmldomstringdumper_p.h')
-rw-r--r-- | src/qmldom/qqmldomstringdumper_p.h | 74 |
1 files changed, 22 insertions, 52 deletions
diff --git a/src/qmldom/qqmldomstringdumper_p.h b/src/qmldom/qqmldomstringdumper_p.h index 7669bfc882..cf5c8e6483 100644 --- a/src/qmldom/qqmldomstringdumper_p.h +++ b/src/qmldom/qqmldomstringdumper_p.h @@ -1,40 +1,6 @@ -/**************************************************************************** -** -** Copyright (C) 2020 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtQml module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -**/ +// Copyright (C) 2020 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only + #ifndef DUMPER_H #define DUMPER_H @@ -51,6 +17,7 @@ #include "qqmldom_global.h" #include "qqmldomconstants_p.h" +#include "qqmldomfunctionref_p.h" #include <QtCore/QString> #include <QtCore/QStringView> @@ -63,8 +30,9 @@ QT_BEGIN_NAMESPACE namespace QQmlJS { namespace Dom { -using Sink = std::function<void(QStringView)>; -using DumperFunction = std::function<void(Sink)>; +using Sink = function_ref<void(QStringView)>; +using SinkF = std::function<void(QStringView)>; +using DumperFunction = std::function<void(const Sink &)>; class Dumper{ public: @@ -73,9 +41,9 @@ private: // We want to avoid the limit of one user conversion: // after doing (* -> QStringView) we cannot have QStringView -> Dumper, as it // would be the second user defined conversion. - // For a similar reason we have a template to accept function<void(Sink)> . + // For a similar reason we have a template to accept function_ref<void(Sink)> . // The end result is that void f(Dumper) can be called nicely, and avoid overloads: - // f(u"bla"), f(QLatin1String("bla")), f(QString()), f([](Sink s){...}),... + // f(u"bla"), f(QLatin1String("bla")), f(QString()), f([](const Sink &s){...}),... template <typename T> using if_compatible_dumper = typename std::enable_if<std::is_convertible<T, DumperFunction>::value, bool>::type; @@ -86,7 +54,7 @@ private: public: Dumper(QStringView s): - dumper([s](Sink sink){ sink(s); }) {} + dumper([s](const Sink &sink){ sink(s); }) {} Dumper(std::nullptr_t): Dumper(QStringView(nullptr)) {} @@ -95,13 +63,13 @@ public: Dumper(QStringView(string)) {} template <typename U, if_compatible_dumper<U> = true> - Dumper(U f): dumper(f) {} + Dumper(U f): dumper(std::move(f)) {} - void operator()(Sink s) { dumper(s); } + void operator()(const Sink &s) const { dumper(s); } }; template <typename T> -void sinkInt(Sink s, T i) { +void sinkInt(const Sink &s, T i) { const int BUFSIZE = 42; // safe up to 128 bits QChar buf[BUFSIZE]; int ibuf = BUFSIZE; @@ -128,22 +96,24 @@ void sinkInt(Sink s, T i) { s(QStringView(&buf[ibuf], BUFSIZE - ibuf -1)); } -QMLDOM_EXPORT QString dumperToString(Dumper writer); +QMLDOM_EXPORT QString dumperToString(const Dumper &writer); -QMLDOM_EXPORT void sinkEscaped(Sink sink, QStringView s, +QMLDOM_EXPORT void sinkEscaped(const Sink &sink, QStringView s, EscapeOptions options = EscapeOptions::OuterQuotes); inline void devNull(QStringView) {} -QMLDOM_EXPORT void sinkIndent(Sink s, int indent); +QMLDOM_EXPORT void sinkIndent(const Sink &s, int indent); + +QMLDOM_EXPORT void sinkNewline(const Sink &s, int indent = 0); -QMLDOM_EXPORT void sinkNewline(Sink s, int indent = 0); +QMLDOM_EXPORT void dumpErrorLevel(const Sink &s, ErrorLevel level); -QMLDOM_EXPORT void dumpErrorLevel(Sink s, ErrorLevel level); +QMLDOM_EXPORT void dumperToQDebug(const Dumper &dumper, QDebug debug); -QMLDOM_EXPORT void dumperToQDebug(Dumper dumper, QDebug debug); +QMLDOM_EXPORT void dumperToQDebug(const Dumper &dumper, ErrorLevel level = ErrorLevel::Debug); -QMLDOM_EXPORT void dumperToQDebug(Dumper dumper, ErrorLevel level = ErrorLevel::Debug); +QMLDOM_EXPORT QDebug operator<<(QDebug d, const Dumper &dumper); } // end namespace Dom } // end namespace QQmlJS |