source: trunk/src/qt3support/tools/q3cstring.h@ 345

Last change on this file since 345 was 2, checked in by Dmitry A. Kuminov, 16 years ago

Initially imported qt-all-opensource-src-4.5.1 from Trolltech.

File size: 9.9 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
4** Contact: Qt Software Information ([email protected])
5**
6** This file is part of the Qt3Support module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial Usage
10** Licensees holding valid Qt Commercial licenses may use this file in
11** accordance with the Qt Commercial License Agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and Nokia.
14**
15** GNU Lesser General Public License Usage
16** Alternatively, this file may be used under the terms of the GNU Lesser
17** General Public License version 2.1 as published by the Free Software
18** Foundation and appearing in the file LICENSE.LGPL included in the
19** packaging of this file. Please review the following information to
20** ensure the GNU Lesser General Public License version 2.1 requirements
21** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
22**
23** In addition, as a special exception, Nokia gives you certain
24** additional rights. These rights are described in the Nokia Qt LGPL
25** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
26** package.
27**
28** GNU General Public License Usage
29** Alternatively, this file may be used under the terms of the GNU
30** General Public License version 3.0 as published by the Free Software
31** Foundation and appearing in the file LICENSE.GPL included in the
32** packaging of this file. Please review the following information to
33** ensure the GNU General Public License version 3.0 requirements will be
34** met: http://www.gnu.org/copyleft/gpl.html.
35**
36** If you are unsure which license is appropriate for your use, please
37** contact the sales department at [email protected].
38** $QT_END_LICENSE$
39**
40****************************************************************************/
41
42#ifndef Q3CSTRING_H
43#define Q3CSTRING_H
44
45#include <QtCore/qbytearray.h>
46
47QT_BEGIN_HEADER
48
49QT_BEGIN_NAMESPACE
50
51QT_MODULE(Qt3SupportLight)
52
53/*****************************************************************************
54 QCString class
55 *****************************************************************************/
56
57class QRegExp;
58
59class Q_COMPAT_EXPORT Q3CString : public QByteArray
60{
61public:
62 Q3CString() {}
63 Q3CString(int size) : QByteArray(size, '\0') {}
64 Q3CString(const Q3CString &s) : QByteArray(s) {}
65 Q3CString(const QByteArray &ba) : QByteArray(ba) {}
66 Q3CString(const char *str) : QByteArray(str) {}
67 Q3CString(const char *str, uint maxlen) : QByteArray(str, qMin(qstrlen(str), maxlen - 1)) {}
68
69 Q3CString &operator=(const Q3CString &s) {
70 QByteArray::operator=(s); return *this;
71 }
72 Q3CString &operator=(const char *str) {
73 QByteArray::operator=(str); return *this;
74 }
75 Q3CString &operator=(const QByteArray &ba) {
76 QByteArray::operator=(ba); return *this;
77 }
78
79 Q3CString copy() const { return *this; }
80 Q3CString &sprintf(const char *format, ...);
81
82 Q3CString left(uint len) const { return QByteArray::left(len); }
83 Q3CString right(uint len) const { return QByteArray::right(len); }
84 Q3CString mid(uint index, uint len=0xffffffff) const { return QByteArray::mid(index, len); }
85
86 Q3CString leftJustify(uint width, char fill=' ', bool trunc=false)const;
87 Q3CString rightJustify(uint width, char fill=' ',bool trunc=false)const;
88
89 Q3CString lower() const { return QByteArray::toLower(); }
90 Q3CString upper() const { return QByteArray::toUpper(); }
91
92 Q3CString stripWhiteSpace() const { return QByteArray::trimmed(); }
93 Q3CString simplifyWhiteSpace() const { return QByteArray::simplified(); }
94
95 Q3CString &insert(uint index, const char *c) { QByteArray::insert(index, c); return *this; }
96 Q3CString &insert(uint index, char c) { QByteArray::insert(index, c); return *this; }
97 Q3CString &append(const char *c) { QByteArray::append(c); return *this; }
98 Q3CString &prepend(const char *c) { QByteArray::prepend(c); return *this; }
99 Q3CString &remove(uint index, uint len) { QByteArray::remove(index, len); return *this; }
100 Q3CString &replace(uint index, uint len, const char *c)
101 { QByteArray::replace(index, len, c); return *this; }
102 Q3CString &replace(char c, const Q3CString &after) { return replace(c, after.constData()); }
103 Q3CString &replace(char c, const char *after) { QByteArray::replace(c, after); return *this; }
104 Q3CString &replace(const Q3CString &b, const Q3CString &a)
105 { return replace(b.constData(), a.constData()); }
106 Q3CString &replace(const char *b, const char *a) { QByteArray::replace(b, a); return *this; }
107 Q3CString &replace(char b, char a) { QByteArray::replace(b, a); return *this; }
108
109 short toShort(bool *ok=0) const;
110 ushort toUShort(bool *ok=0) const;
111 int toInt(bool *ok=0) const;
112 uint toUInt(bool *ok=0) const;
113 long toLong(bool *ok=0) const;
114 ulong toULong(bool *ok=0) const;
115 float toFloat(bool *ok=0) const;
116 double toDouble(bool *ok=0) const;
117
118 Q3CString &setStr(const char *s) { *this = s; return *this; }
119 Q3CString &setNum(short);
120 Q3CString &setNum(ushort);
121 Q3CString &setNum(int);
122 Q3CString &setNum(uint);
123 Q3CString &setNum(long);
124 Q3CString &setNum(ulong);
125 Q3CString &setNum(float, char f='g', int prec=6);
126 Q3CString &setNum(double, char f='g', int prec=6);
127
128 bool setExpand(uint index, char c);
129
130};
131
132
133/*****************************************************************************
134 Q3CString stream functions
135 *****************************************************************************/
136#ifndef QT_NO_DATASTREAM
137Q_COMPAT_EXPORT QDataStream &operator<<(QDataStream &d, const Q3CString &s);
138Q_COMPAT_EXPORT QDataStream &operator>>(QDataStream &d, Q3CString &s);
139#endif
140
141/*****************************************************************************
142 Q3CString inline functions
143 *****************************************************************************/
144
145inline Q3CString &Q3CString::setNum(short n)
146{ return setNum(long(n)); }
147
148inline Q3CString &Q3CString::setNum(ushort n)
149{ return setNum(ulong(n)); }
150
151inline Q3CString &Q3CString::setNum(int n)
152{ return setNum(long(n)); }
153
154inline Q3CString &Q3CString::setNum(uint n)
155{ return setNum(ulong(n)); }
156
157inline Q3CString &Q3CString::setNum(float n, char f, int prec)
158{ return setNum(double(n),f,prec); }
159
160/*****************************************************************************
161 Q3CString non-member operators
162 *****************************************************************************/
163
164Q_COMPAT_EXPORT inline bool operator==(const Q3CString &s1, const Q3CString &s2)
165{ return qstrcmp(s1, s2) == 0; }
166
167Q_COMPAT_EXPORT inline bool operator==(const Q3CString &s1, const char *s2)
168{ return qstrcmp(s1, s2) == 0; }
169
170Q_COMPAT_EXPORT inline bool operator==(const char *s1, const Q3CString &s2)
171{ return qstrcmp(s1, s2) == 0; }
172
173Q_COMPAT_EXPORT inline bool operator!=(const Q3CString &s1, const Q3CString &s2)
174{ return qstrcmp(s1, s2) != 0; }
175
176Q_COMPAT_EXPORT inline bool operator!=(const Q3CString &s1, const char *s2)
177{ return qstrcmp(s1, s2) != 0; }
178
179Q_COMPAT_EXPORT inline bool operator!=(const char *s1, const Q3CString &s2)
180{ return qstrcmp(s1, s2) != 0; }
181
182Q_COMPAT_EXPORT inline bool operator<(const Q3CString &s1, const Q3CString& s2)
183{ return qstrcmp(s1, s2) < 0; }
184
185Q_COMPAT_EXPORT inline bool operator<(const Q3CString &s1, const char *s2)
186{ return qstrcmp(s1, s2) < 0; }
187
188Q_COMPAT_EXPORT inline bool operator<(const char *s1, const Q3CString &s2)
189{ return qstrcmp(s1, s2) < 0; }
190
191Q_COMPAT_EXPORT inline bool operator<=(const Q3CString &s1, const Q3CString &s2)
192{ return qstrcmp(s1, s2) <= 0; }
193
194Q_COMPAT_EXPORT inline bool operator<=(const Q3CString &s1, const char *s2)
195{ return qstrcmp(s1, s2) <= 0; }
196
197Q_COMPAT_EXPORT inline bool operator<=(const char *s1, const Q3CString &s2)
198{ return qstrcmp(s1, s2) <= 0; }
199
200Q_COMPAT_EXPORT inline bool operator>(const Q3CString &s1, const Q3CString &s2)
201{ return qstrcmp(s1, s2) > 0; }
202
203Q_COMPAT_EXPORT inline bool operator>(const Q3CString &s1, const char *s2)
204{ return qstrcmp(s1, s2) > 0; }
205
206Q_COMPAT_EXPORT inline bool operator>(const char *s1, const Q3CString &s2)
207{ return qstrcmp(s1, s2) > 0; }
208
209Q_COMPAT_EXPORT inline bool operator>=(const Q3CString &s1, const Q3CString& s2)
210{ return qstrcmp(s1, s2) >= 0; }
211
212Q_COMPAT_EXPORT inline bool operator>=(const Q3CString &s1, const char *s2)
213{ return qstrcmp(s1, s2) >= 0; }
214
215Q_COMPAT_EXPORT inline bool operator>=(const char *s1, const Q3CString &s2)
216{ return qstrcmp(s1, s2) >= 0; }
217
218Q_COMPAT_EXPORT inline const Q3CString operator+(const Q3CString &s1,
219 const Q3CString &s2)
220{
221 Q3CString tmp(s1);
222 tmp += s2;
223 return tmp;
224}
225Q_COMPAT_EXPORT inline const Q3CString operator+(const Q3CString &s1,
226 const QByteArray &s2)
227{
228 QByteArray tmp(s1);
229 tmp += s2;
230 return tmp;
231}
232Q_COMPAT_EXPORT inline const Q3CString operator+(const QByteArray &s1,
233 const Q3CString &s2)
234{
235 QByteArray tmp(s1);
236 tmp += s2;
237 return tmp;
238}
239
240Q_COMPAT_EXPORT inline const Q3CString operator+(const Q3CString &s1, const char *s2)
241{
242 Q3CString tmp(s1);
243 tmp += s2;
244 return tmp;
245}
246
247Q_COMPAT_EXPORT inline const Q3CString operator+(const char *s1, const Q3CString &s2)
248{
249 Q3CString tmp(s1);
250 tmp += s2;
251 return tmp;
252}
253
254Q_COMPAT_EXPORT inline const Q3CString operator+(const Q3CString &s1, char c2)
255{
256 Q3CString tmp(s1);
257 tmp += c2;
258 return tmp;
259}
260
261Q_COMPAT_EXPORT inline const Q3CString operator+(char c1, const Q3CString &s2)
262{
263 Q3CString tmp;
264 tmp += c1;
265 tmp += s2;
266 return tmp;
267}
268
269QT_END_NAMESPACE
270
271QT_END_HEADER
272
273#endif // Q3CSTRING_H
Note: See TracBrowser for help on using the repository browser.