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 QtCore 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 QSTRING_H
|
---|
43 | #define QSTRING_H
|
---|
44 |
|
---|
45 | #include <QtCore/qchar.h>
|
---|
46 | #include <QtCore/qbytearray.h>
|
---|
47 | #include <QtCore/qatomic.h>
|
---|
48 | #include <QtCore/qnamespace.h>
|
---|
49 | #ifdef QT_INCLUDE_COMPAT
|
---|
50 | #include <Qt3Support/q3cstring.h>
|
---|
51 | #endif
|
---|
52 |
|
---|
53 | #ifndef QT_NO_STL
|
---|
54 | # if defined (Q_CC_MSVC_NET) && _MSC_VER < 1310 // Avoids nasty warning for xlocale, line 450
|
---|
55 | # pragma warning (push)
|
---|
56 | # pragma warning (disable : 4189)
|
---|
57 | # include <string>
|
---|
58 | # pragma warning (pop)
|
---|
59 | # else
|
---|
60 | # include <string>
|
---|
61 | # endif
|
---|
62 |
|
---|
63 | # ifndef QT_NO_STL_WCHAR
|
---|
64 | // workaround for some headers not typedef'ing std::wstring
|
---|
65 | typedef std::basic_string<wchar_t> QStdWString;
|
---|
66 | # endif // QT_NO_STL_WCHAR
|
---|
67 |
|
---|
68 | #endif // QT_NO_STL
|
---|
69 |
|
---|
70 | #include <stdarg.h>
|
---|
71 |
|
---|
72 | #ifdef truncate
|
---|
73 | #error qstring.h must be included before any header file that defines truncate
|
---|
74 | #endif
|
---|
75 |
|
---|
76 | QT_BEGIN_HEADER
|
---|
77 |
|
---|
78 | QT_BEGIN_NAMESPACE
|
---|
79 |
|
---|
80 | QT_MODULE(Core)
|
---|
81 |
|
---|
82 | class QCharRef;
|
---|
83 | class QRegExp;
|
---|
84 | class QStringList;
|
---|
85 | class QTextCodec;
|
---|
86 | class QLatin1String;
|
---|
87 | class QStringRef;
|
---|
88 | template <typename T> class QVector;
|
---|
89 |
|
---|
90 | class Q_CORE_EXPORT QString
|
---|
91 | {
|
---|
92 | public:
|
---|
93 | inline QString();
|
---|
94 | QString(const QChar *unicode, int size);
|
---|
95 | QString(QChar c);
|
---|
96 | QString(int size, QChar c);
|
---|
97 | inline QString(const QLatin1String &latin1);
|
---|
98 | inline QString(const QString &);
|
---|
99 | inline ~QString();
|
---|
100 | QString &operator=(QChar c);
|
---|
101 | QString &operator=(const QString &);
|
---|
102 | inline QString &operator=(const QLatin1String &);
|
---|
103 |
|
---|
104 | inline int size() const { return d->size; }
|
---|
105 | inline int count() const { return d->size; }
|
---|
106 | inline int length() const;
|
---|
107 | inline bool isEmpty() const;
|
---|
108 | void resize(int size);
|
---|
109 |
|
---|
110 | QString &fill(QChar c, int size = -1);
|
---|
111 | void truncate(int pos);
|
---|
112 | void chop(int n);
|
---|
113 |
|
---|
114 | int capacity() const;
|
---|
115 | inline void reserve(int size);
|
---|
116 | inline void squeeze() { if (d->size < d->alloc) realloc(); d->capacity = 0;}
|
---|
117 |
|
---|
118 | inline const QChar *unicode() const;
|
---|
119 | inline QChar *data();
|
---|
120 | inline const QChar *data() const;
|
---|
121 | inline const QChar *constData() const;
|
---|
122 |
|
---|
123 | inline void detach();
|
---|
124 | inline bool isDetached() const;
|
---|
125 | void clear();
|
---|
126 |
|
---|
127 | inline const QChar at(int i) const;
|
---|
128 | const QChar operator[](int i) const;
|
---|
129 | QCharRef operator[](int i);
|
---|
130 | const QChar operator[](uint i) const;
|
---|
131 | QCharRef operator[](uint i);
|
---|
132 |
|
---|
133 | QString arg(qlonglong a, int fieldwidth=0, int base=10,
|
---|
134 | const QChar &fillChar = QLatin1Char(' ')) const Q_REQUIRED_RESULT;
|
---|
135 | QString arg(qulonglong a, int fieldwidth=0, int base=10,
|
---|
136 | const QChar &fillChar = QLatin1Char(' ')) const Q_REQUIRED_RESULT;
|
---|
137 | QString arg(long a, int fieldwidth=0, int base=10,
|
---|
138 | const QChar &fillChar = QLatin1Char(' ')) const Q_REQUIRED_RESULT;
|
---|
139 | QString arg(ulong a, int fieldwidth=0, int base=10,
|
---|
140 | const QChar &fillChar = QLatin1Char(' ')) const Q_REQUIRED_RESULT;
|
---|
141 | QString arg(int a, int fieldWidth = 0, int base = 10,
|
---|
142 | const QChar &fillChar = QLatin1Char(' ')) const Q_REQUIRED_RESULT;
|
---|
143 | QString arg(uint a, int fieldWidth = 0, int base = 10,
|
---|
144 | const QChar &fillChar = QLatin1Char(' ')) const Q_REQUIRED_RESULT;
|
---|
145 | QString arg(short a, int fieldWidth = 0, int base = 10,
|
---|
146 | const QChar &fillChar = QLatin1Char(' ')) const Q_REQUIRED_RESULT;
|
---|
147 | QString arg(ushort a, int fieldWidth = 0, int base = 10,
|
---|
148 | const QChar &fillChar = QLatin1Char(' ')) const Q_REQUIRED_RESULT;
|
---|
149 | QString arg(double a, int fieldWidth = 0, char fmt = 'g', int prec = -1,
|
---|
150 | const QChar &fillChar = QLatin1Char(' ')) const Q_REQUIRED_RESULT;
|
---|
151 | QString arg(char a, int fieldWidth = 0,
|
---|
152 | const QChar &fillChar = QLatin1Char(' ')) const Q_REQUIRED_RESULT;
|
---|
153 | QString arg(QChar a, int fieldWidth = 0,
|
---|
154 | const QChar &fillChar = QLatin1Char(' ')) const Q_REQUIRED_RESULT;
|
---|
155 | QString arg(const QString &a, int fieldWidth = 0,
|
---|
156 | const QChar &fillChar = QLatin1Char(' ')) const Q_REQUIRED_RESULT;
|
---|
157 | QString arg(const QString &a1, const QString &a2) const Q_REQUIRED_RESULT;
|
---|
158 | QString arg(const QString &a1, const QString &a2, const QString &a3) const Q_REQUIRED_RESULT;
|
---|
159 | QString arg(const QString &a1, const QString &a2, const QString &a3,
|
---|
160 | const QString &a4) const Q_REQUIRED_RESULT;
|
---|
161 | QString arg(const QString &a1, const QString &a2, const QString &a3,
|
---|
162 | const QString &a4, const QString &a5) const Q_REQUIRED_RESULT;
|
---|
163 | QString arg(const QString &a1, const QString &a2, const QString &a3,
|
---|
164 | const QString &a4, const QString &a5, const QString &a6) const Q_REQUIRED_RESULT;
|
---|
165 | QString arg(const QString &a1, const QString &a2, const QString &a3,
|
---|
166 | const QString &a4, const QString &a5, const QString &a6,
|
---|
167 | const QString &a7) const Q_REQUIRED_RESULT;
|
---|
168 | QString arg(const QString &a1, const QString &a2, const QString &a3,
|
---|
169 | const QString &a4, const QString &a5, const QString &a6,
|
---|
170 | const QString &a7, const QString &a8) const Q_REQUIRED_RESULT;
|
---|
171 | QString arg(const QString &a1, const QString &a2, const QString &a3,
|
---|
172 | const QString &a4, const QString &a5, const QString &a6,
|
---|
173 | const QString &a7, const QString &a8, const QString &a9) const Q_REQUIRED_RESULT;
|
---|
174 |
|
---|
175 | QString &vsprintf(const char *format, va_list ap)
|
---|
176 | #if defined(Q_CC_GNU) && !defined(__INSURE__)
|
---|
177 | __attribute__ ((format (printf, 2, 0)))
|
---|
178 | #endif
|
---|
179 | ;
|
---|
180 | QString &sprintf(const char *format, ...)
|
---|
181 | #if defined(Q_CC_GNU) && !defined(__INSURE__)
|
---|
182 | __attribute__ ((format (printf, 2, 3)))
|
---|
183 | #endif
|
---|
184 | ;
|
---|
185 |
|
---|
186 | int indexOf(QChar c, int from = 0, Qt::CaseSensitivity cs = Qt::CaseSensitive) const;
|
---|
187 | int indexOf(const QString &s, int from = 0, Qt::CaseSensitivity cs = Qt::CaseSensitive) const;
|
---|
188 | int indexOf(const QLatin1String &s, int from = 0, Qt::CaseSensitivity cs = Qt::CaseSensitive) const;
|
---|
189 | int lastIndexOf(QChar c, int from = -1, Qt::CaseSensitivity cs = Qt::CaseSensitive) const;
|
---|
190 | int lastIndexOf(const QString &s, int from = -1, Qt::CaseSensitivity cs = Qt::CaseSensitive) const;
|
---|
191 | int lastIndexOf(const QLatin1String &s, int from = -1, Qt::CaseSensitivity cs = Qt::CaseSensitive) const;
|
---|
192 |
|
---|
193 | inline QBool contains(QChar c, Qt::CaseSensitivity cs = Qt::CaseSensitive) const;
|
---|
194 | inline QBool contains(const QString &s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const;
|
---|
195 | int count(QChar c, Qt::CaseSensitivity cs = Qt::CaseSensitive) const;
|
---|
196 | int count(const QString &s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const;
|
---|
197 |
|
---|
198 | #ifndef QT_NO_REGEXP
|
---|
199 | int indexOf(const QRegExp &, int from = 0) const;
|
---|
200 | int lastIndexOf(const QRegExp &, int from = -1) const;
|
---|
201 | inline QBool contains(const QRegExp &rx) const { return QBool(indexOf(rx) != -1); }
|
---|
202 | int count(const QRegExp &) const;
|
---|
203 |
|
---|
204 | int indexOf(QRegExp &, int from = 0) const;
|
---|
205 | int lastIndexOf(QRegExp &, int from = -1) const;
|
---|
206 | inline QBool contains(QRegExp &rx) const { return QBool(indexOf(rx) != -1); }
|
---|
207 | #endif
|
---|
208 |
|
---|
209 | enum SectionFlag {
|
---|
210 | SectionDefault = 0x00,
|
---|
211 | SectionSkipEmpty = 0x01,
|
---|
212 | SectionIncludeLeadingSep = 0x02,
|
---|
213 | SectionIncludeTrailingSep = 0x04,
|
---|
214 | SectionCaseInsensitiveSeps = 0x08
|
---|
215 | };
|
---|
216 | Q_DECLARE_FLAGS(SectionFlags, SectionFlag)
|
---|
217 |
|
---|
218 | QString section(QChar sep, int start, int end = -1, SectionFlags flags = SectionDefault) const;
|
---|
219 | QString section(const QString &in_sep, int start, int end = -1, SectionFlags flags = SectionDefault) const;
|
---|
220 | #ifndef QT_NO_REGEXP
|
---|
221 | QString section(const QRegExp ®, int start, int end = -1, SectionFlags flags = SectionDefault) const;
|
---|
222 | #endif
|
---|
223 |
|
---|
224 | QString left(int n) const Q_REQUIRED_RESULT;
|
---|
225 | QString right(int n) const Q_REQUIRED_RESULT;
|
---|
226 | QString mid(int position, int n = -1) const Q_REQUIRED_RESULT;
|
---|
227 | QStringRef leftRef(int n) const Q_REQUIRED_RESULT;
|
---|
228 | QStringRef rightRef(int n) const Q_REQUIRED_RESULT;
|
---|
229 | QStringRef midRef(int position, int n = -1) const Q_REQUIRED_RESULT;
|
---|
230 |
|
---|
231 | bool startsWith(const QString &s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const;
|
---|
232 | bool startsWith(const QLatin1String &s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const;
|
---|
233 | bool startsWith(const QChar &c, Qt::CaseSensitivity cs = Qt::CaseSensitive) const;
|
---|
234 | bool endsWith(const QString &s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const;
|
---|
235 | bool endsWith(const QLatin1String &s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const;
|
---|
236 | bool endsWith(const QChar &c, Qt::CaseSensitivity cs = Qt::CaseSensitive) const;
|
---|
237 |
|
---|
238 | QString leftJustified(int width, QChar fill = QLatin1Char(' '), bool trunc = false) const Q_REQUIRED_RESULT;
|
---|
239 | QString rightJustified(int width, QChar fill = QLatin1Char(' '), bool trunc = false) const Q_REQUIRED_RESULT;
|
---|
240 |
|
---|
241 | QString toLower() const Q_REQUIRED_RESULT;
|
---|
242 | QString toUpper() const Q_REQUIRED_RESULT;
|
---|
243 | QString toCaseFolded() const Q_REQUIRED_RESULT;
|
---|
244 |
|
---|
245 | QString trimmed() const Q_REQUIRED_RESULT;
|
---|
246 | QString simplified() const Q_REQUIRED_RESULT;
|
---|
247 |
|
---|
248 | QString &insert(int i, QChar c);
|
---|
249 | QString &insert(int i, const QChar *uc, int len);
|
---|
250 | inline QString &insert(int i, const QString &s) { return insert(i, s.constData(), s.length()); }
|
---|
251 | QString &insert(int i, const QLatin1String &s);
|
---|
252 | QString &append(QChar c);
|
---|
253 | QString &append(const QString &s);
|
---|
254 | QString &append(const QStringRef &s);
|
---|
255 | QString &append(const QLatin1String &s);
|
---|
256 | inline QString &prepend(QChar c) { return insert(0, c); }
|
---|
257 | inline QString &prepend(const QString &s) { return insert(0, s); }
|
---|
258 | inline QString &prepend(const QLatin1String &s) { return insert(0, s); }
|
---|
259 |
|
---|
260 | inline QString &operator+=(QChar c) {
|
---|
261 | if (d->ref != 1 || d->size + 1 > d->alloc)
|
---|
262 | realloc(grow(d->size + 1));
|
---|
263 | d->data[d->size++] = c.unicode();
|
---|
264 | d->data[d->size] = '\0';
|
---|
265 | return *this;
|
---|
266 | }
|
---|
267 |
|
---|
268 | inline QString &operator+=(QChar::SpecialCharacter c) { return append(QChar(c)); }
|
---|
269 | inline QString &operator+=(const QString &s) { return append(s); }
|
---|
270 | inline QString &operator+=(const QStringRef &s) { return append(s); }
|
---|
271 | inline QString &operator+=(const QLatin1String &s) { return append(s); }
|
---|
272 |
|
---|
273 | QString &remove(int i, int len);
|
---|
274 | QString &remove(QChar c, Qt::CaseSensitivity cs = Qt::CaseSensitive);
|
---|
275 | QString &remove(const QString &s, Qt::CaseSensitivity cs = Qt::CaseSensitive);
|
---|
276 | QString &replace(int i, int len, QChar after);
|
---|
277 | QString &replace(int i, int len, const QChar *s, int slen);
|
---|
278 | QString &replace(int i, int len, const QString &after);
|
---|
279 | QString &replace(QChar before, QChar after, Qt::CaseSensitivity cs = Qt::CaseSensitive);
|
---|
280 | QString &replace(const QChar *before, int blen, const QChar *after, int alen, Qt::CaseSensitivity cs = Qt::CaseSensitive);
|
---|
281 | QString &replace(const QLatin1String &before, const QLatin1String &after, Qt::CaseSensitivity cs = Qt::CaseSensitive);
|
---|
282 | QString &replace(const QLatin1String &before, const QString &after, Qt::CaseSensitivity cs = Qt::CaseSensitive);
|
---|
283 | QString &replace(const QString &before, const QLatin1String &after, Qt::CaseSensitivity cs = Qt::CaseSensitive);
|
---|
284 | QString &replace(const QString &before, const QString &after,
|
---|
285 | Qt::CaseSensitivity cs = Qt::CaseSensitive);
|
---|
286 | QString &replace(QChar c, const QString &after, Qt::CaseSensitivity cs = Qt::CaseSensitive);
|
---|
287 | QString &replace(QChar c, const QLatin1String &after, Qt::CaseSensitivity cs = Qt::CaseSensitive);
|
---|
288 | #ifndef QT_NO_REGEXP
|
---|
289 | QString &replace(const QRegExp &rx, const QString &after);
|
---|
290 | inline QString &remove(const QRegExp &rx)
|
---|
291 | { return replace(rx, QString()); }
|
---|
292 | #endif
|
---|
293 |
|
---|
294 | enum SplitBehavior { KeepEmptyParts, SkipEmptyParts };
|
---|
295 |
|
---|
296 | QStringList split(const QString &sep, SplitBehavior behavior = KeepEmptyParts,
|
---|
297 | Qt::CaseSensitivity cs = Qt::CaseSensitive) const Q_REQUIRED_RESULT;
|
---|
298 | QStringList split(const QChar &sep, SplitBehavior behavior = KeepEmptyParts,
|
---|
299 | Qt::CaseSensitivity cs = Qt::CaseSensitive) const Q_REQUIRED_RESULT;
|
---|
300 | #ifndef QT_NO_REGEXP
|
---|
301 | QStringList split(const QRegExp &sep, SplitBehavior behavior = KeepEmptyParts) const Q_REQUIRED_RESULT;
|
---|
302 | #endif
|
---|
303 |
|
---|
304 | enum NormalizationForm {
|
---|
305 | NormalizationForm_D,
|
---|
306 | NormalizationForm_C,
|
---|
307 | NormalizationForm_KD,
|
---|
308 | NormalizationForm_KC
|
---|
309 | };
|
---|
310 | QString normalized(NormalizationForm mode) const Q_REQUIRED_RESULT;
|
---|
311 | QString normalized(NormalizationForm mode, QChar::UnicodeVersion version) const Q_REQUIRED_RESULT;
|
---|
312 |
|
---|
313 | QString repeated(int times) const;
|
---|
314 |
|
---|
315 | const ushort *utf16() const;
|
---|
316 |
|
---|
317 | QByteArray toAscii() const Q_REQUIRED_RESULT;
|
---|
318 | QByteArray toLatin1() const Q_REQUIRED_RESULT;
|
---|
319 | QByteArray toUtf8() const Q_REQUIRED_RESULT;
|
---|
320 | QByteArray toLocal8Bit() const Q_REQUIRED_RESULT;
|
---|
321 | QVector<uint> toUcs4() const Q_REQUIRED_RESULT;
|
---|
322 |
|
---|
323 | static QString fromAscii(const char *, int size = -1);
|
---|
324 | static QString fromLatin1(const char *, int size = -1);
|
---|
325 | static QString fromUtf8(const char *, int size = -1);
|
---|
326 | static QString fromLocal8Bit(const char *, int size = -1);
|
---|
327 | static QString fromUtf16(const ushort *, int size = -1);
|
---|
328 | static QString fromUcs4(const uint *, int size = -1);
|
---|
329 | static QString fromRawData(const QChar *, int size);
|
---|
330 |
|
---|
331 | int toWCharArray(wchar_t *array) const;
|
---|
332 | static QString fromWCharArray(const wchar_t *, int size = -1);
|
---|
333 |
|
---|
334 | QString &setUnicode(const QChar *unicode, int size);
|
---|
335 | inline QString &setUtf16(const ushort *utf16, int size);
|
---|
336 |
|
---|
337 | // ### Qt 5: merge these two functions
|
---|
338 | int compare(const QString &s) const;
|
---|
339 | int compare(const QString &s, Qt::CaseSensitivity cs) const;
|
---|
340 |
|
---|
341 | int compare(const QLatin1String &other, Qt::CaseSensitivity cs = Qt::CaseSensitive) const;
|
---|
342 |
|
---|
343 | // ### Qt 5: merge these two functions
|
---|
344 | static inline int compare(const QString &s1, const QString &s2)
|
---|
345 | { return s1.compare(s2); }
|
---|
346 | static inline int compare(const QString &s1, const QString &s2, Qt::CaseSensitivity cs)
|
---|
347 | { return s1.compare(s2, cs); }
|
---|
348 |
|
---|
349 | static inline int compare(const QString& s1, const QLatin1String &s2,
|
---|
350 | Qt::CaseSensitivity cs = Qt::CaseSensitive)
|
---|
351 | { return s1.compare(s2, cs); }
|
---|
352 | static inline int compare(const QLatin1String& s1, const QString &s2,
|
---|
353 | Qt::CaseSensitivity cs = Qt::CaseSensitive)
|
---|
354 | { return -s2.compare(s1, cs); }
|
---|
355 |
|
---|
356 | int compare(const QStringRef &s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const;
|
---|
357 | static int compare(const QString &s1, const QStringRef &s2,
|
---|
358 | Qt::CaseSensitivity = Qt::CaseSensitive);
|
---|
359 |
|
---|
360 | int localeAwareCompare(const QString& s) const;
|
---|
361 | static int localeAwareCompare(const QString& s1, const QString& s2)
|
---|
362 | { return s1.localeAwareCompare(s2); }
|
---|
363 |
|
---|
364 | int localeAwareCompare(const QStringRef &s) const;
|
---|
365 | static int localeAwareCompare(const QString& s1, const QStringRef& s2);
|
---|
366 |
|
---|
367 | short toShort(bool *ok=0, int base=10) const;
|
---|
368 | ushort toUShort(bool *ok=0, int base=10) const;
|
---|
369 | int toInt(bool *ok=0, int base=10) const;
|
---|
370 | uint toUInt(bool *ok=0, int base=10) const;
|
---|
371 | long toLong(bool *ok=0, int base=10) const;
|
---|
372 | ulong toULong(bool *ok=0, int base=10) const;
|
---|
373 | qlonglong toLongLong(bool *ok=0, int base=10) const;
|
---|
374 | qulonglong toULongLong(bool *ok=0, int base=10) const;
|
---|
375 | float toFloat(bool *ok=0) const;
|
---|
376 | double toDouble(bool *ok=0) const;
|
---|
377 |
|
---|
378 | QString &setNum(short, int base=10);
|
---|
379 | QString &setNum(ushort, int base=10);
|
---|
380 | QString &setNum(int, int base=10);
|
---|
381 | QString &setNum(uint, int base=10);
|
---|
382 | QString &setNum(long, int base=10);
|
---|
383 | QString &setNum(ulong, int base=10);
|
---|
384 | QString &setNum(qlonglong, int base=10);
|
---|
385 | QString &setNum(qulonglong, int base=10);
|
---|
386 | QString &setNum(float, char f='g', int prec=6);
|
---|
387 | QString &setNum(double, char f='g', int prec=6);
|
---|
388 |
|
---|
389 | static QString number(int, int base=10);
|
---|
390 | static QString number(uint, int base=10);
|
---|
391 | static QString number(long, int base=10);
|
---|
392 | static QString number(ulong, int base=10);
|
---|
393 | static QString number(qlonglong, int base=10);
|
---|
394 | static QString number(qulonglong, int base=10);
|
---|
395 | static QString number(double, char f='g', int prec=6);
|
---|
396 |
|
---|
397 | bool operator==(const QString &s) const;
|
---|
398 | bool operator<(const QString &s) const;
|
---|
399 | inline bool operator>(const QString &s) const { return s < *this; }
|
---|
400 | inline bool operator!=(const QString &s) const { return !operator==(s); }
|
---|
401 | inline bool operator<=(const QString &s) const { return !operator>(s); }
|
---|
402 | inline bool operator>=(const QString &s) const { return !operator<(s); }
|
---|
403 |
|
---|
404 | bool operator==(const QLatin1String &s) const;
|
---|
405 | bool operator<(const QLatin1String &s) const;
|
---|
406 | bool operator>(const QLatin1String &s) const;
|
---|
407 | inline bool operator!=(const QLatin1String &s) const { return !operator==(s); }
|
---|
408 | inline bool operator<=(const QLatin1String &s) const { return !operator>(s); }
|
---|
409 | inline bool operator>=(const QLatin1String &s) const { return !operator<(s); }
|
---|
410 |
|
---|
411 | // ASCII compatibility
|
---|
412 | #ifndef QT_NO_CAST_FROM_ASCII
|
---|
413 | inline QT_ASCII_CAST_WARN_CONSTRUCTOR QString(const char *ch) : d(fromAscii_helper(ch))
|
---|
414 | {}
|
---|
415 | inline QT_ASCII_CAST_WARN_CONSTRUCTOR QString(const QByteArray &a)
|
---|
416 | : d(fromAscii_helper(a.constData(), qstrnlen(a.constData(), a.size())))
|
---|
417 | {}
|
---|
418 | inline QT_ASCII_CAST_WARN QString &operator=(const char *ch)
|
---|
419 | { return (*this = fromAscii(ch)); }
|
---|
420 | inline QT_ASCII_CAST_WARN QString &operator=(const QByteArray &a)
|
---|
421 | { return (*this = fromAscii(a.constData(), qstrnlen(a.constData(), a.size()))); }
|
---|
422 | inline QT_ASCII_CAST_WARN QString &operator=(char c)
|
---|
423 | { return (*this = QChar::fromAscii(c)); }
|
---|
424 |
|
---|
425 | // these are needed, so it compiles with STL support enabled
|
---|
426 | inline QT_ASCII_CAST_WARN QString &prepend(const char *s)
|
---|
427 | { return prepend(QString::fromAscii(s)); }
|
---|
428 | inline QT_ASCII_CAST_WARN QString &prepend(const QByteArray &s)
|
---|
429 | { return prepend(QString::fromAscii(s.constData(), qstrnlen(s.constData(), s.size()))); }
|
---|
430 | inline QT_ASCII_CAST_WARN QString &append(const char *s)
|
---|
431 | { return append(QString::fromAscii(s)); }
|
---|
432 | inline QT_ASCII_CAST_WARN QString &append(const QByteArray &s)
|
---|
433 | { return append(QString::fromAscii(s.constData(), qstrnlen(s.constData(), s.size()))); }
|
---|
434 | inline QT_ASCII_CAST_WARN QString &operator+=(const char *s)
|
---|
435 | { return append(QString::fromAscii(s)); }
|
---|
436 | inline QT_ASCII_CAST_WARN QString &operator+=(const QByteArray &s)
|
---|
437 | { return append(QString::fromAscii(s.constData(), qstrnlen(s.constData(), s.size()))); }
|
---|
438 | inline QT_ASCII_CAST_WARN QString &operator+=(char c)
|
---|
439 | { return append(QChar::fromAscii(c)); }
|
---|
440 |
|
---|
441 | inline QT_ASCII_CAST_WARN bool operator==(const char *s) const;
|
---|
442 | inline QT_ASCII_CAST_WARN bool operator!=(const char *s) const;
|
---|
443 | inline QT_ASCII_CAST_WARN bool operator<(const char *s) const;
|
---|
444 | inline QT_ASCII_CAST_WARN bool operator<=(const char *s2) const;
|
---|
445 | inline QT_ASCII_CAST_WARN bool operator>(const char *s2) const;
|
---|
446 | inline QT_ASCII_CAST_WARN bool operator>=(const char *s2) const;
|
---|
447 |
|
---|
448 | inline QT_ASCII_CAST_WARN bool operator==(const QByteArray &s) const;
|
---|
449 | inline QT_ASCII_CAST_WARN bool operator!=(const QByteArray &s) const;
|
---|
450 | inline QT_ASCII_CAST_WARN bool operator<(const QByteArray &s) const
|
---|
451 | { return *this < QString::fromAscii(s.constData(), s.size()); }
|
---|
452 | inline QT_ASCII_CAST_WARN bool operator>(const QByteArray &s) const
|
---|
453 | { return *this > QString::fromAscii(s.constData(), s.size()); }
|
---|
454 | inline QT_ASCII_CAST_WARN bool operator<=(const QByteArray &s) const
|
---|
455 | { return *this <= QString::fromAscii(s.constData(), s.size()); }
|
---|
456 | inline QT_ASCII_CAST_WARN bool operator>=(const QByteArray &s) const
|
---|
457 | { return *this >= QString::fromAscii(s.constData(), s.size()); }
|
---|
458 | #endif
|
---|
459 |
|
---|
460 | typedef QChar *iterator;
|
---|
461 | typedef const QChar *const_iterator;
|
---|
462 | typedef iterator Iterator;
|
---|
463 | typedef const_iterator ConstIterator;
|
---|
464 | iterator begin();
|
---|
465 | const_iterator begin() const;
|
---|
466 | const_iterator constBegin() const;
|
---|
467 | iterator end();
|
---|
468 | const_iterator end() const;
|
---|
469 | const_iterator constEnd() const;
|
---|
470 |
|
---|
471 | // STL compatibility
|
---|
472 | inline void push_back(QChar c) { append(c); }
|
---|
473 | inline void push_back(const QString &s) { append(s); }
|
---|
474 | inline void push_front(QChar c) { prepend(c); }
|
---|
475 | inline void push_front(const QString &s) { prepend(s); }
|
---|
476 |
|
---|
477 | #ifndef QT_NO_STL
|
---|
478 | static inline QString fromStdString(const std::string &s);
|
---|
479 | inline std::string toStdString() const;
|
---|
480 | # ifdef qdoc
|
---|
481 | static inline QString fromStdWString(const std::wstring &s);
|
---|
482 | inline std::wstring toStdWString() const;
|
---|
483 | # else
|
---|
484 | # ifndef QT_NO_STL_WCHAR
|
---|
485 | static inline QString fromStdWString(const QStdWString &s);
|
---|
486 | inline QStdWString toStdWString() const;
|
---|
487 | # endif // QT_NO_STL_WCHAR
|
---|
488 | # endif // qdoc
|
---|
489 | #endif
|
---|
490 |
|
---|
491 | // compatibility
|
---|
492 | struct Null { };
|
---|
493 | static const Null null;
|
---|
494 | inline QString(const Null &): d(&shared_null) { d->ref.ref(); }
|
---|
495 | inline QString &operator=(const Null &) { *this = QString(); return *this; }
|
---|
496 | inline bool isNull() const { return d == &shared_null; }
|
---|
497 |
|
---|
498 | #ifdef QT3_SUPPORT
|
---|
499 | inline QT3_SUPPORT const char *ascii() const { return ascii_helper(); }
|
---|
500 | inline QT3_SUPPORT const char *latin1() const { return latin1_helper(); }
|
---|
501 | inline QT3_SUPPORT QByteArray utf8() const { return toUtf8(); }
|
---|
502 | inline QT3_SUPPORT QByteArray local8Bit() const{ return toLocal8Bit(); }
|
---|
503 | inline QT3_SUPPORT void setLength(int nl) { resize(nl); }
|
---|
504 | inline QT3_SUPPORT QString copy() const { return *this; }
|
---|
505 | inline QT3_SUPPORT QString &remove(QChar c, bool cs)
|
---|
506 | { return remove(c, cs?Qt::CaseSensitive:Qt::CaseInsensitive); }
|
---|
507 | inline QT3_SUPPORT QString &remove(const QString &s, bool cs)
|
---|
508 | { return remove(s, cs?Qt::CaseSensitive:Qt::CaseInsensitive); }
|
---|
509 | inline QT3_SUPPORT QString &replace(QChar c, const QString &after, bool cs)
|
---|
510 | { return replace(c, after, cs?Qt::CaseSensitive:Qt::CaseInsensitive); }
|
---|
511 | inline QT3_SUPPORT QString &replace(const QString &before, const QString &after, bool cs)
|
---|
512 | { return replace(before, after, cs?Qt::CaseSensitive:Qt::CaseInsensitive); }
|
---|
513 | #ifndef QT_NO_CAST_FROM_ASCII
|
---|
514 | inline QT3_SUPPORT QString &replace(char c, const QString &after, bool cs)
|
---|
515 | { return replace(QChar::fromAscii(c), after, cs ? Qt::CaseSensitive : Qt::CaseInsensitive); }
|
---|
516 | // strange overload, required to avoid GCC 3.3 error
|
---|
517 | inline QT3_SUPPORT QString &replace(char c, const QString &after, Qt::CaseSensitivity cs)
|
---|
518 | { return replace(QChar::fromAscii(c), after, cs ? Qt::CaseSensitive : Qt::CaseInsensitive); }
|
---|
519 | #endif
|
---|
520 | inline QT3_SUPPORT int find(QChar c, int i = 0, bool cs = true) const
|
---|
521 | { return indexOf(c, i, cs?Qt::CaseSensitive:Qt::CaseInsensitive); }
|
---|
522 | inline QT3_SUPPORT int find(const QString &s, int i = 0, bool cs = true) const
|
---|
523 | { return indexOf(s, i, cs?Qt::CaseSensitive:Qt::CaseInsensitive); }
|
---|
524 | inline QT3_SUPPORT int findRev(QChar c, int i = -1, bool cs = true) const
|
---|
525 | { return lastIndexOf(c, i, cs?Qt::CaseSensitive:Qt::CaseInsensitive); }
|
---|
526 | inline QT3_SUPPORT int findRev(const QString &s, int i = -1, bool cs = true) const
|
---|
527 | { return lastIndexOf(s, i, cs?Qt::CaseSensitive:Qt::CaseInsensitive); }
|
---|
528 | #ifndef QT_NO_REGEXP
|
---|
529 | inline QT3_SUPPORT int find(const QRegExp &rx, int i=0) const
|
---|
530 | { return indexOf(rx, i); }
|
---|
531 | inline QT3_SUPPORT int findRev(const QRegExp &rx, int i=-1) const
|
---|
532 | { return lastIndexOf(rx, i); }
|
---|
533 | inline QT3_SUPPORT int find(QRegExp &rx, int i=0) const
|
---|
534 | { return indexOf(rx, i); }
|
---|
535 | inline QT3_SUPPORT int findRev(QRegExp &rx, int i=-1) const
|
---|
536 | { return lastIndexOf(rx, i); }
|
---|
537 | #endif
|
---|
538 | inline QT3_SUPPORT QBool contains(QChar c, bool cs) const
|
---|
539 | { return contains(c, cs?Qt::CaseSensitive:Qt::CaseInsensitive); }
|
---|
540 | inline QT3_SUPPORT QBool contains(const QString &s, bool cs) const
|
---|
541 | { return contains(s, cs?Qt::CaseSensitive:Qt::CaseInsensitive); }
|
---|
542 | inline QT3_SUPPORT bool startsWith(const QString &s, bool cs) const
|
---|
543 | { return startsWith(s, cs?Qt::CaseSensitive:Qt::CaseInsensitive); }
|
---|
544 | inline QT3_SUPPORT bool endsWith(const QString &s, bool cs) const
|
---|
545 | { return endsWith(s, cs?Qt::CaseSensitive:Qt::CaseInsensitive); }
|
---|
546 | inline QT3_SUPPORT QChar constref(uint i) const
|
---|
547 | { return at(i); }
|
---|
548 | QT3_SUPPORT QChar &ref(uint i);
|
---|
549 | inline QT3_SUPPORT QString leftJustify(int width, QChar aFill = QLatin1Char(' '), bool trunc=false) const
|
---|
550 | { return leftJustified(width, aFill, trunc); }
|
---|
551 | inline QT3_SUPPORT QString rightJustify(int width, QChar aFill = QLatin1Char(' '), bool trunc=false) const
|
---|
552 | { return rightJustified(width, aFill, trunc); }
|
---|
553 | inline QT3_SUPPORT QString lower() const { return toLower(); }
|
---|
554 | inline QT3_SUPPORT QString upper() const { return toUpper(); }
|
---|
555 | inline QT3_SUPPORT QString stripWhiteSpace() const { return trimmed(); }
|
---|
556 | inline QT3_SUPPORT QString simplifyWhiteSpace() const { return simplified(); }
|
---|
557 | inline QT3_SUPPORT QString &setUnicodeCodes(const ushort *unicode_as_ushorts, int aSize)
|
---|
558 | { return setUtf16(unicode_as_ushorts, aSize); }
|
---|
559 | inline QT3_SUPPORT const ushort *ucs2() const { return utf16(); }
|
---|
560 | inline static QT3_SUPPORT QString fromUcs2(const ushort *unicode, int size = -1)
|
---|
561 | { return fromUtf16(unicode, size); }
|
---|
562 | inline QT3_SUPPORT QString &setAscii(const char *str, int len = -1)
|
---|
563 | { *this = fromAscii(str, len); return *this; }
|
---|
564 | inline QT3_SUPPORT QString &setLatin1(const char *str, int len = -1)
|
---|
565 | { *this = fromLatin1(str, len); return *this; }
|
---|
566 | protected:
|
---|
567 | friend class QObject;
|
---|
568 | const char *ascii_helper() const;
|
---|
569 | const char *latin1_helper() const;
|
---|
570 | public:
|
---|
571 | #ifndef QT_NO_CAST_TO_ASCII
|
---|
572 | inline QT3_SUPPORT operator const char *() const { return ascii_helper(); }
|
---|
573 | private:
|
---|
574 | QT3_SUPPORT operator QNoImplicitBoolCast() const;
|
---|
575 | public:
|
---|
576 | #endif
|
---|
577 | #endif
|
---|
578 |
|
---|
579 | bool isSimpleText() const { if (!d->clean) updateProperties(); return d->simpletext; }
|
---|
580 | bool isRightToLeft() const { if (!d->clean) updateProperties(); return d->righttoleft; }
|
---|
581 |
|
---|
582 | private:
|
---|
583 | #if defined(QT_NO_CAST_FROM_ASCII) && !defined(Q_NO_DECLARED_NOT_DEFINED)
|
---|
584 | QString &operator+=(const char *s);
|
---|
585 | QString &operator+=(const QByteArray &s);
|
---|
586 | QString(const char *ch);
|
---|
587 | QString(const QByteArray &a);
|
---|
588 | QString &operator=(const char *ch);
|
---|
589 | QString &operator=(const QByteArray &a);
|
---|
590 | #endif
|
---|
591 |
|
---|
592 | struct Data {
|
---|
593 | QBasicAtomicInt ref;
|
---|
594 | int alloc, size;
|
---|
595 | ushort *data;
|
---|
596 | ushort clean : 1;
|
---|
597 | ushort simpletext : 1;
|
---|
598 | ushort righttoleft : 1;
|
---|
599 | ushort asciiCache : 1;
|
---|
600 | ushort capacity : 1;
|
---|
601 | ushort reserved : 11;
|
---|
602 | ushort array[1];
|
---|
603 | };
|
---|
604 | static Data shared_null;
|
---|
605 | static Data shared_empty;
|
---|
606 | Data *d;
|
---|
607 | QString(Data *dd, int /*dummy*/) : d(dd) {}
|
---|
608 | #ifndef QT_NO_TEXTCODEC
|
---|
609 | static QTextCodec *codecForCStrings;
|
---|
610 | #endif
|
---|
611 | static int grow(int);
|
---|
612 | static void free(Data *);
|
---|
613 | void realloc();
|
---|
614 | void realloc(int alloc);
|
---|
615 | void expand(int i);
|
---|
616 | void updateProperties() const;
|
---|
617 | QString multiArg(int numArgs, const QString **args) const;
|
---|
618 | static int compare_helper(const QChar *data1, int length1,
|
---|
619 | const QChar *data2, int length2,
|
---|
620 | Qt::CaseSensitivity cs = Qt::CaseSensitive);
|
---|
621 | static int compare_helper(const QChar *data1, int length1,
|
---|
622 | QLatin1String s2,
|
---|
623 | Qt::CaseSensitivity cs = Qt::CaseSensitive);
|
---|
624 | static int localeAwareCompare_helper(const QChar *data1, int length1,
|
---|
625 | const QChar *data2, int length2);
|
---|
626 | static Data *fromLatin1_helper(const char *str, int size = -1);
|
---|
627 | static Data *fromAscii_helper(const char *str, int size = -1);
|
---|
628 | void replace_helper(uint *indices, int nIndices, int blen, const QChar *after, int alen);
|
---|
629 | friend class QCharRef;
|
---|
630 | friend class QTextCodec;
|
---|
631 | friend class QStringRef;
|
---|
632 | friend inline bool qStringComparisonHelper(const QString &s1, const char *s2);
|
---|
633 | friend inline bool qStringComparisonHelper(const QStringRef &s1, const char *s2);
|
---|
634 | public:
|
---|
635 | typedef Data * DataPtr;
|
---|
636 | inline DataPtr &data_ptr() { return d; }
|
---|
637 | };
|
---|
638 |
|
---|
639 |
|
---|
640 | class Q_CORE_EXPORT QLatin1String
|
---|
641 | {
|
---|
642 | public:
|
---|
643 | inline explicit QLatin1String(const char *s) : chars(s) {}
|
---|
644 | inline QLatin1String &operator=(const QLatin1String &other)
|
---|
645 | { chars = other.chars; return *this; }
|
---|
646 |
|
---|
647 | inline const char *latin1() const { return chars; }
|
---|
648 |
|
---|
649 | inline bool operator==(const QString &s) const
|
---|
650 | { return s == *this; }
|
---|
651 | inline bool operator!=(const QString &s) const
|
---|
652 | { return s != *this; }
|
---|
653 | inline bool operator>(const QString &s) const
|
---|
654 | { return s < *this; }
|
---|
655 | inline bool operator<(const QString &s) const
|
---|
656 | { return s > *this; }
|
---|
657 | inline bool operator>=(const QString &s) const
|
---|
658 | { return s <= *this; }
|
---|
659 | inline bool operator<=(const QString &s) const
|
---|
660 | { return s >= *this; }
|
---|
661 |
|
---|
662 | inline QT_ASCII_CAST_WARN bool operator==(const char *s) const
|
---|
663 | { return QString::fromAscii(s) == *this; }
|
---|
664 | inline QT_ASCII_CAST_WARN bool operator!=(const char *s) const
|
---|
665 | { return QString::fromAscii(s) != *this; }
|
---|
666 | inline QT_ASCII_CAST_WARN bool operator<(const char *s) const
|
---|
667 | { return QString::fromAscii(s) > *this; }
|
---|
668 | inline QT_ASCII_CAST_WARN bool operator>(const char *s) const
|
---|
669 | { return QString::fromAscii(s) < *this; }
|
---|
670 | inline QT_ASCII_CAST_WARN bool operator<=(const char *s) const
|
---|
671 | { return QString::fromAscii(s) >= *this; }
|
---|
672 | inline QT_ASCII_CAST_WARN bool operator>=(const char *s) const
|
---|
673 | { return QString::fromAscii(s) <= *this; }
|
---|
674 | private:
|
---|
675 | const char *chars;
|
---|
676 | };
|
---|
677 |
|
---|
678 |
|
---|
679 |
|
---|
680 | inline QString::QString(const QLatin1String &aLatin1) : d(fromLatin1_helper(aLatin1.latin1()))
|
---|
681 | { }
|
---|
682 | inline int QString::length() const
|
---|
683 | { return d->size; }
|
---|
684 | inline const QChar QString::at(int i) const
|
---|
685 | { Q_ASSERT(i >= 0 && i < size()); return d->data[i]; }
|
---|
686 | inline const QChar QString::operator[](int i) const
|
---|
687 | { Q_ASSERT(i >= 0 && i < size()); return d->data[i]; }
|
---|
688 | inline const QChar QString::operator[](uint i) const
|
---|
689 | { Q_ASSERT(i < uint(size())); return d->data[i]; }
|
---|
690 | inline bool QString::isEmpty() const
|
---|
691 | { return d->size == 0; }
|
---|
692 | inline const QChar *QString::unicode() const
|
---|
693 | { return reinterpret_cast<const QChar*>(d->data); }
|
---|
694 | inline const QChar *QString::data() const
|
---|
695 | { return reinterpret_cast<const QChar*>(d->data); }
|
---|
696 | inline QChar *QString::data()
|
---|
697 | { detach(); return reinterpret_cast<QChar*>(d->data); }
|
---|
698 | inline const QChar *QString::constData() const
|
---|
699 | { return reinterpret_cast<const QChar*>(d->data); }
|
---|
700 | inline void QString::detach()
|
---|
701 | { if (d->ref != 1 || d->data != d->array) realloc(); }
|
---|
702 | inline bool QString::isDetached() const
|
---|
703 | { return d->ref == 1; }
|
---|
704 | inline QString &QString::operator=(const QLatin1String &s)
|
---|
705 | {
|
---|
706 | *this = fromLatin1(s.latin1());
|
---|
707 | return *this;
|
---|
708 | }
|
---|
709 | inline void QString::clear()
|
---|
710 | { if (!isNull()) *this = QString(); }
|
---|
711 | inline QString::QString(const QString &other) : d(other.d)
|
---|
712 | { Q_ASSERT(&other != this); d->ref.ref(); }
|
---|
713 | inline int QString::capacity() const
|
---|
714 | { return d->alloc; }
|
---|
715 | inline QString &QString::setNum(short n, int base)
|
---|
716 | { return setNum(qlonglong(n), base); }
|
---|
717 | inline QString &QString::setNum(ushort n, int base)
|
---|
718 | { return setNum(qulonglong(n), base); }
|
---|
719 | inline QString &QString::setNum(int n, int base)
|
---|
720 | { return setNum(qlonglong(n), base); }
|
---|
721 | inline QString &QString::setNum(uint n, int base)
|
---|
722 | { return setNum(qulonglong(n), base); }
|
---|
723 | inline QString &QString::setNum(long n, int base)
|
---|
724 | { return setNum(qlonglong(n), base); }
|
---|
725 | inline QString &QString::setNum(ulong n, int base)
|
---|
726 | { return setNum(qulonglong(n), base); }
|
---|
727 | inline QString &QString::setNum(float n, char f, int prec)
|
---|
728 | { return setNum(double(n),f,prec); }
|
---|
729 | inline QString QString::arg(int a, int fieldWidth, int base, const QChar &fillChar) const
|
---|
730 | { return arg(qlonglong(a), fieldWidth, base, fillChar); }
|
---|
731 | inline QString QString::arg(uint a, int fieldWidth, int base, const QChar &fillChar) const
|
---|
732 | { return arg(qulonglong(a), fieldWidth, base, fillChar); }
|
---|
733 | inline QString QString::arg(long a, int fieldWidth, int base, const QChar &fillChar) const
|
---|
734 | { return arg(qlonglong(a), fieldWidth, base, fillChar); }
|
---|
735 | inline QString QString::arg(ulong a, int fieldWidth, int base, const QChar &fillChar) const
|
---|
736 | { return arg(qulonglong(a), fieldWidth, base, fillChar); }
|
---|
737 | inline QString QString::arg(short a, int fieldWidth, int base, const QChar &fillChar) const
|
---|
738 | { return arg(qlonglong(a), fieldWidth, base, fillChar); }
|
---|
739 | inline QString QString::arg(ushort a, int fieldWidth, int base, const QChar &fillChar) const
|
---|
740 | { return arg(qulonglong(a), fieldWidth, base, fillChar); }
|
---|
741 | inline QString QString::arg(const QString &a1, const QString &a2) const
|
---|
742 | { const QString *args[2] = { &a1, &a2 }; return multiArg(2, args); }
|
---|
743 | inline QString QString::arg(const QString &a1, const QString &a2, const QString &a3) const
|
---|
744 | { const QString *args[3] = { &a1, &a2, &a3 }; return multiArg(3, args); }
|
---|
745 | inline QString QString::arg(const QString &a1, const QString &a2, const QString &a3,
|
---|
746 | const QString &a4) const
|
---|
747 | { const QString *args[4] = { &a1, &a2, &a3, &a4 }; return multiArg(4, args); }
|
---|
748 | inline QString QString::arg(const QString &a1, const QString &a2, const QString &a3,
|
---|
749 | const QString &a4, const QString &a5) const
|
---|
750 | { const QString *args[5] = { &a1, &a2, &a3, &a4, &a5 }; return multiArg(5, args); }
|
---|
751 | inline QString QString::arg(const QString &a1, const QString &a2, const QString &a3,
|
---|
752 | const QString &a4, const QString &a5, const QString &a6) const
|
---|
753 | { const QString *args[6] = { &a1, &a2, &a3, &a4, &a5, &a6 }; return multiArg(6, args); }
|
---|
754 | inline QString QString::arg(const QString &a1, const QString &a2, const QString &a3,
|
---|
755 | const QString &a4, const QString &a5, const QString &a6,
|
---|
756 | const QString &a7) const
|
---|
757 | { const QString *args[7] = { &a1, &a2, &a3, &a4, &a5, &a6, &a7 }; return multiArg(7, args); }
|
---|
758 | inline QString QString::arg(const QString &a1, const QString &a2, const QString &a3,
|
---|
759 | const QString &a4, const QString &a5, const QString &a6,
|
---|
760 | const QString &a7, const QString &a8) const
|
---|
761 | { const QString *args[8] = { &a1, &a2, &a3, &a4, &a5, &a6, &a7, &a8 }; return multiArg(8, args); }
|
---|
762 | inline QString QString::arg(const QString &a1, const QString &a2, const QString &a3,
|
---|
763 | const QString &a4, const QString &a5, const QString &a6,
|
---|
764 | const QString &a7, const QString &a8, const QString &a9) const
|
---|
765 | { const QString *args[9] = { &a1, &a2, &a3, &a4, &a5, &a6, &a7, &a8, &a9 }; return multiArg(9, args); }
|
---|
766 |
|
---|
767 | inline QString QString::section(QChar asep, int astart, int aend, SectionFlags aflags) const
|
---|
768 | { return section(QString(asep), astart, aend, aflags); }
|
---|
769 |
|
---|
770 |
|
---|
771 | class Q_CORE_EXPORT QCharRef {
|
---|
772 | QString &s;
|
---|
773 | int i;
|
---|
774 | inline QCharRef(QString &str, int idx)
|
---|
775 | : s(str),i(idx) {}
|
---|
776 | friend class QString;
|
---|
777 | public:
|
---|
778 |
|
---|
779 | // most QChar operations repeated here
|
---|
780 |
|
---|
781 | // all this is not documented: We just say "like QChar" and let it be.
|
---|
782 | inline operator QChar() const
|
---|
783 | { return i < s.d->size ? s.d->data[i] : 0; }
|
---|
784 | inline QCharRef &operator=(const QChar &c)
|
---|
785 | { if (i >= s.d->size) s.expand(i); else s.detach();
|
---|
786 | s.d->data[i] = c.unicode(); return *this; }
|
---|
787 |
|
---|
788 | // An operator= for each QChar cast constructors
|
---|
789 | #ifndef QT_NO_CAST_FROM_ASCII
|
---|
790 | inline QT_ASCII_CAST_WARN QCharRef &operator=(char c)
|
---|
791 | { return operator=(QChar::fromAscii(c)); }
|
---|
792 | inline QT_ASCII_CAST_WARN QCharRef &operator=(uchar c)
|
---|
793 | { return operator=(QChar::fromAscii(c)); }
|
---|
794 | #endif
|
---|
795 | inline QCharRef &operator=(const QCharRef &c) { return operator=(QChar(c)); }
|
---|
796 | inline QCharRef &operator=(ushort rc) { return operator=(QChar(rc)); }
|
---|
797 | inline QCharRef &operator=(short rc) { return operator=(QChar(rc)); }
|
---|
798 | inline QCharRef &operator=(uint rc) { return operator=(QChar(rc)); }
|
---|
799 | inline QCharRef &operator=(int rc) { return operator=(QChar(rc)); }
|
---|
800 |
|
---|
801 | // each function...
|
---|
802 | inline bool isNull() const { return QChar(*this).isNull(); }
|
---|
803 | inline bool isPrint() const { return QChar(*this).isPrint(); }
|
---|
804 | inline bool isPunct() const { return QChar(*this).isPunct(); }
|
---|
805 | inline bool isSpace() const { return QChar(*this).isSpace(); }
|
---|
806 | inline bool isMark() const { return QChar(*this).isMark(); }
|
---|
807 | inline bool isLetter() const { return QChar(*this).isLetter(); }
|
---|
808 | inline bool isNumber() const { return QChar(*this).isNumber(); }
|
---|
809 | inline bool isLetterOrNumber() { return QChar(*this).isLetterOrNumber(); }
|
---|
810 | inline bool isDigit() const { return QChar(*this).isDigit(); }
|
---|
811 | inline bool isLower() const { return QChar(*this).isLower(); }
|
---|
812 | inline bool isUpper() const { return QChar(*this).isUpper(); }
|
---|
813 | inline bool isTitleCase() const { return QChar(*this).isTitleCase(); }
|
---|
814 |
|
---|
815 | inline int digitValue() const { return QChar(*this).digitValue(); }
|
---|
816 | QChar toLower() const { return QChar(*this).toLower(); }
|
---|
817 | QChar toUpper() const { return QChar(*this).toUpper(); }
|
---|
818 | QChar toTitleCase () const { return QChar(*this).toTitleCase(); }
|
---|
819 |
|
---|
820 | QChar::Category category() const { return QChar(*this).category(); }
|
---|
821 | QChar::Direction direction() const { return QChar(*this).direction(); }
|
---|
822 | QChar::Joining joining() const { return QChar(*this).joining(); }
|
---|
823 | bool hasMirrored() const { return QChar(*this).hasMirrored(); }
|
---|
824 | QChar mirroredChar() const { return QChar(*this).mirroredChar(); }
|
---|
825 | QString decomposition() const { return QChar(*this).decomposition(); }
|
---|
826 | QChar::Decomposition decompositionTag() const { return QChar(*this).decompositionTag(); }
|
---|
827 | uchar combiningClass() const { return QChar(*this).combiningClass(); }
|
---|
828 |
|
---|
829 | QChar::UnicodeVersion unicodeVersion() const { return QChar(*this).unicodeVersion(); }
|
---|
830 |
|
---|
831 | inline uchar cell() const { return QChar(*this).cell(); }
|
---|
832 | inline uchar row() const { return QChar(*this).row(); }
|
---|
833 | inline void setCell(uchar cell);
|
---|
834 | inline void setRow(uchar row);
|
---|
835 |
|
---|
836 | #ifdef Q_COMPILER_MANGLES_RETURN_TYPE
|
---|
837 | const char toAscii() const { return QChar(*this).toAscii(); }
|
---|
838 | const char toLatin1() const { return QChar(*this).toLatin1(); }
|
---|
839 | const ushort unicode() const { return QChar(*this).unicode(); }
|
---|
840 | #else
|
---|
841 | char toAscii() const { return QChar(*this).toAscii(); }
|
---|
842 | char toLatin1() const { return QChar(*this).toLatin1(); }
|
---|
843 | ushort unicode() const { return QChar(*this).unicode(); }
|
---|
844 | #endif
|
---|
845 | ushort& unicode() { return s.data()[i].unicode(); }
|
---|
846 |
|
---|
847 | #ifdef QT3_SUPPORT
|
---|
848 | inline QT3_SUPPORT bool mirrored() const { return hasMirrored(); }
|
---|
849 | inline QT3_SUPPORT QChar lower() const { return QChar(*this).toLower(); }
|
---|
850 | inline QT3_SUPPORT QChar upper() const { return QChar(*this).toUpper(); }
|
---|
851 | #ifdef Q_COMPILER_MANGLES_RETURN_TYPE
|
---|
852 | const QT3_SUPPORT char latin1() const { return QChar(*this).toLatin1(); }
|
---|
853 | const QT3_SUPPORT char ascii() const { return QChar(*this).toAscii(); }
|
---|
854 | #else
|
---|
855 | QT3_SUPPORT char latin1() const { return QChar(*this).toLatin1(); }
|
---|
856 | QT3_SUPPORT char ascii() const { return QChar(*this).toAscii(); }
|
---|
857 | #endif
|
---|
858 | #endif
|
---|
859 | };
|
---|
860 |
|
---|
861 | inline void QCharRef::setRow(uchar arow) { QChar(*this).setRow(arow); }
|
---|
862 | inline void QCharRef::setCell(uchar acell) { QChar(*this).setCell(acell); }
|
---|
863 |
|
---|
864 |
|
---|
865 | inline QString::QString() : d(&shared_null) { d->ref.ref(); }
|
---|
866 | inline QString::~QString() { if (!d->ref.deref()) free(d); }
|
---|
867 | inline void QString::reserve(int asize) { if (d->ref != 1 || asize > d->alloc) realloc(asize); d->capacity = 1;}
|
---|
868 | inline QString &QString::setUtf16(const ushort *autf16, int asize)
|
---|
869 | { return setUnicode(reinterpret_cast<const QChar *>(autf16), asize); }
|
---|
870 | inline QCharRef QString::operator[](int i)
|
---|
871 | { Q_ASSERT(i >= 0); return QCharRef(*this, i); }
|
---|
872 | inline QCharRef QString::operator[](uint i)
|
---|
873 | { return QCharRef(*this, i); }
|
---|
874 | inline QString::iterator QString::begin()
|
---|
875 | { detach(); return reinterpret_cast<QChar*>(d->data); }
|
---|
876 | inline QString::const_iterator QString::begin() const
|
---|
877 | { return reinterpret_cast<const QChar*>(d->data); }
|
---|
878 | inline QString::const_iterator QString::constBegin() const
|
---|
879 | { return reinterpret_cast<const QChar*>(d->data); }
|
---|
880 | inline QString::iterator QString::end()
|
---|
881 | { detach(); return reinterpret_cast<QChar*>(d->data + d->size); }
|
---|
882 | inline QString::const_iterator QString::end() const
|
---|
883 | { return reinterpret_cast<const QChar*>(d->data + d->size); }
|
---|
884 | inline QString::const_iterator QString::constEnd() const
|
---|
885 | { return reinterpret_cast<const QChar*>(d->data + d->size); }
|
---|
886 | inline QBool QString::contains(const QString &s, Qt::CaseSensitivity cs) const
|
---|
887 | { return QBool(indexOf(s, 0, cs) != -1); }
|
---|
888 | inline QBool QString::contains(QChar c, Qt::CaseSensitivity cs) const
|
---|
889 | { return QBool(indexOf(c, 0, cs) != -1); }
|
---|
890 |
|
---|
891 |
|
---|
892 | inline bool operator==(QString::Null, QString::Null) { return true; }
|
---|
893 | inline bool operator==(QString::Null, const QString &s) { return s.isNull(); }
|
---|
894 | inline bool operator==(const QString &s, QString::Null) { return s.isNull(); }
|
---|
895 | inline bool operator!=(QString::Null, QString::Null) { return false; }
|
---|
896 | inline bool operator!=(QString::Null, const QString &s) { return !s.isNull(); }
|
---|
897 | inline bool operator!=(const QString &s, QString::Null) { return !s.isNull(); }
|
---|
898 |
|
---|
899 | #ifndef QT_NO_CAST_FROM_ASCII
|
---|
900 | inline bool qStringComparisonHelper(const QString &s1, const char *s2)
|
---|
901 | {
|
---|
902 | # ifndef QT_NO_TEXTCODEC
|
---|
903 | if (QString::codecForCStrings) return (s1 == QString::fromAscii(s2));
|
---|
904 | # endif
|
---|
905 | return (s1 == QLatin1String(s2));
|
---|
906 | }
|
---|
907 | inline bool QString::operator==(const char *s) const
|
---|
908 | { return qStringComparisonHelper(*this, s); }
|
---|
909 | inline bool QString::operator!=(const char *s) const
|
---|
910 | { return !qStringComparisonHelper(*this, s); }
|
---|
911 | inline bool QString::operator<(const char *s) const
|
---|
912 | { return *this < QString::fromAscii(s); }
|
---|
913 | inline bool QString::operator>(const char *s) const
|
---|
914 | { return *this > QString::fromAscii(s); }
|
---|
915 | inline bool QString::operator<=(const char *s) const
|
---|
916 | { return *this <= QString::fromAscii(s); }
|
---|
917 | inline bool QString::operator>=(const char *s) const
|
---|
918 | { return *this >= QString::fromAscii(s); }
|
---|
919 |
|
---|
920 | inline QT_ASCII_CAST_WARN bool operator==(const char *s1, const QString &s2)
|
---|
921 | { return qStringComparisonHelper(s2, s1); }
|
---|
922 | inline QT_ASCII_CAST_WARN bool operator!=(const char *s1, const QString &s2)
|
---|
923 | { return !qStringComparisonHelper(s2, s1); }
|
---|
924 | inline QT_ASCII_CAST_WARN bool operator<(const char *s1, const QString &s2)
|
---|
925 | { return (QString::fromAscii(s1) < s2); }
|
---|
926 | inline QT_ASCII_CAST_WARN bool operator>(const char *s1, const QString &s2)
|
---|
927 | { return (QString::fromAscii(s1) > s2); }
|
---|
928 | inline QT_ASCII_CAST_WARN bool operator<=(const char *s1, const QString &s2)
|
---|
929 | { return (QString::fromAscii(s1) <= s2); }
|
---|
930 | inline QT_ASCII_CAST_WARN bool operator>=(const char *s1, const QString &s2)
|
---|
931 | { return (QString::fromAscii(s1) >= s2); }
|
---|
932 |
|
---|
933 | inline QT_ASCII_CAST_WARN bool operator==(const char *s1, const QLatin1String &s2)
|
---|
934 | { return QString::fromAscii(s1) == s2; }
|
---|
935 | inline QT_ASCII_CAST_WARN bool operator!=(const char *s1, const QLatin1String &s2)
|
---|
936 | { return QString::fromAscii(s1) != s2; }
|
---|
937 | inline QT_ASCII_CAST_WARN bool operator<(const char *s1, const QLatin1String &s2)
|
---|
938 | { return (QString::fromAscii(s1) < s2); }
|
---|
939 | inline QT_ASCII_CAST_WARN bool operator>(const char *s1, const QLatin1String &s2)
|
---|
940 | { return (QString::fromAscii(s1) > s2); }
|
---|
941 | inline QT_ASCII_CAST_WARN bool operator<=(const char *s1, const QLatin1String &s2)
|
---|
942 | { return (QString::fromAscii(s1) <= s2); }
|
---|
943 | inline QT_ASCII_CAST_WARN bool operator>=(const char *s1, const QLatin1String &s2)
|
---|
944 | { return (QString::fromAscii(s1) >= s2); }
|
---|
945 |
|
---|
946 | inline bool operator==(const QLatin1String &s1, const QLatin1String &s2)
|
---|
947 | { return (qstrcmp(s1.latin1(), s2.latin1()) == 0); }
|
---|
948 | inline bool operator!=(const QLatin1String &s1, const QLatin1String &s2)
|
---|
949 | { return (qstrcmp(s1.latin1(), s2.latin1()) != 0); }
|
---|
950 | inline bool operator<(const QLatin1String &s1, const QLatin1String &s2)
|
---|
951 | { return (qstrcmp(s1.latin1(), s2.latin1()) < 0); }
|
---|
952 | inline bool operator<=(const QLatin1String &s1, const QLatin1String &s2)
|
---|
953 | { return (qstrcmp(s1.latin1(), s2.latin1()) <= 0); }
|
---|
954 | inline bool operator>(const QLatin1String &s1, const QLatin1String &s2)
|
---|
955 | { return (qstrcmp(s1.latin1(), s2.latin1()) > 0); }
|
---|
956 | inline bool operator>=(const QLatin1String &s1, const QLatin1String &s2)
|
---|
957 | { return (qstrcmp(s1.latin1(), s2.latin1()) >= 0); }
|
---|
958 |
|
---|
959 |
|
---|
960 | inline bool QString::operator==(const QByteArray &s) const
|
---|
961 | { return qStringComparisonHelper(*this, s.constData()); }
|
---|
962 | inline bool QString::operator!=(const QByteArray &s) const
|
---|
963 | { return !qStringComparisonHelper(*this, s.constData()); }
|
---|
964 |
|
---|
965 | inline bool QByteArray::operator==(const QString &s) const
|
---|
966 | { return qStringComparisonHelper(s, constData()); }
|
---|
967 | inline bool QByteArray::operator!=(const QString &s) const
|
---|
968 | { return !qStringComparisonHelper(s, constData()); }
|
---|
969 | inline bool QByteArray::operator<(const QString &s) const
|
---|
970 | { return QString::fromAscii(constData(), size()) < s; }
|
---|
971 | inline bool QByteArray::operator>(const QString &s) const
|
---|
972 | { return QString::fromAscii(constData(), size()) > s; }
|
---|
973 | inline bool QByteArray::operator<=(const QString &s) const
|
---|
974 | { return QString::fromAscii(constData(), size()) <= s; }
|
---|
975 | inline bool QByteArray::operator>=(const QString &s) const
|
---|
976 | { return QString::fromAscii(constData(), size()) >= s; }
|
---|
977 | #endif // QT_NO_CAST_FROM_ASCII
|
---|
978 |
|
---|
979 | #ifndef QT_NO_CAST_TO_ASCII
|
---|
980 | inline QByteArray &QByteArray::append(const QString &s)
|
---|
981 | { return append(s.toAscii()); }
|
---|
982 | inline QByteArray &QByteArray::insert(int i, const QString &s)
|
---|
983 | { return insert(i, s.toAscii()); }
|
---|
984 | inline QByteArray &QByteArray::replace(char c, const QString &after)
|
---|
985 | { return replace(c, after.toAscii()); }
|
---|
986 | inline QByteArray &QByteArray::replace(const QString &before, const char *after)
|
---|
987 | { return replace(before.toAscii(), after); }
|
---|
988 | inline QByteArray &QByteArray::replace(const QString &before, const QByteArray &after)
|
---|
989 | { return replace(before.toAscii(), after); }
|
---|
990 | inline QByteArray &QByteArray::operator+=(const QString &s)
|
---|
991 | { return operator+=(s.toAscii()); }
|
---|
992 | inline int QByteArray::indexOf(const QString &s, int from) const
|
---|
993 | { return indexOf(s.toAscii(), from); }
|
---|
994 | inline int QByteArray::lastIndexOf(const QString &s, int from) const
|
---|
995 | { return lastIndexOf(s.toAscii(), from); }
|
---|
996 | # ifdef QT3_SUPPORT
|
---|
997 | inline int QByteArray::find(const QString &s, int from) const
|
---|
998 | { return indexOf(s.toAscii(), from); }
|
---|
999 | inline int QByteArray::findRev(const QString &s, int from) const
|
---|
1000 | { return lastIndexOf(s.toAscii(), from); }
|
---|
1001 | # endif // QT3_SUPPORT
|
---|
1002 | #endif // QT_NO_CAST_TO_ASCII
|
---|
1003 |
|
---|
1004 | inline const QString operator+(const QString &s1, const QString &s2)
|
---|
1005 | { QString t(s1); t += s2; return t; }
|
---|
1006 | inline const QString operator+(const QString &s1, QChar s2)
|
---|
1007 | { QString t(s1); t += s2; return t; }
|
---|
1008 | inline const QString operator+(QChar s1, const QString &s2)
|
---|
1009 | { QString t(s1); t += s2; return t; }
|
---|
1010 | #ifndef QT_NO_CAST_FROM_ASCII
|
---|
1011 | inline QT_ASCII_CAST_WARN const QString operator+(const QString &s1, const char *s2)
|
---|
1012 | { QString t(s1); t += QString::fromAscii(s2); return t; }
|
---|
1013 | inline QT_ASCII_CAST_WARN const QString operator+(const char *s1, const QString &s2)
|
---|
1014 | { QString t = QString::fromAscii(s1); t += s2; return t; }
|
---|
1015 | inline QT_ASCII_CAST_WARN const QString operator+(char c, const QString &s)
|
---|
1016 | { QString t = s; t.prepend(QChar::fromAscii(c)); return t; }
|
---|
1017 | inline QT_ASCII_CAST_WARN const QString operator+(const QString &s, char c)
|
---|
1018 | { QString t = s; t += QChar::fromAscii(c); return t; }
|
---|
1019 | inline QT_ASCII_CAST_WARN const QString operator+(const QByteArray &ba, const QString &s)
|
---|
1020 | { QString t = QString::fromAscii(ba.constData(), qstrnlen(ba.constData(), ba.size())); t += s; return t; }
|
---|
1021 | inline QT_ASCII_CAST_WARN const QString operator+(const QString &s, const QByteArray &ba)
|
---|
1022 | { QString t(s); t += QString::fromAscii(ba.constData(), qstrnlen(ba.constData(), ba.size())); return t; }
|
---|
1023 | #endif
|
---|
1024 |
|
---|
1025 | #ifndef QT_NO_STL
|
---|
1026 | inline std::string QString::toStdString() const
|
---|
1027 | { const QByteArray asc = toAscii(); return std::string(asc.constData(), asc.length()); }
|
---|
1028 |
|
---|
1029 | inline QString QString::fromStdString(const std::string &s)
|
---|
1030 | { return fromAscii(s.data(), int(s.size())); }
|
---|
1031 |
|
---|
1032 | # ifndef QT_NO_STL_WCHAR
|
---|
1033 | inline QStdWString QString::toStdWString() const
|
---|
1034 | {
|
---|
1035 | QStdWString str;
|
---|
1036 | str.resize(length());
|
---|
1037 |
|
---|
1038 | #if defined(_MSC_VER) && _MSC_VER >= 1400
|
---|
1039 | // VS2005 crashes if the string is empty
|
---|
1040 | if (!length())
|
---|
1041 | return str;
|
---|
1042 | #endif
|
---|
1043 |
|
---|
1044 | str.resize(toWCharArray(&(*str.begin())));
|
---|
1045 | return str;
|
---|
1046 | }
|
---|
1047 | inline QString QString::fromStdWString(const QStdWString &s)
|
---|
1048 | { return fromWCharArray(s.data(), int(s.size())); }
|
---|
1049 | # endif
|
---|
1050 | #endif
|
---|
1051 |
|
---|
1052 | #ifdef QT3_SUPPORT
|
---|
1053 | inline QChar &QString::ref(uint i)
|
---|
1054 | {
|
---|
1055 | if (int(i) > d->size || d->ref != 1)
|
---|
1056 | resize(qMax(int(i), d->size));
|
---|
1057 | return reinterpret_cast<QChar&>(d->data[i]);
|
---|
1058 | }
|
---|
1059 | #endif
|
---|
1060 |
|
---|
1061 | #ifndef QT_NO_DATASTREAM
|
---|
1062 | Q_CORE_EXPORT QDataStream &operator<<(QDataStream &, const QString &);
|
---|
1063 | Q_CORE_EXPORT QDataStream &operator>>(QDataStream &, QString &);
|
---|
1064 | #endif
|
---|
1065 |
|
---|
1066 | #ifdef QT3_SUPPORT
|
---|
1067 | class QConstString : public QString
|
---|
1068 | {
|
---|
1069 | public:
|
---|
1070 | inline QT3_SUPPORT_CONSTRUCTOR QConstString(const QChar *aUnicode, int aSize)
|
---|
1071 | :QString(aUnicode, aSize){} // cannot use fromRawData() due to changed semantics
|
---|
1072 | inline QT3_SUPPORT const QString &string() const { return *this; }
|
---|
1073 | };
|
---|
1074 | #endif
|
---|
1075 |
|
---|
1076 | Q_DECLARE_TYPEINFO(QString, Q_MOVABLE_TYPE);
|
---|
1077 | Q_DECLARE_SHARED(QString)
|
---|
1078 | Q_DECLARE_OPERATORS_FOR_FLAGS(QString::SectionFlags)
|
---|
1079 |
|
---|
1080 | #if defined(Q_OS_WIN32) || defined(Q_OS_WINCE)
|
---|
1081 | extern Q_CORE_EXPORT QByteArray qt_winQString2MB(const QString& s, int len=-1);
|
---|
1082 | extern Q_CORE_EXPORT QByteArray qt_winQString2MB(const QChar *ch, int len);
|
---|
1083 | extern Q_CORE_EXPORT QString qt_winMB2QString(const char* mb, int len=-1);
|
---|
1084 | #endif
|
---|
1085 |
|
---|
1086 |
|
---|
1087 | class Q_CORE_EXPORT QStringRef {
|
---|
1088 | const QString *m_string;
|
---|
1089 | int m_position;
|
---|
1090 | int m_size;
|
---|
1091 | public:
|
---|
1092 | inline QStringRef():m_string(0), m_position(0), m_size(0){}
|
---|
1093 | inline QStringRef(const QString *string, int position, int size);
|
---|
1094 | inline QStringRef(const QString *string);
|
---|
1095 | inline QStringRef(const QStringRef &other)
|
---|
1096 | :m_string(other.m_string), m_position(other.m_position), m_size(other.m_size)
|
---|
1097 | {}
|
---|
1098 |
|
---|
1099 | inline ~QStringRef(){}
|
---|
1100 | inline const QString *string() const { return m_string; }
|
---|
1101 | inline int position() const { return m_position; }
|
---|
1102 | inline int size() const { return m_size; }
|
---|
1103 | inline int count() const { return m_size; }
|
---|
1104 | inline int length() const { return m_size; }
|
---|
1105 |
|
---|
1106 | inline QStringRef &operator=(const QStringRef &other) {
|
---|
1107 | m_string = other.m_string; m_position = other.m_position;
|
---|
1108 | m_size = other.m_size; return *this;
|
---|
1109 | }
|
---|
1110 |
|
---|
1111 | inline QStringRef &operator=(const QString *string);
|
---|
1112 |
|
---|
1113 | inline const QChar *unicode() const {
|
---|
1114 | if (!m_string)
|
---|
1115 | return reinterpret_cast<const QChar *>(QString::shared_null.data);
|
---|
1116 | return m_string->unicode() + m_position;
|
---|
1117 | }
|
---|
1118 | inline const QChar *data() const { return unicode(); }
|
---|
1119 | inline const QChar *constData() const { return unicode(); }
|
---|
1120 |
|
---|
1121 | inline void clear() { m_string = 0; m_position = m_size = 0; }
|
---|
1122 | QString toString() const;
|
---|
1123 | inline bool isEmpty() const { return m_size == 0; }
|
---|
1124 | inline bool isNull() const { return m_string == 0 || m_string->isNull(); }
|
---|
1125 |
|
---|
1126 | QStringRef appendTo(QString *string) const;
|
---|
1127 |
|
---|
1128 | inline const QChar at(int i) const
|
---|
1129 | { Q_ASSERT(i >= 0 && i < size()); return m_string->at(i + m_position); }
|
---|
1130 |
|
---|
1131 | int compare(const QString &s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const;
|
---|
1132 | int compare(const QStringRef &s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const;
|
---|
1133 | int compare(QLatin1String s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const;
|
---|
1134 | static int compare(const QStringRef &s1, const QString &s2,
|
---|
1135 | Qt::CaseSensitivity = Qt::CaseSensitive);
|
---|
1136 | static int compare(const QStringRef &s1, const QStringRef &s2,
|
---|
1137 | Qt::CaseSensitivity = Qt::CaseSensitive);
|
---|
1138 | static int compare(const QStringRef &s1, QLatin1String s2,
|
---|
1139 | Qt::CaseSensitivity cs = Qt::CaseSensitive);
|
---|
1140 |
|
---|
1141 | int localeAwareCompare(const QString &s) const;
|
---|
1142 | int localeAwareCompare(const QStringRef &s) const;
|
---|
1143 | static int localeAwareCompare(const QStringRef &s1, const QString &s2);
|
---|
1144 | static int localeAwareCompare(const QStringRef &s1, const QStringRef &s2);
|
---|
1145 | };
|
---|
1146 |
|
---|
1147 | inline QStringRef &QStringRef::operator=(const QString *aString)
|
---|
1148 | { m_string = aString; m_position = 0; m_size = aString?aString->size():0; return *this; }
|
---|
1149 |
|
---|
1150 | inline QStringRef::QStringRef(const QString *aString, int aPosition, int aSize)
|
---|
1151 | :m_string(aString), m_position(aPosition), m_size(aSize){}
|
---|
1152 |
|
---|
1153 | inline QStringRef::QStringRef(const QString *aString)
|
---|
1154 | :m_string(aString), m_position(0), m_size(aString?aString->size() : 0){}
|
---|
1155 |
|
---|
1156 | Q_CORE_EXPORT bool operator==(const QStringRef &s1,const QStringRef &s2);
|
---|
1157 | inline bool operator!=(const QStringRef &s1,const QStringRef &s2)
|
---|
1158 | { return !(s1 == s2); }
|
---|
1159 | Q_CORE_EXPORT bool operator==(const QString &s1,const QStringRef &s2);
|
---|
1160 | inline bool operator!=(const QString &s1,const QStringRef &s2)
|
---|
1161 | { return !(s1 == s2); }
|
---|
1162 | inline bool operator==(const QStringRef &s1,const QString &s2)
|
---|
1163 | { return s2 == s1; }
|
---|
1164 | inline bool operator!=(const QStringRef &s1,const QString &s2)
|
---|
1165 | { return s2 != s1; }
|
---|
1166 | Q_CORE_EXPORT bool operator==(const QLatin1String &s1, const QStringRef &s2);
|
---|
1167 | inline bool operator!=(const QLatin1String &s1,const QStringRef &s2)
|
---|
1168 | { return !(s1 == s2); }
|
---|
1169 | inline bool operator==(const QStringRef &s1,const QLatin1String &s2)
|
---|
1170 | { return s2 == s1; }
|
---|
1171 | inline bool operator!=(const QStringRef &s1,const QLatin1String &s2)
|
---|
1172 | { return s2 != s1; }
|
---|
1173 |
|
---|
1174 | Q_CORE_EXPORT bool operator<(const QStringRef &s1,const QStringRef &s2);
|
---|
1175 | inline bool operator>(const QStringRef &s1, const QStringRef &s2)
|
---|
1176 | { return s2 < s1; }
|
---|
1177 | inline bool operator<=(const QStringRef &s1, const QStringRef &s2)
|
---|
1178 | { return !(s1 > s2); }
|
---|
1179 | inline bool operator>=(const QStringRef &s1, const QStringRef &s2)
|
---|
1180 | { return !(s1 < s2); }
|
---|
1181 |
|
---|
1182 | inline bool qStringComparisonHelper(const QStringRef &s1, const char *s2)
|
---|
1183 | {
|
---|
1184 | # ifndef QT_NO_TEXTCODEC
|
---|
1185 | if (QString::codecForCStrings) return (s1 == QString::fromAscii(s2));
|
---|
1186 | # endif
|
---|
1187 | return (s1 == QLatin1String(s2));
|
---|
1188 | }
|
---|
1189 |
|
---|
1190 | inline QT_ASCII_CAST_WARN bool operator==(const char *s1, const QStringRef &s2)
|
---|
1191 | { return qStringComparisonHelper(s2, s1); }
|
---|
1192 | inline QT_ASCII_CAST_WARN bool operator==(const QStringRef &s1, const char *s2)
|
---|
1193 | { return qStringComparisonHelper(s1, s2); }
|
---|
1194 | inline QT_ASCII_CAST_WARN bool operator!=(const char *s1, const QStringRef &s2)
|
---|
1195 | { return !qStringComparisonHelper(s2, s1); }
|
---|
1196 | inline QT_ASCII_CAST_WARN bool operator!=(const QStringRef &s1, const char *s2)
|
---|
1197 | { return !qStringComparisonHelper(s1, s2); }
|
---|
1198 |
|
---|
1199 | inline int QString::compare(const QStringRef &s, Qt::CaseSensitivity cs) const
|
---|
1200 | { return QString::compare_helper(constData(), length(), s.constData(), s.length(), cs); }
|
---|
1201 | inline int QString::compare(const QString &s1, const QStringRef &s2, Qt::CaseSensitivity cs)
|
---|
1202 | { return QString::compare_helper(s1.constData(), s1.length(), s2.constData(), s2.length(), cs); }
|
---|
1203 | inline int QStringRef::compare(const QString &s, Qt::CaseSensitivity cs) const
|
---|
1204 | { return QString::compare_helper(constData(), length(), s.constData(), s.length(), cs); }
|
---|
1205 | inline int QStringRef::compare(const QStringRef &s, Qt::CaseSensitivity cs) const
|
---|
1206 | { return QString::compare_helper(constData(), length(), s.constData(), s.length(), cs); }
|
---|
1207 | inline int QStringRef::compare(QLatin1String s, Qt::CaseSensitivity cs) const
|
---|
1208 | { return QString::compare_helper(constData(), length(), s, cs); }
|
---|
1209 | inline int QStringRef::compare(const QStringRef &s1, const QString &s2, Qt::CaseSensitivity cs)
|
---|
1210 | { return QString::compare_helper(s1.constData(), s1.length(), s2.constData(), s2.length(), cs); }
|
---|
1211 | inline int QStringRef::compare(const QStringRef &s1, const QStringRef &s2, Qt::CaseSensitivity cs)
|
---|
1212 | { return QString::compare_helper(s1.constData(), s1.length(), s2.constData(), s2.length(), cs); }
|
---|
1213 | inline int QStringRef::compare(const QStringRef &s1, QLatin1String s2, Qt::CaseSensitivity cs)
|
---|
1214 | { return QString::compare_helper(s1.constData(), s1.length(), s2, cs); }
|
---|
1215 |
|
---|
1216 | inline int QString::localeAwareCompare(const QStringRef &s) const
|
---|
1217 | { return localeAwareCompare_helper(constData(), length(), s.constData(), s.length()); }
|
---|
1218 | inline int QString::localeAwareCompare(const QString& s1, const QStringRef& s2)
|
---|
1219 | { return localeAwareCompare_helper(s1.constData(), s1.length(), s2.constData(), s2.length()); }
|
---|
1220 | inline int QStringRef::localeAwareCompare(const QString &s) const
|
---|
1221 | { return QString::localeAwareCompare_helper(constData(), length(), s.constData(), s.length()); }
|
---|
1222 | inline int QStringRef::localeAwareCompare(const QStringRef &s) const
|
---|
1223 | { return QString::localeAwareCompare_helper(constData(), length(), s.constData(), s.length()); }
|
---|
1224 | inline int QStringRef::localeAwareCompare(const QStringRef &s1, const QString &s2)
|
---|
1225 | { return QString::localeAwareCompare_helper(s1.constData(), s1.length(), s2.constData(), s2.length()); }
|
---|
1226 | inline int QStringRef::localeAwareCompare(const QStringRef &s1, const QStringRef &s2)
|
---|
1227 | { return QString::localeAwareCompare_helper(s1.constData(), s1.length(), s2.constData(), s2.length()); }
|
---|
1228 |
|
---|
1229 |
|
---|
1230 | QT_END_NAMESPACE
|
---|
1231 |
|
---|
1232 | QT_END_HEADER
|
---|
1233 |
|
---|
1234 | #endif // QSTRING_H
|
---|