File indexing completed on 2024-12-08 12:45:03

0001 /* This file is part of the KDE project
0002    Copyright (C) 2010 Jarosław Staniek <staniek@kde.org>
0003 
0004    This program is free software; you can redistribute it and/or
0005    modify it under the terms of the GNU Library General Public
0006    License as published by the Free Software Foundation; either
0007    version 2 of the License, or (at your option) any later version.
0008 
0009    This program is distributed in the hope that it will be useful,
0010    but WITHOUT ANY WARRANTY; without even the implied warranty of
0011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0012    Library General Public License for more details.
0013 
0014    You should have received a copy of the GNU Library General Public License
0015    along with this program; see the file COPYING.  If not, write to
0016    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0017  * Boston, MA 02110-1301, USA.
0018 */
0019 
0020 #ifndef KDB_ESCAPEDSTRING_H
0021 #define KDB_ESCAPEDSTRING_H
0022 
0023 #include <QByteArray>
0024 #include <QString>
0025 #include <QList>
0026 
0027 #include "kdb_export.h"
0028 
0029 //! Specialized string for escaping.
0030 //! In addition to byte array, contains "validity" flag that is transferred
0031 //! when strings are concatenated or in general when any operation with invalid
0032 //! escaped string is performed.
0033 class KDB_EXPORT KDbEscapedString : protected QByteArray
0034 {
0035 public:
0036     inline KDbEscapedString() : m_valid(true) {}
0037 
0038     explicit inline KDbEscapedString(char ch)
0039         : QByteArray(1, ch), m_valid(true) {}
0040 
0041     explicit inline KDbEscapedString(QChar ch)
0042         : QByteArray(1, ch.toLatin1()), m_valid(true) {}
0043 
0044     explicit inline KDbEscapedString(const char* string)
0045         : QByteArray(string), m_valid(true) {}
0046 
0047     explicit inline KDbEscapedString(const QByteArray& string)
0048         : QByteArray(string), m_valid(true) {}
0049 
0050     explicit inline KDbEscapedString(const QString& string)
0051         : QByteArray(string.toUtf8()), m_valid(true) {}
0052 
0053     inline KDbEscapedString(const KDbEscapedString& string)
0054         : QByteArray(string), m_valid(string.isValid()) {}
0055 
0056     inline ~KDbEscapedString() {}
0057 
0058     //! @return invalid escaped string.
0059     static inline KDbEscapedString invalid() { return KDbEscapedString(false); }
0060 
0061     //! @return true if the string is valid. Valid string means that the escaping process
0062     //! has finished successfully. It does not mean that the statement itself parses
0063     //! or can be executed without errors.
0064     inline bool isValid() const { return m_valid; }
0065 
0066     inline QByteArray toByteArray() const { return static_cast<const QByteArray&>(*this); }
0067 
0068     inline QString toString() const {
0069         return QString::fromUtf8(static_cast<const QByteArray&>(*this).constData(), length());
0070     }
0071 
0072     inline KDbEscapedString &operator=(const KDbEscapedString& string) {
0073         QByteArray::operator=(string);
0074         m_valid = string.isValid();
0075         return *this;
0076     }
0077     inline KDbEscapedString &operator=(const QByteArray& string) {
0078         QByteArray::operator=(string);
0079         m_valid = true;
0080         return *this;
0081     }
0082     inline KDbEscapedString &operator=(const char *string) {
0083         QByteArray::operator=(string);
0084         m_valid = true;
0085         return *this;
0086     }
0087 
0088     inline bool operator==(const KDbEscapedString &other) const
0089     {
0090         return isValid() == other.isValid()
0091                && static_cast<const QByteArray&>(*this) == other.toByteArray();
0092     }
0093     inline int size() const { return QByteArray::size(); }
0094     inline bool isEmpty() const { return QByteArray::isEmpty(); }
0095     inline void resize(int size) { QByteArray::resize(size); }
0096 
0097     inline KDbEscapedString &fill(char c, int size = -1) {
0098         m_valid = true;
0099         QByteArray::fill(c, size);
0100         return *this;
0101     }
0102 
0103     inline int capacity() const { return QByteArray::isEmpty(); }
0104     inline void reserve(int size) { QByteArray::reserve(size); }
0105     inline void squeeze() { QByteArray::squeeze(); }
0106 
0107     inline char *data() { return QByteArray::data(); }
0108     inline const char *data() const { return QByteArray::data(); }
0109     inline const char *constData() const { return QByteArray::constData(); }
0110     inline void clear() { m_valid = true; QByteArray::clear(); }
0111 
0112 #ifdef Q_COMPILER_MANGLES_RETURN_TYPE
0113     inline const char at(int i) const { return QByteArray::at(i); }
0114     inline const char operator[](int i) const { return QByteArray::operator[](i); }
0115     inline const char operator[](uint i) const { return QByteArray::operator[](i); }
0116 #else
0117     inline char at(int i) const { return QByteArray::at(i); }
0118     inline char operator[](int i) const { return QByteArray::operator[](i); }
0119     inline char operator[](uint i) const { return QByteArray::operator[](i); }
0120 #endif
0121     inline QByteRef operator[](int i) { return QByteArray::operator[](i); }
0122     inline QByteRef operator[](uint i) { return QByteArray::operator[](i); }
0123 
0124     inline int indexOf(char c, int from = 0) const { return QByteArray::indexOf(c, from); }
0125     inline int indexOf(const char *c, int from = 0) const { return QByteArray::indexOf(c, from); }
0126     inline int indexOf(const QByteArray &a, int from = 0) const { return QByteArray::indexOf(a, from); }
0127     inline int indexOf(const KDbEscapedString &s, int from = 0) const {
0128         return s.isValid() ? QByteArray::indexOf(s, from) : -1;
0129     }
0130     inline int lastIndexOf(char c, int from = -1) const { return QByteArray::lastIndexOf(c, from); }
0131     inline int lastIndexOf(const char *c, int from = -1) const { return QByteArray::lastIndexOf(c, from); }
0132     inline int lastIndexOf(const QByteArray &a, int from = -1) const { return QByteArray::lastIndexOf(a, from); }
0133     inline int lastIndexOf(const KDbEscapedString &s, int from = 0) const {
0134         return s.isValid() ? QByteArray::lastIndexOf(s, from) : -1;
0135     }
0136 
0137     inline int count(char c) const { return QByteArray::count(c); }
0138     inline int count(const char *a) const { return QByteArray::count(a); }
0139     inline int count(const QByteArray &a) const { return QByteArray::count(a); }
0140     inline int count(const KDbEscapedString &s) const {
0141         return s.isValid() ? QByteArray::count(s) : -1;
0142     }
0143 
0144     inline KDbEscapedString left(int len) const {
0145         return m_valid ? KDbEscapedString(QByteArray::left(len)) : KDbEscapedString::invalid();
0146     }
0147     inline KDbEscapedString right(int len) const {
0148         return m_valid ? KDbEscapedString(QByteArray::right(len)) : KDbEscapedString::invalid();
0149     }
0150     inline KDbEscapedString mid(int index, int len = -1) const {
0151         return m_valid ? KDbEscapedString(QByteArray::mid(index, len)) : KDbEscapedString::invalid();
0152     }
0153 
0154     inline bool startsWith(const KDbEscapedString &s) const {
0155         return (m_valid && s.isValid()) ? QByteArray::startsWith(s) : false;
0156     }
0157     inline bool startsWith(const QByteArray &a) const {
0158         return m_valid ? QByteArray::startsWith(a) : false;
0159     }
0160     inline bool startsWith(char c) const {
0161         return m_valid ? QByteArray::startsWith(c) : false;
0162     }
0163     inline bool startsWith(const char *c) const {
0164         return m_valid ? QByteArray::startsWith(c) : false;
0165     }
0166 
0167     inline bool endsWith(const KDbEscapedString &s) const {
0168         return (m_valid && s.isValid()) ? QByteArray::endsWith(s) : false;
0169     }
0170     inline bool endsWith(const QByteArray &a) const {
0171         return m_valid ? QByteArray::endsWith(a) : false;
0172     }
0173     inline bool endsWith(char c) const {
0174         return m_valid ? QByteArray::endsWith(c) : false;
0175     }
0176     inline bool endsWith(const char *c) const {
0177         return m_valid ? QByteArray::endsWith(c) : false;
0178     }
0179 
0180     inline void truncate(int pos) { QByteArray::truncate(pos); }
0181     inline void chop(int n) { QByteArray::chop(n); }
0182 
0183     inline KDbEscapedString toLower() const {
0184         return m_valid ? KDbEscapedString(QByteArray::toLower()) : KDbEscapedString::invalid();
0185     }
0186     inline KDbEscapedString toUpper() const {
0187         return m_valid ? KDbEscapedString(QByteArray::toUpper()) : KDbEscapedString::invalid();
0188     }
0189 
0190     inline KDbEscapedString trimmed() const {
0191         return m_valid ? KDbEscapedString(QByteArray::trimmed()) : KDbEscapedString::invalid();
0192     }
0193     inline KDbEscapedString simplified() const {
0194         return m_valid ? KDbEscapedString(QByteArray::simplified()) : KDbEscapedString::invalid();
0195     }
0196     inline KDbEscapedString leftJustified(int width, char fill = ' ', bool truncate = false) const
0197     {
0198         return m_valid ? KDbEscapedString(QByteArray::leftJustified(width, fill, truncate)) : KDbEscapedString::invalid();
0199     }
0200     inline KDbEscapedString rightJustified(int width, char fill = ' ', bool truncate = false) const
0201     {
0202         return m_valid ? KDbEscapedString(QByteArray::rightJustified(width, fill, truncate)) : KDbEscapedString::invalid();
0203     }
0204 
0205     inline KDbEscapedString &prepend(char c) {
0206         if (m_valid)
0207             QByteArray::prepend(c);
0208         return *this;
0209     }
0210     inline KDbEscapedString &prepend(const char *s) {
0211         if (m_valid)
0212             QByteArray::prepend(s);
0213         return *this;
0214     }
0215     inline KDbEscapedString &prepend(const QByteArray &a) {
0216         if (m_valid)
0217             QByteArray::prepend(a);
0218         return *this;
0219     }
0220     KDbEscapedString &prepend(const KDbEscapedString &s);
0221     inline KDbEscapedString &append(char c) {
0222         if (m_valid)
0223             QByteArray::append(c);
0224         return *this;
0225     }
0226     inline KDbEscapedString &append(const char *s) {
0227         if (m_valid)
0228             QByteArray::append(s);
0229         return *this;
0230     }
0231     inline KDbEscapedString &append(const char *s, int len) {
0232         if (m_valid)
0233             QByteArray::append(s, len);
0234         return *this;
0235     }
0236     inline KDbEscapedString &append(const QByteArray &a) {
0237         if (m_valid)
0238             QByteArray::append(a);
0239         return *this;
0240     }
0241     inline KDbEscapedString &append(const QString &a) {
0242         if (m_valid)
0243             QByteArray::append(a.toUtf8());
0244         return *this;
0245     }
0246     KDbEscapedString &append(const KDbEscapedString &s);
0247     inline KDbEscapedString &insert(int i, char c) {
0248         if (m_valid)
0249             QByteArray::insert(i, c);
0250         return *this;
0251     }
0252     inline KDbEscapedString &insert(int i, const char *s) {
0253         if (m_valid)
0254             QByteArray::insert(i, s);
0255         return *this;
0256     }
0257     inline KDbEscapedString &insert(int i, const QByteArray &a) {
0258         if (m_valid)
0259             QByteArray::insert(i, a);
0260         return *this;
0261     }
0262     KDbEscapedString &insert(int i, const KDbEscapedString &s);
0263     inline KDbEscapedString &remove(int index, int len) {
0264         if (m_valid)
0265             QByteArray::remove(index, len);
0266         return *this;
0267     }
0268     inline KDbEscapedString &replace(int index, int len, const char *s) {
0269         if (m_valid)
0270             QByteArray::replace(index, len, s);
0271         return *this;
0272     }
0273     inline KDbEscapedString &replace(int index, int len, const QByteArray &s) {
0274         if (m_valid)
0275             QByteArray::replace(index, len, s);
0276         return *this;
0277     }
0278     KDbEscapedString &replace(int index, int len, const KDbEscapedString &s);
0279     inline KDbEscapedString &replace(char before, const char *after) {
0280         if (m_valid)
0281             QByteArray::replace(before, after);
0282         return *this;
0283     }
0284     inline KDbEscapedString &replace(char before, const QByteArray &after) {
0285         if (m_valid)
0286             QByteArray::replace(before, after);
0287         return *this;
0288     }
0289     KDbEscapedString &replace(char before, const KDbEscapedString &after);
0290     inline KDbEscapedString &replace(const char *before, const char *after) {
0291         if (m_valid)
0292             QByteArray::replace(before, after);
0293         return *this;
0294     }
0295     inline KDbEscapedString &replace(const char *before, int bsize, const char *after, int asize) {
0296         if (m_valid)
0297             QByteArray::replace(before, bsize, after, asize);
0298         return *this;
0299     }
0300     inline KDbEscapedString &replace(const QByteArray &before, const QByteArray &after) {
0301         if (m_valid)
0302             QByteArray::replace(before, after);
0303         return *this;
0304     }
0305     KDbEscapedString &replace(const KDbEscapedString &before, const QByteArray &after);
0306     KDbEscapedString &replace(const QByteArray &before, const KDbEscapedString &after);
0307     KDbEscapedString &replace(const KDbEscapedString &before, const KDbEscapedString &after);
0308     inline KDbEscapedString &replace(const QByteArray &before, const char *after) {
0309         if (m_valid)
0310             QByteArray::replace(before, after);
0311         return *this;
0312     }
0313     inline KDbEscapedString &replace(const char *before, const QByteArray &after) {
0314         if (m_valid)
0315             QByteArray::replace(before, after);
0316         return *this;
0317     }
0318     inline KDbEscapedString &replace(char before, char after) {
0319         if (m_valid)
0320             QByteArray::replace(before, after);
0321         return *this;
0322     }
0323     inline KDbEscapedString &operator+=(char c) { return append(c); }
0324     inline KDbEscapedString &operator+=(const char *s) { return append(s); }
0325     inline KDbEscapedString &operator+=(const QByteArray &a) { return append(a); }
0326     inline KDbEscapedString &operator+=(const QString &a) { return append(a); }
0327     inline KDbEscapedString &operator+=(const KDbEscapedString &s) { return append(s); }
0328 
0329     //KDbEscapedString operator+(const QVector<T> & other ) const
0330 
0331     QList<KDbEscapedString> split(char sep) const;
0332 
0333     inline KDbEscapedString repeated(int times) const {
0334         return m_valid ? KDbEscapedString(QByteArray::repeated(times)) : KDbEscapedString::invalid();
0335     }
0336     short toShort(bool *ok = nullptr, int base = 10) const;
0337     ushort toUShort(bool *ok = nullptr, int base = 10) const;
0338     int toInt(bool *ok = nullptr, int base = 10) const;
0339     uint toUInt(bool *ok = nullptr, int base = 10) const;
0340     long toLong(bool *ok = nullptr, int base = 10) const;
0341     ulong toULong(bool *ok = nullptr, int base = 10) const;
0342     qlonglong toLongLong(bool *ok = nullptr, int base = 10) const;
0343     qulonglong toULongLong(bool *ok = nullptr, int base = 10) const;
0344     float toFloat(bool *ok = nullptr) const;
0345     double toDouble(bool *ok = nullptr) const;
0346     inline KDbEscapedString toBase64() const {
0347         return m_valid ? KDbEscapedString(QByteArray::toBase64()) : KDbEscapedString::invalid();
0348     }
0349     inline KDbEscapedString toHex() const {
0350         return m_valid ? KDbEscapedString(QByteArray::toHex()) : KDbEscapedString::invalid();
0351     }
0352     inline KDbEscapedString toPercentEncoding(const QByteArray &exclude = QByteArray(),
0353                                  const QByteArray &include = QByteArray(),
0354                                  char percent = '%') const
0355     {
0356         Q_UNUSED(percent);
0357         return m_valid ? KDbEscapedString(QByteArray::toPercentEncoding(exclude, include))
0358                        : KDbEscapedString::invalid();
0359     }
0360 
0361     inline KDbEscapedString &setNum(short val, int base = 10) {
0362         m_valid = true;
0363         QByteArray::setNum(val, base);
0364         return *this;
0365     }
0366     inline KDbEscapedString &setNum(ushort val, int base = 10) {
0367         m_valid = true;
0368         QByteArray::setNum(val, base);
0369         return *this;
0370     }
0371     inline KDbEscapedString &setNum(int val, int base = 10) {
0372         m_valid = true;
0373         QByteArray::setNum(val, base);
0374         return *this;
0375     }
0376     inline KDbEscapedString &setNum(uint val, int base = 10) {
0377         m_valid = true;
0378         QByteArray::setNum(val, base);
0379         return *this;
0380     }
0381     inline KDbEscapedString &setNum(qlonglong val, int base = 10) {
0382         m_valid = true;
0383         QByteArray::setNum(val, base);
0384         return *this;
0385     }
0386     inline KDbEscapedString &setNum(qulonglong val, int base = 10) {
0387         m_valid = true;
0388         QByteArray::setNum(val, base);
0389         return *this;
0390     }
0391     inline KDbEscapedString &setNum(float val, char f = 'g', int prec = 6) {
0392         m_valid = true;
0393         QByteArray::setNum(val, f, prec);
0394         return *this;
0395     }
0396     inline KDbEscapedString &setNum(double val, char f = 'g', int prec = 6) {
0397         m_valid = true;
0398         QByteArray::setNum(val, f, prec);
0399         return *this;
0400     }
0401 
0402     static inline KDbEscapedString number(int val, int base = 10) {
0403         return KDbEscapedString(QByteArray::number(val, base));
0404     }
0405     static inline KDbEscapedString number(uint val, int base = 10) {
0406         return KDbEscapedString(QByteArray::number(val, base));
0407     }
0408     static inline KDbEscapedString number(qlonglong val, int base = 10) {
0409         return KDbEscapedString(QByteArray::number(val, base));
0410     }
0411     static inline KDbEscapedString number(qulonglong val, int base = 10) {
0412         return KDbEscapedString(QByteArray::number(val, base));
0413     }
0414     static inline KDbEscapedString number(double val, char f = 'g', int prec = 6) {
0415         return KDbEscapedString(QByteArray::number(val, f, prec));
0416     }
0417     static inline KDbEscapedString fromRawData(const char *s, int size) {
0418         return KDbEscapedString(QByteArray::fromRawData(s, size));
0419     }
0420     static inline KDbEscapedString fromBase64(const QByteArray &base64) {
0421         return KDbEscapedString(QByteArray::fromBase64(base64));
0422     }
0423     static inline KDbEscapedString fromBase64(const KDbEscapedString &base64) {
0424         return base64.isValid() ? KDbEscapedString(QByteArray::fromBase64(base64)) : KDbEscapedString::invalid();
0425     }
0426     static inline KDbEscapedString fromHex(const QByteArray &hexEncoded) {
0427         return KDbEscapedString(QByteArray::fromHex(hexEncoded));
0428     }
0429     static inline KDbEscapedString fromHex(const KDbEscapedString &hexEncoded) {
0430         return hexEncoded.isValid() ? KDbEscapedString(QByteArray::fromHex(hexEncoded))
0431                                     : KDbEscapedString::invalid();
0432     }
0433     static inline KDbEscapedString fromPercentEncoding(const QByteArray &pctEncoded, char percent = '%') {
0434         return KDbEscapedString(QByteArray::fromPercentEncoding(pctEncoded, percent));
0435     }
0436     static inline KDbEscapedString fromPercentEncoding(const KDbEscapedString &pctEncoded, char percent = '%') {
0437         return pctEncoded.isValid() ? KDbEscapedString(QByteArray::fromPercentEncoding(pctEncoded, percent))
0438                                     : KDbEscapedString::invalid();
0439     }
0440 
0441     inline int count() const { return QByteArray::count(); }
0442     inline int length() const { return QByteArray::length(); }
0443     inline bool isNull() const { return QByteArray::isNull(); }
0444 
0445     KDbEscapedString arg(const KDbEscapedString &a1, const KDbEscapedString &a2) const;
0446     KDbEscapedString arg(const KDbEscapedString &a1, const KDbEscapedString &a2, const KDbEscapedString &a3) const;
0447     KDbEscapedString arg(const KDbEscapedString &a1, const KDbEscapedString &a2, const KDbEscapedString &a3,
0448                       const KDbEscapedString &a4) const;
0449     KDbEscapedString arg(const KDbEscapedString &a1, const KDbEscapedString &a2, const KDbEscapedString &a3,
0450                       const KDbEscapedString &a4, const KDbEscapedString &a5) const;
0451     KDbEscapedString arg(const KDbEscapedString &a1, const KDbEscapedString &a2, const KDbEscapedString &a3,
0452                       const KDbEscapedString &a4, const KDbEscapedString &a5, const KDbEscapedString &a6) const;
0453     KDbEscapedString arg(const KDbEscapedString &a1, const KDbEscapedString &a2, const KDbEscapedString &a3,
0454                       const KDbEscapedString &a4, const KDbEscapedString &a5, const KDbEscapedString &a6,
0455                       const KDbEscapedString &a7) const;
0456     KDbEscapedString arg(const KDbEscapedString &a1, const KDbEscapedString &a2, const KDbEscapedString &a3,
0457                       const KDbEscapedString &a4, const KDbEscapedString &a5, const KDbEscapedString &a6,
0458                       const KDbEscapedString &a7, const KDbEscapedString &a8) const;
0459     KDbEscapedString arg(const KDbEscapedString &a1, const KDbEscapedString &a2, const KDbEscapedString &a3,
0460                       const KDbEscapedString &a4, const KDbEscapedString &a5, const KDbEscapedString &a6,
0461                       const KDbEscapedString &a7, const KDbEscapedString &a8, const KDbEscapedString &a9) const;
0462     KDbEscapedString arg(const KDbEscapedString &a, int fieldWidth = 0, const QChar & fillChar = QLatin1Char( ' ' )) const;
0463     KDbEscapedString arg(const QString &a, int fieldWidth = 0, const QChar & fillChar = QLatin1Char( ' ' )) const;
0464     KDbEscapedString arg(const QByteArray &a, int fieldWidth = 0, const QChar & fillChar = QLatin1Char( ' ' )) const;
0465     KDbEscapedString arg(int a, int fieldWidth = 0, int base = 10, const QChar & fillChar = QLatin1Char( ' ' )) const;
0466     KDbEscapedString arg(uint a, int fieldWidth = 0, int base = 10, const QChar & fillChar = QLatin1Char( ' ' )) const;
0467     KDbEscapedString arg(long a, int fieldWidth = 0, int base = 10, const QChar & fillChar = QLatin1Char( ' ' )) const;
0468     KDbEscapedString arg(ulong a, int fieldWidth = 0, int base = 10, const QChar & fillChar = QLatin1Char( ' ' )) const;
0469     KDbEscapedString arg(qlonglong a, int fieldWidth = 0, int base = 10, const QChar & fillChar = QLatin1Char( ' ' )) const;
0470     KDbEscapedString arg(qulonglong a, int fieldWidth = 0, int base = 10, const QChar & fillChar = QLatin1Char( ' ' )) const;
0471     KDbEscapedString arg(short a, int fieldWidth = 0, int base = 10, const QChar & fillChar = QLatin1Char( ' ' )) const;
0472     KDbEscapedString arg(ushort a, int fieldWidth = 0, int base = 10, const QChar & fillChar = QLatin1Char( ' ' )) const;
0473     KDbEscapedString arg(QChar a, int fieldWidth = 0, const QChar & fillChar = QLatin1Char( ' ' )) const;
0474     KDbEscapedString arg(char a, int fieldWidth = 0, const QChar & fillChar = QLatin1Char( ' ' )) const;
0475     KDbEscapedString arg(double a, int fieldWidth = 0, char format = 'g', int precision = -1, const QChar & fillChar = QLatin1Char( ' ' )) const;
0476 
0477     typedef QByteArray::DataPtr DataPtr;
0478     inline DataPtr &data_ptr() { return QByteArray::data_ptr(); }
0479 
0480 private:
0481     //! Used to create invalid string
0482     explicit inline KDbEscapedString(bool) : m_valid(false) {}
0483 
0484     //! Helper for methods having "bool* ok" argument
0485     inline bool checkValid(bool *ok) const {
0486         if (!m_valid) {
0487             if (ok)
0488                 *ok = false;
0489             return false;
0490         }
0491         return true;
0492     }
0493     //! true if the string is valid; true by default
0494     bool m_valid;
0495 };
0496 
0497 #ifndef QT_NO_DATASTREAM
0498 KDB_EXPORT QDataStream &operator<<(QDataStream &stream, const KDbEscapedString &string);
0499 KDB_EXPORT QDataStream &operator>>(QDataStream &stream, KDbEscapedString &string);
0500 #endif
0501 
0502 inline KDbEscapedString operator+(const KDbEscapedString &a1, const KDbEscapedString &a2)
0503 {
0504     if (!a1.isValid() || !a2.isValid())
0505         return KDbEscapedString::invalid();
0506     return KDbEscapedString(a1.toByteArray() + a2.toByteArray());
0507 }
0508 inline KDbEscapedString operator+(const KDbEscapedString &a1, const QString &a2)
0509 {
0510     if (!a1.isValid())
0511         return KDbEscapedString::invalid();
0512     return a1 + KDbEscapedString(a2);
0513 }
0514 inline KDbEscapedString operator+(const KDbEscapedString &a1, const QByteArray &a2)
0515 {
0516     if (!a1.isValid())
0517         return KDbEscapedString::invalid();
0518     return a1 + KDbEscapedString(a2);
0519 }
0520 inline KDbEscapedString operator+(const KDbEscapedString &a1, const char* a2)
0521 {
0522     if (!a1.isValid())
0523         return KDbEscapedString::invalid();
0524     return a1 + KDbEscapedString(a2);
0525 }
0526 inline KDbEscapedString operator+(const KDbEscapedString &a1, QChar a2)
0527 {
0528     if (!a1.isValid())
0529         return KDbEscapedString::invalid();
0530     return a1 + KDbEscapedString(a2.toLatin1());
0531 }
0532 inline KDbEscapedString operator+(const KDbEscapedString &a1, char a2)
0533 {
0534     if (!a1.isValid())
0535         return KDbEscapedString::invalid();
0536     return a1 + KDbEscapedString(a2);
0537 }
0538 inline KDbEscapedString operator+(const QString &a1, const KDbEscapedString &a2)
0539 {
0540     if (!a2.isValid())
0541         return KDbEscapedString::invalid();
0542     return KDbEscapedString(a1) + a2;
0543 }
0544 inline KDbEscapedString operator+(const QByteArray &a1, const KDbEscapedString &a2)
0545 {
0546     if (!a2.isValid())
0547         return KDbEscapedString::invalid();
0548     return KDbEscapedString(a1) + a2;
0549 }
0550 inline KDbEscapedString operator+(const char* a1, const KDbEscapedString &a2)
0551 {
0552     if (!a2.isValid())
0553         return KDbEscapedString::invalid();
0554     return KDbEscapedString(a1) + a2;
0555 }
0556 inline KDbEscapedString operator+(QChar a1, const KDbEscapedString &a2)
0557 {
0558     if (!a2.isValid())
0559         return KDbEscapedString::invalid();
0560     return KDbEscapedString(a1.toLatin1()) + a2;
0561 }
0562 inline KDbEscapedString operator+(char a1, const KDbEscapedString &a2)
0563 {
0564     if (!a2.isValid())
0565         return KDbEscapedString::invalid();
0566     return KDbEscapedString(a1) + a2;
0567 }
0568 
0569 inline bool operator==(const KDbEscapedString &a1, const QByteArray &a2)
0570 {
0571     return a1.isValid() && a1.toByteArray() == a2;
0572 }
0573 
0574 inline bool operator==(const KDbEscapedString &a1, const char *a2)
0575 {
0576     return a1.isValid() && a1.toByteArray() == a2;
0577 }
0578 
0579 inline bool operator==(const QByteArray &a1, const KDbEscapedString &a2)
0580 {
0581     return a2.isValid() && a1 == a2.toByteArray();
0582 }
0583 
0584 inline bool operator==(const char *a1, const KDbEscapedString &a2)
0585 {
0586     return a2.isValid() && a1 == a2.toByteArray();
0587 }
0588 
0589 Q_DECLARE_TYPEINFO(KDbEscapedString, Q_MOVABLE_TYPE);
0590 //Q_DECLARE_SHARED(KDbEscapedString)
0591 
0592 //! Sends escaped string @a string to debug output @a dbg.
0593 KDB_EXPORT QDebug operator<<(QDebug dbg, const KDbEscapedString& string);
0594 
0595 #endif