Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/corelib/json/qjsonparser.cpp |
Source code | Switch to Preprocessed file |
Line | Source | Count | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | /**************************************************************************** | - | ||||||||||||||||||
2 | ** | - | ||||||||||||||||||
3 | ** Copyright (C) 2015 The Qt Company Ltd. | - | ||||||||||||||||||
4 | ** Copyright (C) 2013 Intel Corporation | - | ||||||||||||||||||
5 | ** Contact: http://www.qt.io/licensing/ | - | ||||||||||||||||||
6 | ** | - | ||||||||||||||||||
7 | ** This file is part of the QtCore module of the Qt Toolkit. | - | ||||||||||||||||||
8 | ** | - | ||||||||||||||||||
9 | ** $QT_BEGIN_LICENSE:LGPL21$ | - | ||||||||||||||||||
10 | ** Commercial License Usage | - | ||||||||||||||||||
11 | ** Licensees holding valid commercial Qt licenses may use this file in | - | ||||||||||||||||||
12 | ** accordance with the commercial license agreement provided with the | - | ||||||||||||||||||
13 | ** Software or, alternatively, in accordance with the terms contained in | - | ||||||||||||||||||
14 | ** a written agreement between you and The Qt Company. For licensing terms | - | ||||||||||||||||||
15 | ** and conditions see http://www.qt.io/terms-conditions. For further | - | ||||||||||||||||||
16 | ** information use the contact form at http://www.qt.io/contact-us. | - | ||||||||||||||||||
17 | ** | - | ||||||||||||||||||
18 | ** GNU Lesser General Public License Usage | - | ||||||||||||||||||
19 | ** Alternatively, this file may be used under the terms of the GNU Lesser | - | ||||||||||||||||||
20 | ** General Public License version 2.1 or version 3 as published by the Free | - | ||||||||||||||||||
21 | ** Software Foundation and appearing in the file LICENSE.LGPLv21 and | - | ||||||||||||||||||
22 | ** LICENSE.LGPLv3 included in the packaging of this file. Please review the | - | ||||||||||||||||||
23 | ** following information to ensure the GNU Lesser General Public License | - | ||||||||||||||||||
24 | ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and | - | ||||||||||||||||||
25 | ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | - | ||||||||||||||||||
26 | ** | - | ||||||||||||||||||
27 | ** As a special exception, The Qt Company gives you certain additional | - | ||||||||||||||||||
28 | ** rights. These rights are described in The Qt Company LGPL Exception | - | ||||||||||||||||||
29 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | - | ||||||||||||||||||
30 | ** | - | ||||||||||||||||||
31 | ** $QT_END_LICENSE$ | - | ||||||||||||||||||
32 | ** | - | ||||||||||||||||||
33 | ****************************************************************************/ | - | ||||||||||||||||||
34 | - | |||||||||||||||||||
35 | #ifndef QT_BOOTSTRAPPED | - | ||||||||||||||||||
36 | #include <qcoreapplication.h> | - | ||||||||||||||||||
37 | #endif | - | ||||||||||||||||||
38 | #include <qdebug.h> | - | ||||||||||||||||||
39 | #include "qjsonparser_p.h" | - | ||||||||||||||||||
40 | #include "qjson_p.h" | - | ||||||||||||||||||
41 | #include "private/qutfcodec_p.h" | - | ||||||||||||||||||
42 | - | |||||||||||||||||||
43 | //#define PARSER_DEBUG | - | ||||||||||||||||||
44 | #ifdef PARSER_DEBUG | - | ||||||||||||||||||
45 | static int indent = 0; | - | ||||||||||||||||||
46 | #define BEGIN qDebug() << QByteArray(4*indent++, ' ').constData() << "pos=" << current | - | ||||||||||||||||||
47 | #define END --indent | - | ||||||||||||||||||
48 | #define DEBUG qDebug() << QByteArray(4*indent, ' ').constData() | - | ||||||||||||||||||
49 | #else | - | ||||||||||||||||||
50 | #define BEGIN if (1) ; else qDebug() | - | ||||||||||||||||||
51 | #define END do {} while (0) | - | ||||||||||||||||||
52 | #define DEBUG if (1) ; else qDebug() | - | ||||||||||||||||||
53 | #endif | - | ||||||||||||||||||
54 | - | |||||||||||||||||||
55 | static const int nestingLimit = 1024; | - | ||||||||||||||||||
56 | - | |||||||||||||||||||
57 | QT_BEGIN_NAMESPACE | - | ||||||||||||||||||
58 | - | |||||||||||||||||||
59 | // error strings for the JSON parser | - | ||||||||||||||||||
60 | #define JSONERR_OK QT_TRANSLATE_NOOP("QJsonParseError", "no error occurred") | - | ||||||||||||||||||
61 | #define JSONERR_UNTERM_OBJ QT_TRANSLATE_NOOP("QJsonParseError", "unterminated object") | - | ||||||||||||||||||
62 | #define JSONERR_MISS_NSEP QT_TRANSLATE_NOOP("QJsonParseError", "missing name separator") | - | ||||||||||||||||||
63 | #define JSONERR_UNTERM_AR QT_TRANSLATE_NOOP("QJsonParseError", "unterminated array") | - | ||||||||||||||||||
64 | #define JSONERR_MISS_VSEP QT_TRANSLATE_NOOP("QJsonParseError", "missing value separator") | - | ||||||||||||||||||
65 | #define JSONERR_ILLEGAL_VAL QT_TRANSLATE_NOOP("QJsonParseError", "illegal value") | - | ||||||||||||||||||
66 | #define JSONERR_END_OF_NUM QT_TRANSLATE_NOOP("QJsonParseError", "invalid termination by number") | - | ||||||||||||||||||
67 | #define JSONERR_ILLEGAL_NUM QT_TRANSLATE_NOOP("QJsonParseError", "illegal number") | - | ||||||||||||||||||
68 | #define JSONERR_STR_ESC_SEQ QT_TRANSLATE_NOOP("QJsonParseError", "invalid escape sequence") | - | ||||||||||||||||||
69 | #define JSONERR_STR_UTF8 QT_TRANSLATE_NOOP("QJsonParseError", "invalid UTF8 string") | - | ||||||||||||||||||
70 | #define JSONERR_UTERM_STR QT_TRANSLATE_NOOP("QJsonParseError", "unterminated string") | - | ||||||||||||||||||
71 | #define JSONERR_MISS_OBJ QT_TRANSLATE_NOOP("QJsonParseError", "object is missing after a comma") | - | ||||||||||||||||||
72 | #define JSONERR_DEEP_NEST QT_TRANSLATE_NOOP("QJsonParseError", "too deeply nested document") | - | ||||||||||||||||||
73 | #define JSONERR_DOC_LARGE QT_TRANSLATE_NOOP("QJsonParseError", "too large document") | - | ||||||||||||||||||
74 | #define JSONERR_GARBAGEEND QT_TRANSLATE_NOOP("QJsonParseError", "garbage at the end of the document") | - | ||||||||||||||||||
75 | - | |||||||||||||||||||
76 | /*! | - | ||||||||||||||||||
77 | \class QJsonParseError | - | ||||||||||||||||||
78 | \inmodule QtCore | - | ||||||||||||||||||
79 | \ingroup json | - | ||||||||||||||||||
80 | \ingroup shared | - | ||||||||||||||||||
81 | \reentrant | - | ||||||||||||||||||
82 | \since 5.0 | - | ||||||||||||||||||
83 | - | |||||||||||||||||||
84 | \brief The QJsonParseError class is used to report errors during JSON parsing. | - | ||||||||||||||||||
85 | - | |||||||||||||||||||
86 | \sa {JSON Support in Qt}, {JSON Save Game Example} | - | ||||||||||||||||||
87 | */ | - | ||||||||||||||||||
88 | - | |||||||||||||||||||
89 | /*! | - | ||||||||||||||||||
90 | \enum QJsonParseError::ParseError | - | ||||||||||||||||||
91 | - | |||||||||||||||||||
92 | This enum describes the type of error that occurred during the parsing of a JSON document. | - | ||||||||||||||||||
93 | - | |||||||||||||||||||
94 | \value NoError No error occurred | - | ||||||||||||||||||
95 | \value UnterminatedObject An object is not correctly terminated with a closing curly bracket | - | ||||||||||||||||||
96 | \value MissingNameSeparator A comma separating different items is missing | - | ||||||||||||||||||
97 | \value UnterminatedArray The array is not correctly terminated with a closing square bracket | - | ||||||||||||||||||
98 | \value MissingValueSeparator A colon separating keys from values inside objects is missing | - | ||||||||||||||||||
99 | \value IllegalValue The value is illegal | - | ||||||||||||||||||
100 | \value TerminationByNumber The input stream ended while parsing a number | - | ||||||||||||||||||
101 | \value IllegalNumber The number is not well formed | - | ||||||||||||||||||
102 | \value IllegalEscapeSequence An illegal escape sequence occurred in the input | - | ||||||||||||||||||
103 | \value IllegalUTF8String An illegal UTF8 sequence occurred in the input | - | ||||||||||||||||||
104 | \value UnterminatedString A string wasn't terminated with a quote | - | ||||||||||||||||||
105 | \value MissingObject An object was expected but couldn't be found | - | ||||||||||||||||||
106 | \value DeepNesting The JSON document is too deeply nested for the parser to parse it | - | ||||||||||||||||||
107 | \value DocumentTooLarge The JSON document is too large for the parser to parse it | - | ||||||||||||||||||
108 | \value GarbageAtEnd The parsed document contains additional garbage characters at the end | - | ||||||||||||||||||
109 | - | |||||||||||||||||||
110 | */ | - | ||||||||||||||||||
111 | - | |||||||||||||||||||
112 | /*! | - | ||||||||||||||||||
113 | \variable QJsonParseError::error | - | ||||||||||||||||||
114 | - | |||||||||||||||||||
115 | Contains the type of the parse error. Is equal to QJsonParseError::NoError if the document | - | ||||||||||||||||||
116 | was parsed correctly. | - | ||||||||||||||||||
117 | - | |||||||||||||||||||
118 | \sa ParseError, errorString() | - | ||||||||||||||||||
119 | */ | - | ||||||||||||||||||
120 | - | |||||||||||||||||||
121 | - | |||||||||||||||||||
122 | /*! | - | ||||||||||||||||||
123 | \variable QJsonParseError::offset | - | ||||||||||||||||||
124 | - | |||||||||||||||||||
125 | Contains the offset in the input string where the parse error occurred. | - | ||||||||||||||||||
126 | - | |||||||||||||||||||
127 | \sa error, errorString() | - | ||||||||||||||||||
128 | */ | - | ||||||||||||||||||
129 | - | |||||||||||||||||||
130 | /*! | - | ||||||||||||||||||
131 | Returns the human-readable message appropriate to the reported JSON parsing error. | - | ||||||||||||||||||
132 | - | |||||||||||||||||||
133 | \sa error | - | ||||||||||||||||||
134 | */ | - | ||||||||||||||||||
135 | QString QJsonParseError::errorString() const | - | ||||||||||||||||||
136 | { | - | ||||||||||||||||||
137 | const char *sz = ""; | - | ||||||||||||||||||
138 | switch (error) { | - | ||||||||||||||||||
139 | case NoError: never executed: case NoError: | 0 | ||||||||||||||||||
140 | sz = JSONERR_OK; | - | ||||||||||||||||||
141 | break; never executed: break; | 0 | ||||||||||||||||||
142 | case UnterminatedObject: never executed: case UnterminatedObject: | 0 | ||||||||||||||||||
143 | sz = JSONERR_UNTERM_OBJ; | - | ||||||||||||||||||
144 | break; never executed: break; | 0 | ||||||||||||||||||
145 | case MissingNameSeparator: never executed: case MissingNameSeparator: | 0 | ||||||||||||||||||
146 | sz = JSONERR_MISS_NSEP; | - | ||||||||||||||||||
147 | break; never executed: break; | 0 | ||||||||||||||||||
148 | case UnterminatedArray: never executed: case UnterminatedArray: | 0 | ||||||||||||||||||
149 | sz = JSONERR_UNTERM_AR; | - | ||||||||||||||||||
150 | break; never executed: break; | 0 | ||||||||||||||||||
151 | case MissingValueSeparator: never executed: case MissingValueSeparator: | 0 | ||||||||||||||||||
152 | sz = JSONERR_MISS_VSEP; | - | ||||||||||||||||||
153 | break; never executed: break; | 0 | ||||||||||||||||||
154 | case IllegalValue: never executed: case IllegalValue: | 0 | ||||||||||||||||||
155 | sz = JSONERR_ILLEGAL_VAL; | - | ||||||||||||||||||
156 | break; never executed: break; | 0 | ||||||||||||||||||
157 | case TerminationByNumber: never executed: case TerminationByNumber: | 0 | ||||||||||||||||||
158 | sz = JSONERR_END_OF_NUM; | - | ||||||||||||||||||
159 | break; never executed: break; | 0 | ||||||||||||||||||
160 | case IllegalNumber: never executed: case IllegalNumber: | 0 | ||||||||||||||||||
161 | sz = JSONERR_ILLEGAL_NUM; | - | ||||||||||||||||||
162 | break; never executed: break; | 0 | ||||||||||||||||||
163 | case IllegalEscapeSequence: never executed: case IllegalEscapeSequence: | 0 | ||||||||||||||||||
164 | sz = JSONERR_STR_ESC_SEQ; | - | ||||||||||||||||||
165 | break; never executed: break; | 0 | ||||||||||||||||||
166 | case IllegalUTF8String: never executed: case IllegalUTF8String: | 0 | ||||||||||||||||||
167 | sz = JSONERR_STR_UTF8; | - | ||||||||||||||||||
168 | break; never executed: break; | 0 | ||||||||||||||||||
169 | case UnterminatedString: never executed: case UnterminatedString: | 0 | ||||||||||||||||||
170 | sz = JSONERR_UTERM_STR; | - | ||||||||||||||||||
171 | break; never executed: break; | 0 | ||||||||||||||||||
172 | case MissingObject: never executed: case MissingObject: | 0 | ||||||||||||||||||
173 | sz = JSONERR_MISS_OBJ; | - | ||||||||||||||||||
174 | break; never executed: break; | 0 | ||||||||||||||||||
175 | case DeepNesting: never executed: case DeepNesting: | 0 | ||||||||||||||||||
176 | sz = JSONERR_DEEP_NEST; | - | ||||||||||||||||||
177 | break; never executed: break; | 0 | ||||||||||||||||||
178 | case DocumentTooLarge: never executed: case DocumentTooLarge: | 0 | ||||||||||||||||||
179 | sz = JSONERR_DOC_LARGE; | - | ||||||||||||||||||
180 | break; never executed: break; | 0 | ||||||||||||||||||
181 | case GarbageAtEnd: never executed: case GarbageAtEnd: | 0 | ||||||||||||||||||
182 | sz = JSONERR_GARBAGEEND; | - | ||||||||||||||||||
183 | break; never executed: break; | 0 | ||||||||||||||||||
184 | } | - | ||||||||||||||||||
185 | #ifndef QT_BOOTSTRAPPED | - | ||||||||||||||||||
186 | return QCoreApplication::translate("QJsonParseError", sz); never executed: return QCoreApplication::translate("QJsonParseError", sz); | 0 | ||||||||||||||||||
187 | #else | - | ||||||||||||||||||
188 | return QLatin1String(sz); | - | ||||||||||||||||||
189 | #endif | - | ||||||||||||||||||
190 | } | - | ||||||||||||||||||
191 | - | |||||||||||||||||||
192 | using namespace QJsonPrivate; | - | ||||||||||||||||||
193 | - | |||||||||||||||||||
194 | Parser::Parser(const char *json, int length) | - | ||||||||||||||||||
195 | : head(json), json(json), data(0), dataLength(0), current(0), nestingLevel(0), lastError(QJsonParseError::NoError) | - | ||||||||||||||||||
196 | { | - | ||||||||||||||||||
197 | end = json + length; | - | ||||||||||||||||||
198 | } executed 10 times by 4 tests: end of block Executed by:
| 10 | ||||||||||||||||||
199 | - | |||||||||||||||||||
200 | - | |||||||||||||||||||
201 | - | |||||||||||||||||||
202 | /* | - | ||||||||||||||||||
203 | - | |||||||||||||||||||
204 | begin-array = ws %x5B ws ; [ left square bracket | - | ||||||||||||||||||
205 | - | |||||||||||||||||||
206 | begin-object = ws %x7B ws ; { left curly bracket | - | ||||||||||||||||||
207 | - | |||||||||||||||||||
208 | end-array = ws %x5D ws ; ] right square bracket | - | ||||||||||||||||||
209 | - | |||||||||||||||||||
210 | end-object = ws %x7D ws ; } right curly bracket | - | ||||||||||||||||||
211 | - | |||||||||||||||||||
212 | name-separator = ws %x3A ws ; : colon | - | ||||||||||||||||||
213 | - | |||||||||||||||||||
214 | value-separator = ws %x2C ws ; , comma | - | ||||||||||||||||||
215 | - | |||||||||||||||||||
216 | Insignificant whitespace is allowed before or after any of the six | - | ||||||||||||||||||
217 | structural characters. | - | ||||||||||||||||||
218 | - | |||||||||||||||||||
219 | ws = *( | - | ||||||||||||||||||
220 | %x20 / ; Space | - | ||||||||||||||||||
221 | %x09 / ; Horizontal tab | - | ||||||||||||||||||
222 | %x0A / ; Line feed or New line | - | ||||||||||||||||||
223 | %x0D ; Carriage return | - | ||||||||||||||||||
224 | ) | - | ||||||||||||||||||
225 | - | |||||||||||||||||||
226 | */ | - | ||||||||||||||||||
227 | - | |||||||||||||||||||
228 | enum { | - | ||||||||||||||||||
229 | Space = 0x20, | - | ||||||||||||||||||
230 | Tab = 0x09, | - | ||||||||||||||||||
231 | LineFeed = 0x0a, | - | ||||||||||||||||||
232 | Return = 0x0d, | - | ||||||||||||||||||
233 | BeginArray = 0x5b, | - | ||||||||||||||||||
234 | BeginObject = 0x7b, | - | ||||||||||||||||||
235 | EndArray = 0x5d, | - | ||||||||||||||||||
236 | EndObject = 0x7d, | - | ||||||||||||||||||
237 | NameSeparator = 0x3a, | - | ||||||||||||||||||
238 | ValueSeparator = 0x2c, | - | ||||||||||||||||||
239 | Quote = 0x22 | - | ||||||||||||||||||
240 | }; | - | ||||||||||||||||||
241 | - | |||||||||||||||||||
242 | void Parser::eatBOM() | - | ||||||||||||||||||
243 | { | - | ||||||||||||||||||
244 | // eat UTF-8 byte order mark | - | ||||||||||||||||||
245 | uchar utf8bom[3] = { 0xef, 0xbb, 0xbf }; | - | ||||||||||||||||||
246 | if (end - json > 3 &&
| 0-10 | ||||||||||||||||||
247 | (uchar)json[0] == utf8bom[0] &&
| 0-10 | ||||||||||||||||||
248 | (uchar)json[1] == utf8bom[1] &&
| 0 | ||||||||||||||||||
249 | (uchar)json[2] == utf8bom[2])
| 0 | ||||||||||||||||||
250 | json += 3; never executed: json += 3; | 0 | ||||||||||||||||||
251 | } executed 10 times by 4 tests: end of block Executed by:
| 10 | ||||||||||||||||||
252 | - | |||||||||||||||||||
253 | bool Parser::eatSpace() | - | ||||||||||||||||||
254 | { | - | ||||||||||||||||||
255 | while (json < end) {
| 14-30245 | ||||||||||||||||||
256 | if (*json > Space)
| 9523-20722 | ||||||||||||||||||
257 | break; executed 9523 times by 4 tests: break; Executed by:
| 9523 | ||||||||||||||||||
258 | if (*json != Space &&
| 2643-18079 | ||||||||||||||||||
259 | *json != Tab &&
| 0-2643 | ||||||||||||||||||
260 | *json != LineFeed &&
| 0-2643 | ||||||||||||||||||
261 | *json != Return)
| 0 | ||||||||||||||||||
262 | break; never executed: break; | 0 | ||||||||||||||||||
263 | ++json; | - | ||||||||||||||||||
264 | } executed 20722 times by 4 tests: end of block Executed by:
| 20722 | ||||||||||||||||||
265 | return (json < end); executed 9537 times by 4 tests: return (json < end); Executed by:
| 9537 | ||||||||||||||||||
266 | } | - | ||||||||||||||||||
267 | - | |||||||||||||||||||
268 | char Parser::nextToken() | - | ||||||||||||||||||
269 | { | - | ||||||||||||||||||
270 | if (!eatSpace())
| 0-5213 | ||||||||||||||||||
271 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
272 | char token = *json++; | - | ||||||||||||||||||
273 | switch (token) { | - | ||||||||||||||||||
274 | case BeginArray: executed 1 time by 1 test: case BeginArray: Executed by:
| 1 | ||||||||||||||||||
275 | case BeginObject: executed 8 times by 3 tests: case BeginObject: Executed by:
| 8 | ||||||||||||||||||
276 | case NameSeparator: executed 1439 times by 3 tests: case NameSeparator: Executed by:
| 1439 | ||||||||||||||||||
277 | case ValueSeparator: executed 1278 times by 3 tests: case ValueSeparator: Executed by:
| 1278 | ||||||||||||||||||
278 | case EndArray: executed 546 times by 3 tests: case EndArray: Executed by:
| 546 | ||||||||||||||||||
279 | case EndObject: executed 499 times by 3 tests: case EndObject: Executed by:
| 499 | ||||||||||||||||||
280 | eatSpace(); | - | ||||||||||||||||||
281 | case Quote: code before this statement executed 3771 times by 4 tests: case Quote: Executed by:
executed 1439 times by 3 tests: case Quote: Executed by:
| 1439-3771 | ||||||||||||||||||
282 | break; executed 5210 times by 4 tests: break; Executed by:
| 5210 | ||||||||||||||||||
283 | default: executed 3 times by 2 tests: default: Executed by:
| 3 | ||||||||||||||||||
284 | token = 0; | - | ||||||||||||||||||
285 | break; executed 3 times by 2 tests: break; Executed by:
| 3 | ||||||||||||||||||
286 | } | - | ||||||||||||||||||
287 | return token; executed 5213 times by 4 tests: return token; Executed by:
| 5213 | ||||||||||||||||||
288 | } | - | ||||||||||||||||||
289 | - | |||||||||||||||||||
290 | /* | - | ||||||||||||||||||
291 | JSON-text = object / array | - | ||||||||||||||||||
292 | */ | - | ||||||||||||||||||
293 | QJsonDocument Parser::parse(QJsonParseError *error) | - | ||||||||||||||||||
294 | { | - | ||||||||||||||||||
295 | #ifdef PARSER_DEBUG | - | ||||||||||||||||||
296 | indent = 0; | - | ||||||||||||||||||
297 | qDebug() << ">>>>> parser begin"; | - | ||||||||||||||||||
298 | #endif | - | ||||||||||||||||||
299 | // allocate some space | - | ||||||||||||||||||
300 | dataLength = qMax(end - json, (ptrdiff_t) 256); | - | ||||||||||||||||||
301 | data = (char *)malloc(dataLength); | - | ||||||||||||||||||
302 | - | |||||||||||||||||||
303 | // fill in Header data | - | ||||||||||||||||||
304 | QJsonPrivate::Header *h = (QJsonPrivate::Header *)data; | - | ||||||||||||||||||
305 | h->tag = QJsonDocument::BinaryFormatTag; | - | ||||||||||||||||||
306 | h->version = 1u; | - | ||||||||||||||||||
307 | - | |||||||||||||||||||
308 | current = sizeof(QJsonPrivate::Header); | - | ||||||||||||||||||
309 | - | |||||||||||||||||||
310 | eatBOM(); | - | ||||||||||||||||||
311 | char token = nextToken(); | - | ||||||||||||||||||
312 | - | |||||||||||||||||||
313 | DEBUG << hex << (uint)token; executed 10 times by 4 tests: ; Executed by:
dead code: QMessageLogger(__FILE__, 313, __PRETTY_FUNCTION__).debug() << hex << (uint)token; | - | ||||||||||||||||||
314 | if (token == BeginArray) {
| 1-9 | ||||||||||||||||||
315 | if (!parseArray())
| 0-1 | ||||||||||||||||||
316 | goto error; never executed: goto error; | 0 | ||||||||||||||||||
317 | } else if (token == BeginObject) { executed 1 time by 1 test: end of block Executed by:
| 1-8 | ||||||||||||||||||
318 | if (!parseObject())
| 2-6 | ||||||||||||||||||
319 | goto error; executed 2 times by 1 test: goto error; Executed by:
| 2 | ||||||||||||||||||
320 | } else { executed 6 times by 2 tests: end of block Executed by:
| 6 | ||||||||||||||||||
321 | lastError = QJsonParseError::IllegalValue; | - | ||||||||||||||||||
322 | goto error; executed 1 time by 1 test: goto error; Executed by:
| 1 | ||||||||||||||||||
323 | } | - | ||||||||||||||||||
324 | - | |||||||||||||||||||
325 | eatSpace(); | - | ||||||||||||||||||
326 | if (json < end) {
| 0-7 | ||||||||||||||||||
327 | lastError = QJsonParseError::GarbageAtEnd; | - | ||||||||||||||||||
328 | goto error; never executed: goto error; | 0 | ||||||||||||||||||
329 | } | - | ||||||||||||||||||
330 | - | |||||||||||||||||||
331 | END; | - | ||||||||||||||||||
332 | { | - | ||||||||||||||||||
333 | if (error) {
| 2-5 | ||||||||||||||||||
334 | error->offset = 0; | - | ||||||||||||||||||
335 | error->error = QJsonParseError::NoError; | - | ||||||||||||||||||
336 | } executed 5 times by 1 test: end of block Executed by:
| 5 | ||||||||||||||||||
337 | QJsonPrivate::Data *d = new QJsonPrivate::Data(data, current); | - | ||||||||||||||||||
338 | return QJsonDocument(d); executed 7 times by 3 tests: return QJsonDocument(d); Executed by:
| 7 | ||||||||||||||||||
339 | } | - | ||||||||||||||||||
340 | - | |||||||||||||||||||
341 | error: | - | ||||||||||||||||||
342 | #ifdef PARSER_DEBUG | - | ||||||||||||||||||
343 | qDebug() << ">>>>> parser error"; | - | ||||||||||||||||||
344 | #endif | - | ||||||||||||||||||
345 | if (error) {
| 0-3 | ||||||||||||||||||
346 | error->offset = json - head; | - | ||||||||||||||||||
347 | error->error = lastError; | - | ||||||||||||||||||
348 | } never executed: end of block | 0 | ||||||||||||||||||
349 | free(data); | - | ||||||||||||||||||
350 | return QJsonDocument(); executed 3 times by 2 tests: return QJsonDocument(); Executed by:
| 3 | ||||||||||||||||||
351 | } | - | ||||||||||||||||||
352 | - | |||||||||||||||||||
353 | - | |||||||||||||||||||
354 | void Parser::ParsedObject::insert(uint offset) { | - | ||||||||||||||||||
355 | const QJsonPrivate::Entry *newEntry = reinterpret_cast<const QJsonPrivate::Entry *>(parser->data + objectPosition + offset); | - | ||||||||||||||||||
356 | int min = 0; | - | ||||||||||||||||||
357 | int n = offsets.size(); | - | ||||||||||||||||||
358 | while (n > 0) {
| 1397-1439 | ||||||||||||||||||
359 | int half = n >> 1; | - | ||||||||||||||||||
360 | int middle = min + half; | - | ||||||||||||||||||
361 | if (*entryAt(middle) >= *newEntry) {
| 674-723 | ||||||||||||||||||
362 | n = half; | - | ||||||||||||||||||
363 | } else { executed 723 times by 3 tests: end of block Executed by:
| 723 | ||||||||||||||||||
364 | min = middle + 1; | - | ||||||||||||||||||
365 | n -= half + 1; | - | ||||||||||||||||||
366 | } executed 674 times by 3 tests: end of block Executed by:
| 674 | ||||||||||||||||||
367 | } | - | ||||||||||||||||||
368 | if (min < offsets.size() && *entryAt(min) == *newEntry) {
| 0-728 | ||||||||||||||||||
369 | offsets[min] = offset; | - | ||||||||||||||||||
370 | } else { never executed: end of block | 0 | ||||||||||||||||||
371 | offsets.insert(min, offset); | - | ||||||||||||||||||
372 | } executed 1439 times by 3 tests: end of block Executed by:
| 1439 | ||||||||||||||||||
373 | } | - | ||||||||||||||||||
374 | - | |||||||||||||||||||
375 | /* | - | ||||||||||||||||||
376 | object = begin-object [ member *( value-separator member ) ] | - | ||||||||||||||||||
377 | end-object | - | ||||||||||||||||||
378 | */ | - | ||||||||||||||||||
379 | - | |||||||||||||||||||
380 | bool Parser::parseObject() | - | ||||||||||||||||||
381 | { | - | ||||||||||||||||||
382 | if (++nestingLevel > nestingLimit) {
| 0-501 | ||||||||||||||||||
383 | lastError = QJsonParseError::DeepNesting; | - | ||||||||||||||||||
384 | return false; never executed: return false; | 0 | ||||||||||||||||||
385 | } | - | ||||||||||||||||||
386 | - | |||||||||||||||||||
387 | int objectOffset = reserveSpace(sizeof(QJsonPrivate::Object)); | - | ||||||||||||||||||
388 | if (objectOffset < 0)
| 0-501 | ||||||||||||||||||
389 | return false; never executed: return false; | 0 | ||||||||||||||||||
390 | BEGIN << "parseObject pos=" << objectOffset << current << json; executed 501 times by 4 tests: ; Executed by:
dead code: QMessageLogger(__FILE__, 390, __PRETTY_FUNCTION__).debug() << "parseObject pos=" << objectOffset << current << json; | - | ||||||||||||||||||
391 | - | |||||||||||||||||||
392 | ParsedObject parsedObject(this, objectOffset); | - | ||||||||||||||||||
393 | - | |||||||||||||||||||
394 | char token = nextToken(); | - | ||||||||||||||||||
395 | while (token == Quote) {
| 2-1439 | ||||||||||||||||||
396 | int off = current - objectOffset; | - | ||||||||||||||||||
397 | if (!parseMember(objectOffset))
| 0-1439 | ||||||||||||||||||
398 | return false; never executed: return false; | 0 | ||||||||||||||||||
399 | parsedObject.insert(off); | - | ||||||||||||||||||
400 | token = nextToken(); | - | ||||||||||||||||||
401 | if (token != ValueSeparator)
| 499-940 | ||||||||||||||||||
402 | break; executed 499 times by 3 tests: break; Executed by:
| 499 | ||||||||||||||||||
403 | token = nextToken(); | - | ||||||||||||||||||
404 | if (token == EndObject) {
| 0-940 | ||||||||||||||||||
405 | lastError = QJsonParseError::MissingObject; | - | ||||||||||||||||||
406 | return false; never executed: return false; | 0 | ||||||||||||||||||
407 | } | - | ||||||||||||||||||
408 | } executed 940 times by 3 tests: end of block Executed by:
| 940 | ||||||||||||||||||
409 | - | |||||||||||||||||||
410 | DEBUG << "end token=" << token; executed 501 times by 4 tests: ; Executed by:
dead code: QMessageLogger(__FILE__, 410, __PRETTY_FUNCTION__).debug() << "end token=" << token; | - | ||||||||||||||||||
411 | if (token != EndObject) {
| 2-499 | ||||||||||||||||||
412 | lastError = QJsonParseError::UnterminatedObject; | - | ||||||||||||||||||
413 | return false; executed 2 times by 1 test: return false; Executed by:
| 2 | ||||||||||||||||||
414 | } | - | ||||||||||||||||||
415 | - | |||||||||||||||||||
416 | DEBUG << "numEntries" << parsedObject.offsets.size(); executed 499 times by 3 tests: ; Executed by:
dead code: QMessageLogger(__FILE__, 416, __PRETTY_FUNCTION__).debug() << "numEntries" << parsedObject.offsets.size(); | - | ||||||||||||||||||
417 | int table = objectOffset; | - | ||||||||||||||||||
418 | // finalize the object | - | ||||||||||||||||||
419 | if (parsedObject.offsets.size()) {
| 0-499 | ||||||||||||||||||
420 | int tableSize = parsedObject.offsets.size()*sizeof(uint); | - | ||||||||||||||||||
421 | table = reserveSpace(tableSize); | - | ||||||||||||||||||
422 | if (table < 0)
| 0-499 | ||||||||||||||||||
423 | return false; never executed: return false; | 0 | ||||||||||||||||||
424 | - | |||||||||||||||||||
425 | #if Q_BYTE_ORDER == Q_LITTLE_ENDIAN | - | ||||||||||||||||||
426 | memcpy(data + table, parsedObject.offsets.constData(), tableSize); | - | ||||||||||||||||||
427 | #else | - | ||||||||||||||||||
428 | offset *o = (offset *)(data + table); | - | ||||||||||||||||||
429 | for (int i = 0; i < parsedObject.offsets.size(); ++i) | - | ||||||||||||||||||
430 | o[i] = parsedObject.offsets[i]; | - | ||||||||||||||||||
431 | - | |||||||||||||||||||
432 | #endif | - | ||||||||||||||||||
433 | } executed 499 times by 3 tests: end of block Executed by:
| 499 | ||||||||||||||||||
434 | - | |||||||||||||||||||
435 | QJsonPrivate::Object *o = (QJsonPrivate::Object *)(data + objectOffset); | - | ||||||||||||||||||
436 | o->tableOffset = table - objectOffset; | - | ||||||||||||||||||
437 | o->size = current - objectOffset; | - | ||||||||||||||||||
438 | o->is_object = true; | - | ||||||||||||||||||
439 | o->length = parsedObject.offsets.size(); | - | ||||||||||||||||||
440 | - | |||||||||||||||||||
441 | DEBUG << "current=" << current; executed 499 times by 3 tests: ; Executed by:
dead code: QMessageLogger(__FILE__, 441, __PRETTY_FUNCTION__).debug() << "current=" << current; | - | ||||||||||||||||||
442 | END; | - | ||||||||||||||||||
443 | - | |||||||||||||||||||
444 | --nestingLevel; | - | ||||||||||||||||||
445 | return true; executed 499 times by 3 tests: return true; Executed by:
| 499 | ||||||||||||||||||
446 | } | - | ||||||||||||||||||
447 | - | |||||||||||||||||||
448 | /* | - | ||||||||||||||||||
449 | member = string name-separator value | - | ||||||||||||||||||
450 | */ | - | ||||||||||||||||||
451 | bool Parser::parseMember(int baseOffset) | - | ||||||||||||||||||
452 | { | - | ||||||||||||||||||
453 | int entryOffset = reserveSpace(sizeof(QJsonPrivate::Entry)); | - | ||||||||||||||||||
454 | if (entryOffset < 0)
| 0-1439 | ||||||||||||||||||
455 | return false; never executed: return false; | 0 | ||||||||||||||||||
456 | BEGIN << "parseMember pos=" << entryOffset; executed 1439 times by 3 tests: ; Executed by:
dead code: QMessageLogger(__FILE__, 456, __PRETTY_FUNCTION__).debug() << "parseMember pos=" << entryOffset; | - | ||||||||||||||||||
457 | - | |||||||||||||||||||
458 | bool latin1; | - | ||||||||||||||||||
459 | if (!parseString(&latin1))
| 0-1439 | ||||||||||||||||||
460 | return false; never executed: return false; | 0 | ||||||||||||||||||
461 | char token = nextToken(); | - | ||||||||||||||||||
462 | if (token != NameSeparator) {
| 0-1439 | ||||||||||||||||||
463 | lastError = QJsonParseError::MissingNameSeparator; | - | ||||||||||||||||||
464 | return false; never executed: return false; | 0 | ||||||||||||||||||
465 | } | - | ||||||||||||||||||
466 | QJsonPrivate::Value val; | - | ||||||||||||||||||
467 | if (!parseValue(&val, baseOffset))
| 0-1439 | ||||||||||||||||||
468 | return false; never executed: return false; | 0 | ||||||||||||||||||
469 | - | |||||||||||||||||||
470 | // finalize the entry | - | ||||||||||||||||||
471 | QJsonPrivate::Entry *e = (QJsonPrivate::Entry *)(data + entryOffset); | - | ||||||||||||||||||
472 | e->value = val; | - | ||||||||||||||||||
473 | e->value.latinKey = latin1; | - | ||||||||||||||||||
474 | - | |||||||||||||||||||
475 | END; | - | ||||||||||||||||||
476 | return true; executed 1439 times by 3 tests: return true; Executed by:
| 1439 | ||||||||||||||||||
477 | } | - | ||||||||||||||||||
478 | - | |||||||||||||||||||
479 | namespace { | - | ||||||||||||||||||
480 | struct ValueArray { | - | ||||||||||||||||||
481 | static const int prealloc = 128; | - | ||||||||||||||||||
482 | ValueArray() : data(stackValues), alloc(prealloc), size(0) {} executed 546 times by 3 tests: end of block Executed by:
| 546 | ||||||||||||||||||
483 | ~ValueArray() { if (data != stackValues) free(data); } executed 546 times by 3 tests: end of block Executed by:
executed 1 time by 1 test: free(data); Executed by:
| 1-546 | ||||||||||||||||||
484 | - | |||||||||||||||||||
485 | inline bool grow() { | - | ||||||||||||||||||
486 | alloc *= 2; | - | ||||||||||||||||||
487 | if (data == stackValues) {
| 0-1 | ||||||||||||||||||
488 | QJsonPrivate::Value *newValues = static_cast<QJsonPrivate::Value *>(malloc(alloc*sizeof(QJsonPrivate::Value))); | - | ||||||||||||||||||
489 | if (!newValues)
| 0-1 | ||||||||||||||||||
490 | return false; never executed: return false; | 0 | ||||||||||||||||||
491 | memcpy(newValues, data, size*sizeof(QJsonPrivate::Value)); | - | ||||||||||||||||||
492 | data = newValues; | - | ||||||||||||||||||
493 | } else { executed 1 time by 1 test: end of block Executed by:
| 1 | ||||||||||||||||||
494 | void *newValues = realloc(data, alloc * sizeof(QJsonPrivate::Value)); | - | ||||||||||||||||||
495 | if (!newValues)
| 0 | ||||||||||||||||||
496 | return false; never executed: return false; | 0 | ||||||||||||||||||
497 | data = static_cast<QJsonPrivate::Value *>(newValues); | - | ||||||||||||||||||
498 | } never executed: end of block | 0 | ||||||||||||||||||
499 | return true; executed 1 time by 1 test: return true; Executed by:
| 1 | ||||||||||||||||||
500 | } | - | ||||||||||||||||||
501 | bool append(const QJsonPrivate::Value &v) { | - | ||||||||||||||||||
502 | if (alloc == size && !grow())
| 0-796 | ||||||||||||||||||
503 | return false; never executed: return false; | 0 | ||||||||||||||||||
504 | data[size] = v; | - | ||||||||||||||||||
505 | ++size; | - | ||||||||||||||||||
506 | return true; executed 797 times by 3 tests: return true; Executed by:
| 797 | ||||||||||||||||||
507 | } | - | ||||||||||||||||||
508 | - | |||||||||||||||||||
509 | QJsonPrivate::Value stackValues[prealloc]; | - | ||||||||||||||||||
510 | QJsonPrivate::Value *data; | - | ||||||||||||||||||
511 | int alloc; | - | ||||||||||||||||||
512 | int size; | - | ||||||||||||||||||
513 | }; | - | ||||||||||||||||||
514 | } | - | ||||||||||||||||||
515 | - | |||||||||||||||||||
516 | /* | - | ||||||||||||||||||
517 | array = begin-array [ value *( value-separator value ) ] end-array | - | ||||||||||||||||||
518 | */ | - | ||||||||||||||||||
519 | bool Parser::parseArray() | - | ||||||||||||||||||
520 | { | - | ||||||||||||||||||
521 | BEGIN << "parseArray"; executed 546 times by 3 tests: ; Executed by:
dead code: QMessageLogger(__FILE__, 521, __PRETTY_FUNCTION__).debug() << "parseArray"; | - | ||||||||||||||||||
522 | - | |||||||||||||||||||
523 | if (++nestingLevel > nestingLimit) {
| 0-546 | ||||||||||||||||||
524 | lastError = QJsonParseError::DeepNesting; | - | ||||||||||||||||||
525 | return false; never executed: return false; | 0 | ||||||||||||||||||
526 | } | - | ||||||||||||||||||
527 | - | |||||||||||||||||||
528 | int arrayOffset = reserveSpace(sizeof(QJsonPrivate::Array)); | - | ||||||||||||||||||
529 | if (arrayOffset < 0)
| 0-546 | ||||||||||||||||||
530 | return false; never executed: return false; | 0 | ||||||||||||||||||
531 | - | |||||||||||||||||||
532 | ValueArray values; | - | ||||||||||||||||||
533 | - | |||||||||||||||||||
534 | if (!eatSpace()) {
| 0-546 | ||||||||||||||||||
535 | lastError = QJsonParseError::UnterminatedArray; | - | ||||||||||||||||||
536 | return false; never executed: return false; | 0 | ||||||||||||||||||
537 | } | - | ||||||||||||||||||
538 | if (*json == EndArray) {
| 87-459 | ||||||||||||||||||
539 | nextToken(); | - | ||||||||||||||||||
540 | } else { executed 87 times by 1 test: end of block Executed by:
| 87 | ||||||||||||||||||
541 | while (1) { | - | ||||||||||||||||||
542 | QJsonPrivate::Value val; | - | ||||||||||||||||||
543 | if (!parseValue(&val, arrayOffset))
| 0-797 | ||||||||||||||||||
544 | return false; never executed: return false; | 0 | ||||||||||||||||||
545 | if (!values.append(val)) {
| 0-797 | ||||||||||||||||||
546 | lastError = QJsonParseError::DocumentTooLarge; | - | ||||||||||||||||||
547 | return false; never executed: return false; | 0 | ||||||||||||||||||
548 | } | - | ||||||||||||||||||
549 | char token = nextToken(); | - | ||||||||||||||||||
550 | if (token == EndArray)
| 338-459 | ||||||||||||||||||
551 | break; executed 459 times by 3 tests: break; Executed by:
| 459 | ||||||||||||||||||
552 | else if (token != ValueSeparator) {
| 0-338 | ||||||||||||||||||
553 | if (!eatSpace())
| 0 | ||||||||||||||||||
554 | lastError = QJsonParseError::UnterminatedArray; never executed: lastError = QJsonParseError::UnterminatedArray; | 0 | ||||||||||||||||||
555 | else | - | ||||||||||||||||||
556 | lastError = QJsonParseError::MissingValueSeparator; never executed: lastError = QJsonParseError::MissingValueSeparator; | 0 | ||||||||||||||||||
557 | return false; never executed: return false; | 0 | ||||||||||||||||||
558 | } | - | ||||||||||||||||||
559 | } executed 338 times by 3 tests: end of block Executed by:
| 338 | ||||||||||||||||||
560 | } executed 459 times by 3 tests: end of block Executed by:
| 459 | ||||||||||||||||||
561 | - | |||||||||||||||||||
562 | DEBUG << "size =" << values.size; executed 546 times by 3 tests: ; Executed by:
dead code: QMessageLogger(__FILE__, 562, __PRETTY_FUNCTION__).debug() << "size =" << values.size; | - | ||||||||||||||||||
563 | int table = arrayOffset; | - | ||||||||||||||||||
564 | // finalize the object | - | ||||||||||||||||||
565 | if (values.size) {
| 87-459 | ||||||||||||||||||
566 | int tableSize = values.size*sizeof(QJsonPrivate::Value); | - | ||||||||||||||||||
567 | table = reserveSpace(tableSize); | - | ||||||||||||||||||
568 | if (table < 0)
| 0-459 | ||||||||||||||||||
569 | return false; never executed: return false; | 0 | ||||||||||||||||||
570 | memcpy(data + table, values.data, tableSize); | - | ||||||||||||||||||
571 | } executed 459 times by 3 tests: end of block Executed by:
| 459 | ||||||||||||||||||
572 | - | |||||||||||||||||||
573 | QJsonPrivate::Array *a = (QJsonPrivate::Array *)(data + arrayOffset); | - | ||||||||||||||||||
574 | a->tableOffset = table - arrayOffset; | - | ||||||||||||||||||
575 | a->size = current - arrayOffset; | - | ||||||||||||||||||
576 | a->is_object = false; | - | ||||||||||||||||||
577 | a->length = values.size; | - | ||||||||||||||||||
578 | - | |||||||||||||||||||
579 | DEBUG << "current=" << current; executed 546 times by 3 tests: ; Executed by:
dead code: QMessageLogger(__FILE__, 579, __PRETTY_FUNCTION__).debug() << "current=" << current; | - | ||||||||||||||||||
580 | END; | - | ||||||||||||||||||
581 | - | |||||||||||||||||||
582 | --nestingLevel; | - | ||||||||||||||||||
583 | return true; executed 546 times by 3 tests: return true; Executed by:
| 546 | ||||||||||||||||||
584 | } | - | ||||||||||||||||||
585 | - | |||||||||||||||||||
586 | /* | - | ||||||||||||||||||
587 | value = false / null / true / object / array / number / string | - | ||||||||||||||||||
588 | - | |||||||||||||||||||
589 | */ | - | ||||||||||||||||||
590 | - | |||||||||||||||||||
591 | bool Parser::parseValue(QJsonPrivate::Value *val, int baseOffset) | - | ||||||||||||||||||
592 | { | - | ||||||||||||||||||
593 | BEGIN << "parse Value" << json; executed 2236 times by 3 tests: ; Executed by:
dead code: QMessageLogger(__FILE__, 593, __PRETTY_FUNCTION__).debug() << "parse Value" << json; | - | ||||||||||||||||||
594 | val->_dummy = 0; | - | ||||||||||||||||||
595 | - | |||||||||||||||||||
596 | switch (*json++) { | - | ||||||||||||||||||
597 | case 'n': executed 1 time by 1 test: case 'n': Executed by:
| 1 | ||||||||||||||||||
598 | if (end - json < 4) {
| 0-1 | ||||||||||||||||||
599 | lastError = QJsonParseError::IllegalValue; | - | ||||||||||||||||||
600 | return false; never executed: return false; | 0 | ||||||||||||||||||
601 | } | - | ||||||||||||||||||
602 | if (*json++ == 'u' &&
| 0-1 | ||||||||||||||||||
603 | *json++ == 'l' &&
| 0-1 | ||||||||||||||||||
604 | *json++ == 'l') {
| 0-1 | ||||||||||||||||||
605 | val->type = QJsonValue::Null; | - | ||||||||||||||||||
606 | DEBUG << "value: null"; executed 1 time by 1 test: ; Executed by:
dead code: QMessageLogger(__FILE__, 606, __PRETTY_FUNCTION__).debug() << "value: null"; | - | ||||||||||||||||||
607 | END; | - | ||||||||||||||||||
608 | return true; executed 1 time by 1 test: return true; Executed by:
| 1 | ||||||||||||||||||
609 | } | - | ||||||||||||||||||
610 | lastError = QJsonParseError::IllegalValue; | - | ||||||||||||||||||
611 | return false; never executed: return false; | 0 | ||||||||||||||||||
612 | case 't': executed 1 time by 1 test: case 't': Executed by:
| 1 | ||||||||||||||||||
613 | if (end - json < 4) {
| 0-1 | ||||||||||||||||||
614 | lastError = QJsonParseError::IllegalValue; | - | ||||||||||||||||||
615 | return false; never executed: return false; | 0 | ||||||||||||||||||
616 | } | - | ||||||||||||||||||
617 | if (*json++ == 'r' &&
| 0-1 | ||||||||||||||||||
618 | *json++ == 'u' &&
| 0-1 | ||||||||||||||||||
619 | *json++ == 'e') {
| 0-1 | ||||||||||||||||||
620 | val->type = QJsonValue::Bool; | - | ||||||||||||||||||
621 | val->value = true; | - | ||||||||||||||||||
622 | DEBUG << "value: true"; executed 1 time by 1 test: ; Executed by:
dead code: QMessageLogger(__FILE__, 622, __PRETTY_FUNCTION__).debug() << "value: true"; | - | ||||||||||||||||||
623 | END; | - | ||||||||||||||||||
624 | return true; executed 1 time by 1 test: return true; Executed by:
| 1 | ||||||||||||||||||
625 | } | - | ||||||||||||||||||
626 | lastError = QJsonParseError::IllegalValue; | - | ||||||||||||||||||
627 | return false; never executed: return false; | 0 | ||||||||||||||||||
628 | case 'f': executed 1 time by 1 test: case 'f': Executed by:
| 1 | ||||||||||||||||||
629 | if (end - json < 5) {
| 0-1 | ||||||||||||||||||
630 | lastError = QJsonParseError::IllegalValue; | - | ||||||||||||||||||
631 | return false; never executed: return false; | 0 | ||||||||||||||||||
632 | } | - | ||||||||||||||||||
633 | if (*json++ == 'a' &&
| 0-1 | ||||||||||||||||||
634 | *json++ == 'l' &&
| 0-1 | ||||||||||||||||||
635 | *json++ == 's' &&
| 0-1 | ||||||||||||||||||
636 | *json++ == 'e') {
| 0-1 | ||||||||||||||||||
637 | val->type = QJsonValue::Bool; | - | ||||||||||||||||||
638 | val->value = false; | - | ||||||||||||||||||
639 | DEBUG << "value: false"; executed 1 time by 1 test: ; Executed by:
dead code: QMessageLogger(__FILE__, 639, __PRETTY_FUNCTION__).debug() << "value: false"; | - | ||||||||||||||||||
640 | END; | - | ||||||||||||||||||
641 | return true; executed 1 time by 1 test: return true; Executed by:
| 1 | ||||||||||||||||||
642 | } | - | ||||||||||||||||||
643 | lastError = QJsonParseError::IllegalValue; | - | ||||||||||||||||||
644 | return false; never executed: return false; | 0 | ||||||||||||||||||
645 | case Quote: { executed 1144 times by 3 tests: case Quote: Executed by:
| 1144 | ||||||||||||||||||
646 | val->type = QJsonValue::String; | - | ||||||||||||||||||
647 | if (current - baseOffset >= Value::MaxSize) {
| 0-1144 | ||||||||||||||||||
648 | lastError = QJsonParseError::DocumentTooLarge; | - | ||||||||||||||||||
649 | return false; never executed: return false; | 0 | ||||||||||||||||||
650 | } | - | ||||||||||||||||||
651 | val->value = current - baseOffset; | - | ||||||||||||||||||
652 | bool latin1; | - | ||||||||||||||||||
653 | if (!parseString(&latin1))
| 0-1144 | ||||||||||||||||||
654 | return false; never executed: return false; | 0 | ||||||||||||||||||
655 | val->latinOrIntValue = latin1; | - | ||||||||||||||||||
656 | DEBUG << "value: string"; executed 1144 times by 3 tests: ; Executed by:
dead code: QMessageLogger(__FILE__, 656, __PRETTY_FUNCTION__).debug() << "value: string"; | - | ||||||||||||||||||
657 | END; | - | ||||||||||||||||||
658 | return true; executed 1144 times by 3 tests: return true; Executed by:
| 1144 | ||||||||||||||||||
659 | } | - | ||||||||||||||||||
660 | case BeginArray: executed 545 times by 3 tests: case BeginArray: Executed by:
| 545 | ||||||||||||||||||
661 | val->type = QJsonValue::Array; | - | ||||||||||||||||||
662 | if (current - baseOffset >= Value::MaxSize) {
| 0-545 | ||||||||||||||||||
663 | lastError = QJsonParseError::DocumentTooLarge; | - | ||||||||||||||||||
664 | return false; never executed: return false; | 0 | ||||||||||||||||||
665 | } | - | ||||||||||||||||||
666 | val->value = current - baseOffset; | - | ||||||||||||||||||
667 | if (!parseArray())
| 0-545 | ||||||||||||||||||
668 | return false; never executed: return false; | 0 | ||||||||||||||||||
669 | DEBUG << "value: array"; executed 545 times by 3 tests: ; Executed by:
dead code: QMessageLogger(__FILE__, 669, __PRETTY_FUNCTION__).debug() << "value: array"; | - | ||||||||||||||||||
670 | END; | - | ||||||||||||||||||
671 | return true; executed 545 times by 3 tests: return true; Executed by:
| 545 | ||||||||||||||||||
672 | case BeginObject: executed 493 times by 3 tests: case BeginObject: Executed by:
| 493 | ||||||||||||||||||
673 | val->type = QJsonValue::Object; | - | ||||||||||||||||||
674 | if (current - baseOffset >= Value::MaxSize) {
| 0-493 | ||||||||||||||||||
675 | lastError = QJsonParseError::DocumentTooLarge; | - | ||||||||||||||||||
676 | return false; never executed: return false; | 0 | ||||||||||||||||||
677 | } | - | ||||||||||||||||||
678 | val->value = current - baseOffset; | - | ||||||||||||||||||
679 | if (!parseObject())
| 0-493 | ||||||||||||||||||
680 | return false; never executed: return false; | 0 | ||||||||||||||||||
681 | DEBUG << "value: object"; executed 493 times by 3 tests: ; Executed by:
dead code: QMessageLogger(__FILE__, 681, __PRETTY_FUNCTION__).debug() << "value: object"; | - | ||||||||||||||||||
682 | END; | - | ||||||||||||||||||
683 | return true; executed 493 times by 3 tests: return true; Executed by:
| 493 | ||||||||||||||||||
684 | case EndArray: never executed: case EndArray: | 0 | ||||||||||||||||||
685 | lastError = QJsonParseError::MissingObject; | - | ||||||||||||||||||
686 | return false; never executed: return false; | 0 | ||||||||||||||||||
687 | default: executed 51 times by 2 tests: default: Executed by:
| 51 | ||||||||||||||||||
688 | --json; | - | ||||||||||||||||||
689 | if (!parseNumber(val, baseOffset))
| 0-51 | ||||||||||||||||||
690 | return false; never executed: return false; | 0 | ||||||||||||||||||
691 | DEBUG << "value: number"; executed 51 times by 2 tests: ; Executed by:
dead code: QMessageLogger(__FILE__, 691, __PRETTY_FUNCTION__).debug() << "value: number"; | - | ||||||||||||||||||
692 | END; | - | ||||||||||||||||||
693 | } executed 51 times by 2 tests: end of block Executed by:
| 51 | ||||||||||||||||||
694 | - | |||||||||||||||||||
695 | return true; executed 51 times by 2 tests: return true; Executed by:
| 51 | ||||||||||||||||||
696 | } | - | ||||||||||||||||||
697 | - | |||||||||||||||||||
698 | - | |||||||||||||||||||
699 | - | |||||||||||||||||||
700 | - | |||||||||||||||||||
701 | - | |||||||||||||||||||
702 | /* | - | ||||||||||||||||||
703 | number = [ minus ] int [ frac ] [ exp ] | - | ||||||||||||||||||
704 | decimal-point = %x2E ; . | - | ||||||||||||||||||
705 | digit1-9 = %x31-39 ; 1-9 | - | ||||||||||||||||||
706 | e = %x65 / %x45 ; e E | - | ||||||||||||||||||
707 | exp = e [ minus / plus ] 1*DIGIT | - | ||||||||||||||||||
708 | frac = decimal-point 1*DIGIT | - | ||||||||||||||||||
709 | int = zero / ( digit1-9 *DIGIT ) | - | ||||||||||||||||||
710 | minus = %x2D ; - | - | ||||||||||||||||||
711 | plus = %x2B ; + | - | ||||||||||||||||||
712 | zero = %x30 ; 0 | - | ||||||||||||||||||
713 | - | |||||||||||||||||||
714 | */ | - | ||||||||||||||||||
715 | - | |||||||||||||||||||
716 | bool Parser::parseNumber(QJsonPrivate::Value *val, int baseOffset) | - | ||||||||||||||||||
717 | { | - | ||||||||||||||||||
718 | BEGIN << "parseNumber" << json; executed 51 times by 2 tests: ; Executed by:
dead code: QMessageLogger(__FILE__, 718, __PRETTY_FUNCTION__).debug() << "parseNumber" << json; | - | ||||||||||||||||||
719 | val->type = QJsonValue::Double; | - | ||||||||||||||||||
720 | - | |||||||||||||||||||
721 | const char *start = json; | - | ||||||||||||||||||
722 | bool isInt = true; | - | ||||||||||||||||||
723 | - | |||||||||||||||||||
724 | // minus | - | ||||||||||||||||||
725 | if (json < end && *json == '-')
| 0-51 | ||||||||||||||||||
726 | ++json; never executed: ++json; | 0 | ||||||||||||||||||
727 | - | |||||||||||||||||||
728 | // int = zero / ( digit1-9 *DIGIT ) | - | ||||||||||||||||||
729 | if (json < end && *json == '0') {
| 0-51 | ||||||||||||||||||
730 | ++json; | - | ||||||||||||||||||
731 | } else { never executed: end of block | 0 | ||||||||||||||||||
732 | while (json < end && *json >= '0' && *json <= '9')
| 0-114 | ||||||||||||||||||
733 | ++json; executed 63 times by 2 tests: ++json; Executed by:
| 63 | ||||||||||||||||||
734 | } executed 51 times by 2 tests: end of block Executed by:
| 51 | ||||||||||||||||||
735 | - | |||||||||||||||||||
736 | // frac = decimal-point 1*DIGIT | - | ||||||||||||||||||
737 | if (json < end && *json == '.') {
| 0-51 | ||||||||||||||||||
738 | isInt = false; | - | ||||||||||||||||||
739 | ++json; | - | ||||||||||||||||||
740 | while (json < end && *json >= '0' && *json <= '9')
| 0 | ||||||||||||||||||
741 | ++json; never executed: ++json; | 0 | ||||||||||||||||||
742 | } never executed: end of block | 0 | ||||||||||||||||||
743 | - | |||||||||||||||||||
744 | // exp = e [ minus / plus ] 1*DIGIT | - | ||||||||||||||||||
745 | if (json < end && (*json == 'e' || *json == 'E')) {
| 0-51 | ||||||||||||||||||
746 | isInt = false; | - | ||||||||||||||||||
747 | ++json; | - | ||||||||||||||||||
748 | if (json < end && (*json == '-' || *json == '+'))
| 0 | ||||||||||||||||||
749 | ++json; never executed: ++json; | 0 | ||||||||||||||||||
750 | while (json < end && *json >= '0' && *json <= '9')
| 0 | ||||||||||||||||||
751 | ++json; never executed: ++json; | 0 | ||||||||||||||||||
752 | } never executed: end of block | 0 | ||||||||||||||||||
753 | - | |||||||||||||||||||
754 | if (json >= end) {
| 0-51 | ||||||||||||||||||
755 | lastError = QJsonParseError::TerminationByNumber; | - | ||||||||||||||||||
756 | return false; never executed: return false; | 0 | ||||||||||||||||||
757 | } | - | ||||||||||||||||||
758 | - | |||||||||||||||||||
759 | QByteArray number(start, json - start); | - | ||||||||||||||||||
760 | DEBUG << "numberstring" << number; executed 51 times by 2 tests: ; Executed by:
dead code: QMessageLogger(__FILE__, 760, __PRETTY_FUNCTION__).debug() << "numberstring" << number; | - | ||||||||||||||||||
761 | - | |||||||||||||||||||
762 | if (isInt) {
| 0-51 | ||||||||||||||||||
763 | bool ok; | - | ||||||||||||||||||
764 | int n = number.toInt(&ok); | - | ||||||||||||||||||
765 | if (ok && n < (1<<25) && n > -(1<<25)) {
| 0-51 | ||||||||||||||||||
766 | val->int_value = n; | - | ||||||||||||||||||
767 | val->latinOrIntValue = true; | - | ||||||||||||||||||
768 | END; | - | ||||||||||||||||||
769 | return true; executed 51 times by 2 tests: return true; Executed by:
| 51 | ||||||||||||||||||
770 | } | - | ||||||||||||||||||
771 | } never executed: end of block | 0 | ||||||||||||||||||
772 | - | |||||||||||||||||||
773 | bool ok; | - | ||||||||||||||||||
774 | union { | - | ||||||||||||||||||
775 | quint64 ui; | - | ||||||||||||||||||
776 | double d; | - | ||||||||||||||||||
777 | }; | - | ||||||||||||||||||
778 | d = number.toDouble(&ok); | - | ||||||||||||||||||
779 | - | |||||||||||||||||||
780 | if (!ok) {
| 0 | ||||||||||||||||||
781 | lastError = QJsonParseError::IllegalNumber; | - | ||||||||||||||||||
782 | return false; never executed: return false; | 0 | ||||||||||||||||||
783 | } | - | ||||||||||||||||||
784 | - | |||||||||||||||||||
785 | int pos = reserveSpace(sizeof(double)); | - | ||||||||||||||||||
786 | if (pos < 0)
| 0 | ||||||||||||||||||
787 | return false; never executed: return false; | 0 | ||||||||||||||||||
788 | qToLittleEndian(ui, reinterpret_cast<uchar *>(data + pos)); | - | ||||||||||||||||||
789 | if (current - baseOffset >= Value::MaxSize) {
| 0 | ||||||||||||||||||
790 | lastError = QJsonParseError::DocumentTooLarge; | - | ||||||||||||||||||
791 | return false; never executed: return false; | 0 | ||||||||||||||||||
792 | } | - | ||||||||||||||||||
793 | val->value = pos - baseOffset; | - | ||||||||||||||||||
794 | val->latinOrIntValue = false; | - | ||||||||||||||||||
795 | - | |||||||||||||||||||
796 | END; | - | ||||||||||||||||||
797 | return true; never executed: return true; | 0 | ||||||||||||||||||
798 | } | - | ||||||||||||||||||
799 | - | |||||||||||||||||||
800 | /* | - | ||||||||||||||||||
801 | - | |||||||||||||||||||
802 | string = quotation-mark *char quotation-mark | - | ||||||||||||||||||
803 | - | |||||||||||||||||||
804 | char = unescaped / | - | ||||||||||||||||||
805 | escape ( | - | ||||||||||||||||||
806 | %x22 / ; " quotation mark U+0022 | - | ||||||||||||||||||
807 | %x5C / ; \ reverse solidus U+005C | - | ||||||||||||||||||
808 | %x2F / ; / solidus U+002F | - | ||||||||||||||||||
809 | %x62 / ; b backspace U+0008 | - | ||||||||||||||||||
810 | %x66 / ; f form feed U+000C | - | ||||||||||||||||||
811 | %x6E / ; n line feed U+000A | - | ||||||||||||||||||
812 | %x72 / ; r carriage return U+000D | - | ||||||||||||||||||
813 | %x74 / ; t tab U+0009 | - | ||||||||||||||||||
814 | %x75 4HEXDIG ) ; uXXXX U+XXXX | - | ||||||||||||||||||
815 | - | |||||||||||||||||||
816 | escape = %x5C ; \ | - | ||||||||||||||||||
817 | - | |||||||||||||||||||
818 | quotation-mark = %x22 ; " | - | ||||||||||||||||||
819 | - | |||||||||||||||||||
820 | unescaped = %x20-21 / %x23-5B / %x5D-10FFFF | - | ||||||||||||||||||
821 | */ | - | ||||||||||||||||||
822 | static inline bool addHexDigit(char digit, uint *result) | - | ||||||||||||||||||
823 | { | - | ||||||||||||||||||
824 | *result <<= 4; | - | ||||||||||||||||||
825 | if (digit >= '0' && digit <= '9')
| 0-412 | ||||||||||||||||||
826 | *result |= (digit - '0'); executed 300 times by 1 test: *result |= (digit - '0'); Executed by:
| 300 | ||||||||||||||||||
827 | else if (digit >= 'a' && digit <= 'f')
| 0-112 | ||||||||||||||||||
828 | *result |= (digit - 'a') + 10; never executed: *result |= (digit - 'a') + 10; | 0 | ||||||||||||||||||
829 | else if (digit >= 'A' && digit <= 'F')
| 0-112 | ||||||||||||||||||
830 | *result |= (digit - 'A') + 10; executed 112 times by 1 test: *result |= (digit - 'A') + 10; Executed by:
| 112 | ||||||||||||||||||
831 | else | - | ||||||||||||||||||
832 | return false; never executed: return false; | 0 | ||||||||||||||||||
833 | return true; executed 412 times by 1 test: return true; Executed by:
| 412 | ||||||||||||||||||
834 | } | - | ||||||||||||||||||
835 | - | |||||||||||||||||||
836 | static inline bool scanEscapeSequence(const char *&json, const char *end, uint *ch) | - | ||||||||||||||||||
837 | { | - | ||||||||||||||||||
838 | ++json; | - | ||||||||||||||||||
839 | if (json >= end)
| 0-206 | ||||||||||||||||||
840 | return false; never executed: return false; | 0 | ||||||||||||||||||
841 | - | |||||||||||||||||||
842 | DEBUG << "scan escape" << (char)*json; executed 206 times by 1 test: ; Executed by:
dead code: QMessageLogger(__FILE__, 842, __PRETTY_FUNCTION__).debug() << "scan escape" << (char)*json; | - | ||||||||||||||||||
843 | uint escaped = *json++; | - | ||||||||||||||||||
844 | switch (escaped) { | - | ||||||||||||||||||
845 | case '"': executed 98 times by 1 test: case '"': Executed by:
| 98 | ||||||||||||||||||
846 | *ch = '"'; break; executed 98 times by 1 test: break; Executed by:
| 98 | ||||||||||||||||||
847 | case '\\': executed 4 times by 1 test: case '\\': Executed by:
| 4 | ||||||||||||||||||
848 | *ch = '\\'; break; executed 4 times by 1 test: break; Executed by:
| 4 | ||||||||||||||||||
849 | case '/': never executed: case '/': | 0 | ||||||||||||||||||
850 | *ch = '/'; break; never executed: break; | 0 | ||||||||||||||||||
851 | case 'b': never executed: case 'b': | 0 | ||||||||||||||||||
852 | *ch = 0x8; break; never executed: break; | 0 | ||||||||||||||||||
853 | case 'f': never executed: case 'f': | 0 | ||||||||||||||||||
854 | *ch = 0xc; break; never executed: break; | 0 | ||||||||||||||||||
855 | case 'n': never executed: case 'n': | 0 | ||||||||||||||||||
856 | *ch = 0xa; break; never executed: break; | 0 | ||||||||||||||||||
857 | case 'r': executed 1 time by 1 test: case 'r': Executed by:
| 1 | ||||||||||||||||||
858 | *ch = 0xd; break; executed 1 time by 1 test: break; Executed by:
| 1 | ||||||||||||||||||
859 | case 't': never executed: case 't': | 0 | ||||||||||||||||||
860 | *ch = 0x9; break; never executed: break; | 0 | ||||||||||||||||||
861 | case 'u': { executed 103 times by 1 test: case 'u': Executed by:
| 103 | ||||||||||||||||||
862 | *ch = 0; | - | ||||||||||||||||||
863 | if (json > end - 4)
| 0-103 | ||||||||||||||||||
864 | return false; never executed: return false; | 0 | ||||||||||||||||||
865 | for (int i = 0; i < 4; ++i) {
| 103-412 | ||||||||||||||||||
866 | if (!addHexDigit(*json, ch))
| 0-412 | ||||||||||||||||||
867 | return false; never executed: return false; | 0 | ||||||||||||||||||
868 | ++json; | - | ||||||||||||||||||
869 | } executed 412 times by 1 test: end of block Executed by:
| 412 | ||||||||||||||||||
870 | return true; executed 103 times by 1 test: return true; Executed by:
| 103 | ||||||||||||||||||
871 | } | - | ||||||||||||||||||
872 | default: never executed: default: | 0 | ||||||||||||||||||
873 | // this is not as strict as one could be, but allows for more Json files | - | ||||||||||||||||||
874 | // to be parsed correctly. | - | ||||||||||||||||||
875 | *ch = escaped; | - | ||||||||||||||||||
876 | return true; never executed: return true; | 0 | ||||||||||||||||||
877 | } | - | ||||||||||||||||||
878 | return true; executed 103 times by 1 test: return true; Executed by:
| 103 | ||||||||||||||||||
879 | } | - | ||||||||||||||||||
880 | - | |||||||||||||||||||
881 | static inline bool scanUtf8Char(const char *&json, const char *end, uint *result) | - | ||||||||||||||||||
882 | { | - | ||||||||||||||||||
883 | const uchar *&src = reinterpret_cast<const uchar *&>(json); | - | ||||||||||||||||||
884 | const uchar *uend = reinterpret_cast<const uchar *>(end); | - | ||||||||||||||||||
885 | uchar b = *src++; | - | ||||||||||||||||||
886 | int res = QUtf8Functions::fromUtf8<QUtf8BaseTraits>(b, result, src, uend); | - | ||||||||||||||||||
887 | if (res < 0) {
| 0-35995 | ||||||||||||||||||
888 | // decoding error, backtrack the character we read above | - | ||||||||||||||||||
889 | --json; | - | ||||||||||||||||||
890 | return false; never executed: return false; | 0 | ||||||||||||||||||
891 | } | - | ||||||||||||||||||
892 | - | |||||||||||||||||||
893 | return true; executed 35995 times by 3 tests: return true; Executed by:
| 35995 | ||||||||||||||||||
894 | } | - | ||||||||||||||||||
895 | - | |||||||||||||||||||
896 | bool Parser::parseString(bool *latin1) | - | ||||||||||||||||||
897 | { | - | ||||||||||||||||||
898 | *latin1 = true; | - | ||||||||||||||||||
899 | - | |||||||||||||||||||
900 | const char *start = json; | - | ||||||||||||||||||
901 | int outStart = current; | - | ||||||||||||||||||
902 | - | |||||||||||||||||||
903 | // try to write out a latin1 string | - | ||||||||||||||||||
904 | - | |||||||||||||||||||
905 | int stringPos = reserveSpace(2); | - | ||||||||||||||||||
906 | if (stringPos < 0)
| 0-2583 | ||||||||||||||||||
907 | return false; never executed: return false; | 0 | ||||||||||||||||||
908 | - | |||||||||||||||||||
909 | BEGIN << "parse string stringPos=" << stringPos << json; executed 2583 times by 3 tests: ; Executed by:
dead code: QMessageLogger(__FILE__, 909, __PRETTY_FUNCTION__).debug() << "parse string stringPos=" << stringPos << json; | - | ||||||||||||||||||
910 | while (json < end) {
| 0-38666 | ||||||||||||||||||
911 | uint ch = 0; | - | ||||||||||||||||||
912 | if (*json == '"')
| 2573-36093 | ||||||||||||||||||
913 | break; executed 2573 times by 3 tests: break; Executed by:
| 2573 | ||||||||||||||||||
914 | else if (*json == '\\') {
| 110-35983 | ||||||||||||||||||
915 | if (!scanEscapeSequence(json, end, &ch)) {
| 0-110 | ||||||||||||||||||
916 | lastError = QJsonParseError::IllegalEscapeSequence; | - | ||||||||||||||||||
917 | return false; never executed: return false; | 0 | ||||||||||||||||||
918 | } | - | ||||||||||||||||||
919 | } else { executed 110 times by 1 test: end of block Executed by:
| 110 | ||||||||||||||||||
920 | if (!scanUtf8Char(json, end, &ch)) {
| 0-35983 | ||||||||||||||||||
921 | lastError = QJsonParseError::IllegalUTF8String; | - | ||||||||||||||||||
922 | return false; never executed: return false; | 0 | ||||||||||||||||||
923 | } | - | ||||||||||||||||||
924 | } executed 35983 times by 3 tests: end of block Executed by:
| 35983 | ||||||||||||||||||
925 | // bail out if the string is not pure latin1 or too long to hold as a latin1string (which has only 16 bit for the length) | - | ||||||||||||||||||
926 | if (ch > 0xff || json - start >= 0x8000) {
| 0-36083 | ||||||||||||||||||
927 | *latin1 = false; | - | ||||||||||||||||||
928 | break; executed 10 times by 1 test: break; Executed by:
| 10 | ||||||||||||||||||
929 | } | - | ||||||||||||||||||
930 | int pos = reserveSpace(1); | - | ||||||||||||||||||
931 | if (pos < 0)
| 0-36083 | ||||||||||||||||||
932 | return false; never executed: return false; | 0 | ||||||||||||||||||
933 | DEBUG << " " << ch << (char)ch; executed 36083 times by 3 tests: ; Executed by:
dead code: QMessageLogger(__FILE__, 933, __PRETTY_FUNCTION__).debug() << " " << ch << (char)ch; | - | ||||||||||||||||||
934 | data[pos] = (uchar)ch; | - | ||||||||||||||||||
935 | } executed 36083 times by 3 tests: end of block Executed by:
| 36083 | ||||||||||||||||||
936 | ++json; | - | ||||||||||||||||||
937 | DEBUG << "end of string"; executed 2583 times by 3 tests: ; Executed by:
dead code: QMessageLogger(__FILE__, 937, __PRETTY_FUNCTION__).debug() << "end of string"; | - | ||||||||||||||||||
938 | if (json >= end) {
| 0-2583 | ||||||||||||||||||
939 | lastError = QJsonParseError::UnterminatedString; | - | ||||||||||||||||||
940 | return false; never executed: return false; | 0 | ||||||||||||||||||
941 | } | - | ||||||||||||||||||
942 | - | |||||||||||||||||||
943 | // no unicode string, we are done | - | ||||||||||||||||||
944 | if (*latin1) {
| 10-2573 | ||||||||||||||||||
945 | // write string length | - | ||||||||||||||||||
946 | *(QJsonPrivate::qle_ushort *)(data + stringPos) = ushort(current - outStart - sizeof(ushort)); | - | ||||||||||||||||||
947 | int pos = reserveSpace((4 - current) & 3); | - | ||||||||||||||||||
948 | if (pos < 0)
| 0-2573 | ||||||||||||||||||
949 | return false; never executed: return false; | 0 | ||||||||||||||||||
950 | while (pos & 3)
| 2573-4433 | ||||||||||||||||||
951 | data[pos++] = 0; executed 4433 times by 3 tests: data[pos++] = 0; Executed by:
| 4433 | ||||||||||||||||||
952 | END; | - | ||||||||||||||||||
953 | return true; executed 2573 times by 3 tests: return true; Executed by:
| 2573 | ||||||||||||||||||
954 | } | - | ||||||||||||||||||
955 | - | |||||||||||||||||||
956 | *latin1 = false; | - | ||||||||||||||||||
957 | DEBUG << "not latin"; executed 10 times by 1 test: ; Executed by:
dead code: QMessageLogger(__FILE__, 957, __PRETTY_FUNCTION__).debug() << "not latin"; | - | ||||||||||||||||||
958 | - | |||||||||||||||||||
959 | json = start; | - | ||||||||||||||||||
960 | current = outStart + sizeof(int); | - | ||||||||||||||||||
961 | - | |||||||||||||||||||
962 | while (json < end) {
| 0-118 | ||||||||||||||||||
963 | uint ch = 0; | - | ||||||||||||||||||
964 | if (*json == '"')
| 10-108 | ||||||||||||||||||
965 | break; executed 10 times by 1 test: break; Executed by:
| 10 | ||||||||||||||||||
966 | else if (*json == '\\') {
| 12-96 | ||||||||||||||||||
967 | if (!scanEscapeSequence(json, end, &ch)) {
| 0-96 | ||||||||||||||||||
968 | lastError = QJsonParseError::IllegalEscapeSequence; | - | ||||||||||||||||||
969 | return false; never executed: return false; | 0 | ||||||||||||||||||
970 | } | - | ||||||||||||||||||
971 | } else { executed 96 times by 1 test: end of block Executed by:
| 96 | ||||||||||||||||||
972 | if (!scanUtf8Char(json, end, &ch)) {
| 0-12 | ||||||||||||||||||
973 | lastError = QJsonParseError::IllegalUTF8String; | - | ||||||||||||||||||
974 | return false; never executed: return false; | 0 | ||||||||||||||||||
975 | } | - | ||||||||||||||||||
976 | } executed 12 times by 1 test: end of block Executed by:
| 12 | ||||||||||||||||||
977 | if (QChar::requiresSurrogates(ch)) {
| 0-108 | ||||||||||||||||||
978 | int pos = reserveSpace(4); | - | ||||||||||||||||||
979 | if (pos < 0)
| 0 | ||||||||||||||||||
980 | return false; never executed: return false; | 0 | ||||||||||||||||||
981 | *(QJsonPrivate::qle_ushort *)(data + pos) = QChar::highSurrogate(ch); | - | ||||||||||||||||||
982 | *(QJsonPrivate::qle_ushort *)(data + pos + 2) = QChar::lowSurrogate(ch); | - | ||||||||||||||||||
983 | } else { never executed: end of block | 0 | ||||||||||||||||||
984 | int pos = reserveSpace(2); | - | ||||||||||||||||||
985 | if (pos < 0)
| 0-108 | ||||||||||||||||||
986 | return false; never executed: return false; | 0 | ||||||||||||||||||
987 | *(QJsonPrivate::qle_ushort *)(data + pos) = (ushort)ch; | - | ||||||||||||||||||
988 | } executed 108 times by 1 test: end of block Executed by:
| 108 | ||||||||||||||||||
989 | } | - | ||||||||||||||||||
990 | ++json; | - | ||||||||||||||||||
991 | - | |||||||||||||||||||
992 | if (json >= end) {
| 0-10 | ||||||||||||||||||
993 | lastError = QJsonParseError::UnterminatedString; | - | ||||||||||||||||||
994 | return false; never executed: return false; | 0 | ||||||||||||||||||
995 | } | - | ||||||||||||||||||
996 | - | |||||||||||||||||||
997 | // write string length | - | ||||||||||||||||||
998 | *(QJsonPrivate::qle_int *)(data + stringPos) = (current - outStart - sizeof(int))/2; | - | ||||||||||||||||||
999 | int pos = reserveSpace((4 - current) & 3); | - | ||||||||||||||||||
1000 | if (pos < 0)
| 0-10 | ||||||||||||||||||
1001 | return false; never executed: return false; | 0 | ||||||||||||||||||
1002 | while (pos & 3)
| 10-12 | ||||||||||||||||||
1003 | data[pos++] = 0; executed 12 times by 1 test: data[pos++] = 0; Executed by:
| 12 | ||||||||||||||||||
1004 | END; | - | ||||||||||||||||||
1005 | return true; executed 10 times by 1 test: return true; Executed by:
| 10 | ||||||||||||||||||
1006 | } | - | ||||||||||||||||||
1007 | - | |||||||||||||||||||
1008 | QT_END_NAMESPACE | - | ||||||||||||||||||
Source code | Switch to Preprocessed file |