Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qqmldomstringdumper.cpp
Go to the documentation of this file.
1// Copyright (C) 2020 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
5#include <QtCore/QDebug>
6
8
9namespace QQmlJS {
10namespace Dom {
11
47{
48 QString s;
49 QTextStream d(&s);
50 writer([&d](QStringView s){ d << s; });
51 d.flush();
52 return s;
53}
54
63 if (options == EscapeOptions::OuterQuotes)
64 sink(u"\"");
65 int it0=0;
66 for (int it = 0; it < s.size();++it) {
67 QChar c=s[it];
68 bool noslash = c != QLatin1Char('\\');
69 bool noquote = c != QLatin1Char('"');
70 bool nonewline = c != QLatin1Char('\n');
71 bool noreturn = c != QLatin1Char('\r');
72 if (noslash && noquote && nonewline && noreturn)
73 continue;
74 sink(s.mid(it0, it - it0));
75 it0 = it + 1;
76 if (!noslash)
77 sink(u"\\\\");
78 else if (!noquote)
79 sink(u"\\\"");
80 else if (!nonewline)
81 sink(u"\\n");
82 else if (!noreturn)
83 sink(u"\\r");
84 else
85 Q_ASSERT(0);
86 }
87 sink(s.mid(it0, s.size() - it0));
88 if (options == EscapeOptions::OuterQuotes)
89 sink(u"\"");
90}
91
99{
100 switch (level) {
102 s(u"Debug");
103 break;
104 case ErrorLevel::Info:
105 s(u"Info");
106 break;
108 s(u"Warning");
109 break;
111 s(u"Error");
112 break;
114 s(u"Fatal");
115 break;
116 }
117
118}
119
120void dumperToQDebug(const Dumper &dumper, QDebug debug)
121{
122 QDebug & d = debug.noquote().nospace();
123 dumper([&d](QStringView s){
124 d << s;
125 });
126}
127
135{
136 QDebug d = qDebug().noquote().nospace();
137 switch (level) {
139 break;
140 case ErrorLevel::Info:
141 d = qInfo().noquote().nospace();
142 break;
144 d = qWarning().noquote().nospace();
145 break;
147 case ErrorLevel::Fatal: // should be handled differently (avoid allocations...), we try to catch them before ending up here
148 d = qCritical().noquote().nospace();
149 break;
150 }
151 dumper([&d](QStringView s){
152 d << s;
153 });
154}
155
160void sinkIndent(const Sink &s, int indent)
161{
162 if (indent > 0) {
163 QStringView spaces = u" ";
164 while (indent > spaces.size()) {
165 s(spaces);
166 indent -= spaces.size();
167 }
168 s(spaces.left(indent));
169 }
170}
171
176void sinkNewline(const Sink &s, int indent)
177{
178 s(u"\n");
179 if (indent > 0)
180 sinkIndent(s, indent);
181}
182
190{
191 QDebug dd = d.noquote().nospace();
192 dumper([&dd](QStringView s) { dd << s; });
193 return d;
194}
195
196} // end namespace Dom
197} // end namespace QQmlJS
198
\inmodule QtCore
\inmodule QtCore
A Sink is a function that accepts a QStringView as input.
qsizetype size() const
Definition qset.h:50
\inmodule QtCore
Definition qstringview.h:78
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
\inmodule QtCore
QSet< QString >::iterator it
void dumpErrorLevel(const Sink &s, ErrorLevel level)
Dumps a string describing the given error level (ErrorLevel::Error -> Error,...)
QDebug operator<<(QDebug d, AST::Node *n)
void sinkEscaped(const Sink &sink, QStringView s, EscapeOptions options)
dumps a string as quoted string (escaping things like quotes or newlines)
void sinkNewline(const Sink &s, int indent)
sinks a neline and indents by the given amount
void sinkIndent(const Sink &s, int indent)
sinks the requested amount of spaces
QString dumperToString(const Dumper &writer)
Converts a dumper to a string.
void dumperToQDebug(const Dumper &dumper, QDebug debug)
Combined button and popup list for selecting options.
#define qCritical
Definition qlogging.h:167
#define qInfo
Definition qlogging.h:165
#define qDebug
[1]
Definition qlogging.h:164
#define qWarning
Definition qlogging.h:166
GLenum GLuint GLint level
GLdouble s
[6]
Definition qopenglext.h:235
const GLubyte * c
GLsizei GLenum GLboolean sink
#define Q_ASSERT(cond)
Definition qrandom.cpp:47
\inmodule QtCore \reentrant
Definition qchar.h:18