qdebug.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/corelib/io/qdebug.cpp
Switch to Source codePreprocessed file
LineSourceCount
1-
2-
3-
4using QtMiscUtils::toHexUpper;-
5using QtMiscUtils::fromHex;-
6QDebug::~QDebug()-
7{-
8 if (!--stream->ref) {-
9 if (stream->space && stream->buffer.endsWith(QLatin1Char(' ')))-
10 stream->buffer.chop(1);-
11 if (stream->message_output) {-
12 qt_message_output(stream->type,-
13 stream->context,-
14 stream->buffer);-
15 }-
16 delete stream;-
17 }-
18}-
19-
20-
21-
22-
23void QDebug::putUcs4(uint ucs4)-
24{-
25 maybeQuote('\'');-
26 if (ucs4 < 0x20) {-
27 stream->ts << "\\x" << hex << ucs4 << reset;-
28 } else if (ucs4 < 0x80) {-
29 stream->ts << char(ucs4);-
30 } else {-
31 if (ucs4 < 0x10000)-
32 stream->ts << "\\u" << qSetFieldWidth(4);-
33 else-
34 stream->ts << "\\U" << qSetFieldWidth(8);-
35 stream->ts << hex << qSetPadChar(QLatin1Char('0')) << ucs4 << reset;-
36 }-
37 maybeQuote('\'');-
38}-
39-
40-
41-
42-
43static inline bool isPrintable(uint ucs4)-
44{ return QChar::isPrint(ucs4); }-
45static inline bool isPrintable(ushort uc)-
46{ return QChar::isPrint(uc); }-
47static inline bool isPrintable(uchar c)-
48{ return c >= ' ' && c < 0x7f; }-
49-
50template <typename Char>-
51static inline void putEscapedString(QTextStreamPrivate *d, const Char *begin, int length, bool isUnicode = true)-
52{-
53 QChar quote(QLatin1Char('"'));-
54 d->write(&quote, 1);-
55-
56 bool lastWasHexEscape = false;-
57 const Char *end = begin + length;-
58 for (const Char *p = begin; p != end; ++p) {-
59-
60 if (__builtin_expect(!!(lastWasHexEscape), false)) {-
61 if (fromHex(*p) != -1) {-
62-
63 QChar quotes[] = { QLatin1Char('"'), QLatin1Char('"') };-
64 d->write(quotes, 2);-
65 }-
66 lastWasHexEscape = false;-
67 }-
68-
69 if (sizeof(Char) == sizeof(QChar)) {-
70-
71 int runLength = 0;-
72 while (p + runLength != end &&-
73 isPrintable(p[runLength]) && p[runLength] != '\\' && p[runLength] != '"')-
74 ++runLength;-
75 if (runLength) {-
76 d->write(reinterpret_cast<const QChar *>(p), runLength);-
77 p += runLength - 1;-
78 continue;-
79 }-
80 } else if (isPrintable(*p) && *p != '\\' && *p != '"') {-
81 QChar c = QLatin1Char(*p);-
82 d->write(&c, 1);-
83 continue;-
84 }-
85-
86-
87 int buflen = 2;-
88 ushort buf[sizeof "\\U12345678" - 1];-
89 buf[0] = '\\';-
90-
91 switch (*p) {-
92 case '"':-
93 case '\\':-
94 buf[1] = *p;-
95 break;-
96 case '\b':-
97 buf[1] = 'b';-
98 break;-
99 case '\f':-
100 buf[1] = 'f';-
101 break;-
102 case '\n':-
103 buf[1] = 'n';-
104 break;-
105 case '\r':-
106 buf[1] = 'r';-
107 break;-
108 case '\t':-
109 buf[1] = 't';-
110 break;-
111 default:-
112 if (!isUnicode) {-
113-
114 buf[1] = 'x';-
115 buf[2] = toHexUpper(uchar(*p) >> 4);-
116 buf[3] = toHexUpper(uchar(*p));-
117 buflen = 4;-
118 lastWasHexEscape = true;-
119 break;-
120 }-
121 if (QChar::isHighSurrogate(*p)) {-
122 if ((p + 1) != end && QChar::isLowSurrogate(p[1])) {-
123-
124 uint ucs4 = QChar::surrogateToUcs4(*p, p[1]);-
125 if (isPrintable(ucs4)) {-
126 buf[0] = *p;-
127 buf[1] = p[1];-
128 buflen = 2;-
129 } else {-
130 buf[1] = 'U';-
131 buf[2] = '0';-
132 buf[3] = '0';-
133 buf[4] = toHexUpper(ucs4 >> 20);-
134 buf[5] = toHexUpper(ucs4 >> 16);-
135 buf[6] = toHexUpper(ucs4 >> 12);-
136 buf[7] = toHexUpper(ucs4 >> 8);-
137 buf[8] = toHexUpper(ucs4 >> 4);-
138 buf[9] = toHexUpper(ucs4);-
139 buflen = 10;-
140 }-
141 ++p;-
142 break;-
143 }-
144-
145 }-
146 buf[1] = 'u';-
147 buf[2] = toHexUpper(ushort(*p) >> 12);-
148 buf[3] = toHexUpper(ushort(*p) >> 8);-
149 buf[4] = toHexUpper(*p >> 4);-
150 buf[5] = toHexUpper(*p);-
151 buflen = 6;-
152 }-
153 d->write(reinterpret_cast<QChar *>(buf), buflen);-
154 }-
155-
156 d->write(&quote, 1);-
157}-
158-
159-
160-
161-
162-
163void QDebug::putString(const QChar *begin, size_t length)-
164{-
165 if (stream->testFlag(Stream::NoQuotes)) {-
166-
167-
168 stream->ts.d_ptr->putString(begin, int(length));-
169 } else {-
170-
171 QDebugStateSaver saver(*this);-
172 stream->ts.d_ptr->params.reset();-
173 putEscapedString(stream->ts.d_ptr.data(), reinterpret_cast<const ushort *>(begin), int(length));-
174 }-
175}-
176-
177-
178-
179-
180-
181void QDebug::putByteArray(const char *begin, size_t length, Latin1Content content)-
182{-
183 if (stream->testFlag(Stream::NoQuotes)) {-
184-
185-
186 QString string = content == ContainsLatin1 ? QString::fromLatin1(begin, int(length)) : QString::fromUtf8(begin, int(length));-
187 stream->ts.d_ptr->putString(string);-
188 } else {-
189-
190 QDebugStateSaver saver(*this);-
191 stream->ts.d_ptr->params.reset();-
192 putEscapedString(stream->ts.d_ptr.data(), reinterpret_cast<const uchar *>(begin),-
193 int(length), content == ContainsLatin1);-
194 }-
195}-
196QDebug &QDebug::resetFormat()-
197{-
198 stream->ts.reset();-
199 stream->space = true;-
200 if (stream->context.version > 1
stream->context.version > 1Description
TRUEevaluated 921 times by 12 tests
Evaluated by:
  • tst_QDebug
  • tst_QGuiVariant
  • tst_QLocalSocket
  • tst_QMetaObject
  • tst_QNetworkConfigurationManager
  • tst_QNetworkProxyFactory
  • tst_QNetworkReply
  • tst_QSslSocket
  • tst_QTcpServer
  • tst_QTcpSocket
  • tst_QUdpSocket
  • tst_QWidget
FALSEnever evaluated
)
0-921
201 stream->flags = 0;
executed 921 times by 12 tests: stream->flags = 0;
Executed by:
  • tst_QDebug
  • tst_QGuiVariant
  • tst_QLocalSocket
  • tst_QMetaObject
  • tst_QNetworkConfigurationManager
  • tst_QNetworkProxyFactory
  • tst_QNetworkReply
  • tst_QSslSocket
  • tst_QTcpServer
  • tst_QTcpSocket
  • tst_QUdpSocket
  • tst_QWidget
921
202 stream->setVerbosity(Stream::defaultVerbosityDefaultVerbosity);-
203 return
executed 921 times by 12 tests: return *this;
Executed by:
  • tst_QDebug
  • tst_QGuiVariant
  • tst_QLocalSocket
  • tst_QMetaObject
  • tst_QNetworkConfigurationManager
  • tst_QNetworkProxyFactory
  • tst_QNetworkReply
  • tst_QSslSocket
  • tst_QTcpServer
  • tst_QTcpSocket
  • tst_QUdpSocket
  • tst_QWidget
*this;
executed 921 times by 12 tests: return *this;
Executed by:
  • tst_QDebug
  • tst_QGuiVariant
  • tst_QLocalSocket
  • tst_QMetaObject
  • tst_QNetworkConfigurationManager
  • tst_QNetworkProxyFactory
  • tst_QNetworkReply
  • tst_QSslSocket
  • tst_QTcpServer
  • tst_QTcpSocket
  • tst_QUdpSocket
  • tst_QWidget
921
204}-
205class QDebugStateSaverPrivate-
206{-
207public:-
208 QDebugStateSaverPrivate(QDebug &dbg)-
209 : m_dbg(dbg),-
210 m_spaces(dbg.autoInsertSpaces()),-
211 m_flags(0),-
212 m_streamParams(dbg.stream->ts.d_ptr->params)-
213 {-
214 if (m_dbg.stream->context.version > 1)-
215 m_flags = m_dbg.stream->flags;-
216 }-
217 void restoreState()-
218 {-
219 const bool currentSpaces = m_dbg.autoInsertSpaces();-
220 if (currentSpaces && !m_spaces)-
221 if (m_dbg.stream->buffer.endsWith(QLatin1Char(' ')))-
222 m_dbg.stream->buffer.chop(1);-
223-
224 m_dbg.setAutoInsertSpaces(m_spaces);-
225 m_dbg.stream->ts.d_ptr->params = m_streamParams;-
226 if (m_dbg.stream->context.version > 1)-
227 m_dbg.stream->flags = m_flags;-
228-
229 if (!currentSpaces && m_spaces)-
230 m_dbg.stream->ts << ' ';-
231 }-
232-
233 QDebug &m_dbg;-
234-
235-
236 const bool m_spaces;-
237 int m_flags;-
238-
239-
240 const QTextStreamPrivate::Params m_streamParams;-
241};-
242QDebugStateSaver::QDebugStateSaver(QDebug &dbg)-
243 : d(new QDebugStateSaverPrivate(dbg))-
244{-
245}-
246-
247-
248-
249-
250-
251-
252-
253QDebugStateSaver::~QDebugStateSaver()-
254{-
255 d->restoreState();-
256}-
257void qt_QMetaEnum_flagDebugOperator(QDebug &debug, size_t sizeofT, int value)-
258{-
259 qt_QMetaEnum_flagDebugOperator<int>(debug, sizeofT, value);-
260}
executed 13 times by 2 tests: end of block
Executed by:
  • tst_QDebug
  • tst_QNetworkConfigurationManager
13
261-
262-
263-
264-
265-
266QDebug qt_QMetaEnum_debugOperator(QDebug &dbg, int value, const QMetaObject *meta, const char *name)-
267{-
268 QDebugStateSaver saver(dbg);-
269 QMetaEnum me = meta->enumerator(meta->indexOfEnumerator(name));-
270 const char *key = me.valueToKey(value);-
271 dbg.nospace() << meta->className() << "::" << name << '(';-
272 if (key)-
273 dbg << key;-
274 else-
275 dbg << value;-
276 dbg << ')';-
277 return dbg;-
278}-
279-
280QDebug qt_QMetaEnum_flagDebugOperator(QDebug &debug, quint64 value, const QMetaObject *meta, const char *name)-
281{-
282 QDebugStateSaver saver(debug);-
283 debug.resetFormat();-
284 debug.noquote();-
285 debug.nospace();-
286 debug << "QFlags<";-
287 const QMetaEnum me = meta->enumerator(meta->indexOfEnumerator(name));-
288 if (const char *scope = me.scope())-
289 debug << scope << "::";-
290 debug << me.name() << ">(" << me.valueToKeys(value) << ')';-
291 return debug;-
292}-
293-
294-
295-
Switch to Source codePreprocessed file

Generated by Squish Coco Non-Commercial 4.3.0-BETA-master-30-08-2018-4cb69e9