LCOV - code coverage report
Current view: top level - usr/include/x86_64-linux-gnu/qt5/QtCore - qstring.h (source / functions) Hit Total Coverage
Test: coverage.info Lines: 47 67 70.1 %
Date: 2016-11-29 15:07:43 Functions: 33 56 58.9 %

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

Generated by: LCOV version 1.11