1
/****************************************************************************
3
** Copyright (C) 1992-2005 Trolltech AS. All rights reserved.
5
** This file is part of the Qt 3 compatibility classes of the Qt Toolkit.
7
** This file may be distributed under the terms of the Q Public License
8
** as defined by Trolltech AS of Norway and appearing in the file
9
** LICENSE.QPL included in the packaging of this file.
11
** This file may be distributed and/or modified under the terms of the
12
** GNU General Public License version 2 as published by the Free Software
13
** Foundation and appearing in the file LICENSE.GPL included in the
14
** packaging of this file.
16
** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
17
** information about Qt Commercial License Agreements.
18
** See http://www.trolltech.com/qpl/ for QPL licensing information.
19
** See http://www.trolltech.com/gpl/ for GPL licensing information.
21
** Contact info@trolltech.com if any conditions of this licensing are
24
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
25
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
27
****************************************************************************/
32
#include "QtCore/qbytearray.h"
34
/*****************************************************************************
36
*****************************************************************************/
40
class Q_COMPAT_EXPORT Q3CString : public QByteArray
44
Q3CString(int size) : QByteArray(size, '\0') {}
45
Q3CString(const Q3CString &s) : QByteArray(s) {}
46
Q3CString(const QByteArray &ba) : QByteArray(ba) {}
47
Q3CString(const char *str) : QByteArray(str) {}
48
Q3CString(const char *str, uint maxlen) : QByteArray(str, qMin(qstrlen(str), maxlen - 1)) {}
50
Q3CString &operator=(const Q3CString &s) {
51
QByteArray::operator=(s); return *this;
53
Q3CString &operator=(const char *str) {
54
QByteArray::operator=(str); return *this;
56
Q3CString &operator=(const QByteArray &ba) {
57
QByteArray::operator=(ba); return *this;
60
Q3CString copy() const { return *this; }
61
Q3CString &sprintf(const char *format, ...);
63
Q3CString left(uint len) const { return QByteArray::left(len); }
64
Q3CString right(uint len) const { return QByteArray::right(len); }
65
Q3CString mid(uint index, uint len=0xffffffff) const { return QByteArray::mid(index, len); }
67
Q3CString leftJustify(uint width, char fill=' ', bool trunc=false)const;
68
Q3CString rightJustify(uint width, char fill=' ',bool trunc=false)const;
70
Q3CString lower() const { return QByteArray::toLower(); }
71
Q3CString upper() const { return QByteArray::toUpper(); }
73
Q3CString stripWhiteSpace() const { return QByteArray::trimmed(); }
74
Q3CString simplifyWhiteSpace() const { return QByteArray::simplified(); }
76
Q3CString &insert(uint index, const char *c) { QByteArray::insert(index, c); return *this; }
77
Q3CString &insert(uint index, char c) { QByteArray::insert(index, c); return *this; }
78
Q3CString &append(const char *c) { QByteArray::append(c); return *this; }
79
Q3CString &prepend(const char *c) { QByteArray::prepend(c); return *this; }
80
Q3CString &remove(uint index, uint len) { QByteArray::remove(index, len); return *this; }
81
Q3CString &replace(uint index, uint len, const char *c)
82
{ QByteArray::replace(index, len, c); return *this; }
83
Q3CString &replace(char c, const Q3CString &after) { return replace(c, after.constData()); }
84
Q3CString &replace(char c, const char *after) { QByteArray::replace(c, after); return *this; }
85
Q3CString &replace(const Q3CString &b, const Q3CString &a)
86
{ return replace(b.constData(), a.constData()); }
87
Q3CString &replace(const char *b, const char *a) { QByteArray::replace(b, a); return *this; }
88
Q3CString &replace(char b, char a) { QByteArray::replace(b, a); return *this; }
90
short toShort(bool *ok=0) const;
91
ushort toUShort(bool *ok=0) const;
92
int toInt(bool *ok=0) const;
93
uint toUInt(bool *ok=0) const;
94
long toLong(bool *ok=0) const;
95
ulong toULong(bool *ok=0) const;
96
float toFloat(bool *ok=0) const;
97
double toDouble(bool *ok=0) const;
99
Q3CString &setStr(const char *s) { *this = s; return *this; }
100
Q3CString &setNum(short);
101
Q3CString &setNum(ushort);
102
Q3CString &setNum(int);
103
Q3CString &setNum(uint);
104
Q3CString &setNum(long);
105
Q3CString &setNum(ulong);
106
Q3CString &setNum(float, char f='g', int prec=6);
107
Q3CString &setNum(double, char f='g', int prec=6);
109
bool setExpand(uint index, char c);
114
/*****************************************************************************
115
Q3CString stream functions
116
*****************************************************************************/
117
#ifndef QT_NO_DATASTREAM
118
inline Q_COMPAT_EXPORT QDataStream &operator<<(QDataStream &d, const Q3CString &s) {
119
return operator<<(d, static_cast<const QByteArray &>(s));
121
inline Q_COMPAT_EXPORT QDataStream &operator>>(QDataStream &d, Q3CString &s) {
122
return operator>>(d, static_cast<QByteArray &>(s));
126
/*****************************************************************************
127
Q3CString inline functions
128
*****************************************************************************/
130
inline Q3CString &Q3CString::setNum(short n)
131
{ return setNum(long(n)); }
133
inline Q3CString &Q3CString::setNum(ushort n)
134
{ return setNum(ulong(n)); }
136
inline Q3CString &Q3CString::setNum(int n)
137
{ return setNum(long(n)); }
139
inline Q3CString &Q3CString::setNum(uint n)
140
{ return setNum(ulong(n)); }
142
inline Q3CString &Q3CString::setNum(float n, char f, int prec)
143
{ return setNum(double(n),f,prec); }
145
/*****************************************************************************
146
Q3CString non-member operators
147
*****************************************************************************/
149
Q_COMPAT_EXPORT inline bool operator==(const Q3CString &s1, const Q3CString &s2)
150
{ return qstrcmp(s1, s2) == 0; }
152
Q_COMPAT_EXPORT inline bool operator==(const Q3CString &s1, const char *s2)
153
{ return qstrcmp(s1, s2) == 0; }
155
Q_COMPAT_EXPORT inline bool operator==(const char *s1, const Q3CString &s2)
156
{ return qstrcmp(s1, s2) == 0; }
158
Q_COMPAT_EXPORT inline bool operator!=(const Q3CString &s1, const Q3CString &s2)
159
{ return qstrcmp(s1, s2) != 0; }
161
Q_COMPAT_EXPORT inline bool operator!=(const Q3CString &s1, const char *s2)
162
{ return qstrcmp(s1, s2) != 0; }
164
Q_COMPAT_EXPORT inline bool operator!=(const char *s1, const Q3CString &s2)
165
{ return qstrcmp(s1, s2) != 0; }
167
Q_COMPAT_EXPORT inline bool operator<(const Q3CString &s1, const Q3CString& s2)
168
{ return qstrcmp(s1, s2) < 0; }
170
Q_COMPAT_EXPORT inline bool operator<(const Q3CString &s1, const char *s2)
171
{ return qstrcmp(s1, s2) < 0; }
173
Q_COMPAT_EXPORT inline bool operator<(const char *s1, const Q3CString &s2)
174
{ return qstrcmp(s1, s2) < 0; }
176
Q_COMPAT_EXPORT inline bool operator<=(const Q3CString &s1, const Q3CString &s2)
177
{ return qstrcmp(s1, s2) <= 0; }
179
Q_COMPAT_EXPORT inline bool operator<=(const Q3CString &s1, const char *s2)
180
{ return qstrcmp(s1, s2) <= 0; }
182
Q_COMPAT_EXPORT inline bool operator<=(const char *s1, const Q3CString &s2)
183
{ return qstrcmp(s1, s2) <= 0; }
185
Q_COMPAT_EXPORT inline bool operator>(const Q3CString &s1, const Q3CString &s2)
186
{ return qstrcmp(s1, s2) > 0; }
188
Q_COMPAT_EXPORT inline bool operator>(const Q3CString &s1, const char *s2)
189
{ return qstrcmp(s1, s2) > 0; }
191
Q_COMPAT_EXPORT inline bool operator>(const char *s1, const Q3CString &s2)
192
{ return qstrcmp(s1, s2) > 0; }
194
Q_COMPAT_EXPORT inline bool operator>=(const Q3CString &s1, const Q3CString& s2)
195
{ return qstrcmp(s1, s2) >= 0; }
197
Q_COMPAT_EXPORT inline bool operator>=(const Q3CString &s1, const char *s2)
198
{ return qstrcmp(s1, s2) >= 0; }
200
Q_COMPAT_EXPORT inline bool operator>=(const char *s1, const Q3CString &s2)
201
{ return qstrcmp(s1, s2) >= 0; }
203
Q_COMPAT_EXPORT inline const Q3CString operator+(const Q3CString &s1,
210
Q_COMPAT_EXPORT inline const Q3CString operator+(const Q3CString &s1,
211
const QByteArray &s2)
217
Q_COMPAT_EXPORT inline const Q3CString operator+(const QByteArray &s1,
225
Q_COMPAT_EXPORT inline const Q3CString operator+(const Q3CString &s1, const char *s2)
232
Q_COMPAT_EXPORT inline const Q3CString operator+(const char *s1, const Q3CString &s2)
239
Q_COMPAT_EXPORT inline const Q3CString operator+(const Q3CString &s1, char c2)
246
Q_COMPAT_EXPORT inline const Q3CString operator+(char c1, const Q3CString &s2)
254
#endif // Q3CSTRING_H