~oif-team/ubuntu/natty/qt4-x11/xi2.1

« back to all changes in this revision

Viewing changes to src/qt3support/tools/q3cstring.h

  • Committer: Bazaar Package Importer
  • Author(s): Adam Conrad
  • Date: 2005-08-24 04:09:09 UTC
  • Revision ID: james.westby@ubuntu.com-20050824040909-xmxe9jfr4a0w5671
Tags: upstream-4.0.0
ImportĀ upstreamĀ versionĀ 4.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/****************************************************************************
 
2
**
 
3
** Copyright (C) 1992-2005 Trolltech AS. All rights reserved.
 
4
**
 
5
** This file is part of the Qt 3 compatibility classes of the Qt Toolkit.
 
6
**
 
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.
 
10
**
 
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.
 
15
**
 
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.
 
20
**
 
21
** Contact info@trolltech.com if any conditions of this licensing are
 
22
** not clear to you.
 
23
**
 
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.
 
26
**
 
27
****************************************************************************/
 
28
 
 
29
#ifndef Q3CSTRING_H
 
30
#define Q3CSTRING_H
 
31
 
 
32
#include "QtCore/qbytearray.h"
 
33
 
 
34
/*****************************************************************************
 
35
  QCString class
 
36
 *****************************************************************************/
 
37
 
 
38
class QRegExp;
 
39
 
 
40
class Q_COMPAT_EXPORT Q3CString : public QByteArray
 
41
{
 
42
public:
 
43
    Q3CString() {}
 
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)) {}
 
49
 
 
50
    Q3CString    &operator=(const Q3CString &s) {
 
51
        QByteArray::operator=(s); return *this;
 
52
    }
 
53
    Q3CString    &operator=(const char *str) {
 
54
        QByteArray::operator=(str); return *this;
 
55
    }
 
56
    Q3CString    &operator=(const QByteArray &ba) {
 
57
        QByteArray::operator=(ba); return *this;
 
58
    }
 
59
 
 
60
    Q3CString        copy()        const { return *this; }
 
61
    Q3CString    &sprintf(const char *format, ...);
 
62
 
 
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); }
 
66
 
 
67
    Q3CString        leftJustify(uint width, char fill=' ', bool trunc=false)const;
 
68
    Q3CString        rightJustify(uint width, char fill=' ',bool trunc=false)const;
 
69
 
 
70
    Q3CString        lower() const { return QByteArray::toLower(); }
 
71
    Q3CString        upper() const { return QByteArray::toUpper(); }
 
72
 
 
73
    Q3CString        stripWhiteSpace()        const { return QByteArray::trimmed(); }
 
74
    Q3CString        simplifyWhiteSpace()        const { return QByteArray::simplified(); }
 
75
 
 
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; }
 
89
 
 
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;
 
98
 
 
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);
 
108
 
 
109
    bool        setExpand(uint index, char c);
 
110
 
 
111
};
 
112
 
 
113
 
 
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));
 
120
}
 
121
inline Q_COMPAT_EXPORT QDataStream &operator>>(QDataStream &d, Q3CString &s) {
 
122
    return operator>>(d, static_cast<QByteArray &>(s));
 
123
}
 
124
#endif
 
125
 
 
126
/*****************************************************************************
 
127
  Q3CString inline functions
 
128
 *****************************************************************************/
 
129
 
 
130
inline Q3CString &Q3CString::setNum(short n)
 
131
{ return setNum(long(n)); }
 
132
 
 
133
inline Q3CString &Q3CString::setNum(ushort n)
 
134
{ return setNum(ulong(n)); }
 
135
 
 
136
inline Q3CString &Q3CString::setNum(int n)
 
137
{ return setNum(long(n)); }
 
138
 
 
139
inline Q3CString &Q3CString::setNum(uint n)
 
140
{ return setNum(ulong(n)); }
 
141
 
 
142
inline Q3CString &Q3CString::setNum(float n, char f, int prec)
 
143
{ return setNum(double(n),f,prec); }
 
144
 
 
145
/*****************************************************************************
 
146
  Q3CString non-member operators
 
147
 *****************************************************************************/
 
148
 
 
149
Q_COMPAT_EXPORT inline bool operator==(const Q3CString &s1, const Q3CString &s2)
 
150
{ return qstrcmp(s1, s2) == 0; }
 
151
 
 
152
Q_COMPAT_EXPORT inline bool operator==(const Q3CString &s1, const char *s2)
 
153
{ return qstrcmp(s1, s2) == 0; }
 
154
 
 
155
Q_COMPAT_EXPORT inline bool operator==(const char *s1, const Q3CString &s2)
 
156
{ return qstrcmp(s1, s2) == 0; }
 
157
 
 
158
Q_COMPAT_EXPORT inline bool operator!=(const Q3CString &s1, const Q3CString &s2)
 
159
{ return qstrcmp(s1, s2) != 0; }
 
160
 
 
161
Q_COMPAT_EXPORT inline bool operator!=(const Q3CString &s1, const char *s2)
 
162
{ return qstrcmp(s1, s2) != 0; }
 
163
 
 
164
Q_COMPAT_EXPORT inline bool operator!=(const char *s1, const Q3CString &s2)
 
165
{ return qstrcmp(s1, s2) != 0; }
 
166
 
 
167
Q_COMPAT_EXPORT inline bool operator<(const Q3CString &s1, const Q3CString& s2)
 
168
{ return qstrcmp(s1, s2) < 0; }
 
169
 
 
170
Q_COMPAT_EXPORT inline bool operator<(const Q3CString &s1, const char *s2)
 
171
{ return qstrcmp(s1, s2) < 0; }
 
172
 
 
173
Q_COMPAT_EXPORT inline bool operator<(const char *s1, const Q3CString &s2)
 
174
{ return qstrcmp(s1, s2) < 0; }
 
175
 
 
176
Q_COMPAT_EXPORT inline bool operator<=(const Q3CString &s1, const Q3CString &s2)
 
177
{ return qstrcmp(s1, s2) <= 0; }
 
178
 
 
179
Q_COMPAT_EXPORT inline bool operator<=(const Q3CString &s1, const char *s2)
 
180
{ return qstrcmp(s1, s2) <= 0; }
 
181
 
 
182
Q_COMPAT_EXPORT inline bool operator<=(const char *s1, const Q3CString &s2)
 
183
{ return qstrcmp(s1, s2) <= 0; }
 
184
 
 
185
Q_COMPAT_EXPORT inline bool operator>(const Q3CString &s1, const Q3CString &s2)
 
186
{ return qstrcmp(s1, s2) > 0; }
 
187
 
 
188
Q_COMPAT_EXPORT inline bool operator>(const Q3CString &s1, const char *s2)
 
189
{ return qstrcmp(s1, s2) > 0; }
 
190
 
 
191
Q_COMPAT_EXPORT inline bool operator>(const char *s1, const Q3CString &s2)
 
192
{ return qstrcmp(s1, s2) > 0; }
 
193
 
 
194
Q_COMPAT_EXPORT inline bool operator>=(const Q3CString &s1, const Q3CString& s2)
 
195
{ return qstrcmp(s1, s2) >= 0; }
 
196
 
 
197
Q_COMPAT_EXPORT inline bool operator>=(const Q3CString &s1, const char *s2)
 
198
{ return qstrcmp(s1, s2) >= 0; }
 
199
 
 
200
Q_COMPAT_EXPORT inline bool operator>=(const char *s1, const Q3CString &s2)
 
201
{ return qstrcmp(s1, s2) >= 0; }
 
202
 
 
203
Q_COMPAT_EXPORT inline const Q3CString operator+(const Q3CString &s1,
 
204
                                          const Q3CString &s2)
 
205
{
 
206
    Q3CString tmp(s1);
 
207
    tmp += s2;
 
208
    return tmp;
 
209
}
 
210
Q_COMPAT_EXPORT inline const Q3CString operator+(const Q3CString &s1,
 
211
                                          const QByteArray &s2)
 
212
{
 
213
    QByteArray tmp(s1);
 
214
    tmp += s2;
 
215
    return tmp;
 
216
}
 
217
Q_COMPAT_EXPORT inline const Q3CString operator+(const QByteArray &s1,
 
218
                                          const Q3CString &s2)
 
219
{
 
220
    QByteArray tmp(s1);
 
221
    tmp += s2;
 
222
    return tmp;
 
223
}
 
224
 
 
225
Q_COMPAT_EXPORT inline const Q3CString operator+(const Q3CString &s1, const char *s2)
 
226
{
 
227
    Q3CString tmp(s1);
 
228
    tmp += s2;
 
229
    return tmp;
 
230
}
 
231
 
 
232
Q_COMPAT_EXPORT inline const Q3CString operator+(const char *s1, const Q3CString &s2)
 
233
{
 
234
    Q3CString tmp(s1);
 
235
    tmp += s2;
 
236
    return tmp;
 
237
}
 
238
 
 
239
Q_COMPAT_EXPORT inline const Q3CString operator+(const Q3CString &s1, char c2)
 
240
{
 
241
    Q3CString tmp(s1);
 
242
    tmp += c2;
 
243
    return tmp;
 
244
}
 
245
 
 
246
Q_COMPAT_EXPORT inline const Q3CString operator+(char c1, const Q3CString &s2)
 
247
{
 
248
    Q3CString tmp;
 
249
    tmp += c1;
 
250
    tmp += s2;
 
251
    return tmp;
 
252
}
 
253
 
 
254
#endif // Q3CSTRING_H