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