io/qurlquery.cpp

Switch to Source codePreprocessed file
LineSource CodeCoverage
1 -
2 -
3 -
4typedef QList<QPair<QString, QString> > Map; -
5 -
6class QUrlQueryPrivate : public QSharedData -
7{ -
8public: -
9 QUrlQueryPrivate(const QString &query = QString()) -
10 : valueDelimiter(QUrlQuery::defaultQueryValueDelimiter()), -
11 pairDelimiter(QUrlQuery::defaultQueryPairDelimiter()) -
12 { if (!query.isEmpty()) setQuery(query); }
executed: setQuery(query);
Execution Count:46
executed: }
Execution Count:101
evaluated: !query.isEmpty()
TRUEFALSE
yes
Evaluation Count:46
yes
Evaluation Count:55
46-101
13 -
14 QString recodeFromUser(const QString &input) const; -
15 QString recodeToUser(const QString &input, QUrl::ComponentFormattingOptions encoding) const; -
16 -
17 void setQuery(const QString &query); -
18 -
19 void addQueryItem(const QString &key, const QString &value) -
20 { itemList.append(qMakePair(recodeFromUser(key), recodeFromUser(value))); }
executed: }
Execution Count:104
104
21 int findRecodedKey(const QString &key, int from = 0) const -
22 { -
23 for (int i = from; i < itemList.size(); ++i)
evaluated: i < itemList.size()
TRUEFALSE
yes
Evaluation Count:96
yes
Evaluation Count:17
17-96
24 if (itemList.at(i).first == key)
evaluated: itemList.at(i).first == key
TRUEFALSE
yes
Evaluation Count:52
yes
Evaluation Count:44
44-52
25 return i;
executed: return i;
Execution Count:52
52
26 return itemList.size();
executed: return itemList.size();
Execution Count:17
17
27 } -
28 Map::const_iterator findKey(const QString &key) const -
29 { return itemList.constBegin() + findRecodedKey(recodeFromUser(key)); }
executed: return itemList.constBegin() + findRecodedKey(recodeFromUser(key));
Execution Count:32
32
30 Map::iterator findKey(const QString &key) -
31 { return itemList.begin() + findRecodedKey(recodeFromUser(key)); }
executed: return itemList.begin() + findRecodedKey(recodeFromUser(key));
Execution Count:6
6
32 -
33 -
34 Map itemList; -
35 QChar valueDelimiter; -
36 QChar pairDelimiter; -
37}; -
38 -
39template<> void QSharedDataPointer<QUrlQueryPrivate>::detach() -
40{ -
41 if (d && d->ref.load() == 1)
evaluated: d
TRUEFALSE
yes
Evaluation Count:111
yes
Evaluation Count:55
evaluated: d->ref.load() == 1
TRUEFALSE
yes
Evaluation Count:107
yes
Evaluation Count:4
4-111
42 return;
executed: return;
Execution Count:107
107
43 QUrlQueryPrivate *x = (d ? new QUrlQueryPrivate(*d)
evaluated: d
TRUEFALSE
yes
Evaluation Count:4
yes
Evaluation Count:55
4-55
44 : new QUrlQueryPrivate); -
45 x->ref.ref(); -
46 if (d && !d->ref.deref())
evaluated: d
TRUEFALSE
yes
Evaluation Count:4
yes
Evaluation Count:55
partially evaluated: !d->ref.deref()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:4
0-55
47 delete d;
never executed: delete d;
0
48 d = x; -
49}
executed: }
Execution Count:59
59
50static const ushort prettyDecodedActions[] = { ushort(0x100 | ('+')), 0 }; -
51 -
52inline QString QUrlQueryPrivate::recodeFromUser(const QString &input) const -
53{ -
54 -
55 QString output; -
56 if (qt_urlRecode(output, input.constData(), input.constData() + input.length(), 26-235
57 QUrl::DecodeReserved, 26-235
58 prettyDecodedActions))
evaluated: qt_urlRecode(output, input.constData(), input.constData() + input.length(), QUrl::DecodeReserved, prettyDecodedActions)
TRUEFALSE
yes
Evaluation Count:26
yes
Evaluation Count:235
26-235
59 return output;
executed: return output;
Execution Count:26
26
60 return input;
executed: return input;
Execution Count:235
235
61} -
62 -
63inline bool idempotentRecodeToUser(QUrl::ComponentFormattingOptions encoding) -
64{ -
65 return encoding == QUrl::PrettyDecoded;
executed: return encoding == QUrl::PrettyDecoded;
Execution Count:146
146
66} -
67 -
68inline QString QUrlQueryPrivate::recodeToUser(const QString &input, QUrl::ComponentFormattingOptions encoding) const -
69{ -
70 -
71 -
72 if (idempotentRecodeToUser(encoding))
evaluated: idempotentRecodeToUser(encoding)
TRUEFALSE
yes
Evaluation Count:35
yes
Evaluation Count:24
24-35
73 return input;
executed: return input;
Execution Count:35
35
74 -
75 if (!(encoding & QUrl::EncodeDelimiters)) {
evaluated: !(encoding & QUrl::EncodeDelimiters)
TRUEFALSE
yes
Evaluation Count:8
yes
Evaluation Count:16
8-16
76 QString output; -
77 if (qt_urlRecode(output, input.constData(), input.constData() + input.length(), 4
78 encoding, prettyDecodedActions))
evaluated: qt_urlRecode(output, input.constData(), input.constData() + input.length(), encoding, prettyDecodedActions)
TRUEFALSE
yes
Evaluation Count:4
yes
Evaluation Count:4
4
79 return output;
executed: return output;
Execution Count:4
4
80 return input;
executed: return input;
Execution Count:4
4
81 } -
82 -
83 -
84 ushort actions[] = { ushort(0x200 | (pairDelimiter.unicode())), ushort(0x200 | (valueDelimiter.unicode())), -
85 ushort(0x200 | ('#')), 0 }; -
86 QString output; -
87 if (qt_urlRecode(output, input.constData(), input.constData() + input.length(), encoding, actions))
evaluated: qt_urlRecode(output, input.constData(), input.constData() + input.length(), encoding, actions)
TRUEFALSE
yes
Evaluation Count:6
yes
Evaluation Count:10
6-10
88 return output;
executed: return output;
Execution Count:6
6
89 return input;
executed: return input;
Execution Count:10
10
90} -
91 -
92void QUrlQueryPrivate::setQuery(const QString &query) -
93{ -
94 itemList.clear(); -
95 const QChar *pos = query.constData(); -
96 const QChar *const end = pos + query.size(); -
97 while (pos != end) {
evaluated: pos != end
TRUEFALSE
yes
Evaluation Count:72
yes
Evaluation Count:49
49-72
98 const QChar *begin = pos; -
99 const QChar *delimiter = 0; -
100 while (pos != end) {
evaluated: pos != end
TRUEFALSE
yes
Evaluation Count:530
yes
Evaluation Count:48
48-530
101 -
102 if (!delimiter && pos->unicode() == valueDelimiter)
evaluated: !delimiter
TRUEFALSE
yes
Evaluation Count:309
yes
Evaluation Count:221
evaluated: pos->unicode() == valueDelimiter
TRUEFALSE
yes
Evaluation Count:62
yes
Evaluation Count:247
62-309
103 delimiter = pos;
executed: delimiter = pos;
Execution Count:62
62
104 if (pos->unicode() == pairDelimiter)
evaluated: pos->unicode() == pairDelimiter
TRUEFALSE
yes
Evaluation Count:24
yes
Evaluation Count:506
24-506
105 break;
executed: break;
Execution Count:24
24
106 ++pos; -
107 }
executed: }
Execution Count:506
506
108 if (!delimiter)
evaluated: !delimiter
TRUEFALSE
yes
Evaluation Count:10
yes
Evaluation Count:62
10-62
109 delimiter = pos;
executed: delimiter = pos;
Execution Count:10
10
110 -
111 -
112 -
113 -
114 QString key; -
115 if (!qt_urlRecode(key, begin, delimiter, 12-60
116 QUrl::DecodeReserved, 12-60
117 prettyDecodedActions))
evaluated: !qt_urlRecode(key, begin, delimiter, QUrl::DecodeReserved, prettyDecodedActions)
TRUEFALSE
yes
Evaluation Count:60
yes
Evaluation Count:12
12-60
118 key = QString(begin, delimiter - begin);
executed: key = QString(begin, delimiter - begin);
Execution Count:60
60
119 -
120 if (delimiter == pos) {
evaluated: delimiter == pos
TRUEFALSE
yes
Evaluation Count:10
yes
Evaluation Count:62
10-62
121 -
122 itemList.append(qMakePair(key, QString())); -
123 } else if (delimiter + 1 == pos) {
evaluated: delimiter + 1 == pos
TRUEFALSE
yes
Evaluation Count:5
yes
Evaluation Count:57
executed: }
Execution Count:10
5-57
124 -
125 itemList.append(qMakePair(key, QString(0, Qt::Uninitialized))); -
126 } else {
executed: }
Execution Count:5
5
127 QString value; -
128 if (!qt_urlRecode(value, delimiter + 1, pos, 12-45
129 QUrl::DecodeReserved, 12-45
130 prettyDecodedActions))
evaluated: !qt_urlRecode(value, delimiter + 1, pos, QUrl::DecodeReserved, prettyDecodedActions)
TRUEFALSE
yes
Evaluation Count:45
yes
Evaluation Count:12
12-45
131 value = QString(delimiter + 1, pos - delimiter - 1);
executed: value = QString(delimiter + 1, pos - delimiter - 1);
Execution Count:45
45
132 itemList.append(qMakePair(key, value)); -
133 }
executed: }
Execution Count:57
57
134 -
135 if (pos != end)
evaluated: pos != end
TRUEFALSE
yes
Evaluation Count:24
yes
Evaluation Count:48
24-48
136 ++pos;
executed: ++pos;
Execution Count:24
24
137 }
executed: }
Execution Count:72
72
138}
executed: }
Execution Count:49
49
139 -
140 -
141template <> inline QUrlQueryPrivate * -
142QSharedDataPointer<QUrlQueryPrivate>::clone() -
143{ -
144 return d ? new QUrlQueryPrivate(*d) : new QUrlQueryPrivate;
never executed: return d ? new QUrlQueryPrivate(*d) : new QUrlQueryPrivate;
0
145} -
146 -
147 -
148 -
149 -
150 -
151 -
152 -
153QUrlQuery::QUrlQuery() -
154 : d(0) -
155{ -
156}
executed: }
Execution Count:60
60
157 -
158 -
159 -
160 -
161 -
162 -
163 -
164QUrlQuery::QUrlQuery(const QString &queryString) -
165 : d(queryString.isEmpty() ? 0 : new QUrlQueryPrivate(queryString)) -
166{ -
167}
executed: }
Execution Count:49
49
168QUrlQuery::QUrlQuery(const QUrl &url) -
169 : d(0) -
170{ -
171 -
172 -
173 if (url.hasQuery())
never evaluated: url.hasQuery()
0
174 d = new QUrlQueryPrivate(url.query());
never executed: d = new QUrlQueryPrivate(url.query());
0
175}
never executed: }
0
176 -
177 -
178 -
179 -
180 -
181QUrlQuery::QUrlQuery(const QUrlQuery &other) -
182 : d(other.d) -
183{ -
184}
executed: }
Execution Count:5
5
185 -
186 -
187 -
188 -
189 -
190QUrlQuery &QUrlQuery::operator =(const QUrlQuery &other) -
191{ -
192 d = other.d; -
193 return *this;
executed: return *this;
Execution Count:4
4
194} -
195QUrlQuery::~QUrlQuery() -
196{ -
197 -
198} -
199 -
200 -
201 -
202 -
203 -
204bool QUrlQuery::operator ==(const QUrlQuery &other) const -
205{ -
206 if (d == other.d)
evaluated: d == other.d
TRUEFALSE
yes
Evaluation Count:7
yes
Evaluation Count:10
7-10
207 return true;
executed: return true;
Execution Count:7
7
208 if (d && other.d)
partially evaluated: d
TRUEFALSE
yes
Evaluation Count:10
no
Evaluation Count:0
evaluated: other.d
TRUEFALSE
yes
Evaluation Count:8
yes
Evaluation Count:2
0-10
209 return d->valueDelimiter == other.d->valueDelimiter && 8
210 d->pairDelimiter == other.d->pairDelimiter && 8
211 d->itemList == other.d->itemList;
executed: return d->valueDelimiter == other.d->valueDelimiter && d->pairDelimiter == other.d->pairDelimiter && d->itemList == other.d->itemList;
Execution Count:8
8
212 return false;
executed: return false;
Execution Count:2
2
213} -
214 -
215 -
216 -
217 -
218 -
219 -
220 -
221bool QUrlQuery::isEmpty() const -
222{ -
223 return d ? d->itemList.isEmpty() : true;
executed: return d ? d->itemList.isEmpty() : true;
Execution Count:37
37
224} -
225 -
226 -
227 -
228 -
229bool QUrlQuery::isDetached() const -
230{ -
231 return d && d->ref.load() == 1;
executed: return d && d->ref.load() == 1;
Execution Count:4
4
232} -
233void QUrlQuery::clear() -
234{ -
235 if (d.constData())
evaluated: d.constData()
TRUEFALSE
yes
Evaluation Count:16
yes
Evaluation Count:5
5-16
236 d->itemList.clear();
executed: d->itemList.clear();
Execution Count:16
16
237}
executed: }
Execution Count:21
21
238 -
239 -
240 -
241 -
242 -
243 -
244 -
245void QUrlQuery::setQuery(const QString &queryString) -
246{ -
247 d->setQuery(queryString); -
248}
executed: }
Execution Count:3
3
249 -
250static void recodeAndAppend(QString &to, const QString &input, -
251 QUrl::ComponentFormattingOptions encoding, const ushort *tableModifications) -
252{ -
253 if (!qt_urlRecode(to, input.constData(), input.constData() + input.length(), encoding, tableModifications))
evaluated: !qt_urlRecode(to, input.constData(), input.constData() + input.length(), encoding, tableModifications)
TRUEFALSE
yes
Evaluation Count:123
yes
Evaluation Count:32
32-123
254 to += input;
executed: to += input;
Execution Count:123
123
255}
executed: }
Execution Count:155
155
256QString QUrlQuery::query(QUrl::ComponentFormattingOptions encoding) const -
257{ -
258 if (!d)
evaluated: !d
TRUEFALSE
yes
Evaluation Count:2
yes
Evaluation Count:66
2-66
259 return QString();
executed: return QString();
Execution Count:2
2
260 ushort tableActions[] = { -
261 ushort(0x100 | ('+')), -
262 ushort(0x200 | (d->pairDelimiter.unicode())), -
263 ushort(0x200 | (d->valueDelimiter.unicode())), -
264 ushort('#'), -
265 0 -
266 }; -
267 if (encoding & QUrl::EncodeDelimiters) {
evaluated: encoding & QUrl::EncodeDelimiters
TRUEFALSE
yes
Evaluation Count:6
yes
Evaluation Count:60
6-60
268 tableActions[3] = ushort(0x200 | ('#')); -
269 }
executed: }
Execution Count:6
6
270 -
271 QString result; -
272 Map::const_iterator it = d->itemList.constBegin(); -
273 Map::const_iterator end = d->itemList.constEnd(); -
274 -
275 { -
276 int size = 0; -
277 for ( ; it != end; ++it)
evaluated: it != end
TRUEFALSE
yes
Evaluation Count:81
yes
Evaluation Count:66
66-81
278 size += it->first.length() + 1 + it->second.length() + 1;
executed: size += it->first.length() + 1 + it->second.length() + 1;
Execution Count:81
81
279 result.reserve(size + size / 4); -
280 } -
281 -
282 for (it = d->itemList.constBegin(); it != end; ++it) {
evaluated: it != end
TRUEFALSE
yes
Evaluation Count:81
yes
Evaluation Count:66
66-81
283 if (!result.isEmpty())
evaluated: !result.isEmpty()
TRUEFALSE
yes
Evaluation Count:15
yes
Evaluation Count:66
15-66
284 result += QChar(d->pairDelimiter);
executed: result += QChar(d->pairDelimiter);
Execution Count:15
15
285 recodeAndAppend(result, it->first, encoding, tableActions); -
286 if (!it->second.isNull()) {
evaluated: !it->second.isNull()
TRUEFALSE
yes
Evaluation Count:74
yes
Evaluation Count:7
7-74
287 result += QChar(d->valueDelimiter); -
288 recodeAndAppend(result, it->second, encoding, tableActions); -
289 }
executed: }
Execution Count:74
74
290 }
executed: }
Execution Count:81
81
291 return result;
executed: return result;
Execution Count:66
66
292} -
293void QUrlQuery::setQueryDelimiters(QChar valueDelimiter, QChar pairDelimiter) -
294{ -
295 d->valueDelimiter = valueDelimiter.unicode(); -
296 d->pairDelimiter = pairDelimiter.unicode(); -
297}
executed: }
Execution Count:3
3
298 -
299 -
300 -
301 -
302 -
303 -
304 -
305QChar QUrlQuery::queryValueDelimiter() const -
306{ -
307 return d ? d->valueDelimiter : defaultQueryValueDelimiter();
executed: return d ? d->valueDelimiter : defaultQueryValueDelimiter();
Execution Count:2
2
308} -
309 -
310 -
311 -
312 -
313 -
314 -
315 -
316QChar QUrlQuery::queryPairDelimiter() const -
317{ -
318 return d ? d->pairDelimiter : defaultQueryPairDelimiter();
executed: return d ? d->pairDelimiter : defaultQueryPairDelimiter();
Execution Count:2
2
319} -
320void QUrlQuery::setQueryItems(const QList<QPair<QString, QString> > &query) -
321{ -
322 clear(); -
323 if (query.isEmpty())
evaluated: query.isEmpty()
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:9
1-9
324 return;
executed: return;
Execution Count:1
1
325 -
326 QUrlQueryPrivate *dd = d; -
327 QList<QPair<QString, QString> >::const_iterator it = query.constBegin(), -
328 end = query.constEnd(); -
329 for ( ; it != end; ++it)
evaluated: it != end
TRUEFALSE
yes
Evaluation Count:24
yes
Evaluation Count:9
9-24
330 dd->addQueryItem(it->first, it->second);
executed: dd->addQueryItem(it->first, it->second);
Execution Count:24
24
331}
executed: }
Execution Count:9
9
332QList<QPair<QString, QString> > QUrlQuery::queryItems(QUrl::ComponentFormattingOptions encoding) const -
333{ -
334 if (!d)
evaluated: !d
TRUEFALSE
yes
Evaluation Count:5
yes
Evaluation Count:87
5-87
335 return QList<QPair<QString, QString> >();
executed: return QList<QPair<QString, QString> >();
Execution Count:5
5
336 if (idempotentRecodeToUser(encoding))
evaluated: idempotentRecodeToUser(encoding)
TRUEFALSE
yes
Evaluation Count:76
yes
Evaluation Count:11
11-76
337 return d->itemList;
executed: return d->itemList;
Execution Count:76
76
338 -
339 QList<QPair<QString, QString> > result; -
340 Map::const_iterator it = d->itemList.constBegin(); -
341 Map::const_iterator end = d->itemList.constEnd(); -
342 for ( ; it != end; ++it)
evaluated: it != end
TRUEFALSE
yes
Evaluation Count:12
yes
Evaluation Count:11
11-12
343 result << qMakePair(d->recodeToUser(it->first, encoding), 12
344 d->recodeToUser(it->second, encoding));
executed: result << qMakePair(d->recodeToUser(it->first, encoding), d->recodeToUser(it->second, encoding));
Execution Count:12
12
345 return result;
executed: return result;
Execution Count:11
11
346} -
347 -
348 -
349 -
350 -
351 -
352 -
353 -
354bool QUrlQuery::hasQueryItem(const QString &key) const -
355{ -
356 if (!d)
evaluated: !d
TRUEFALSE
yes
Evaluation Count:4
yes
Evaluation Count:16
4-16
357 return false;
executed: return false;
Execution Count:4
4
358 return d->findKey(key) != d->itemList.constEnd();
executed: return d->findKey(key) != d->itemList.constEnd();
Execution Count:16
16
359} -
360void QUrlQuery::addQueryItem(const QString &key, const QString &value) -
361{ -
362 d->addQueryItem(key, value); -
363}
executed: }
Execution Count:80
80
364QString QUrlQuery::queryItemValue(const QString &key, QUrl::ComponentFormattingOptions encoding) const -
365{ -
366 QString result; -
367 if (d) {
evaluated: d
TRUEFALSE
yes
Evaluation Count:16
yes
Evaluation Count:3
3-16
368 Map::const_iterator it = d->findKey(key); -
369 if (it != d->itemList.constEnd())
partially evaluated: it != d->itemList.constEnd()
TRUEFALSE
yes
Evaluation Count:16
no
Evaluation Count:0
0-16
370 result = d->recodeToUser(it->second, encoding);
executed: result = d->recodeToUser(it->second, encoding);
Execution Count:16
16
371 }
executed: }
Execution Count:16
16
372 return result;
executed: return result;
Execution Count:19
19
373} -
374QStringList QUrlQuery::allQueryItemValues(const QString &key, QUrl::ComponentFormattingOptions encoding) const -
375{ -
376 QStringList result; -
377 if (d) {
evaluated: d
TRUEFALSE
yes
Evaluation Count:12
yes
Evaluation Count:3
3-12
378 QString encodedKey = d->recodeFromUser(key); -
379 int idx = d->findRecodedKey(encodedKey); -
380 while (idx < d->itemList.size()) {
evaluated: idx < d->itemList.size()
TRUEFALSE
yes
Evaluation Count:19
yes
Evaluation Count:12
12-19
381 result << d->recodeToUser(d->itemList.at(idx).second, encoding); -
382 idx = d->findRecodedKey(encodedKey, idx + 1); -
383 }
executed: }
Execution Count:19
19
384 }
executed: }
Execution Count:12
12
385 return result;
executed: return result;
Execution Count:15
15
386} -
387void QUrlQuery::removeQueryItem(const QString &key) -
388{ -
389 if (d) {
partially evaluated: d
TRUEFALSE
yes
Evaluation Count:6
no
Evaluation Count:0
0-6
390 Map::iterator it = d->findKey(key); -
391 if (it != d->itemList.end())
evaluated: it != d->itemList.end()
TRUEFALSE
yes
Evaluation Count:5
yes
Evaluation Count:1
1-5
392 d->itemList.erase(it);
executed: d->itemList.erase(it);
Execution Count:5
5
393 }
executed: }
Execution Count:6
6
394}
executed: }
Execution Count:6
6
395 -
396 -
397 -
398 -
399 -
400 -
401 -
402void QUrlQuery::removeAllQueryItems(const QString &key) -
403{ -
404 if (d.constData()) {
partially evaluated: d.constData()
TRUEFALSE
yes
Evaluation Count:3
no
Evaluation Count:0
0-3
405 QString encodedKey = d->recodeFromUser(key); -
406 Map::iterator it = d->itemList.begin(); -
407 while (it != d->itemList.end()) {
evaluated: it != d->itemList.end()
TRUEFALSE
yes
Evaluation Count:14
yes
Evaluation Count:3
3-14
408 if (it->first == encodedKey)
evaluated: it->first == encodedKey
TRUEFALSE
yes
Evaluation Count:6
yes
Evaluation Count:8
6-8
409 it = d->itemList.erase(it);
executed: it = d->itemList.erase(it);
Execution Count:6
6
410 else -
411 ++it;
executed: ++it;
Execution Count:8
8
412 } -
413 }
executed: }
Execution Count:3
3
414}
executed: }
Execution Count:3
3
415 -
416 -
Switch to Source codePreprocessed file

Generated by Squish Coco Non-Commercial