KDb

KDbEscapedString.cpp
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#include "KDbEscapedString.h"
21#include "kdb_debug.h"
22
23#include <QDataStream>
24
25KDbEscapedString &KDbEscapedString::prepend(const KDbEscapedString &s)
26{
27 if (s.isValid()) {
28 if (m_valid)
30 }
31 else {
33 m_valid = false;
34 }
35 return *this;
36}
37
38KDbEscapedString &KDbEscapedString::append(const KDbEscapedString &s)
39{
40 if (s.isValid()) {
41 if (m_valid)
43 }
44 else {
46 m_valid = false;
47 }
48 return *this;
49}
50
51KDbEscapedString &KDbEscapedString::insert(int i, const KDbEscapedString &s)
52{
53 if (s.isValid()) {
54 if (m_valid)
56 }
57 else {
59 m_valid = false;
60 }
61 return *this;
62}
63
64KDbEscapedString &KDbEscapedString::replace(int index, int len, const KDbEscapedString &s)
65{
66 if (s.isValid()) {
67 if (m_valid)
68 QByteArray::replace(index, len, s);
69 }
70 else {
72 m_valid = false;
73 }
74 return *this;
75}
76
77KDbEscapedString &KDbEscapedString::replace(char before, const KDbEscapedString &after)
78{
79 if (after.isValid()) {
80 if (m_valid)
81 QByteArray::replace(before, after);
82 }
83 else {
85 m_valid = false;
86 }
87 return *this;
88}
89
90KDbEscapedString &KDbEscapedString::replace(const KDbEscapedString &before, const QByteArray &after)
91{
92 if (before.isValid()) {
93 if (m_valid)
94 QByteArray::replace(before, after);
95 }
96 else {
98 m_valid = false;
99 }
100 return *this;
101}
102
103KDbEscapedString &KDbEscapedString::replace(const QByteArray &before, const KDbEscapedString &after)
104{
105 if (after.isValid()) {
106 if (m_valid)
107 QByteArray::replace(before, after);
108 }
109 else {
111 m_valid = false;
112 }
113 return *this;
114}
115
116KDbEscapedString &KDbEscapedString::replace(const KDbEscapedString &before, const KDbEscapedString &after)
117{
118 if (before.isValid() && after.isValid()) {
119 if (m_valid)
120 QByteArray::replace(before, after);
121 }
122 else {
124 m_valid = false;
125 }
126 return *this;
127}
128
129QList<KDbEscapedString> KDbEscapedString::split(char sep) const
130{
132 foreach(const QByteArray& ba, QByteArray::split(sep))
133 result.append(KDbEscapedString(ba));
134 return result;
135}
136
137#ifndef QT_NO_DATASTREAM
138KDB_EXPORT QDataStream& operator<<(QDataStream &stream, const KDbEscapedString &string)
139{
140 stream << string.isValid();
141 if (string.isValid())
142 stream << string.toByteArray();
143 return stream;
144}
145
146KDB_EXPORT QDataStream& operator>>(QDataStream &stream, KDbEscapedString &string)
147{
148 bool valid;
149 stream >> valid;
150 if (valid) {
151 QByteArray ba;
152 stream >> ba;
153 string = ba;
154 }
155 else {
156 string = KDbEscapedString::invalid();
157 }
158 return stream;
159}
160#endif
161
162short KDbEscapedString::toShort(bool *ok, int base) const
163{
164 if (!checkValid(ok))
165 return 0;
166 return QByteArray::toShort(ok, base);
167}
168
169ushort KDbEscapedString::toUShort(bool *ok, int base) const
170{
171 if (!checkValid(ok))
172 return 0;
173 return QByteArray::toUShort(ok, base);
174}
175
176int KDbEscapedString::toInt(bool *ok, int base) const
177{
178 if (!checkValid(ok))
179 return 0;
180 return QByteArray::toInt(ok, base);
181}
182
183uint KDbEscapedString::toUInt(bool *ok, int base) const
184{
185 if (!checkValid(ok))
186 return 0;
187 return QByteArray::toUInt(ok, base);
188}
189
190long KDbEscapedString::toLong(bool *ok, int base) const
191{
192 if (!checkValid(ok))
193 return 0;
194 return QByteArray::toLong(ok, base);
195}
196
197ulong KDbEscapedString::toULong(bool *ok, int base) const
198{
199 if (!checkValid(ok))
200 return 0;
201 return QByteArray::toULong(ok, base);
202}
203
204qlonglong KDbEscapedString::toLongLong(bool *ok, int base) const
205{
206 if (!checkValid(ok))
207 return 0;
208 return QByteArray::toLongLong(ok, base);
209}
210
211qulonglong KDbEscapedString::toULongLong(bool *ok, int base) const
212{
213 if (!checkValid(ok))
214 return 0;
215 return QByteArray::toULongLong(ok, base);
216}
217
218float KDbEscapedString::toFloat(bool *ok) const
219{
220 if (!checkValid(ok))
221 return 0;
222 return QByteArray::toFloat(ok);
223}
224
225double KDbEscapedString::toDouble(bool *ok) const
226{
227 if (!checkValid(ok))
228 return 0;
229 return QByteArray::toDouble(ok);
230}
231
232KDbEscapedString KDbEscapedString::arg(const KDbEscapedString &a1, const KDbEscapedString &a2) const
233{
234 if (!m_valid || !a1.isValid() || !a2.isValid())
236 return KDbEscapedString(toString().arg(a1.toString(), a2.toString()));
237}
238
239KDbEscapedString KDbEscapedString::arg(const KDbEscapedString &a1, const KDbEscapedString &a2, const KDbEscapedString &a3) const
240{
241 if (!m_valid || !a1.isValid() || !a2.isValid() || !a3.isValid())
243 return KDbEscapedString(toString().arg(a1.toString(), a2.toString(), a3.toString()));
244}
245
246KDbEscapedString KDbEscapedString::arg(const KDbEscapedString &a1, const KDbEscapedString &a2, const KDbEscapedString &a3,
247 const KDbEscapedString &a4) const
248{
249 if (!m_valid || !a1.isValid() || !a2.isValid() || !a3.isValid() || !a4.isValid())
251 return KDbEscapedString(toString().arg(a1.toString(), a2.toString(), a3.toString(), a4.toString()));
252}
253
254KDbEscapedString KDbEscapedString::arg(const KDbEscapedString &a1, const KDbEscapedString &a2, const KDbEscapedString &a3,
255 const KDbEscapedString &a4, const KDbEscapedString &a5) const
256{
257 if (!m_valid || !a1.isValid() || !a2.isValid() || !a3.isValid() || !a4.isValid() || !a5.isValid())
259 return KDbEscapedString(toString().arg(a1.toString(), a2.toString(), a3.toString(), a4.toString(),
260 a5.toString()));
261}
262
263KDbEscapedString KDbEscapedString::arg(const KDbEscapedString &a1, const KDbEscapedString &a2, const KDbEscapedString &a3,
264 const KDbEscapedString &a4, const KDbEscapedString &a5, const KDbEscapedString &a6) const
265{
266 if (!m_valid || !a1.isValid() || !a2.isValid() || !a3.isValid() || !a4.isValid() || !a5.isValid()
267 || !a6.isValid())
269 return KDbEscapedString(toString().arg(a1.toString(), a2.toString(), a3.toString(), a4.toString(),
270 a5.toString(), a6.toString()));
271}
272
273KDbEscapedString KDbEscapedString::arg(const KDbEscapedString &a1, const KDbEscapedString &a2, const KDbEscapedString &a3,
274 const KDbEscapedString &a4, const KDbEscapedString &a5, const KDbEscapedString &a6,
275 const KDbEscapedString &a7) const
276{
277 if (!m_valid || !a1.isValid() || !a2.isValid() || !a3.isValid() || !a4.isValid() || !a5.isValid()
278 || !a6.isValid() || !a7.isValid())
280 return KDbEscapedString(toString().arg(a1.toString(), a2.toString(), a3.toString(), a4.toString(),
281 a5.toString(), a6.toString(), a7.toString()));
282}
283
284KDbEscapedString KDbEscapedString::arg(const KDbEscapedString &a1, const KDbEscapedString &a2, const KDbEscapedString &a3,
285 const KDbEscapedString &a4, const KDbEscapedString &a5, const KDbEscapedString &a6,
286 const KDbEscapedString &a7, const KDbEscapedString &a8) const
287{
288 if (!m_valid || !a1.isValid() || !a2.isValid() || !a3.isValid() || !a4.isValid() || !a5.isValid()
289 || !a6.isValid() || !a7.isValid() || !a8.isValid())
291 return KDbEscapedString(toString().arg(a1.toString(), a2.toString(), a3.toString(), a4.toString(),
292 a5.toString(), a6.toString(), a7.toString(), a8.toString()));
293}
294
295KDbEscapedString KDbEscapedString::arg(const KDbEscapedString &a1, const KDbEscapedString &a2, const KDbEscapedString &a3,
296 const KDbEscapedString &a4, const KDbEscapedString &a5, const KDbEscapedString &a6,
297 const KDbEscapedString &a7, const KDbEscapedString &a8, const KDbEscapedString &a9) const
298{
299 if (!m_valid || !a1.isValid() || !a2.isValid() || !a3.isValid() || !a4.isValid() || !a5.isValid()
300 || !a6.isValid() || !a7.isValid() || !a8.isValid() || !a9.isValid())
302 return KDbEscapedString(toString().arg(a1.toString(), a2.toString(), a3.toString(), a4.toString(),
303 a5.toString(), a6.toString(), a7.toString(), a8.toString(), a9.toString()));
304}
305
306KDbEscapedString KDbEscapedString::arg(const KDbEscapedString &a, int fieldWidth, const QChar & fillChar) const
307{
308 if (!m_valid || !a.isValid())
310 return KDbEscapedString(toString().arg(a.toString(), fieldWidth, fillChar));
311}
312
313KDbEscapedString KDbEscapedString::arg(const QString &a, int fieldWidth, const QChar & fillChar) const
314{
315 if (!m_valid)
317 return KDbEscapedString(toString().arg(a, fieldWidth, fillChar));
318}
319
320KDbEscapedString KDbEscapedString::arg(const QByteArray &a, int fieldWidth, const QChar & fillChar) const
321{
322 if (!m_valid)
324 return KDbEscapedString(toString().arg(QLatin1String(a), fieldWidth, fillChar));
325}
326
327KDbEscapedString KDbEscapedString::arg(int a, int fieldWidth, int base, const QChar & fillChar) const
328{
329 if (!m_valid)
331 return KDbEscapedString(toString().arg(a, fieldWidth, base, fillChar));
332}
333
334KDbEscapedString KDbEscapedString::arg(uint a, int fieldWidth, int base, const QChar & fillChar) const
335{
336 if (!m_valid)
338 return KDbEscapedString(toString().arg(a, fieldWidth, base, fillChar));
339}
340
341KDbEscapedString KDbEscapedString::arg(long a, int fieldWidth, int base, const QChar & fillChar) const
342{
343 if (!m_valid)
345 return KDbEscapedString(toString().arg(a, fieldWidth, base, fillChar));
346}
347
348KDbEscapedString KDbEscapedString::arg(ulong a, int fieldWidth, int base, const QChar & fillChar) const
349{
350 if (!m_valid)
352 return KDbEscapedString(toString().arg(a, fieldWidth, base, fillChar));
353}
354
355KDbEscapedString KDbEscapedString::arg(qlonglong a, int fieldWidth, int base, const QChar & fillChar) const
356{
357 if (!m_valid)
359 return KDbEscapedString(toString().arg(a, fieldWidth, base, fillChar));
360}
361
362KDbEscapedString KDbEscapedString::arg(qulonglong a, int fieldWidth, int base, const QChar & fillChar) const
363{
364 if (!m_valid)
366 return KDbEscapedString(toString().arg(a, fieldWidth, base, fillChar));
367}
368
369KDbEscapedString KDbEscapedString::arg(short a, int fieldWidth, int base, const QChar & fillChar) const
370{
371 if (!m_valid)
373 return KDbEscapedString(toString().arg(a, fieldWidth, base, fillChar));
374}
375
376KDbEscapedString KDbEscapedString::arg(ushort a, int fieldWidth, int base, const QChar & fillChar) const
377{
378 if (!m_valid)
380 return KDbEscapedString(toString().arg(a, fieldWidth, base, fillChar));
381}
382
383KDbEscapedString KDbEscapedString::arg(QChar a, int fieldWidth, const QChar & fillChar) const
384{
385 if (!m_valid)
387 return KDbEscapedString(toString().arg(a, fieldWidth, fillChar));
388}
389
390KDbEscapedString KDbEscapedString::arg(char a, int fieldWidth, const QChar & fillChar) const
391{
392 if (!m_valid)
394 return KDbEscapedString(toString().arg(a, fieldWidth, fillChar));
395}
396
397KDbEscapedString KDbEscapedString::arg(double a, int fieldWidth, char format, int precision, const QChar & fillChar) const
398{
399 if (!m_valid)
401 return KDbEscapedString(toString().arg(a, fieldWidth, format, precision, fillChar));
402}
403
404KDB_EXPORT QDebug operator<<(QDebug dbg, const KDbEscapedString& string)
405{
406 if (string.isValid())
407 dbg.nospace() << "KDbEscapedString:" << string.toByteArray();
408 else
409 dbg.nospace() << "KDbEscapedString(INVALID)";
410 return dbg.space();
411}
Specialized string for escaping.
static KDbEscapedString invalid()
bool isValid() const
KCALENDARCORE_EXPORT QDataStream & operator>>(QDataStream &in, const KCalendarCore::Alarm::Ptr &)
bool isValid(QStringView ifopt)
QDebug operator<<(QDebug dbg, const PerceptualColor::LchaDouble &value)
QByteArray & append(QByteArrayView data)
void clear()
QByteArray & insert(qsizetype i, QByteArrayView data)
QByteArray & prepend(QByteArrayView ba)
QByteArray & replace(QByteArrayView before, QByteArrayView after)
QList< QByteArray > split(char sep) const const
double toDouble(bool *ok) const const
float toFloat(bool *ok) 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
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
QDebug & nospace()
QDebug & space()
void append(QList< T > &&value)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Tue Mar 26 2024 11:20:59 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.