diff options
Diffstat (limited to 'src/qmldom/qqmldomstringdumper.cpp')
-rw-r--r-- | src/qmldom/qqmldomstringdumper.cpp | 83 |
1 files changed, 22 insertions, 61 deletions
diff --git a/src/qmldom/qqmldomstringdumper.cpp b/src/qmldom/qqmldomstringdumper.cpp index 1788d79d3d..4859614f77 100644 --- a/src/qmldom/qqmldomstringdumper.cpp +++ b/src/qmldom/qqmldomstringdumper.cpp @@ -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 + #include "qqmldomstringdumper_p.h" #include <QtCore/QDebug> @@ -68,7 +34,7 @@ namespace Dom { * \brief Helper class to accept eithe a string or a dumper (a function that writes to a sink) * * Using a Dumper as input parameter one always obtains a dumper (i.e. a - * std::function<void(std::function<void(QStringView)>)> , but can pass in any + * function_ref<void(function_ref<void(QStringView)>)> , but can pass in any * object accepted by QStringView, and it is automatically converted to a dumper. */ @@ -77,7 +43,7 @@ namespace Dom { * \brief Converts a dumper to a string * \param writer The dumper convert to a string */ -QString dumperToString(Dumper writer) +QString dumperToString(const Dumper &writer) { QString s; QTextStream d(&s); @@ -93,11 +59,11 @@ QString dumperToString(Dumper writer) * \param s The string to sink * \param options If quotes should be outputted around the string (defaults to yes) */ -void sinkEscaped(Sink sink, QStringView s, EscapeOptions options) { +void sinkEscaped(const Sink &sink, QStringView s, EscapeOptions options) { if (options == EscapeOptions::OuterQuotes) sink(u"\""); int it0=0; - for (int it = 0; it < s.length();++it) { + for (int it = 0; it < s.size();++it) { QChar c=s[it]; bool noslash = c != QLatin1Char('\\'); bool noquote = c != QLatin1Char('"'); @@ -118,7 +84,7 @@ void sinkEscaped(Sink sink, QStringView s, EscapeOptions options) { else Q_ASSERT(0); } - sink(s.mid(it0, s.length() - it0)); + sink(s.mid(it0, s.size() - it0)); if (options == EscapeOptions::OuterQuotes) sink(u"\""); } @@ -129,7 +95,7 @@ void sinkEscaped(Sink sink, QStringView s, EscapeOptions options) { * \param s the sink to write to * \param level the level to describe */ -void dumpErrorLevel(Sink s, ErrorLevel level) +void dumpErrorLevel(const Sink &s, ErrorLevel level) { switch (level) { case ErrorLevel::Debug: @@ -138,18 +104,9 @@ void dumpErrorLevel(Sink s, ErrorLevel level) case ErrorLevel::Info: s(u"Info"); break; - case ErrorLevel::Hint: - s(u"Hint"); - break; - case ErrorLevel::MaybeWarning: - s(u"MaybeWarn"); - break; case ErrorLevel::Warning: s(u"Warning"); break; - case ErrorLevel::MaybeError: - s(u"MaybeErr"); - break; case ErrorLevel::Error: s(u"Error"); break; @@ -160,7 +117,7 @@ void dumpErrorLevel(Sink s, ErrorLevel level) } -void dumperToQDebug(Dumper dumper, QDebug debug) +void dumperToQDebug(const Dumper &dumper, QDebug debug) { QDebug & d = debug.noquote().nospace(); dumper([&d](QStringView s){ @@ -174,21 +131,18 @@ void dumperToQDebug(Dumper dumper, QDebug debug) * \param level the error level of the message * \param dumper the dumper that writes a message */ -void dumperToQDebug(Dumper dumper, ErrorLevel level) +void dumperToQDebug(const Dumper &dumper, ErrorLevel level) { QDebug d = qDebug().noquote().nospace(); switch (level) { case ErrorLevel::Debug: break; case ErrorLevel::Info: - case ErrorLevel::Hint: d = qInfo().noquote().nospace(); break; - case ErrorLevel::MaybeWarning: case ErrorLevel::Warning: d = qWarning().noquote().nospace(); break; - case ErrorLevel::MaybeError: case ErrorLevel::Error: case ErrorLevel::Fatal: // should be handled differently (avoid allocations...), we try to catch them before ending up here d = qCritical().noquote().nospace(); @@ -203,13 +157,13 @@ void dumperToQDebug(Dumper dumper, ErrorLevel level) * \internal * \brief sinks the requested amount of spaces */ -void sinkIndent(Sink s, int indent) +void sinkIndent(const Sink &s, int indent) { if (indent > 0) { QStringView spaces = u" "; - while (indent > spaces.length()) { + while (indent > spaces.size()) { s(spaces); - indent -= spaces.length(); + indent -= spaces.size(); } s(spaces.left(indent)); } @@ -219,7 +173,7 @@ void sinkIndent(Sink s, int indent) * \internal * \brief sinks a neline and indents by the given amount */ -void sinkNewline(Sink s, int indent) +void sinkNewline(const Sink &s, int indent) { s(u"\n"); if (indent > 0) @@ -232,6 +186,13 @@ void sinkNewline(Sink s, int indent) * \brief A sink that ignores whatever it receives */ +QDebug operator<<(QDebug d, const Dumper &dumper) +{ + QDebug dd = d.noquote().nospace(); + dumper([&dd](QStringView s) { dd << s; }); + return d; +} + } // end namespace Dom } // end namespace QQmlJS |