1 /****************************************************************************
2 **
3 ** Copyright (C) 2015 The Qt Company Ltd.
4 ** Contact: http://www.qt.io/licensing/
5 **
6 ** This file is part of the Qt3Support module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and The Qt Company. For licensing terms
14 ** and conditions see http://www.qt.io/terms-conditions. For further
15 ** information use the contact form at http://www.qt.io/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 or version 3 as published by the Free
20 ** Software Foundation and appearing in the file LICENSE.LGPLv21 and
21 ** LICENSE.LGPLv3 included in the packaging of this file. Please review the
22 ** following information to ensure the GNU Lesser General Public License
23 ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
24 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25 **
26 ** As a special exception, The Qt Company gives you certain additional
27 ** rights. These rights are described in The Qt Company LGPL Exception
28 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29 **
30 ** GNU General Public License Usage
31 ** Alternatively, this file may be used under the terms of the GNU
32 ** General Public License version 3.0 as published by the Free Software
33 ** Foundation and appearing in the file LICENSE.GPL included in the
34 ** packaging of this file.  Please review the following information to
35 ** ensure the GNU General Public License version 3.0 requirements will be
36 ** met: http://www.gnu.org/copyleft/gpl.html.
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 #ifndef Q3CSTRING_H
43 #define Q3CSTRING_H
44 
45 #include <QtCore/qbytearray.h>
46 
47 QT_BEGIN_HEADER
48 
49 QT_BEGIN_NAMESPACE
50 
QT_MODULE(Qt3SupportLight)51 QT_MODULE(Qt3SupportLight)
52 
53 /*****************************************************************************
54   QCString class
55  *****************************************************************************/
56 
57 class QRegExp;
58 
59 class Q_COMPAT_EXPORT Q3CString : public QByteArray
60 {
61 public:
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
137 Q_COMPAT_EXPORT QDataStream &operator<<(QDataStream &d, const Q3CString &s);
138 Q_COMPAT_EXPORT QDataStream &operator>>(QDataStream &d, Q3CString &s);
139 #endif
140 
141 /*****************************************************************************
142   Q3CString inline functions
143  *****************************************************************************/
144 
setNum(short n)145 inline Q3CString &Q3CString::setNum(short n)
146 { return setNum(long(n)); }
147 
setNum(ushort n)148 inline Q3CString &Q3CString::setNum(ushort n)
149 { return setNum(ulong(n)); }
150 
setNum(int n)151 inline Q3CString &Q3CString::setNum(int n)
152 { return setNum(long(n)); }
153 
setNum(uint n)154 inline Q3CString &Q3CString::setNum(uint n)
155 { return setNum(ulong(n)); }
156 
setNum(float n,char f,int prec)157 inline 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 
164 Q_COMPAT_EXPORT_INLINE bool operator==(const Q3CString &s1, const Q3CString &s2)
165 { return qstrcmp(s1, s2) == 0; }
166 
167 Q_COMPAT_EXPORT_INLINE bool operator==(const Q3CString &s1, const char *s2)
168 { return qstrcmp(s1, s2) == 0; }
169 
170 Q_COMPAT_EXPORT_INLINE bool operator==(const char *s1, const Q3CString &s2)
171 { return qstrcmp(s1, s2) == 0; }
172 
173 Q_COMPAT_EXPORT_INLINE bool operator!=(const Q3CString &s1, const Q3CString &s2)
174 { return qstrcmp(s1, s2) != 0; }
175 
176 Q_COMPAT_EXPORT_INLINE bool operator!=(const Q3CString &s1, const char *s2)
177 { return qstrcmp(s1, s2) != 0; }
178 
179 Q_COMPAT_EXPORT_INLINE bool operator!=(const char *s1, const Q3CString &s2)
180 { return qstrcmp(s1, s2) != 0; }
181 
182 Q_COMPAT_EXPORT_INLINE bool operator<(const Q3CString &s1, const Q3CString& s2)
183 { return qstrcmp(s1, s2) < 0; }
184 
185 Q_COMPAT_EXPORT_INLINE bool operator<(const Q3CString &s1, const char *s2)
186 { return qstrcmp(s1, s2) < 0; }
187 
188 Q_COMPAT_EXPORT_INLINE bool operator<(const char *s1, const Q3CString &s2)
189 { return qstrcmp(s1, s2) < 0; }
190 
191 Q_COMPAT_EXPORT_INLINE bool operator<=(const Q3CString &s1, const Q3CString &s2)
192 { return qstrcmp(s1, s2) <= 0; }
193 
194 Q_COMPAT_EXPORT_INLINE bool operator<=(const Q3CString &s1, const char *s2)
195 { return qstrcmp(s1, s2) <= 0; }
196 
197 Q_COMPAT_EXPORT_INLINE bool operator<=(const char *s1, const Q3CString &s2)
198 { return qstrcmp(s1, s2) <= 0; }
199 
200 Q_COMPAT_EXPORT_INLINE bool operator>(const Q3CString &s1, const Q3CString &s2)
201 { return qstrcmp(s1, s2) > 0; }
202 
203 Q_COMPAT_EXPORT_INLINE bool operator>(const Q3CString &s1, const char *s2)
204 { return qstrcmp(s1, s2) > 0; }
205 
206 Q_COMPAT_EXPORT_INLINE bool operator>(const char *s1, const Q3CString &s2)
207 { return qstrcmp(s1, s2) > 0; }
208 
209 Q_COMPAT_EXPORT_INLINE bool operator>=(const Q3CString &s1, const Q3CString& s2)
210 { return qstrcmp(s1, s2) >= 0; }
211 
212 Q_COMPAT_EXPORT_INLINE bool operator>=(const Q3CString &s1, const char *s2)
213 { return qstrcmp(s1, s2) >= 0; }
214 
215 Q_COMPAT_EXPORT_INLINE bool operator>=(const char *s1, const Q3CString &s2)
216 { return qstrcmp(s1, s2) >= 0; }
217 
218 Q_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 }
225 Q_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 }
232 Q_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 
240 Q_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 
247 Q_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 
254 Q_COMPAT_EXPORT_INLINE const Q3CString operator+(const Q3CString &s1, char c2)
255 {
256     Q3CString tmp(s1);
257     tmp += c2;
258     return tmp;
259 }
260 
261 Q_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 
269 QT_END_NAMESPACE
270 
271 QT_END_HEADER
272 
273 #endif // Q3CSTRING_H
274