Line | Source Code | Coverage |
---|
1 | | - |
2 | | - |
3 | | - |
4 | using namespace QJsonPrivate; | - |
5 | | - |
6 | static void objectContentToJson(const QJsonPrivate::Object *o, QByteArray &json, int indent, bool compact); | - |
7 | static void arrayContentToJson(const QJsonPrivate::Array *a, QByteArray &json, int indent, bool compact); | - |
8 | | - |
9 | static inline uchar hexdig(uint u) | - |
10 | { | - |
11 | return (u < 0xa ? '0' + u : 'a' + u - 0xa); executed: return (u < 0xa ? '0' + u : 'a' + u - 0xa); Execution Count:10542 | 10542 |
12 | } | - |
13 | | - |
14 | static QByteArray escapedString(const QString &s) | - |
15 | { | - |
16 | const uchar replacement = '?'; | - |
17 | QByteArray ba(s.length(), Qt::Uninitialized); | - |
18 | | - |
19 | uchar *cursor = (uchar *)ba.data(); | - |
20 | const uchar *ba_end = cursor + ba.length(); | - |
21 | | - |
22 | const QChar *ch = (const QChar *)s.constData(); | - |
23 | const QChar *end = ch + s.length(); | - |
24 | | - |
25 | int surrogate_high = -1; | - |
26 | | - |
27 | while (ch < end) { evaluated: ch < end yes Evaluation Count:27278864 | yes Evaluation Count:1332760 |
| 1332760-27278864 |
28 | if (cursor >= ba_end - 6) { evaluated: cursor >= ba_end - 6 yes Evaluation Count:1996087 | yes Evaluation Count:25282777 |
| 1996087-25282777 |
29 | | - |
30 | int pos = cursor - (const uchar *)ba.constData(); | - |
31 | ba.resize(ba.size()*2); | - |
32 | cursor = (uchar *)ba.data() + pos; | - |
33 | ba_end = (const uchar *)ba.constData() + ba.length(); | - |
34 | } executed: } Execution Count:1996087 | 1996087 |
35 | | - |
36 | uint u = ch->unicode(); | - |
37 | if (surrogate_high >= 0) { partially evaluated: surrogate_high >= 0 no Evaluation Count:0 | yes Evaluation Count:27278864 |
| 0-27278864 |
38 | if (ch->isLowSurrogate()) { never evaluated: ch->isLowSurrogate() | 0 |
39 | u = QChar::surrogateToUcs4(surrogate_high, u); | - |
40 | surrogate_high = -1; | - |
41 | } else { | 0 |
42 | | - |
43 | *cursor = replacement; | - |
44 | ++ch; | - |
45 | surrogate_high = -1; | - |
46 | continue; never executed: continue; | 0 |
47 | } | - |
48 | } else if (ch->isLowSurrogate()) { partially evaluated: ch->isLowSurrogate() no Evaluation Count:0 | yes Evaluation Count:27278864 |
| 0-27278864 |
49 | | - |
50 | *cursor = replacement; | - |
51 | ++ch; | - |
52 | continue; never executed: continue; | 0 |
53 | } else if (ch->isHighSurrogate()) { partially evaluated: ch->isHighSurrogate() no Evaluation Count:0 | yes Evaluation Count:27278864 |
| 0-27278864 |
54 | surrogate_high = u; | - |
55 | ++ch; | - |
56 | continue; never executed: continue; | 0 |
57 | } | - |
58 | | - |
59 | if (u < 0x80) { evaluated: u < 0x80 yes Evaluation Count:27262928 | yes Evaluation Count:15936 |
| 15936-27262928 |
60 | if (u < 0x20 || u == 0x22 || u == 0x5c) { evaluated: u < 0x20 yes Evaluation Count:12955 | yes Evaluation Count:27249973 |
evaluated: u == 0x22 yes Evaluation Count:5208 | yes Evaluation Count:27244765 |
evaluated: u == 0x5c yes Evaluation Count:751 | yes Evaluation Count:27244014 |
| 751-27249973 |
61 | *cursor++ = '\\'; | - |
62 | switch (u) { | - |
63 | case 0x22: | - |
64 | *cursor++ = '"'; | - |
65 | break; executed: break; Execution Count:5208 | 5208 |
66 | case 0x5c: | - |
67 | *cursor++ = '\\'; | - |
68 | break; executed: break; Execution Count:751 | 751 |
69 | case 0x8: | - |
70 | *cursor++ = 'b'; | - |
71 | break; executed: break; Execution Count:1525 | 1525 |
72 | case 0xc: | - |
73 | *cursor++ = 'f'; | - |
74 | break; executed: break; Execution Count:1564 | 1564 |
75 | case 0xa: | - |
76 | *cursor++ = 'n'; | - |
77 | break; executed: break; Execution Count:1547 | 1547 |
78 | case 0xd: | - |
79 | *cursor++ = 'r'; | - |
80 | break; executed: break; Execution Count:1536 | 1536 |
81 | case 0x9: | - |
82 | *cursor++ = 't'; | - |
83 | break; executed: break; Execution Count:1512 | 1512 |
84 | default: | - |
85 | *cursor++ = 'u'; | - |
86 | *cursor++ = '0'; | - |
87 | *cursor++ = '0'; | - |
88 | *cursor++ = hexdig(u>>4); | - |
89 | *cursor++ = hexdig(u & 0xf); | - |
90 | } executed: } Execution Count:5271 | 5271 |
91 | } else { executed: } Execution Count:18914 | 18914 |
92 | *cursor++ = (uchar)u; | - |
93 | } executed: } Execution Count:27244014 | 27244014 |
94 | } else { | - |
95 | if (u < 0x0800) { evaluated: u < 0x0800 yes Evaluation Count:7737 | yes Evaluation Count:8199 |
| 7737-8199 |
96 | *cursor++ = 0xc0 | ((uchar) (u >> 6)); | - |
97 | } else { executed: } Execution Count:7737 | 7737 |
98 | | - |
99 | if (QChar::isNonCharacter(u)) { partially evaluated: QChar::isNonCharacter(u) no Evaluation Count:0 | yes Evaluation Count:8199 |
| 0-8199 |
100 | *cursor++ = replacement; | - |
101 | ++ch; | - |
102 | continue; never executed: continue; | 0 |
103 | } | - |
104 | | - |
105 | if (QChar::requiresSurrogates(u)) { partially evaluated: QChar::requiresSurrogates(u) no Evaluation Count:0 | yes Evaluation Count:8199 |
| 0-8199 |
106 | *cursor++ = 0xf0 | ((uchar) (u >> 18)); | - |
107 | *cursor++ = 0x80 | (((uchar) (u >> 12)) & 0x3f); | - |
108 | } else { | 0 |
109 | *cursor++ = 0xe0 | (((uchar) (u >> 12)) & 0x3f); | - |
110 | } executed: } Execution Count:8199 | 8199 |
111 | *cursor++ = 0x80 | (((uchar) (u >> 6)) & 0x3f); | - |
112 | } executed: } Execution Count:8199 | 8199 |
113 | *cursor++ = 0x80 | ((uchar) (u&0x3f)); | - |
114 | } executed: } Execution Count:15936 | 15936 |
115 | ++ch; | - |
116 | } executed: } Execution Count:27278864 | 27278864 |
117 | | - |
118 | ba.resize(cursor - (const uchar *)ba.constData()); | - |
119 | return ba; executed: return ba; Execution Count:1332760 | 1332760 |
120 | } | - |
121 | | - |
122 | static void valueToJson(const QJsonPrivate::Base *b, const QJsonPrivate::Value &v, QByteArray &json, int indent, bool compact) | - |
123 | { | - |
124 | QJsonValue::Type type = (QJsonValue::Type)(uint)v.type; | - |
125 | switch (type) { | - |
126 | case QJsonValue::Bool: | - |
127 | json += v.toBoolean() ? "true" : "false"; evaluated: v.toBoolean() yes Evaluation Count:1477 | yes Evaluation Count:1466 |
| 1466-1477 |
128 | break; executed: break; Execution Count:2943 | 2943 |
129 | case QJsonValue::Double: | - |
130 | json += QByteArray::number(v.toDouble(b)); | - |
131 | break; executed: break; Execution Count:450215 | 450215 |
132 | case QJsonValue::String: | - |
133 | json += '"'; | - |
134 | json += escapedString(v.toString(b)); | - |
135 | json += '"'; | - |
136 | break; executed: break; Execution Count:349688 | 349688 |
137 | case QJsonValue::Array: | - |
138 | json += compact ? "[" : "[\n"; partially evaluated: compact no Evaluation Count:0 | yes Evaluation Count:36437 |
| 0-36437 |
139 | arrayContentToJson(static_cast<QJsonPrivate::Array *>(v.base(b)), json, indent + (compact ? 0 : 1), compact); | - |
140 | json += QByteArray(4*indent, ' '); | - |
141 | json += "]"; | - |
142 | break; executed: break; Execution Count:36437 | 36437 |
143 | case QJsonValue::Object: | - |
144 | json += compact ? "{" : "{\n"; partially evaluated: compact no Evaluation Count:0 | yes Evaluation Count:319522 |
| 0-319522 |
145 | objectContentToJson(static_cast<QJsonPrivate::Object *>(v.base(b)), json, indent + (compact ? 0 : 1), compact); | - |
146 | json += QByteArray(4*indent, ' '); | - |
147 | json += "}"; | - |
148 | break; executed: break; Execution Count:319522 | 319522 |
149 | case QJsonValue::Null: | - |
150 | default: | - |
151 | json += "null"; | - |
152 | } executed: } Execution Count:1538 | 1538 |
153 | } executed: } Execution Count:1160343 | 1160343 |
154 | | - |
155 | static void arrayContentToJson(const QJsonPrivate::Array *a, QByteArray &json, int indent, bool compact) | - |
156 | { | - |
157 | if (!a || !a->length) partially evaluated: !a no Evaluation Count:0 | yes Evaluation Count:37193 |
evaluated: !a->length yes Evaluation Count:1470 | yes Evaluation Count:35723 |
| 0-37193 |
158 | return; executed: return; Execution Count:1470 | 1470 |
159 | | - |
160 | QByteArray indentString(4*indent, ' '); | - |
161 | | - |
162 | uint i = 0; | - |
163 | while (1) { partially evaluated: 1 yes Evaluation Count:177271 | no Evaluation Count:0 |
| 0-177271 |
164 | json += indentString; | - |
165 | valueToJson(a, a->at(i), json, indent, compact); | - |
166 | | - |
167 | if (++i == a->length) { evaluated: ++i == a->length yes Evaluation Count:35723 | yes Evaluation Count:141548 |
| 35723-141548 |
168 | if (!compact) evaluated: !compact yes Evaluation Count:35720 | yes Evaluation Count:3 |
| 3-35720 |
169 | json += '\n'; executed: json += '\n'; Execution Count:35720 | 35720 |
170 | break; executed: break; Execution Count:35723 | 35723 |
171 | } | - |
172 | | - |
173 | json += compact ? "," : ",\n"; evaluated: compact yes Evaluation Count:3 | yes Evaluation Count:141545 |
| 3-141545 |
174 | } executed: } Execution Count:141548 | 141548 |
175 | } executed: } Execution Count:35723 | 35723 |
176 | | - |
177 | | - |
178 | static void objectContentToJson(const QJsonPrivate::Object *o, QByteArray &json, int indent, bool compact) | - |
179 | { | - |
180 | if (!o || !o->length) partially evaluated: !o no Evaluation Count:0 | yes Evaluation Count:319956 |
evaluated: !o->length yes Evaluation Count:1470 | yes Evaluation Count:318486 |
| 0-319956 |
181 | return; executed: return; Execution Count:1470 | 1470 |
182 | | - |
183 | QByteArray indentString(4*indent, ' '); | - |
184 | | - |
185 | uint i = 0; | - |
186 | while (1) { partially evaluated: 1 yes Evaluation Count:983072 | no Evaluation Count:0 |
| 0-983072 |
187 | QJsonPrivate::Entry *e = o->entryAt(i); | - |
188 | json += indentString; | - |
189 | json += '"'; | - |
190 | json += escapedString(e->key()); | - |
191 | json += "\": "; | - |
192 | valueToJson(o, e->value, json, indent, compact); | - |
193 | | - |
194 | if (++i == o->length) { evaluated: ++i == o->length yes Evaluation Count:318486 | yes Evaluation Count:664586 |
| 318486-664586 |
195 | if (!compact) evaluated: !compact yes Evaluation Count:318483 | yes Evaluation Count:3 |
| 3-318483 |
196 | json += '\n'; executed: json += '\n'; Execution Count:318483 | 318483 |
197 | break; executed: break; Execution Count:318486 | 318486 |
198 | } | - |
199 | | - |
200 | json += compact ? "," : ",\n"; partially evaluated: compact no Evaluation Count:0 | yes Evaluation Count:664586 |
| 0-664586 |
201 | } executed: } Execution Count:664586 | 664586 |
202 | } executed: } Execution Count:318486 | 318486 |
203 | | - |
204 | void Writer::objectToJson(const QJsonPrivate::Object *o, QByteArray &json, int indent, bool compact) | - |
205 | { | - |
206 | json.reserve(json.size() + (o ? (int)o->size : 16)); | - |
207 | json += compact ? "{" : "{\n"; evaluated: compact yes Evaluation Count:3 | yes Evaluation Count:431 |
| 3-431 |
208 | objectContentToJson(o, json, indent + (compact ? 0 : 1), compact); | - |
209 | json += QByteArray(4*indent, ' '); | - |
210 | json += compact ? "}" : "}\n"; evaluated: compact yes Evaluation Count:3 | yes Evaluation Count:431 |
| 3-431 |
211 | } executed: } Execution Count:434 | 434 |
212 | | - |
213 | void Writer::arrayToJson(const QJsonPrivate::Array *a, QByteArray &json, int indent, bool compact) | - |
214 | { | - |
215 | json.reserve(json.size() + (a ? (int)a->size : 16)); | - |
216 | json += compact ? "[" : "[\n"; evaluated: compact yes Evaluation Count:3 | yes Evaluation Count:753 |
| 3-753 |
217 | arrayContentToJson(a, json, indent + (compact ? 0 : 1), compact); | - |
218 | json += QByteArray(4*indent, ' '); | - |
219 | json += compact ? "]" : "]\n"; evaluated: compact yes Evaluation Count:3 | yes Evaluation Count:753 |
| 3-753 |
220 | } executed: } Execution Count:756 | 756 |
221 | | - |
222 | | - |
223 | | - |
| | |