KDb

KDbEscapedString.h
1/* This file is part of the KDE project
2 Copyright (C) 2010 Jarosław Staniek <staniek@kde.org>
3
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this program; see the file COPYING. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18*/
19
20#ifndef KDB_ESCAPEDSTRING_H
21#define KDB_ESCAPEDSTRING_H
22
23#include <QByteArray>
24#include <QString>
25#include <QList>
26
27#include "kdb_export.h"
28
29//! Specialized string for escaping.
30//! In addition to byte array, contains "validity" flag that is transferred
31//! when strings are concatenated or in general when any operation with invalid
32//! escaped string is performed.
33class KDB_EXPORT KDbEscapedString : protected QByteArray
34{
35public:
36 inline KDbEscapedString() : m_valid(true) {}
37
38 explicit inline KDbEscapedString(char ch)
39 : QByteArray(1, ch), m_valid(true) {}
40
41 explicit inline KDbEscapedString(QChar ch)
42 : QByteArray(1, ch.toLatin1()), m_valid(true) {}
43
44 explicit inline KDbEscapedString(const char* string)
45 : QByteArray(string), m_valid(true) {}
46
47 explicit inline KDbEscapedString(const QByteArray& string)
48 : QByteArray(string), m_valid(true) {}
49
50 explicit inline KDbEscapedString(const QString& string)
51 : QByteArray(string.toUtf8()), m_valid(true) {}
52
53 inline KDbEscapedString(const KDbEscapedString& string)
54 : QByteArray(string), m_valid(string.isValid()) {}
55
56 inline ~KDbEscapedString() {}
57
58 //! @return invalid escaped string.
59 static inline KDbEscapedString invalid() { return KDbEscapedString(false); }
60
61 //! @return true if the string is valid. Valid string means that the escaping process
62 //! has finished successfully. It does not mean that the statement itself parses
63 //! or can be executed without errors.
64 inline bool isValid() const { return m_valid; }
65
66 inline QByteArray toByteArray() const { return static_cast<const QByteArray&>(*this); }
67
68 inline QString toString() const {
69 return QString::fromUtf8(static_cast<const QByteArray&>(*this).constData(), length());
70 }
71
72 inline KDbEscapedString &operator=(const KDbEscapedString& string) {
74 m_valid = string.isValid();
75 return *this;
76 }
77 inline KDbEscapedString &operator=(const QByteArray& string) {
79 m_valid = true;
80 return *this;
81 }
82 inline KDbEscapedString &operator=(const char *string) {
84 m_valid = true;
85 return *this;
86 }
87
88 inline bool operator==(const KDbEscapedString &other) const
89 {
90 return isValid() == other.isValid()
91 && static_cast<const QByteArray&>(*this) == other.toByteArray();
92 }
93 inline int size() const { return QByteArray::size(); }
94 inline bool isEmpty() const { return QByteArray::isEmpty(); }
95 inline void resize(int size) { QByteArray::resize(size); }
96
97 inline KDbEscapedString &fill(char c, int size = -1) {
98 m_valid = true;
99 QByteArray::fill(c, size);
100 return *this;
101 }
102
103 inline int capacity() const { return QByteArray::isEmpty(); }
104 inline void reserve(int size) { QByteArray::reserve(size); }
105 inline void squeeze() { QByteArray::squeeze(); }
106
107 inline char *data() { return QByteArray::data(); }
108 inline const char *data() const { return QByteArray::data(); }
109 inline const char *constData() const { return QByteArray::constData(); }
110 inline void clear() { m_valid = true; QByteArray::clear(); }
111
112#ifdef Q_COMPILER_MANGLES_RETURN_TYPE
113 inline const char at(int i) const { return QByteArray::at(i); }
114 inline const char operator[](int i) const { return QByteArray::operator[](i); }
115 inline const char operator[](uint i) const { return QByteArray::operator[](i); }
116#else
117 inline char at(int i) const { return QByteArray::at(i); }
118 inline char operator[](int i) const { return QByteArray::operator[](i); }
119 inline char operator[](uint i) const { return QByteArray::operator[](i); }
120#endif
121 inline QByteRef operator[](int i) { return QByteArray::operator[](i); }
122 inline QByteRef operator[](uint i) { return QByteArray::operator[](i); }
123
124 inline int indexOf(char c, int from = 0) const { return QByteArray::indexOf(c, from); }
125 inline int indexOf(const char *c, int from = 0) const { return QByteArray::indexOf(c, from); }
126 inline int indexOf(const QByteArray &a, int from = 0) const { return QByteArray::indexOf(a, from); }
127 inline int indexOf(const KDbEscapedString &s, int from = 0) const {
128 return s.isValid() ? QByteArray::indexOf(s, from) : -1;
129 }
130 inline int lastIndexOf(char c, int from = -1) const { return QByteArray::lastIndexOf(c, from); }
131 inline int lastIndexOf(const char *c, int from = -1) const { return QByteArray::lastIndexOf(c, from); }
132 inline int lastIndexOf(const QByteArray &a, int from = -1) const { return QByteArray::lastIndexOf(a, from); }
133 inline int lastIndexOf(const KDbEscapedString &s, int from = 0) const {
134 return s.isValid() ? QByteArray::lastIndexOf(s, from) : -1;
135 }
136
137 inline int count(char c) const { return QByteArray::count(c); }
138 inline int count(const char *a) const { return QByteArray::count(a); }
139 inline int count(const QByteArray &a) const { return QByteArray::count(a); }
140 inline int count(const KDbEscapedString &s) const {
141 return s.isValid() ? QByteArray::count(s) : -1;
142 }
143
144 inline KDbEscapedString left(int len) const {
145 return m_valid ? KDbEscapedString(QByteArray::left(len)) : KDbEscapedString::invalid();
146 }
147 inline KDbEscapedString right(int len) const {
148 return m_valid ? KDbEscapedString(QByteArray::right(len)) : KDbEscapedString::invalid();
149 }
150 inline KDbEscapedString mid(int index, int len = -1) const {
151 return m_valid ? KDbEscapedString(QByteArray::mid(index, len)) : KDbEscapedString::invalid();
152 }
153
154 inline bool startsWith(const KDbEscapedString &s) const {
155 return (m_valid && s.isValid()) ? QByteArray::startsWith(s) : false;
156 }
157 inline bool startsWith(const QByteArray &a) const {
158 return m_valid ? QByteArray::startsWith(a) : false;
159 }
160 inline bool startsWith(char c) const {
161 return m_valid ? QByteArray::startsWith(c) : false;
162 }
163 inline bool startsWith(const char *c) const {
164 return m_valid ? QByteArray::startsWith(c) : false;
165 }
166
167 inline bool endsWith(const KDbEscapedString &s) const {
168 return (m_valid && s.isValid()) ? QByteArray::endsWith(s) : false;
169 }
170 inline bool endsWith(const QByteArray &a) const {
171 return m_valid ? QByteArray::endsWith(a) : false;
172 }
173 inline bool endsWith(char c) const {
174 return m_valid ? QByteArray::endsWith(c) : false;
175 }
176 inline bool endsWith(const char *c) const {
177 return m_valid ? QByteArray::endsWith(c) : false;
178 }
179
180 inline void truncate(int pos) { QByteArray::truncate(pos); }
181 inline void chop(int n) { QByteArray::chop(n); }
182
183 inline KDbEscapedString toLower() const {
184 return m_valid ? KDbEscapedString(QByteArray::toLower()) : KDbEscapedString::invalid();
185 }
186 inline KDbEscapedString toUpper() const {
187 return m_valid ? KDbEscapedString(QByteArray::toUpper()) : KDbEscapedString::invalid();
188 }
189
190 inline KDbEscapedString trimmed() const {
191 return m_valid ? KDbEscapedString(QByteArray::trimmed()) : KDbEscapedString::invalid();
192 }
193 inline KDbEscapedString simplified() const {
194 return m_valid ? KDbEscapedString(QByteArray::simplified()) : KDbEscapedString::invalid();
195 }
196 inline KDbEscapedString leftJustified(int width, char fill = ' ', bool truncate = false) const
197 {
198 return m_valid ? KDbEscapedString(QByteArray::leftJustified(width, fill, truncate)) : KDbEscapedString::invalid();
199 }
200 inline KDbEscapedString rightJustified(int width, char fill = ' ', bool truncate = false) const
201 {
202 return m_valid ? KDbEscapedString(QByteArray::rightJustified(width, fill, truncate)) : KDbEscapedString::invalid();
203 }
204
205 inline KDbEscapedString &prepend(char c) {
206 if (m_valid)
208 return *this;
209 }
210 inline KDbEscapedString &prepend(const char *s) {
211 if (m_valid)
213 return *this;
214 }
215 inline KDbEscapedString &prepend(const QByteArray &a) {
216 if (m_valid)
218 return *this;
219 }
221 inline KDbEscapedString &append(char c) {
222 if (m_valid)
224 return *this;
225 }
226 inline KDbEscapedString &append(const char *s) {
227 if (m_valid)
229 return *this;
230 }
231 inline KDbEscapedString &append(const char *s, int len) {
232 if (m_valid)
233 QByteArray::append(s, len);
234 return *this;
235 }
236 inline KDbEscapedString &append(const QByteArray &a) {
237 if (m_valid)
239 return *this;
240 }
241 inline KDbEscapedString &append(const QString &a) {
242 if (m_valid)
244 return *this;
245 }
247 inline KDbEscapedString &insert(int i, char c) {
248 if (m_valid)
249 QByteArray::insert(i, c);
250 return *this;
251 }
252 inline KDbEscapedString &insert(int i, const char *s) {
253 if (m_valid)
254 QByteArray::insert(i, s);
255 return *this;
256 }
257 inline KDbEscapedString &insert(int i, const QByteArray &a) {
258 if (m_valid)
259 QByteArray::insert(i, a);
260 return *this;
261 }
262 KDbEscapedString &insert(int i, const KDbEscapedString &s);
263 inline KDbEscapedString &remove(int index, int len) {
264 if (m_valid)
265 QByteArray::remove(index, len);
266 return *this;
267 }
268 inline KDbEscapedString &replace(int index, int len, const char *s) {
269 if (m_valid)
270 QByteArray::replace(index, len, s);
271 return *this;
272 }
273 inline KDbEscapedString &replace(int index, int len, const QByteArray &s) {
274 if (m_valid)
275 QByteArray::replace(index, len, s);
276 return *this;
277 }
278 KDbEscapedString &replace(int index, int len, const KDbEscapedString &s);
279 inline KDbEscapedString &replace(char before, const char *after) {
280 if (m_valid)
281 QByteArray::replace(before, after);
282 return *this;
283 }
284 inline KDbEscapedString &replace(char before, const QByteArray &after) {
285 if (m_valid)
286 QByteArray::replace(before, after);
287 return *this;
288 }
289 KDbEscapedString &replace(char before, const KDbEscapedString &after);
290 inline KDbEscapedString &replace(const char *before, const char *after) {
291 if (m_valid)
292 QByteArray::replace(before, after);
293 return *this;
294 }
295 inline KDbEscapedString &replace(const char *before, int bsize, const char *after, int asize) {
296 if (m_valid)
297 QByteArray::replace(before, bsize, after, asize);
298 return *this;
299 }
300 inline KDbEscapedString &replace(const QByteArray &before, const QByteArray &after) {
301 if (m_valid)
302 QByteArray::replace(before, after);
303 return *this;
304 }
305 KDbEscapedString &replace(const KDbEscapedString &before, const QByteArray &after);
306 KDbEscapedString &replace(const QByteArray &before, const KDbEscapedString &after);
307 KDbEscapedString &replace(const KDbEscapedString &before, const KDbEscapedString &after);
308 inline KDbEscapedString &replace(const QByteArray &before, const char *after) {
309 if (m_valid)
310 QByteArray::replace(before, after);
311 return *this;
312 }
313 inline KDbEscapedString &replace(const char *before, const QByteArray &after) {
314 if (m_valid)
315 QByteArray::replace(before, after);
316 return *this;
317 }
318 inline KDbEscapedString &replace(char before, char after) {
319 if (m_valid)
320 QByteArray::replace(before, after);
321 return *this;
322 }
323 inline KDbEscapedString &operator+=(char c) { return append(c); }
324 inline KDbEscapedString &operator+=(const char *s) { return append(s); }
325 inline KDbEscapedString &operator+=(const QByteArray &a) { return append(a); }
326 inline KDbEscapedString &operator+=(const QString &a) { return append(a); }
327 inline KDbEscapedString &operator+=(const KDbEscapedString &s) { return append(s); }
328
329 //KDbEscapedString operator+(const QVector<T> & other ) const
330
331 QList<KDbEscapedString> split(char sep) const;
332
333 inline KDbEscapedString repeated(int times) const {
334 return m_valid ? KDbEscapedString(QByteArray::repeated(times)) : KDbEscapedString::invalid();
335 }
336 short toShort(bool *ok = nullptr, int base = 10) const;
337 ushort toUShort(bool *ok = nullptr, int base = 10) const;
338 int toInt(bool *ok = nullptr, int base = 10) const;
339 uint toUInt(bool *ok = nullptr, int base = 10) const;
340 long toLong(bool *ok = nullptr, int base = 10) const;
341 ulong toULong(bool *ok = nullptr, int base = 10) const;
342 qlonglong toLongLong(bool *ok = nullptr, int base = 10) const;
343 qulonglong toULongLong(bool *ok = nullptr, int base = 10) const;
344 float toFloat(bool *ok = nullptr) const;
345 double toDouble(bool *ok = nullptr) const;
346 inline KDbEscapedString toBase64() const {
347 return m_valid ? KDbEscapedString(QByteArray::toBase64()) : KDbEscapedString::invalid();
348 }
349 inline KDbEscapedString toHex() const {
350 return m_valid ? KDbEscapedString(QByteArray::toHex()) : KDbEscapedString::invalid();
351 }
353 const QByteArray &include = QByteArray(),
354 char percent = '%') const
355 {
356 Q_UNUSED(percent);
357 return m_valid ? KDbEscapedString(QByteArray::toPercentEncoding(exclude, include))
358 : KDbEscapedString::invalid();
359 }
360
361 inline KDbEscapedString &setNum(short val, int base = 10) {
362 m_valid = true;
363 QByteArray::setNum(val, base);
364 return *this;
365 }
366 inline KDbEscapedString &setNum(ushort val, int base = 10) {
367 m_valid = true;
368 QByteArray::setNum(val, base);
369 return *this;
370 }
371 inline KDbEscapedString &setNum(int val, int base = 10) {
372 m_valid = true;
373 QByteArray::setNum(val, base);
374 return *this;
375 }
376 inline KDbEscapedString &setNum(uint val, int base = 10) {
377 m_valid = true;
378 QByteArray::setNum(val, base);
379 return *this;
380 }
381 inline KDbEscapedString &setNum(qlonglong val, int base = 10) {
382 m_valid = true;
383 QByteArray::setNum(val, base);
384 return *this;
385 }
386 inline KDbEscapedString &setNum(qulonglong val, int base = 10) {
387 m_valid = true;
388 QByteArray::setNum(val, base);
389 return *this;
390 }
391 inline KDbEscapedString &setNum(float val, char f = 'g', int prec = 6) {
392 m_valid = true;
393 QByteArray::setNum(val, f, prec);
394 return *this;
395 }
396 inline KDbEscapedString &setNum(double val, char f = 'g', int prec = 6) {
397 m_valid = true;
398 QByteArray::setNum(val, f, prec);
399 return *this;
400 }
401
402 static inline KDbEscapedString number(int val, int base = 10) {
403 return KDbEscapedString(QByteArray::number(val, base));
404 }
405 static inline KDbEscapedString number(uint val, int base = 10) {
406 return KDbEscapedString(QByteArray::number(val, base));
407 }
408 static inline KDbEscapedString number(qlonglong val, int base = 10) {
409 return KDbEscapedString(QByteArray::number(val, base));
410 }
411 static inline KDbEscapedString number(qulonglong val, int base = 10) {
412 return KDbEscapedString(QByteArray::number(val, base));
413 }
414 static inline KDbEscapedString number(double val, char f = 'g', int prec = 6) {
415 return KDbEscapedString(QByteArray::number(val, f, prec));
416 }
417 static inline KDbEscapedString fromRawData(const char *s, int size) {
419 }
420 static inline KDbEscapedString fromBase64(const QByteArray &base64) {
422 }
423 static inline KDbEscapedString fromBase64(const KDbEscapedString &base64) {
424 return base64.isValid() ? KDbEscapedString(QByteArray::fromBase64(base64)) : KDbEscapedString::invalid();
425 }
426 static inline KDbEscapedString fromHex(const QByteArray &hexEncoded) {
427 return KDbEscapedString(QByteArray::fromHex(hexEncoded));
428 }
429 static inline KDbEscapedString fromHex(const KDbEscapedString &hexEncoded) {
430 return hexEncoded.isValid() ? KDbEscapedString(QByteArray::fromHex(hexEncoded))
431 : KDbEscapedString::invalid();
432 }
433 static inline KDbEscapedString fromPercentEncoding(const QByteArray &pctEncoded, char percent = '%') {
434 return KDbEscapedString(QByteArray::fromPercentEncoding(pctEncoded, percent));
435 }
436 static inline KDbEscapedString fromPercentEncoding(const KDbEscapedString &pctEncoded, char percent = '%') {
437 return pctEncoded.isValid() ? KDbEscapedString(QByteArray::fromPercentEncoding(pctEncoded, percent))
438 : KDbEscapedString::invalid();
439 }
440
441 inline int count() const { return QByteArray::count(); }
442 inline int length() const { return QByteArray::length(); }
443 inline bool isNull() const { return QByteArray::isNull(); }
444
445 KDbEscapedString arg(const KDbEscapedString &a1, const KDbEscapedString &a2) const;
446 KDbEscapedString arg(const KDbEscapedString &a1, const KDbEscapedString &a2, const KDbEscapedString &a3) const;
447 KDbEscapedString arg(const KDbEscapedString &a1, const KDbEscapedString &a2, const KDbEscapedString &a3,
448 const KDbEscapedString &a4) const;
449 KDbEscapedString arg(const KDbEscapedString &a1, const KDbEscapedString &a2, const KDbEscapedString &a3,
450 const KDbEscapedString &a4, const KDbEscapedString &a5) const;
451 KDbEscapedString arg(const KDbEscapedString &a1, const KDbEscapedString &a2, const KDbEscapedString &a3,
452 const KDbEscapedString &a4, const KDbEscapedString &a5, const KDbEscapedString &a6) const;
453 KDbEscapedString arg(const KDbEscapedString &a1, const KDbEscapedString &a2, const KDbEscapedString &a3,
454 const KDbEscapedString &a4, const KDbEscapedString &a5, const KDbEscapedString &a6,
455 const KDbEscapedString &a7) const;
456 KDbEscapedString arg(const KDbEscapedString &a1, const KDbEscapedString &a2, const KDbEscapedString &a3,
457 const KDbEscapedString &a4, const KDbEscapedString &a5, const KDbEscapedString &a6,
458 const KDbEscapedString &a7, const KDbEscapedString &a8) const;
459 KDbEscapedString arg(const KDbEscapedString &a1, const KDbEscapedString &a2, const KDbEscapedString &a3,
460 const KDbEscapedString &a4, const KDbEscapedString &a5, const KDbEscapedString &a6,
461 const KDbEscapedString &a7, const KDbEscapedString &a8, const KDbEscapedString &a9) const;
462 KDbEscapedString arg(const KDbEscapedString &a, int fieldWidth = 0, const QChar & fillChar = QLatin1Char( ' ' )) const;
463 KDbEscapedString arg(const QString &a, int fieldWidth = 0, const QChar & fillChar = QLatin1Char( ' ' )) const;
464 KDbEscapedString arg(const QByteArray &a, int fieldWidth = 0, const QChar & fillChar = QLatin1Char( ' ' )) const;
465 KDbEscapedString arg(int a, int fieldWidth = 0, int base = 10, const QChar & fillChar = QLatin1Char( ' ' )) const;
466 KDbEscapedString arg(uint a, int fieldWidth = 0, int base = 10, const QChar & fillChar = QLatin1Char( ' ' )) const;
467 KDbEscapedString arg(long a, int fieldWidth = 0, int base = 10, const QChar & fillChar = QLatin1Char( ' ' )) const;
468 KDbEscapedString arg(ulong a, int fieldWidth = 0, int base = 10, const QChar & fillChar = QLatin1Char( ' ' )) const;
469 KDbEscapedString arg(qlonglong a, int fieldWidth = 0, int base = 10, const QChar & fillChar = QLatin1Char( ' ' )) const;
470 KDbEscapedString arg(qulonglong a, int fieldWidth = 0, int base = 10, const QChar & fillChar = QLatin1Char( ' ' )) const;
471 KDbEscapedString arg(short a, int fieldWidth = 0, int base = 10, const QChar & fillChar = QLatin1Char( ' ' )) const;
472 KDbEscapedString arg(ushort a, int fieldWidth = 0, int base = 10, const QChar & fillChar = QLatin1Char( ' ' )) const;
473 KDbEscapedString arg(QChar a, int fieldWidth = 0, const QChar & fillChar = QLatin1Char( ' ' )) const;
474 KDbEscapedString arg(char a, int fieldWidth = 0, const QChar & fillChar = QLatin1Char( ' ' )) const;
475 KDbEscapedString arg(double a, int fieldWidth = 0, char format = 'g', int precision = -1, const QChar & fillChar = QLatin1Char( ' ' )) const;
476
477 typedef QByteArray::DataPtr DataPtr;
478 inline DataPtr &data_ptr() { return QByteArray::data_ptr(); }
479
480private:
481 //! Used to create invalid string
482 explicit inline KDbEscapedString(bool) : m_valid(false) {}
483
484 //! Helper for methods having "bool* ok" argument
485 inline bool checkValid(bool *ok) const {
486 if (!m_valid) {
487 if (ok)
488 *ok = false;
489 return false;
490 }
491 return true;
492 }
493 //! true if the string is valid; true by default
494 bool m_valid;
495};
496
497#ifndef QT_NO_DATASTREAM
498KDB_EXPORT QDataStream &operator<<(QDataStream &stream, const KDbEscapedString &string);
499KDB_EXPORT QDataStream &operator>>(QDataStream &stream, KDbEscapedString &string);
500#endif
501
503{
504 if (!a1.isValid() || !a2.isValid())
506 return KDbEscapedString(a1.toByteArray() + a2.toByteArray());
507}
508inline KDbEscapedString operator+(const KDbEscapedString &a1, const QString &a2)
509{
510 if (!a1.isValid())
512 return a1 + KDbEscapedString(a2);
513}
514inline KDbEscapedString operator+(const KDbEscapedString &a1, const QByteArray &a2)
515{
516 if (!a1.isValid())
518 return a1 + KDbEscapedString(a2);
519}
520inline KDbEscapedString operator+(const KDbEscapedString &a1, const char* a2)
521{
522 if (!a1.isValid())
524 return a1 + KDbEscapedString(a2);
525}
527{
528 if (!a1.isValid())
530 return a1 + KDbEscapedString(a2.toLatin1());
531}
532inline KDbEscapedString operator+(const KDbEscapedString &a1, char a2)
533{
534 if (!a1.isValid())
536 return a1 + KDbEscapedString(a2);
537}
538inline KDbEscapedString operator+(const QString &a1, const KDbEscapedString &a2)
539{
540 if (!a2.isValid())
542 return KDbEscapedString(a1) + a2;
543}
544inline KDbEscapedString operator+(const QByteArray &a1, const KDbEscapedString &a2)
545{
546 if (!a2.isValid())
548 return KDbEscapedString(a1) + a2;
549}
550inline KDbEscapedString operator+(const char* a1, const KDbEscapedString &a2)
551{
552 if (!a2.isValid())
554 return KDbEscapedString(a1) + a2;
555}
557{
558 if (!a2.isValid())
560 return KDbEscapedString(a1.toLatin1()) + a2;
561}
562inline KDbEscapedString operator+(char a1, const KDbEscapedString &a2)
563{
564 if (!a2.isValid())
566 return KDbEscapedString(a1) + a2;
567}
568
569inline bool operator==(const KDbEscapedString &a1, const QByteArray &a2)
570{
571 return a1.isValid() && a1.toByteArray() == a2;
572}
573
574inline bool operator==(const KDbEscapedString &a1, const char *a2)
575{
576 return a1.isValid() && a1.toByteArray() == a2;
577}
578
579inline bool operator==(const QByteArray &a1, const KDbEscapedString &a2)
580{
581 return a2.isValid() && a1 == a2.toByteArray();
582}
583
584inline bool operator==(const char *a1, const KDbEscapedString &a2)
585{
586 return a2.isValid() && a1 == a2.toByteArray();
587}
588
589Q_DECLARE_TYPEINFO(KDbEscapedString, Q_MOVABLE_TYPE);
590//Q_DECLARE_SHARED(KDbEscapedString)
591
592//! Sends escaped string @a string to debug output @a dbg.
593KDB_EXPORT QDebug operator<<(QDebug dbg, const KDbEscapedString& string);
594
595#endif
Specialized string for escaping.
static KDbEscapedString invalid()
bool isValid() const
char * toString(const EngineQuery &query)
KCALENDARCORE_EXPORT QDataStream & operator>>(QDataStream &in, const KCalendarCore::Alarm::Ptr &)
bool isValid(QStringView ifopt)
bool operator==(const StyleDelim &l, const StyleDelim &r)
QDebug operator<<(QDebug dbg, const PerceptualColor::MultiSpinBoxSection &value)
QCA_EXPORT const SecureArray operator+(const SecureArray &a, const SecureArray &b)
qsizetype count() const const
QByteArray & append(QByteArrayView data)
char at(qsizetype i) const const
qsizetype capacity() const const
void chop(qsizetype n)
void clear()
const char * constData() const const
char * data()
bool endsWith(QByteArrayView bv) const const
QByteArray & fill(char ch, qsizetype size)
QByteArray fromBase64(const QByteArray &base64, Base64Options options)
QByteArray fromHex(const QByteArray &hexEncoded)
QByteArray fromPercentEncoding(const QByteArray &input, char percent)
QByteArray fromRawData(const char *data, qsizetype size)
qsizetype indexOf(QByteArrayView bv, qsizetype from) const const
QByteArray & insert(qsizetype i, QByteArrayView data)
bool isEmpty() const const
bool isNull() const const
qsizetype lastIndexOf(QByteArrayView bv) const const
QByteArray left(qsizetype len) const const
QByteArray leftJustified(qsizetype width, char fill, bool truncate) const const
qsizetype length() const const
QByteArray mid(qsizetype pos, qsizetype len) const const
QByteArray number(double n, char format, int precision)
QByteArray & operator+=(char ch)
char & operator[](qsizetype i)
QByteArray & operator=(QByteArray &&other)
bool operator==(const QByteArray &a1, const QByteArray &a2)
QByteArray & prepend(QByteArrayView ba)
QByteArray & remove(qsizetype pos, qsizetype len)
QByteArray repeated(qsizetype times) const const
QByteArray & replace(QByteArrayView before, QByteArrayView after)
void reserve(qsizetype size)
void resize(qsizetype newSize, char c)
QByteArray right(qsizetype len) const const
QByteArray rightJustified(qsizetype width, char fill, bool truncate) const const
QByteArray & setNum(double n, char format, int precision)
QByteArray simplified() const const
qsizetype size() const const
QList< QByteArray > split(char sep) const const
void squeeze()
bool startsWith(QByteArrayView bv) const const
QByteArray toBase64(Base64Options options) const const
double toDouble(bool *ok) const const
float toFloat(bool *ok) const const
QByteArray toHex(char separator) const const
int toInt(bool *ok, int base) const const
long toLong(bool *ok, int base) const const
qlonglong toLongLong(bool *ok, int base) const const
QByteArray toLower() const const
QByteArray toPercentEncoding(const QByteArray &exclude, const QByteArray &include, char percent) const const
short toShort(bool *ok, int base) const const
uint toUInt(bool *ok, int base) const const
ulong toULong(bool *ok, int base) const const
qulonglong toULongLong(bool *ok, int base) const const
ushort toUShort(bool *ok, int base) const const
QByteArray toUpper() const const
QByteArray trimmed() const const
void truncate(qsizetype pos)
char toLatin1() const const
QString fromUtf8(QByteArrayView str)
QByteArray toUtf8() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:19:07 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.