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