| 1 | // Copyright (C) 2020 The Qt Company Ltd. | 
| 2 | // Copyright (C) 2018 Intel Corporation. | 
| 3 | // Copyright (C) 2019 Mail.ru Group. | 
| 4 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only | 
| 5 |  | 
| 6 | #include "qstringref.h" | 
| 7 |  | 
| 8 | #include <QtCore/qnumeric.h> | 
| 9 | #include <QtCore/qlist.h> | 
| 10 | #include <QtCore/qvarlengtharray.h> | 
| 11 |  | 
| 12 | #ifdef Q_OS_MACOS | 
| 13 | #include <private/qcore_mac_p.h> | 
| 14 | #endif | 
| 15 |  | 
| 16 | #include <private/qfunctions_p.h> | 
| 17 | #include <private/qstringalgorithms_p.h> | 
| 18 | #include <private/qstringconverter_p.h> | 
| 19 | #include <private/qstringiterator_p.h> | 
| 20 | #include <private/qunicodetables_p.h> | 
| 21 |  | 
| 22 | #include <limits.h> | 
| 23 | #include <string.h> | 
| 24 | #include <stdlib.h> | 
| 25 | #include <stdio.h> | 
| 26 | #include <stdarg.h> | 
| 27 | #include <wchar.h> | 
| 28 |  | 
| 29 | #ifdef Q_OS_WIN | 
| 30 | #  include <qt_windows.h> | 
| 31 | #endif | 
| 32 |  | 
| 33 | #ifdef truncate | 
| 34 | #  undef truncate | 
| 35 | #endif | 
| 36 |  | 
| 37 | QT_BEGIN_NAMESPACE | 
| 38 |  | 
| 39 | // internal | 
| 40 | static inline qsizetype qFindChar(QStringView str, QChar ch, qsizetype from, Qt::CaseSensitivity cs) noexcept; | 
| 41 |  | 
| 42 | static inline bool qt_starts_with(QStringView haystack, QStringView needle, Qt::CaseSensitivity cs); | 
| 43 | static inline bool qt_starts_with(QStringView haystack, QLatin1String needle, Qt::CaseSensitivity cs); | 
| 44 | static inline bool qt_starts_with(QStringView haystack, QChar needle, Qt::CaseSensitivity cs); | 
| 45 | static inline bool qt_ends_with(QStringView haystack, QStringView needle, Qt::CaseSensitivity cs); | 
| 46 | static inline bool qt_ends_with(QStringView haystack, QLatin1String needle, Qt::CaseSensitivity cs); | 
| 47 | static inline bool qt_ends_with(QStringView haystack, QChar needle, Qt::CaseSensitivity cs); | 
| 48 |  | 
| 49 | // Code imported from QUnicodeTables | 
| 50 |  | 
| 51 | namespace QUnicodeTablesPrivate | 
| 52 | { | 
| 53 |     static const unsigned short specialCaseMap[] = { | 
| 54 |         0x0, // placeholder | 
| 55 |         0x1,   0x2c65, 0x1,    0x2c66, 0x1,   0x2c7e, 0x1,   0x2c7f, 0x1,    0x2c6f, 0x1,   0x2c6d, | 
| 56 |         0x1,   0x2c70, 0x1,    0xa7ab, 0x1,   0xa7ac, 0x1,   0xa78d, 0x1,    0xa7aa, 0x1,   0xa7ae, | 
| 57 |         0x1,   0x2c62, 0x1,    0xa7ad, 0x1,   0x2c6e, 0x1,   0x2c64, 0x1,    0xa7c5, 0x1,   0xa7b1, | 
| 58 |         0x1,   0xa7b2, 0x1,    0xa7b0, 0x1,   0xab70, 0x1,   0xab71, 0x1,    0xab72, 0x1,   0xab73, | 
| 59 |         0x1,   0xab74, 0x1,    0xab75, 0x1,   0xab76, 0x1,   0xab77, 0x1,    0xab78, 0x1,   0xab79, | 
| 60 |         0x1,   0xab7a, 0x1,    0xab7b, 0x1,   0xab7c, 0x1,   0xab7d, 0x1,    0xab7e, 0x1,   0xab7f, | 
| 61 |         0x1,   0xab80, 0x1,    0xab81, 0x1,   0xab82, 0x1,   0xab83, 0x1,    0xab84, 0x1,   0xab85, | 
| 62 |         0x1,   0xab86, 0x1,    0xab87, 0x1,   0xab88, 0x1,   0xab89, 0x1,    0xab8a, 0x1,   0xab8b, | 
| 63 |         0x1,   0xab8c, 0x1,    0xab8d, 0x1,   0xab8e, 0x1,   0xab8f, 0x1,    0xab90, 0x1,   0xab91, | 
| 64 |         0x1,   0xab92, 0x1,    0xab93, 0x1,   0xab94, 0x1,   0xab95, 0x1,    0xab96, 0x1,   0xab97, | 
| 65 |         0x1,   0xab98, 0x1,    0xab99, 0x1,   0xab9a, 0x1,   0xab9b, 0x1,    0xab9c, 0x1,   0xab9d, | 
| 66 |         0x1,   0xab9e, 0x1,    0xab9f, 0x1,   0xaba0, 0x1,   0xaba1, 0x1,    0xaba2, 0x1,   0xaba3, | 
| 67 |         0x1,   0xaba4, 0x1,    0xaba5, 0x1,   0xaba6, 0x1,   0xaba7, 0x1,    0xaba8, 0x1,   0xaba9, | 
| 68 |         0x1,   0xabaa, 0x1,    0xabab, 0x1,   0xabac, 0x1,   0xabad, 0x1,    0xabae, 0x1,   0xabaf, | 
| 69 |         0x1,   0xabb0, 0x1,    0xabb1, 0x1,   0xabb2, 0x1,   0xabb3, 0x1,    0xabb4, 0x1,   0xabb5, | 
| 70 |         0x1,   0xabb6, 0x1,    0xabb7, 0x1,   0xabb8, 0x1,   0xabb9, 0x1,    0xabba, 0x1,   0xabbb, | 
| 71 |         0x1,   0xabbc, 0x1,    0xabbd, 0x1,   0xabbe, 0x1,   0xabbf, 0x1,    0xa64a, 0x1,   0xa77d, | 
| 72 |         0x1,   0xa7c6, 0x1,    0x6b,   0x1,   0xe5,   0x1,   0x26b,  0x1,    0x27d,  0x1,   0x23a, | 
| 73 |         0x1,   0x23e,  0x1,    0x251,  0x1,   0x271,  0x1,   0x250,  0x1,    0x252,  0x1,   0x23f, | 
| 74 |         0x1,   0x240,  0x1,    0x1d79, 0x1,   0x265,  0x1,   0x266,  0x1,    0x25c,  0x1,   0x261, | 
| 75 |         0x1,   0x26c,  0x1,    0x26a,  0x1,   0x29e,  0x1,   0x287,  0x1,    0x29d,  0x1,   0x282, | 
| 76 |         0x1,   0x1d8e, 0x1,    0x13a0, 0x1,   0x13a1, 0x1,   0x13a2, 0x1,    0x13a3, 0x1,   0x13a4, | 
| 77 |         0x1,   0x13a5, 0x1,    0x13a6, 0x1,   0x13a7, 0x1,   0x13a8, 0x1,    0x13a9, 0x1,   0x13aa, | 
| 78 |         0x1,   0x13ab, 0x1,    0x13ac, 0x1,   0x13ad, 0x1,   0x13ae, 0x1,    0x13af, 0x1,   0x13b0, | 
| 79 |         0x1,   0x13b1, 0x1,    0x13b2, 0x1,   0x13b3, 0x1,   0x13b4, 0x1,    0x13b5, 0x1,   0x13b6, | 
| 80 |         0x1,   0x13b7, 0x1,    0x13b8, 0x1,   0x13b9, 0x1,   0x13ba, 0x1,    0x13bb, 0x1,   0x13bc, | 
| 81 |         0x1,   0x13bd, 0x1,    0x13be, 0x1,   0x13bf, 0x1,   0x13c0, 0x1,    0x13c1, 0x1,   0x13c2, | 
| 82 |         0x1,   0x13c3, 0x1,    0x13c4, 0x1,   0x13c5, 0x1,   0x13c6, 0x1,    0x13c7, 0x1,   0x13c8, | 
| 83 |         0x1,   0x13c9, 0x1,    0x13ca, 0x1,   0x13cb, 0x1,   0x13cc, 0x1,    0x13cd, 0x1,   0x13ce, | 
| 84 |         0x1,   0x13cf, 0x1,    0x13d0, 0x1,   0x13d1, 0x1,   0x13d2, 0x1,    0x13d3, 0x1,   0x13d4, | 
| 85 |         0x1,   0x13d5, 0x1,    0x13d6, 0x1,   0x13d7, 0x1,   0x13d8, 0x1,    0x13d9, 0x1,   0x13da, | 
| 86 |         0x1,   0x13db, 0x1,    0x13dc, 0x1,   0x13dd, 0x1,   0x13de, 0x1,    0x13df, 0x1,   0x13e0, | 
| 87 |         0x1,   0x13e1, 0x1,    0x13e2, 0x1,   0x13e3, 0x1,   0x13e4, 0x1,    0x13e5, 0x1,   0x13e6, | 
| 88 |         0x1,   0x13e7, 0x1,    0x13e8, 0x1,   0x13e9, 0x1,   0x13ea, 0x1,    0x13eb, 0x1,   0x13ec, | 
| 89 |         0x1,   0x13ed, 0x1,    0x13ee, 0x1,   0x13ef, 0x2,   0x53,   0x73,   0x2,    0x53,  0x53, | 
| 90 |         0x2,   0x69,   0x307,  0x2,    0x46,  0x66,   0x2,   0x46,   0x46,   0x2,    0x46,  0x69, | 
| 91 |         0x2,   0x46,   0x49,   0x2,    0x46,  0x6c,   0x2,   0x46,   0x4c,   0x3,    0x46,  0x66, | 
| 92 |         0x69,  0x3,    0x46,   0x46,   0x49,  0x3,    0x46,  0x66,   0x6c,   0x3,    0x46,  0x46, | 
| 93 |         0x4c,  0x2,    0x53,   0x74,   0x2,   0x53,   0x54,  0x2,    0x535,  0x582,  0x2,   0x535, | 
| 94 |         0x552, 0x2,    0x544,  0x576,  0x2,   0x544,  0x546, 0x2,    0x544,  0x565,  0x2,   0x544, | 
| 95 |         0x535, 0x2,    0x544,  0x56b,  0x2,   0x544,  0x53b, 0x2,    0x54e,  0x576,  0x2,   0x54e, | 
| 96 |         0x546, 0x2,    0x544,  0x56d,  0x2,   0x544,  0x53d, 0x2,    0x2bc,  0x4e,   0x3,   0x399, | 
| 97 |         0x308, 0x301,  0x3,    0x3a5,  0x308, 0x301,  0x2,   0x4a,   0x30c,  0x2,    0x48,  0x331, | 
| 98 |         0x2,   0x54,   0x308,  0x2,    0x57,  0x30a,  0x2,   0x59,   0x30a,  0x2,    0x41,  0x2be, | 
| 99 |         0x2,   0x3a5,  0x313,  0x3,    0x3a5, 0x313,  0x300, 0x3,    0x3a5,  0x313,  0x301, 0x3, | 
| 100 |         0x3a5, 0x313,  0x342,  0x2,    0x391, 0x342,  0x2,   0x397,  0x342,  0x3,    0x399, 0x308, | 
| 101 |         0x300, 0x2,    0x399,  0x342,  0x3,   0x399,  0x308, 0x342,  0x3,    0x3a5,  0x308, 0x300, | 
| 102 |         0x2,   0x3a1,  0x313,  0x2,    0x3a5, 0x342,  0x3,   0x3a5,  0x308,  0x342,  0x2,   0x3a9, | 
| 103 |         0x342, 0x2,    0x1f08, 0x399,  0x2,   0x1f09, 0x399, 0x2,    0x1f0a, 0x399,  0x2,   0x1f0b, | 
| 104 |         0x399, 0x2,    0x1f0c, 0x399,  0x2,   0x1f0d, 0x399, 0x2,    0x1f0e, 0x399,  0x2,   0x1f0f, | 
| 105 |         0x399, 0x2,    0x1f28, 0x399,  0x2,   0x1f29, 0x399, 0x2,    0x1f2a, 0x399,  0x2,   0x1f2b, | 
| 106 |         0x399, 0x2,    0x1f2c, 0x399,  0x2,   0x1f2d, 0x399, 0x2,    0x1f2e, 0x399,  0x2,   0x1f2f, | 
| 107 |         0x399, 0x2,    0x1f68, 0x399,  0x2,   0x1f69, 0x399, 0x2,    0x1f6a, 0x399,  0x2,   0x1f6b, | 
| 108 |         0x399, 0x2,    0x1f6c, 0x399,  0x2,   0x1f6d, 0x399, 0x2,    0x1f6e, 0x399,  0x2,   0x1f6f, | 
| 109 |         0x399, 0x2,    0x391,  0x399,  0x2,   0x397,  0x399, 0x2,    0x3a9,  0x399,  0x2,   0x1fba, | 
| 110 |         0x345, 0x2,    0x1fba, 0x399,  0x2,   0x386,  0x345, 0x2,    0x386,  0x399,  0x2,   0x1fca, | 
| 111 |         0x345, 0x2,    0x1fca, 0x399,  0x2,   0x389,  0x345, 0x2,    0x389,  0x399,  0x2,   0x1ffa, | 
| 112 |         0x345, 0x2,    0x1ffa, 0x399,  0x2,   0x38f,  0x345, 0x2,    0x38f,  0x399,  0x3,   0x391, | 
| 113 |         0x342, 0x345,  0x3,    0x391,  0x342, 0x399,  0x3,   0x397,  0x342,  0x345,  0x3,   0x397, | 
| 114 |         0x342, 0x399,  0x3,    0x3a9,  0x342, 0x345,  0x3,   0x3a9,  0x342,  0x399,  0x1,   0xa64b | 
| 115 |     }; | 
| 116 | } | 
| 117 |  | 
| 118 | // Code imported from QChar | 
| 119 |  | 
| 120 | namespace QCharPrivate | 
| 121 | { | 
| 122 |     template<typename T> | 
| 123 |     Q_DECL_CONST_FUNCTION static inline T convertCase_helper(T uc, QUnicodeTables::Case which) noexcept | 
| 124 |     { | 
| 125 |         const auto fold = QUnicodeTables::properties(uc)->cases[which]; | 
| 126 |  | 
| 127 |         if (Q_UNLIKELY(fold.special)) { | 
| 128 |             const ushort *specialCase = QUnicodeTablesPrivate::specialCaseMap + fold.diff; | 
| 129 |             // so far, there are no special cases beyond BMP (guaranteed by the qunicodetables | 
| 130 |             // generator) | 
| 131 |             return *specialCase == 1 ? specialCase[1] : uc; | 
| 132 |         } | 
| 133 |  | 
| 134 |         return uc + fold.diff; | 
| 135 |     } | 
| 136 |  | 
| 137 |     [[maybe_unused]] static inline char32_t foldCase(char32_t ch, char32_t &last) noexcept | 
| 138 |     { | 
| 139 |         char32_t ucs4 = ch; | 
| 140 |         if (QChar::isLowSurrogate(ucs4) && QChar::isHighSurrogate(ucs4: last)) | 
| 141 |             ucs4 = QChar::surrogateToUcs4(high: last, low: ucs4); | 
| 142 |         last = ch; | 
| 143 |         return convertCase_helper(uc: ucs4, which: QUnicodeTables::CaseFold); | 
| 144 |     } | 
| 145 |  | 
| 146 |     static inline char16_t foldCase(char16_t ch) noexcept | 
| 147 |     { | 
| 148 |         return convertCase_helper(uc: ch, which: QUnicodeTables::CaseFold); | 
| 149 |     } | 
| 150 |  | 
| 151 |     static inline QChar foldCase(QChar ch) noexcept | 
| 152 |     { | 
| 153 |         return QChar(foldCase(ch: ch.unicode())); | 
| 154 |     } | 
| 155 | } | 
| 156 |  | 
| 157 | static int qt_compare_strings(QStringView lhs, QStringView rhs, Qt::CaseSensitivity cs) noexcept | 
| 158 | { | 
| 159 |     return lhs.compare(other: rhs, cs); | 
| 160 | } | 
| 161 |  | 
| 162 | static int qt_compare_strings(QStringView lhs, QLatin1String rhs, Qt::CaseSensitivity cs) noexcept | 
| 163 | { | 
| 164 |     return lhs.compare(s: rhs, cs); | 
| 165 | } | 
| 166 |  | 
| 167 | static QByteArray qt_convert_to_local_8bit(QStringView string) | 
| 168 | { | 
| 169 |     if (string.isNull()) | 
| 170 |         return QByteArray(); | 
| 171 |     QStringEncoder fromUtf16(QStringEncoder::System, QStringEncoder::Flag::Stateless); | 
| 172 |     return fromUtf16(string); | 
| 173 | } | 
| 174 |  | 
| 175 | static QByteArray qt_convert_to_utf8(QStringView str) | 
| 176 | { | 
| 177 |     if (str.isNull()) | 
| 178 |         return QByteArray(); | 
| 179 |  | 
| 180 |     return QUtf8::convertFromUnicode(in: str); | 
| 181 | } | 
| 182 |  | 
| 183 | static QList<uint> qt_convert_to_ucs4(QStringView string) | 
| 184 | { | 
| 185 |     QList<uint> v(string.size()); | 
| 186 |     uint *a = const_cast<uint*>(v.constData()); | 
| 187 |     QStringIterator it(string); | 
| 188 |     while (it.hasNext()) | 
| 189 |         *a++ = it.next(); | 
| 190 |     v.resize(size: a - v.constData()); | 
| 191 |     return v; | 
| 192 | } | 
| 193 |  | 
| 194 | /*! | 
| 195 |     \internal | 
| 196 |     \since 4.5 | 
| 197 | */ | 
| 198 | int QStringRef::compare_helper(const QChar *data1, qsizetype length1, const QChar *data2, qsizetype length2, | 
| 199 |                             Qt::CaseSensitivity cs) noexcept | 
| 200 | { | 
| 201 |     Q_ASSERT(length1 >= 0); | 
| 202 |     Q_ASSERT(length2 >= 0); | 
| 203 |     Q_ASSERT(data1 || length1 == 0); | 
| 204 |     Q_ASSERT(data2 || length2 == 0); | 
| 205 |     return qt_compare_strings(lhs: QStringView(data1, length1), rhs: QStringView(data2, length2), cs); | 
| 206 | } | 
| 207 |  | 
| 208 | /*! | 
| 209 |     \internal | 
| 210 |     \since 5.0 | 
| 211 | */ | 
| 212 | int QStringRef::compare_helper(const QChar *data1, qsizetype length1, const char *data2, qsizetype length2, | 
| 213 |                             Qt::CaseSensitivity cs) | 
| 214 | { | 
| 215 |     Q_ASSERT(length1 >= 0); | 
| 216 |     Q_ASSERT(data1 || length1 == 0); | 
| 217 |     if (!data2) | 
| 218 |         return length1; | 
| 219 |     if (Q_UNLIKELY(length2 < 0)) | 
| 220 |         length2 = qsizetype(strlen(s: data2)); | 
| 221 |     // ### make me nothrow in all cases | 
| 222 |     QVarLengthArray<ushort> s2(length2); | 
| 223 |     const auto beg = reinterpret_cast<QChar *>(s2.data()); | 
| 224 |     const auto end = QUtf8::convertToUnicode(buffer: beg, in: QByteArrayView(data2, length2)); | 
| 225 |     return qt_compare_strings(lhs: QStringView(data1, length1), rhs: QStringView(beg, end - beg), cs); | 
| 226 | } | 
| 227 |  | 
| 228 | /*! | 
| 229 |     \internal | 
| 230 |     \since 4.5 | 
| 231 | */ | 
| 232 | int QStringRef::compare_helper(const QChar *data1, qsizetype length1, QLatin1String s2, | 
| 233 |                             Qt::CaseSensitivity cs) noexcept | 
| 234 | { | 
| 235 |     Q_ASSERT(length1 >= 0); | 
| 236 |     Q_ASSERT(data1 || length1 == 0); | 
| 237 |     return qt_compare_strings(lhs: QStringView(data1, length1), rhs: s2, cs); | 
| 238 | } | 
| 239 |  | 
| 240 | namespace { | 
| 241 | template<class ResultList, class StringSource> | 
| 242 | static ResultList splitString(const StringSource &source, QStringView sep, | 
| 243 |                               Qt::SplitBehavior behavior, Qt::CaseSensitivity cs) | 
| 244 | { | 
| 245 |     ResultList list; | 
| 246 |     typename StringSource::size_type start = 0; | 
| 247 |     typename StringSource::size_type end; | 
| 248 |     typename StringSource::size_type  = 0; | 
| 249 |     while ((end = QtPrivate::findString(QStringView(source.constData(), source.size()), start + extra, sep, cs)) != -1) { | 
| 250 |         if (start != end || behavior == Qt::KeepEmptyParts) | 
| 251 |             list.append(source.mid(start, end - start)); | 
| 252 |         start = end + sep.size(); | 
| 253 |         extra = (sep.size() == 0 ? 1 : 0); | 
| 254 |     } | 
| 255 |     if (start != source.size() || behavior == Qt::KeepEmptyParts) | 
| 256 |         list.append(source.mid(start)); | 
| 257 |     return list; | 
| 258 | } | 
| 259 |  | 
| 260 | } // namespace | 
| 261 |  | 
| 262 | /*! | 
| 263 |     Splits the string into substrings references wherever \a sep occurs, and | 
| 264 |     returns the list of those strings. | 
| 265 |  | 
| 266 |     See QString::split() for how \a sep, \a behavior and \a cs interact to form | 
| 267 |     the result. | 
| 268 |  | 
| 269 |     \note All references are valid as long this string is alive. Destroying this | 
| 270 |     string will cause all references to be dangling pointers. | 
| 271 |  | 
| 272 |     \since 5.14 | 
| 273 | */ | 
| 274 | QList<QStringRef> QStringRef::split(const QString &sep, Qt::SplitBehavior behavior, Qt::CaseSensitivity cs) const | 
| 275 | { | 
| 276 |     return splitString<QList<QStringRef>>(source: *this, sep, behavior, cs); | 
| 277 | } | 
| 278 |  | 
| 279 | /*! | 
| 280 |     \overload | 
| 281 |     \since 5.14 | 
| 282 | */ | 
| 283 | QList<QStringRef> QStringRef::split(QChar sep, Qt::SplitBehavior behavior, Qt::CaseSensitivity cs) const | 
| 284 | { | 
| 285 |     return splitString<QList<QStringRef>>(source: *this, sep: QStringView(&sep, 1), behavior, cs); | 
| 286 | } | 
| 287 |  | 
| 288 | /*! | 
| 289 |     \class QStringRef | 
| 290 |     \inmodule QtCore5Compat | 
| 291 |     \since 4.3 | 
| 292 |     \brief The QStringRef class provides a thin wrapper around QString substrings. | 
| 293 |     \reentrant | 
| 294 |     \ingroup tools | 
| 295 |     \ingroup string-processing | 
| 296 |  | 
| 297 |     QStringRef provides a read-only subset of the QString API. | 
| 298 |  | 
| 299 |     A string reference explicitly references a portion of a string() | 
| 300 |     with a given size(), starting at a specific position(). Calling | 
| 301 |     toString() returns a copy of the data as a real QString instance. | 
| 302 |  | 
| 303 |     This class is designed to improve the performance of substring | 
| 304 |     handling when manipulating substrings obtained from existing QString | 
| 305 |     instances. QStringRef avoids the memory allocation and reference | 
| 306 |     counting overhead of a standard QString by simply referencing a | 
| 307 |     part of the original string. This can prove to be advantageous in | 
| 308 |     low level code, such as that used in a parser, at the expense of | 
| 309 |     potentially more complex code. | 
| 310 |  | 
| 311 |     For most users, there are no semantic benefits to using QStringRef | 
| 312 |     instead of QString since QStringRef requires attention to be paid | 
| 313 |     to memory management issues, potentially making code more complex | 
| 314 |     to write and maintain. | 
| 315 |  | 
| 316 |     \warning A QStringRef is only valid as long as the referenced | 
| 317 |     string exists. If the original string is deleted, the string | 
| 318 |     reference points to an invalid memory location. | 
| 319 |  | 
| 320 |     We suggest that you only use this class in stable code where profiling | 
| 321 |     has clearly identified that performance improvements can be made by | 
| 322 |     replacing standard string operations with the optimized substring | 
| 323 |     handling provided by this class. | 
| 324 |  | 
| 325 |     \sa {Implicitly Shared Classes} | 
| 326 | */ | 
| 327 |  | 
| 328 | /*! | 
| 329 |     \typedef QStringRef::size_type | 
| 330 |     \internal | 
| 331 | */ | 
| 332 |  | 
| 333 | /*! | 
| 334 |     \typedef QStringRef::value_type | 
| 335 |     \internal | 
| 336 | */ | 
| 337 |  | 
| 338 | /*! | 
| 339 |     \typedef QStringRef::const_pointer | 
| 340 |     \internal | 
| 341 | */ | 
| 342 |  | 
| 343 | /*! | 
| 344 |     \typedef QStringRef::const_reference | 
| 345 |     \internal | 
| 346 | */ | 
| 347 |  | 
| 348 | /*! | 
| 349 |     \typedef QStringRef::const_iterator | 
| 350 |     \since 5.4 | 
| 351 |  | 
| 352 |     \sa QStringRef::const_reverse_iterator | 
| 353 | */ | 
| 354 |  | 
| 355 | /*! | 
| 356 |     \typedef QStringRef::const_reverse_iterator | 
| 357 |     \since 5.7 | 
| 358 |  | 
| 359 |     \sa QStringRef::const_iterator | 
| 360 | */ | 
| 361 |  | 
| 362 | /*! | 
| 363 |  \fn QStringRef::QStringRef() | 
| 364 |  | 
| 365 |  Constructs an empty string reference. | 
| 366 | */ | 
| 367 |  | 
| 368 | /*! \fn QStringRef::QStringRef(const QString *string, int position, int length) | 
| 369 |  | 
| 370 | Constructs a string reference to the range of characters in the given | 
| 371 | \a string specified by the starting \a position and \a length in characters. | 
| 372 |  | 
| 373 | \warning This function exists to improve performance as much as possible, | 
| 374 | and performs no bounds checking. For program correctness, \a position and | 
| 375 | \a length must describe a valid substring of \a string. | 
| 376 |  | 
| 377 | This means that the starting \a position must be positive or 0 and smaller | 
| 378 | than \a string's length, and \a length must be positive or 0 but smaller than | 
| 379 | the string's length minus the starting \a position; | 
| 380 | i.e, 0 <= position < string->length() and | 
| 381 | 0 <= length <= string->length() - position must both be satisfied. | 
| 382 | */ | 
| 383 |  | 
| 384 | /*! \fn QStringRef::QStringRef(const QString *string) | 
| 385 |  | 
| 386 | Constructs a string reference to the given \a string. | 
| 387 | */ | 
| 388 |  | 
| 389 | /*! \fn QStringRef::QStringRef(const QStringRef &other) | 
| 390 |  | 
| 391 | Constructs a copy of the \a other string reference. | 
| 392 |  */ | 
| 393 | /*! | 
| 394 | \fn QStringRef::~QStringRef() | 
| 395 |  | 
| 396 | Destroys the string reference. | 
| 397 |  | 
| 398 | Since this class is only used to refer to string data, and does not take | 
| 399 | ownership of it, no memory is freed when instances are destroyed. | 
| 400 | */ | 
| 401 |  | 
| 402 | /*! | 
| 403 |     \fn int QStringRef::position() const | 
| 404 |  | 
| 405 |     Returns the starting position in the referenced string that is referred to | 
| 406 |     by the string reference. | 
| 407 |  | 
| 408 |     \sa size(), string() | 
| 409 | */ | 
| 410 |  | 
| 411 | /*! | 
| 412 |     \fn int QStringRef::size() const | 
| 413 |  | 
| 414 |     Returns the number of characters referred to by the string reference. | 
| 415 |     Equivalent to length() and count(). | 
| 416 |  | 
| 417 |     \sa position(), string() | 
| 418 | */ | 
| 419 | /*! | 
| 420 |     \fn int QStringRef::count() const | 
| 421 |     Returns the number of characters referred to by the string reference. | 
| 422 |     Equivalent to size() and length(). | 
| 423 |  | 
| 424 |     \sa position(), string() | 
| 425 | */ | 
| 426 | /*! | 
| 427 |     \fn int QStringRef::length() const | 
| 428 |     Returns the number of characters referred to by the string reference. | 
| 429 |     Equivalent to size() and count(). | 
| 430 |  | 
| 431 |     \sa position(), string() | 
| 432 | */ | 
| 433 |  | 
| 434 |  | 
| 435 | /*! | 
| 436 |     \fn bool QStringRef::isEmpty() const | 
| 437 |  | 
| 438 |     Returns \c true if the string reference has no characters; otherwise returns | 
| 439 |     \c false. | 
| 440 |  | 
| 441 |     A string reference is empty if its size is zero. | 
| 442 |  | 
| 443 |     \sa size() | 
| 444 | */ | 
| 445 |  | 
| 446 | /*! | 
| 447 |     \fn bool QStringRef::isNull() const | 
| 448 |  | 
| 449 |     Returns \c true if this string reference does not reference a string or if | 
| 450 |     the string it references is null (i.e. QString::isNull() is true). | 
| 451 |  | 
| 452 |     \sa size() | 
| 453 | */ | 
| 454 |  | 
| 455 | /*! | 
| 456 |     \fn const QString *QStringRef::string() const | 
| 457 |  | 
| 458 |     Returns a pointer to the string referred to by the string reference, or | 
| 459 |     0 if it does not reference a string. | 
| 460 |  | 
| 461 |     \sa unicode() | 
| 462 | */ | 
| 463 |  | 
| 464 |  | 
| 465 | /*! | 
| 466 |     \fn const QChar *QStringRef::unicode() const | 
| 467 |  | 
| 468 |     Returns a Unicode representation of the string reference. Since | 
| 469 |     the data stems directly from the referenced string, it is not | 
| 470 |     \\0'-terminated unless the string reference includes the string's | 
| 471 |     null terminator. | 
| 472 |  | 
| 473 |     \sa string() | 
| 474 | */ | 
| 475 |  | 
| 476 | /*! | 
| 477 |     \fn const QChar *QStringRef::data() const | 
| 478 |  | 
| 479 |     Same as unicode(). | 
| 480 | */ | 
| 481 |  | 
| 482 | /*! | 
| 483 |     \fn const QChar *QStringRef::constData() const | 
| 484 |  | 
| 485 |     Same as unicode(). | 
| 486 | */ | 
| 487 |  | 
| 488 | /*! | 
| 489 |     \fn QStringRef::const_iterator QStringRef::begin() const | 
| 490 |     \since 5.4 | 
| 491 |  | 
| 492 |     Returns a const \l{STL-style iterators}{STL-style iterator} pointing to the first character in | 
| 493 |     the string. | 
| 494 |  | 
| 495 |     \sa cbegin(), constBegin(), end(), constEnd(), rbegin(), rend() | 
| 496 | */ | 
| 497 |  | 
| 498 | /*! | 
| 499 |     \fn QStringRef::const_iterator QStringRef::cbegin() const | 
| 500 |     \since 5.4 | 
| 501 |  | 
| 502 |     Same as begin(). | 
| 503 |  | 
| 504 |     \sa begin(), constBegin(), cend(), constEnd(), rbegin(), rend() | 
| 505 | */ | 
| 506 |  | 
| 507 | /*! | 
| 508 |     \fn QStringRef::const_iterator QStringRef::constBegin() const | 
| 509 |     \since 5.9 | 
| 510 |  | 
| 511 |     Same as begin(). | 
| 512 |  | 
| 513 |     \sa begin(), cend(), constEnd(), rbegin(), rend() | 
| 514 | */ | 
| 515 |  | 
| 516 | /*! | 
| 517 |     \fn QStringRef::const_iterator QStringRef::end() const | 
| 518 |     \since 5.4 | 
| 519 |  | 
| 520 |     Returns a const \l{STL-style iterators}{STL-style iterator} pointing to the imaginary | 
| 521 |     character after the last character in the list. | 
| 522 |  | 
| 523 |     \sa cbegin(), constBegin(), end(), constEnd(), rbegin(), rend() | 
| 524 | */ | 
| 525 |  | 
| 526 | /*! \fn QStringRef::const_iterator QStringRef::cend() const | 
| 527 |     \since 5.4 | 
| 528 |  | 
| 529 |     Same as end(). | 
| 530 |  | 
| 531 |     \sa end(), constEnd(), cbegin(), constBegin(), rbegin(), rend() | 
| 532 | */ | 
| 533 |  | 
| 534 | /*! \fn QStringRef::const_iterator QStringRef::constEnd() const | 
| 535 |     \since 5.9 | 
| 536 |  | 
| 537 |     Same as end(). | 
| 538 |  | 
| 539 |     \sa end(), cend(), cbegin(), constBegin(), rbegin(), rend() | 
| 540 | */ | 
| 541 |  | 
| 542 | /*! | 
| 543 |     \fn QStringRef::const_reverse_iterator QStringRef::rbegin() const | 
| 544 |     \since 5.7 | 
| 545 |  | 
| 546 |     Returns a const \l{STL-style iterators}{STL-style} reverse iterator pointing to the first | 
| 547 |     character in the string, in reverse order. | 
| 548 |  | 
| 549 |     \sa begin(), crbegin(), rend() | 
| 550 | */ | 
| 551 |  | 
| 552 | /*! | 
| 553 |     \fn QStringRef::const_reverse_iterator QStringRef::crbegin() const | 
| 554 |     \since 5.7 | 
| 555 |  | 
| 556 |     Same as rbegin(). | 
| 557 |  | 
| 558 |     \sa begin(), rbegin(), rend() | 
| 559 | */ | 
| 560 |  | 
| 561 | /*! | 
| 562 |     \fn QStringRef::const_reverse_iterator QStringRef::rend() const | 
| 563 |     \since 5.7 | 
| 564 |  | 
| 565 |     Returns a \l{STL-style iterators}{STL-style} reverse iterator pointing to one past | 
| 566 |     the last character in the string, in reverse order. | 
| 567 |  | 
| 568 |     \sa end(), crend(), rbegin() | 
| 569 | */ | 
| 570 |  | 
| 571 |  | 
| 572 | /*! | 
| 573 |     \fn QStringRef::const_reverse_iterator QStringRef::crend() const | 
| 574 |     \since 5.7 | 
| 575 |  | 
| 576 |     Same as rend(). | 
| 577 |  | 
| 578 |     \sa end(), rend(), rbegin() | 
| 579 | */ | 
| 580 |  | 
| 581 | /*! | 
| 582 |     Returns a copy of the string reference as a QString object. | 
| 583 |  | 
| 584 |     If the string reference is not a complete reference of the string | 
| 585 |     (meaning that position() is 0 and size() equals string()->size()), | 
| 586 |     this function will allocate a new string to return. | 
| 587 |  | 
| 588 |     \sa string() | 
| 589 | */ | 
| 590 |  | 
| 591 | QString QStringRef::toString() const { | 
| 592 |     if (isNull()) | 
| 593 |         return QString(); | 
| 594 |     if (m_size && m_position == 0 && m_size == m_string->size()) | 
| 595 |         return *m_string; | 
| 596 |     return QString(m_string->unicode() + m_position, m_size); | 
| 597 | } | 
| 598 |  | 
| 599 |  | 
| 600 | /*! \relates QStringRef | 
| 601 |  | 
| 602 |    Returns \c true if string reference \a s1 is lexically equal to string reference \a s2; otherwise | 
| 603 |    returns \c false. | 
| 604 | */ | 
| 605 | bool operator==(const QStringRef &s1,const QStringRef &s2) noexcept | 
| 606 | { | 
| 607 |     return s1.size() == s2.size() && qt_compare_strings(lhs: s1, rhs: s2, cs: Qt::CaseSensitive) == 0; | 
| 608 | } | 
| 609 |  | 
| 610 | /*! \relates QStringRef | 
| 611 |  | 
| 612 |    Returns \c true if string \a s1 is lexically equal to string reference \a s2; otherwise | 
| 613 |    returns \c false. | 
| 614 | */ | 
| 615 | bool operator==(const QString &s1,const QStringRef &s2) noexcept | 
| 616 | { | 
| 617 |     return s1.size() == s2.size() && qt_compare_strings(lhs: s1, rhs: s2, cs: Qt::CaseSensitive) == 0; | 
| 618 | } | 
| 619 |  | 
| 620 | /*! \relates QStringRef | 
| 621 |  | 
| 622 |    Returns \c true if string  \a s1 is lexically equal to string reference \a s2; otherwise | 
| 623 |    returns \c false. | 
| 624 | */ | 
| 625 | bool operator==(QLatin1String s1, const QStringRef &s2) noexcept | 
| 626 | { | 
| 627 |     if (s1.size() != s2.size()) | 
| 628 |         return false; | 
| 629 |  | 
| 630 |     return qt_compare_strings(lhs: s2, rhs: s1, cs: Qt::CaseSensitive) == 0; | 
| 631 | } | 
| 632 |  | 
| 633 | /*! | 
| 634 |    \relates QStringRef | 
| 635 |  | 
| 636 |     Returns \c true if string reference \a s1 is lexically less than | 
| 637 |     string reference \a s2; otherwise returns \c false. | 
| 638 |  | 
| 639 |     \sa {Comparing Strings} | 
| 640 | */ | 
| 641 | bool operator<(const QStringRef &s1,const QStringRef &s2) noexcept | 
| 642 | { | 
| 643 |     return qt_compare_strings(lhs: s1, rhs: s2, cs: Qt::CaseSensitive) < 0; | 
| 644 | } | 
| 645 |  | 
| 646 | /*!\fn bool operator<=(const QStringRef &s1,const QStringRef &s2) | 
| 647 |  | 
| 648 |    \relates QStringRef | 
| 649 |  | 
| 650 |     Returns \c true if string reference \a s1 is lexically less than | 
| 651 |     or equal to string reference \a s2; otherwise returns \c false. | 
| 652 |  | 
| 653 |     \sa {Comparing Strings} | 
| 654 | */ | 
| 655 |  | 
| 656 | /*!\fn bool operator>=(const QStringRef &s1,const QStringRef &s2) | 
| 657 |  | 
| 658 |    \relates QStringRef | 
| 659 |  | 
| 660 |     Returns \c true if string reference \a s1 is lexically greater than | 
| 661 |     or equal to string reference \a s2; otherwise returns \c false. | 
| 662 |  | 
| 663 |     \sa {Comparing Strings} | 
| 664 | */ | 
| 665 |  | 
| 666 | /*!\fn bool operator>(const QStringRef &s1,const QStringRef &s2) | 
| 667 |  | 
| 668 |    \relates QStringRef | 
| 669 |  | 
| 670 |     Returns \c true if string reference \a s1 is lexically greater than | 
| 671 |     string reference \a s2; otherwise returns \c false. | 
| 672 |  | 
| 673 |     \sa {Comparing Strings} | 
| 674 | */ | 
| 675 |  | 
| 676 |  | 
| 677 | /*! | 
| 678 |     \fn const QChar QStringRef::at(int position) const | 
| 679 |  | 
| 680 |     Returns the character at the given index \a position in the | 
| 681 |     string reference. | 
| 682 |  | 
| 683 |     The \a position must be a valid index position in the string | 
| 684 |     (i.e., 0 <= \a position < size()). | 
| 685 | */ | 
| 686 |  | 
| 687 | /*! | 
| 688 |     \fn QChar QStringRef::operator[](int position) const | 
| 689 |     \since 5.7 | 
| 690 |  | 
| 691 |     Returns the character at the given index \a position in the | 
| 692 |     string reference. | 
| 693 |  | 
| 694 |     The \a position must be a valid index position in the string | 
| 695 |     reference (i.e., 0 <= \a position < size()). | 
| 696 |  | 
| 697 |     \sa at() | 
| 698 | */ | 
| 699 |  | 
| 700 | /*! | 
| 701 |     \fn QChar QStringRef::front() const | 
| 702 |     \since 5.10 | 
| 703 |  | 
| 704 |     Returns the first character in the string. | 
| 705 |     Same as \c{at(0)}. | 
| 706 |  | 
| 707 |     This function is provided for STL compatibility. | 
| 708 |  | 
| 709 |     \warning Calling this function on an empty string constitutes | 
| 710 |     undefined behavior. | 
| 711 |  | 
| 712 |     \sa back(), at(), operator[]() | 
| 713 | */ | 
| 714 |  | 
| 715 | /*! | 
| 716 |     \fn QChar QStringRef::back() const | 
| 717 |     \since 5.10 | 
| 718 |  | 
| 719 |     Returns the last character in the string. | 
| 720 |     Same as \c{at(size() - 1)}. | 
| 721 |  | 
| 722 |     This function is provided for STL compatibility. | 
| 723 |  | 
| 724 |     \warning Calling this function on an empty string constitutes | 
| 725 |     undefined behavior. | 
| 726 |  | 
| 727 |     \sa front(), at(), operator[]() | 
| 728 | */ | 
| 729 |  | 
| 730 | /*! | 
| 731 |     \fn void QStringRef::clear() | 
| 732 |  | 
| 733 |     Clears the contents of the string reference by making it null and empty. | 
| 734 |  | 
| 735 |     \sa isEmpty(), isNull() | 
| 736 | */ | 
| 737 |  | 
| 738 | /*! | 
| 739 |     \fn QStringRef &QStringRef::operator=(const QStringRef &other) | 
| 740 |  | 
| 741 |     Assigns the \a other string reference to this string reference, and | 
| 742 |     returns the result. | 
| 743 | */ | 
| 744 |  | 
| 745 | /*! | 
| 746 |     \fn QStringRef &QStringRef::operator=(const QString *string) | 
| 747 |  | 
| 748 |     Constructs a string reference to the given \a string and assigns it to | 
| 749 |     this string reference, returning the result. | 
| 750 | */ | 
| 751 |  | 
| 752 | /*! | 
| 753 |     \fn bool QStringRef::operator==(const char * s) const | 
| 754 |  | 
| 755 |     \overload operator==() | 
| 756 |  | 
| 757 |     The \a s byte array is converted to a QStringRef using the | 
| 758 |     fromUtf8() function. This function stops conversion at the | 
| 759 |     first NUL character found, or the end of the byte array. | 
| 760 |  | 
| 761 |     You can disable this operator by defining \c | 
| 762 |     QT_NO_CAST_FROM_ASCII when you compile your applications. This | 
| 763 |     can be useful if you want to ensure that all user-visible strings | 
| 764 |     go through QObject::tr(), for example. | 
| 765 |  | 
| 766 |     Returns \c true if this string is lexically equal to the parameter | 
| 767 |     string \a s. Otherwise returns \c false. | 
| 768 |  | 
| 769 |     \sa QT_NO_CAST_FROM_ASCII | 
| 770 | */ | 
| 771 |  | 
| 772 | /*! | 
| 773 |     \fn bool QStringRef::operator!=(const char * s) const | 
| 774 |  | 
| 775 |     \overload operator!=() | 
| 776 |  | 
| 777 |     The \a s const char pointer is converted to a QStringRef using | 
| 778 |     the fromUtf8() function. | 
| 779 |  | 
| 780 |     You can disable this operator by defining \c | 
| 781 |     QT_NO_CAST_FROM_ASCII when you compile your applications. This | 
| 782 |     can be useful if you want to ensure that all user-visible strings | 
| 783 |     go through QObject::tr(), for example. | 
| 784 |  | 
| 785 |     Returns \c true if this string is not lexically equal to the parameter | 
| 786 |     string \a s. Otherwise returns \c false. | 
| 787 |  | 
| 788 |     \sa QT_NO_CAST_FROM_ASCII | 
| 789 | */ | 
| 790 |  | 
| 791 | /*! | 
| 792 |     \fn bool QStringRef::operator<(const char * s) const | 
| 793 |  | 
| 794 |     \overload operator<() | 
| 795 |  | 
| 796 |     The \a s const char pointer is converted to a QStringRef using | 
| 797 |     the fromUtf8() function. | 
| 798 |  | 
| 799 |     You can disable this operator by defining \c | 
| 800 |     QT_NO_CAST_FROM_ASCII when you compile your applications. This | 
| 801 |     can be useful if you want to ensure that all user-visible strings | 
| 802 |     go through QObject::tr(), for example. | 
| 803 |  | 
| 804 |     Returns \c true if this string is lexically smaller than the parameter | 
| 805 |     string \a s. Otherwise returns \c false. | 
| 806 |  | 
| 807 |     \sa QT_NO_CAST_FROM_ASCII | 
| 808 | */ | 
| 809 |  | 
| 810 | /*! | 
| 811 |     \fn bool QStringRef::operator<=(const char * s) const | 
| 812 |  | 
| 813 |     \overload operator<=() | 
| 814 |  | 
| 815 |     The \a s const char pointer is converted to a QStringRef using | 
| 816 |     the fromUtf8() function. | 
| 817 |  | 
| 818 |     You can disable this operator by defining \c | 
| 819 |     QT_NO_CAST_FROM_ASCII when you compile your applications. This | 
| 820 |     can be useful if you want to ensure that all user-visible strings | 
| 821 |     go through QObject::tr(), for example. | 
| 822 |  | 
| 823 |     Returns \c true if this string is lexically smaller than or equal to the parameter | 
| 824 |     string \a s. Otherwise returns \c false. | 
| 825 |  | 
| 826 |     \sa QT_NO_CAST_FROM_ASCII | 
| 827 | */ | 
| 828 |  | 
| 829 | /*! | 
| 830 |     \fn bool QStringRef::operator>(const char * s) const | 
| 831 |  | 
| 832 |  | 
| 833 |     \overload operator>() | 
| 834 |  | 
| 835 |     The \a s const char pointer is converted to a QStringRef using | 
| 836 |     the fromUtf8() function. | 
| 837 |  | 
| 838 |     You can disable this operator by defining \c | 
| 839 |     QT_NO_CAST_FROM_ASCII when you compile your applications. This | 
| 840 |     can be useful if you want to ensure that all user-visible strings | 
| 841 |     go through QObject::tr(), for example. | 
| 842 |  | 
| 843 |     Returns \c true if this string is lexically greater than the parameter | 
| 844 |     string \a s. Otherwise returns \c false. | 
| 845 |  | 
| 846 |     \sa QT_NO_CAST_FROM_ASCII | 
| 847 | */ | 
| 848 |  | 
| 849 | /*! | 
| 850 |     \fn bool QStringRef::operator>= (const char * s) const | 
| 851 |  | 
| 852 |     \overload operator>=() | 
| 853 |  | 
| 854 |     The \a s const char pointer is converted to a QStringRef using | 
| 855 |     the fromUtf8() function. | 
| 856 |  | 
| 857 |     You can disable this operator by defining \c | 
| 858 |     QT_NO_CAST_FROM_ASCII when you compile your applications. This | 
| 859 |     can be useful if you want to ensure that all user-visible strings | 
| 860 |     go through QObject::tr(), for example. | 
| 861 |  | 
| 862 |     Returns \c true if this string is lexically greater than or equal to the | 
| 863 |     parameter string \a s. Otherwise returns \c false. | 
| 864 |  | 
| 865 |     \sa QT_NO_CAST_FROM_ASCII | 
| 866 | */ | 
| 867 |  | 
| 868 | /*!  Appends the string reference to \a string, and returns a new | 
| 869 | reference to the combined string data. | 
| 870 |  */ | 
| 871 | QStringRef QStringRef::appendTo(QString *string) const | 
| 872 | { | 
| 873 |     if (!string) | 
| 874 |         return QStringRef(); | 
| 875 |     int pos = string->size(); | 
| 876 |     string->insert(i: pos, uc: unicode(), len: size()); | 
| 877 |     return QStringRef(string, pos, size()); | 
| 878 | } | 
| 879 |  | 
| 880 | /*! | 
| 881 |     \fn int QStringRef::compare(const QStringRef &s1, const QString &s2, Qt::CaseSensitivity cs = Qt::CaseSensitive) | 
| 882 |     \since 4.5 | 
| 883 |  | 
| 884 |     Compares \a s1 with \a s2 and returns a negative | 
| 885 |     integer if \a s1 is less than \a s2, a positive integer if it is greater | 
| 886 |     than \a s2, and zero if they are equal. | 
| 887 |  | 
| 888 |     If \a cs is Qt::CaseSensitive, the comparison is case sensitive; | 
| 889 |     otherwise the comparison is case insensitive. | 
| 890 | */ | 
| 891 |  | 
| 892 | /*! | 
| 893 |     \fn int QStringRef::compare(const QStringRef &s1, const QStringRef &s2, Qt::CaseSensitivity cs = Qt::CaseSensitive) | 
| 894 |     \since 4.5 | 
| 895 |     \overload | 
| 896 |  | 
| 897 |     Compares \a s1 with \a s2 and returns a negative | 
| 898 |     integer if \a s1 is less than \a s2, a positive integer if it is greater | 
| 899 |     than \a s2, and zero if they are equal. | 
| 900 |  | 
| 901 |     If \a cs is Qt::CaseSensitive, the comparison is case sensitive; | 
| 902 |     otherwise the comparison is case insensitive. | 
| 903 | */ | 
| 904 |  | 
| 905 | /*! | 
| 906 |     \fn int QStringRef::compare(const QStringRef &s1, QLatin1String s2, Qt::CaseSensitivity cs = Qt::CaseSensitive) | 
| 907 |     \since 4.5 | 
| 908 |     \overload | 
| 909 |  | 
| 910 |     Compares \a s1 with \a s2 and returns a negative | 
| 911 |     integer if \a s1 is less than \a s2, a positive integer if it is greater | 
| 912 |     than \a s2, and zero if they are equal. | 
| 913 |  | 
| 914 |     If \a cs is Qt::CaseSensitive, the comparison is case sensitive; | 
| 915 |     otherwise the comparison is case insensitive. | 
| 916 | */ | 
| 917 |  | 
| 918 | /*! | 
| 919 |     \overload | 
| 920 |     \fn int QStringRef::compare(const QString &other, Qt::CaseSensitivity cs = Qt::CaseSensitive) const | 
| 921 |     \since 4.5 | 
| 922 |  | 
| 923 |     Compares \c {*this} with \a other and returns a negative integer if | 
| 924 |     \c {*this} is less than \a other, a positive integer if it is greater | 
| 925 |     than \a other, and zero if they are equal. | 
| 926 |  | 
| 927 |     If \a cs is Qt::CaseSensitive, the comparison is case sensitive; | 
| 928 |     otherwise the comparison is case insensitive. | 
| 929 |  | 
| 930 |     Equivalent to \c {compare(*this, other, cs)}. | 
| 931 | */ | 
| 932 |  | 
| 933 | /*! | 
| 934 |     \overload | 
| 935 |     \fn int QStringRef::compare(const QStringRef &other, Qt::CaseSensitivity cs = Qt::CaseSensitive) const | 
| 936 |     \since 4.5 | 
| 937 |  | 
| 938 |     Compares \c {*this} with \a other and returns a negative integer if | 
| 939 |     \c {*this} is less than \a other, a positive integer if it is greater | 
| 940 |     than \a other, and zero if they are equal. | 
| 941 |  | 
| 942 |     If \a cs is Qt::CaseSensitive, the comparison is case sensitive; | 
| 943 |     otherwise the comparison is case insensitive. | 
| 944 |  | 
| 945 |     Equivalent to \c {compare(*this, other, cs)}. | 
| 946 | */ | 
| 947 |  | 
| 948 | /*! | 
| 949 |     \overload | 
| 950 |     \fn int QStringRef::compare(QChar ch, Qt::CaseSensitivity cs = Qt::CaseSensitive) const | 
| 951 |     \since 5.14 | 
| 952 |  | 
| 953 |     Compares \c {*this} with \a ch and returns a negative integer if \c {*this} | 
| 954 |     is less than \a ch, a positive integer if it is greater than \a ch, and zero | 
| 955 |     if they are equal. Here, \a ch interpreted as a string of length one. | 
| 956 |  | 
| 957 |     If \a cs is Qt::CaseSensitive, the comparison is case sensitive; | 
| 958 |     otherwise the comparison is case insensitive. | 
| 959 | */ | 
| 960 |  | 
| 961 | /*! | 
| 962 |     \overload | 
| 963 |     \fn int QStringRef::compare(QLatin1String other, Qt::CaseSensitivity cs = Qt::CaseSensitive) const | 
| 964 |     \since 4.5 | 
| 965 |  | 
| 966 |     Compares \c {*this} with \a other and returns a negative integer if \c {*this} | 
| 967 |     is less than \a other, a positive integer if it is greater than \a other, and | 
| 968 |     zero if they are equal. | 
| 969 |  | 
| 970 |     If \a cs is Qt::CaseSensitive, the comparison is case sensitive; | 
| 971 |     otherwise the comparison is case insensitive. | 
| 972 |  | 
| 973 |     Equivalent to \c {compare(*this, other, cs)}. | 
| 974 | */ | 
| 975 |  | 
| 976 | /*! | 
| 977 |     \overload | 
| 978 |     \fn int QStringRef::compare(const QByteArray &other, Qt::CaseSensitivity cs = Qt::CaseSensitive) const | 
| 979 |     \since 5.8 | 
| 980 |  | 
| 981 |     Compares \c {*this} with \a other and returns a negative integer if \c {*this} | 
| 982 |     is less than \a other, a positive integer if it is greater than \a other, and | 
| 983 |      zero if they are equal. The contents of \a other is interpreted as UTF-8. | 
| 984 |  | 
| 985 |     If \a cs is Qt::CaseSensitive, the comparison is case sensitive; | 
| 986 |     otherwise the comparison is case insensitive. | 
| 987 |  | 
| 988 |     Equivalent to \c {compare(*this, other, cs)}. | 
| 989 | */ | 
| 990 |  | 
| 991 | /*! | 
| 992 |     \fn int QStringRef::localeAwareCompare(const QStringRef &s1, const QString & s2) | 
| 993 |     \since 4.5 | 
| 994 |  | 
| 995 |     Compares \a s1 with \a s2 and returns a negative | 
| 996 |     integer if \a s1 is less than \a s2, a positive integer if it is greater | 
| 997 |     than \a s2, and zero if they are equal. | 
| 998 |  | 
| 999 |     The comparison is performed in a locale- and also | 
| 1000 |     platform-dependent manner. Use this function to present sorted | 
| 1001 |     lists of strings to the user. | 
| 1002 |  | 
| 1003 |     \sa compare(), QLocale, {Comparing Strings} | 
| 1004 | */ | 
| 1005 |  | 
| 1006 | /*! | 
| 1007 |     \fn int QStringRef::localeAwareCompare(const QStringRef &s1, const QStringRef & s2) | 
| 1008 |     \since 4.5 | 
| 1009 |     \overload | 
| 1010 |  | 
| 1011 |     Compares \a s1 with \a s2 and returns a negative | 
| 1012 |     integer if \a s1 is less than \a s2, a positive integer if it is greater | 
| 1013 |     than \a s2, and zero if they are equal. | 
| 1014 |  | 
| 1015 |     The comparison is performed in a locale- and also | 
| 1016 |     platform-dependent manner. Use this function to present sorted | 
| 1017 |     lists of strings to the user. | 
| 1018 |  | 
| 1019 |     \sa {Comparing Strings} | 
| 1020 | */ | 
| 1021 |  | 
| 1022 | /*! | 
| 1023 |     \fn int QStringRef::localeAwareCompare(const QString &other) const | 
| 1024 |     \since 4.5 | 
| 1025 |     \overload | 
| 1026 |  | 
| 1027 |     Compares \c {*this} with \a other and returns a negative integer if \c {*this} | 
| 1028 |     is less than \a other, a positive integer if it is greater than \a other, and | 
| 1029 |     zero if they are equal. | 
| 1030 |  | 
| 1031 |     The comparison is performed in a locale- and also | 
| 1032 |     platform-dependent manner. Use this function to present sorted | 
| 1033 |     lists of strings to the user. | 
| 1034 |  | 
| 1035 |     \sa {Comparing Strings} | 
| 1036 | */ | 
| 1037 |  | 
| 1038 | /*! | 
| 1039 |     \fn int QStringRef::localeAwareCompare(const QStringRef &other) const | 
| 1040 |     \since 4.5 | 
| 1041 |     \overload | 
| 1042 |  | 
| 1043 |     Compares \c {*this} with \a other and returns a negative integer if \c {*this} | 
| 1044 |     is less than \a other, a positive integer if it is greater than \a other, and | 
| 1045 |     zero if they are equal. | 
| 1046 |  | 
| 1047 |     The comparison is performed in a locale- and also | 
| 1048 |     platform-dependent manner. Use this function to present sorted | 
| 1049 |     lists of strings to the user. | 
| 1050 |  | 
| 1051 |     \sa {Comparing Strings} | 
| 1052 | */ | 
| 1053 |  | 
| 1054 | /*! | 
| 1055 |     \fn QStringRef::left(int n) const | 
| 1056 |     \since 5.2 | 
| 1057 |  | 
| 1058 |     Returns a substring reference to the \a n leftmost characters | 
| 1059 |     of the string. | 
| 1060 |  | 
| 1061 |     If \a n is greater than or equal to size(), or less than zero, | 
| 1062 |     a reference to the entire string is returned. | 
| 1063 |  | 
| 1064 |     \sa right(), mid(), startsWith(), chopped(), chop(), truncate() | 
| 1065 | */ | 
| 1066 | QStringRef QStringRef::left(int n) const | 
| 1067 | { | 
| 1068 |     if (size_t(n) >= size_t(m_size)) | 
| 1069 |         return *this; | 
| 1070 |     return QStringRef(m_string, m_position, n); | 
| 1071 | } | 
| 1072 |  | 
| 1073 | /*! | 
| 1074 |     \fn QStringRef::right(int n) const | 
| 1075 |     \since 5.2 | 
| 1076 |  | 
| 1077 |     Returns a substring reference to the \a n rightmost characters | 
| 1078 |     of the string. | 
| 1079 |  | 
| 1080 |     If \a n is greater than or equal to size(), or less than zero, | 
| 1081 |     a reference to the entire string is returned. | 
| 1082 |  | 
| 1083 |     \sa left(), mid(), endsWith(), chopped(), chop(), truncate() | 
| 1084 | */ | 
| 1085 | QStringRef QStringRef::right(int n) const | 
| 1086 | { | 
| 1087 |     if (size_t(n) >= size_t(m_size)) | 
| 1088 |         return *this; | 
| 1089 |     return QStringRef(m_string, m_size - n + m_position, n); | 
| 1090 | } | 
| 1091 |  | 
| 1092 | /*! | 
| 1093 |     \fn QStringRef QStringRef::mid(int position, int n = -1) const | 
| 1094 |     \since 5.2 | 
| 1095 |  | 
| 1096 |     Returns a substring reference to \a n characters of this string, | 
| 1097 |     starting at the specified \a position. | 
| 1098 |  | 
| 1099 |     If the \a position exceeds the length of the string, a null | 
| 1100 |     reference is returned. | 
| 1101 |  | 
| 1102 |     If there are less than \a n characters available in the string, | 
| 1103 |     starting at the given \a position, or if \a n is -1 (default), the | 
| 1104 |     function returns all characters from the specified \a position | 
| 1105 |     onwards. | 
| 1106 |  | 
| 1107 |     \sa left(), right(), chopped(), chop(), truncate() | 
| 1108 | */ | 
| 1109 | QStringRef QStringRef::mid(int pos, int n) const | 
| 1110 | { | 
| 1111 |     qsizetype p = pos; | 
| 1112 |     qsizetype l = n; | 
| 1113 |     using namespace QtPrivate; | 
| 1114 |     switch (QContainerImplHelper::mid(originalLength: m_size, position: &p, length: &l)) { | 
| 1115 |     case QContainerImplHelper::Null: | 
| 1116 |         return QStringRef(); | 
| 1117 |     case QContainerImplHelper::Empty: | 
| 1118 |         return QStringRef(m_string, 0, 0); | 
| 1119 |     case QContainerImplHelper::Full: | 
| 1120 |         return *this; | 
| 1121 |     case QContainerImplHelper::Subset: | 
| 1122 |         return QStringRef(m_string, p + m_position, l); | 
| 1123 |     } | 
| 1124 |     Q_UNREACHABLE_RETURN(QStringRef()); | 
| 1125 | } | 
| 1126 |  | 
| 1127 | /*! | 
| 1128 |     \fn QStringRef QStringRef::chopped(int len) const | 
| 1129 |     \since 5.10 | 
| 1130 |  | 
| 1131 |     Returns a substring reference to the size() - \a len leftmost characters | 
| 1132 |     of this string. | 
| 1133 |  | 
| 1134 |     \note The behavior is undefined if \a len is negative or greater than size(). | 
| 1135 |  | 
| 1136 |     \sa endsWith(), left(), right(), mid(), chop(), truncate() | 
| 1137 | */ | 
| 1138 |  | 
| 1139 | /*! | 
| 1140 |     \fn void QStringRef::truncate(int position) | 
| 1141 |     \since 5.6 | 
| 1142 |  | 
| 1143 |     Truncates the string at the given \a position index. | 
| 1144 |  | 
| 1145 |     If the specified \a position index is beyond the end of the | 
| 1146 |     string, nothing happens. | 
| 1147 |  | 
| 1148 |     If \a position is negative, it is equivalent to passing zero. | 
| 1149 |  | 
| 1150 |     \sa QString::truncate() | 
| 1151 | */ | 
| 1152 |  | 
| 1153 | /*! | 
| 1154 |     \fn void QStringRef::chop(int n) | 
| 1155 |     \since 5.8 | 
| 1156 |  | 
| 1157 |     Removes \a n characters from the end of the string. | 
| 1158 |  | 
| 1159 |     If \a n is greater than or equal to size(), the result is an | 
| 1160 |     empty string; if \a n is negative, it is equivalent to passing zero. | 
| 1161 |  | 
| 1162 |     \sa QString::chop(), truncate() | 
| 1163 | */ | 
| 1164 |  | 
| 1165 | /*! | 
| 1166 |   \since 4.8 | 
| 1167 |  | 
| 1168 |   Returns the index position of the first occurrence of the string \a | 
| 1169 |   str in this string reference, searching forward from index position | 
| 1170 |   \a from. Returns -1 if \a str is not found. | 
| 1171 |  | 
| 1172 |   If \a cs is Qt::CaseSensitive (default), the search is case | 
| 1173 |   sensitive; otherwise the search is case insensitive. | 
| 1174 |  | 
| 1175 |   If \a from is -1, the search starts at the last character; if it is | 
| 1176 |   -2, at the next to last character and so on. | 
| 1177 |  | 
| 1178 |   \sa QString::indexOf(), lastIndexOf(), contains(), count() | 
| 1179 | */ | 
| 1180 | int QStringRef::indexOf(const QString &str, int from, Qt::CaseSensitivity cs) const | 
| 1181 | { | 
| 1182 |     // ### Qt6: qsizetype | 
| 1183 |     return int(QtPrivate::findString(haystack: QStringView(unicode(), length()), from, needle: QStringView(str.unicode(), str.size()), cs)); | 
| 1184 | } | 
| 1185 |  | 
| 1186 | /*! | 
| 1187 |     \fn int QStringRef::indexOf(QStringView str, int from, Qt::CaseSensitivity cs) const | 
| 1188 |     \since 5.14 | 
| 1189 |     \overload indexOf() | 
| 1190 |  | 
| 1191 |     Returns the index position of the first occurrence of the string view \a str | 
| 1192 |     in this string reference, searching forward from index position \a from. | 
| 1193 |     Returns -1 if \a str is not found. | 
| 1194 |  | 
| 1195 |     If \a cs is Qt::CaseSensitive (default), the search is case | 
| 1196 |     sensitive; otherwise the search is case insensitive. | 
| 1197 |  | 
| 1198 |     If \a from is -1, the search starts at the last character; if it is | 
| 1199 |     -2, at the next to last character and so on. | 
| 1200 |  | 
| 1201 |     \sa QString::indexOf(), QStringView::indexOf(), lastIndexOf(), contains(), count() | 
| 1202 | */ | 
| 1203 |  | 
| 1204 | /*! | 
| 1205 |     \since 4.8 | 
| 1206 |     \overload indexOf() | 
| 1207 |  | 
| 1208 |     Returns the index position of the first occurrence of the | 
| 1209 |     character \a ch in the string reference, searching forward from | 
| 1210 |     index position \a from. Returns -1 if \a ch could not be found. | 
| 1211 |  | 
| 1212 |     \sa QString::indexOf(), lastIndexOf(), contains(), count() | 
| 1213 | */ | 
| 1214 | int QStringRef::indexOf(QChar ch, int from, Qt::CaseSensitivity cs) const | 
| 1215 | { | 
| 1216 |     // ### Qt6: qsizetype | 
| 1217 |     return int(qFindChar(str: QStringView(unicode(), length()), ch, from, cs)); | 
| 1218 | } | 
| 1219 |  | 
| 1220 | /*! | 
| 1221 |   \since 4.8 | 
| 1222 |  | 
| 1223 |   Returns the index position of the first occurrence of the string \a | 
| 1224 |   str in this string reference, searching forward from index position | 
| 1225 |   \a from. Returns -1 if \a str is not found. | 
| 1226 |  | 
| 1227 |   If \a cs is Qt::CaseSensitive (default), the search is case | 
| 1228 |   sensitive; otherwise the search is case insensitive. | 
| 1229 |  | 
| 1230 |   If \a from is -1, the search starts at the last character; if it is | 
| 1231 |   -2, at the next to last character and so on. | 
| 1232 |  | 
| 1233 |   \sa QString::indexOf(), lastIndexOf(), contains(), count() | 
| 1234 | */ | 
| 1235 | int QStringRef::indexOf(QLatin1String str, int from, Qt::CaseSensitivity cs) const | 
| 1236 | { | 
| 1237 |     // ### Qt6: qsizetype | 
| 1238 |     return int(QtPrivate::findString(haystack: QStringView(unicode(), size()), from, needle: str, cs)); | 
| 1239 | } | 
| 1240 |  | 
| 1241 | /*! | 
| 1242 |     \since 4.8 | 
| 1243 |  | 
| 1244 |     \overload indexOf() | 
| 1245 |  | 
| 1246 |     Returns the index position of the first occurrence of the string | 
| 1247 |     reference \a str in this string reference, searching forward from | 
| 1248 |     index position \a from. Returns -1 if \a str is not found. | 
| 1249 |  | 
| 1250 |     If \a cs is Qt::CaseSensitive (default), the search is case | 
| 1251 |     sensitive; otherwise the search is case insensitive. | 
| 1252 |  | 
| 1253 |     \sa QString::indexOf(), lastIndexOf(), contains(), count() | 
| 1254 | */ | 
| 1255 | int QStringRef::indexOf(const QStringRef &str, int from, Qt::CaseSensitivity cs) const | 
| 1256 | { | 
| 1257 |     // ### Qt6: qsizetype | 
| 1258 |     return int(QtPrivate::findString(haystack: QStringView(unicode(), size()), from, needle: QStringView(str.unicode(), str.size()), cs)); | 
| 1259 | } | 
| 1260 |  | 
| 1261 | /*! | 
| 1262 |   \since 4.8 | 
| 1263 |  | 
| 1264 |   Returns the index position of the last occurrence of the string \a | 
| 1265 |   str in this string reference, searching backward from index position | 
| 1266 |   \a from. If \a from is -1 (default), the search starts at the last | 
| 1267 |   character; if \a from is -2, at the next to last character and so | 
| 1268 |   on. Returns -1 if \a str is not found. | 
| 1269 |  | 
| 1270 |   If \a cs is Qt::CaseSensitive (default), the search is case | 
| 1271 |   sensitive; otherwise the search is case insensitive. | 
| 1272 |  | 
| 1273 |   \sa QString::lastIndexOf(), indexOf(), contains(), count() | 
| 1274 | */ | 
| 1275 | int QStringRef::lastIndexOf(const QString &str, int from, Qt::CaseSensitivity cs) const | 
| 1276 | { | 
| 1277 |     // ### Qt6: qsizetype | 
| 1278 |     return int(QtPrivate::lastIndexOf(haystack: *this, from, needle: str, cs)); | 
| 1279 | } | 
| 1280 |  | 
| 1281 | /*! | 
| 1282 |   \since 4.8 | 
| 1283 |   \overload lastIndexOf() | 
| 1284 |  | 
| 1285 |   Returns the index position of the last occurrence of the character | 
| 1286 |   \a ch, searching backward from position \a from. | 
| 1287 |  | 
| 1288 |   \sa QString::lastIndexOf(), indexOf(), contains(), count() | 
| 1289 | */ | 
| 1290 | int QStringRef::lastIndexOf(QChar ch, int from, Qt::CaseSensitivity cs) const | 
| 1291 | { | 
| 1292 |     // ### Qt6: qsizetype | 
| 1293 |     return int(QStringView{ *this }.lastIndexOf(c: ch, from, cs)); | 
| 1294 | } | 
| 1295 |  | 
| 1296 | /*! | 
| 1297 |   \since 4.8 | 
| 1298 |   \overload lastIndexOf() | 
| 1299 |  | 
| 1300 |   Returns the index position of the last occurrence of the string \a | 
| 1301 |   str in this string reference, searching backward from index position | 
| 1302 |   \a from. If \a from is -1 (default), the search starts at the last | 
| 1303 |   character; if \a from is -2, at the next to last character and so | 
| 1304 |   on. Returns -1 if \a str is not found. | 
| 1305 |  | 
| 1306 |   If \a cs is Qt::CaseSensitive (default), the search is case | 
| 1307 |   sensitive; otherwise the search is case insensitive. | 
| 1308 |  | 
| 1309 |   \sa QString::lastIndexOf(), indexOf(), contains(), count() | 
| 1310 | */ | 
| 1311 | int QStringRef::lastIndexOf(QLatin1String str, int from, Qt::CaseSensitivity cs) const | 
| 1312 | { | 
| 1313 |     // ### Qt6: qsizetype | 
| 1314 |     return int(QtPrivate::lastIndexOf(haystack: *this, from, needle: str, cs)); | 
| 1315 | } | 
| 1316 |  | 
| 1317 | /*! | 
| 1318 |   \since 4.8 | 
| 1319 |   \overload lastIndexOf() | 
| 1320 |  | 
| 1321 |   Returns the index position of the last occurrence of the string | 
| 1322 |   reference \a str in this string reference, searching backward from | 
| 1323 |   index position \a from. If \a from is -1 (default), the search | 
| 1324 |   starts at the last character; if \a from is -2, at the next to last | 
| 1325 |   character and so on. Returns -1 if \a str is not found. | 
| 1326 |  | 
| 1327 |   If \a cs is Qt::CaseSensitive (default), the search is case | 
| 1328 |   sensitive; otherwise the search is case insensitive. | 
| 1329 |  | 
| 1330 |   \sa QString::lastIndexOf(), indexOf(), contains(), count() | 
| 1331 | */ | 
| 1332 | int QStringRef::lastIndexOf(const QStringRef &str, int from, Qt::CaseSensitivity cs) const | 
| 1333 | { | 
| 1334 |     // ### Qt6: qsizetype | 
| 1335 |     return int(QtPrivate::lastIndexOf(haystack: *this, from, needle: str, cs)); | 
| 1336 | } | 
| 1337 |  | 
| 1338 | /*! | 
| 1339 |   \fn int QStringRef::lastIndexOf(QStringView str, int from, Qt::CaseSensitivity cs) const | 
| 1340 |   \since 5.14 | 
| 1341 |   \overload lastIndexOf() | 
| 1342 |  | 
| 1343 |   Returns the index position of the last occurrence of the string view \a | 
| 1344 |   str in this string, searching backward from index position \a | 
| 1345 |   from. If \a from is -1 (default), the search starts at the last | 
| 1346 |   character; if \a from is -2, at the next to last character and so | 
| 1347 |   on. Returns -1 if \a str is not found. | 
| 1348 |  | 
| 1349 |   If \a cs is Qt::CaseSensitive (default), the search is case | 
| 1350 |   sensitive; otherwise the search is case insensitive. | 
| 1351 |  | 
| 1352 |   \sa indexOf(), contains(), count() | 
| 1353 | */ | 
| 1354 |  | 
| 1355 | /*! | 
| 1356 |     \since 4.8 | 
| 1357 |     Returns the number of (potentially overlapping) occurrences of | 
| 1358 |     the string \a str in this string reference. | 
| 1359 |  | 
| 1360 |     If \a cs is Qt::CaseSensitive (default), the search is | 
| 1361 |     case sensitive; otherwise the search is case insensitive. | 
| 1362 |  | 
| 1363 |     \sa QString::count(), contains(), indexOf() | 
| 1364 | */ | 
| 1365 | int QStringRef::count(const QString &str, Qt::CaseSensitivity cs) const | 
| 1366 | { | 
| 1367 |     // ### Qt6: qsizetype | 
| 1368 |     return int(QtPrivate::count(haystack: QStringView(unicode(), size()), needle: QStringView(str.unicode(), str.size()), cs)); | 
| 1369 | } | 
| 1370 |  | 
| 1371 | /*! | 
| 1372 |     \since 4.8 | 
| 1373 |     \overload count() | 
| 1374 |  | 
| 1375 |     Returns the number of occurrences of the character \a ch in the | 
| 1376 |     string reference. | 
| 1377 |  | 
| 1378 |     If \a cs is Qt::CaseSensitive (default), the search is | 
| 1379 |     case sensitive; otherwise the search is case insensitive. | 
| 1380 |  | 
| 1381 |     \sa QString::count(), contains(), indexOf() | 
| 1382 | */ | 
| 1383 | int QStringRef::count(QChar ch, Qt::CaseSensitivity cs) const | 
| 1384 | { | 
| 1385 |     // ### Qt6: qsizetype | 
| 1386 |     return int(QtPrivate::count(haystack: QStringView(unicode(), size()), needle: ch, cs)); | 
| 1387 | } | 
| 1388 |  | 
| 1389 | /*! | 
| 1390 |     \since 4.8 | 
| 1391 |     \overload count() | 
| 1392 |  | 
| 1393 |     Returns the number of (potentially overlapping) occurrences of the | 
| 1394 |     string reference \a str in this string reference. | 
| 1395 |  | 
| 1396 |     If \a cs is Qt::CaseSensitive (default), the search is | 
| 1397 |     case sensitive; otherwise the search is case insensitive. | 
| 1398 |  | 
| 1399 |     \sa QString::count(), contains(), indexOf() | 
| 1400 | */ | 
| 1401 | int QStringRef::count(const QStringRef &str, Qt::CaseSensitivity cs) const | 
| 1402 | { | 
| 1403 |     // ### Qt6: qsizetype | 
| 1404 |     return int(QtPrivate::count(haystack: QStringView(unicode(), size()), needle: QStringView(str.unicode(), str.size()), cs)); | 
| 1405 | } | 
| 1406 |  | 
| 1407 | /*! | 
| 1408 |     \since 5.9 | 
| 1409 |  | 
| 1410 |     Returns \c true if the string is read right to left. | 
| 1411 |  | 
| 1412 |     \sa QString::isRightToLeft() | 
| 1413 | */ | 
| 1414 | bool QStringRef::isRightToLeft() const | 
| 1415 | { | 
| 1416 |     return QtPrivate::isRightToLeft(string: QStringView(unicode(), size())); | 
| 1417 | } | 
| 1418 |  | 
| 1419 | /*! | 
| 1420 |     \since 4.8 | 
| 1421 |  | 
| 1422 |     Returns \c true if the string reference starts with \a str; otherwise | 
| 1423 |     returns \c false. | 
| 1424 |  | 
| 1425 |     If \a cs is Qt::CaseSensitive (default), the search is | 
| 1426 |     case sensitive; otherwise the search is case insensitive. | 
| 1427 |  | 
| 1428 |     \sa QString::startsWith(), endsWith() | 
| 1429 | */ | 
| 1430 | bool QStringRef::startsWith(const QString &str, Qt::CaseSensitivity cs) const | 
| 1431 | { | 
| 1432 |     return qt_starts_with(haystack: *this, needle: str, cs); | 
| 1433 | } | 
| 1434 |  | 
| 1435 | /*! | 
| 1436 |     \since 4.8 | 
| 1437 |     \overload startsWith() | 
| 1438 |     \sa QString::startsWith(), endsWith() | 
| 1439 | */ | 
| 1440 | bool QStringRef::startsWith(QLatin1String str, Qt::CaseSensitivity cs) const | 
| 1441 | { | 
| 1442 |     return qt_starts_with(haystack: *this, needle: str, cs); | 
| 1443 | } | 
| 1444 |  | 
| 1445 | /*! | 
| 1446 |     \fn bool QStringRef::startsWith(QStringView str, Qt::CaseSensitivity cs) const | 
| 1447 |     \since 5.10 | 
| 1448 |     \overload startsWith() | 
| 1449 |     \sa QString::startsWith(), endsWith() | 
| 1450 | */ | 
| 1451 |  | 
| 1452 | /*! | 
| 1453 |     \since 4.8 | 
| 1454 |     \overload startsWith() | 
| 1455 |     \sa QString::startsWith(), endsWith() | 
| 1456 | */ | 
| 1457 | bool QStringRef::startsWith(const QStringRef &str, Qt::CaseSensitivity cs) const | 
| 1458 | { | 
| 1459 |     return qt_starts_with(haystack: *this, needle: str, cs); | 
| 1460 | } | 
| 1461 |  | 
| 1462 | /*! | 
| 1463 |     \since 4.8 | 
| 1464 |     \overload startsWith() | 
| 1465 |  | 
| 1466 |     Returns \c true if the string reference starts with \a ch; otherwise | 
| 1467 |     returns \c false. | 
| 1468 |  | 
| 1469 |     If \a cs is Qt::CaseSensitive (default), the search is case | 
| 1470 |     sensitive; otherwise the search is case insensitive. | 
| 1471 |  | 
| 1472 |     \sa QString::startsWith(), endsWith() | 
| 1473 | */ | 
| 1474 | bool QStringRef::startsWith(QChar ch, Qt::CaseSensitivity cs) const | 
| 1475 | { | 
| 1476 |     return qt_starts_with(haystack: *this, needle: ch, cs); | 
| 1477 | } | 
| 1478 |  | 
| 1479 | /*! | 
| 1480 |     \since 4.8 | 
| 1481 |     Returns \c true if the string reference ends with \a str; otherwise | 
| 1482 |     returns \c false. | 
| 1483 |  | 
| 1484 |     If \a cs is Qt::CaseSensitive (default), the search is case | 
| 1485 |     sensitive; otherwise the search is case insensitive. | 
| 1486 |  | 
| 1487 |     \sa QString::endsWith(), startsWith() | 
| 1488 | */ | 
| 1489 | bool QStringRef::endsWith(const QString &str, Qt::CaseSensitivity cs) const | 
| 1490 | { | 
| 1491 |     return qt_ends_with(haystack: *this, needle: str, cs); | 
| 1492 | } | 
| 1493 |  | 
| 1494 | /*! | 
| 1495 |     \since 4.8 | 
| 1496 |     \overload endsWith() | 
| 1497 |  | 
| 1498 |     Returns \c true if the string reference ends with \a ch; otherwise | 
| 1499 |     returns \c false. | 
| 1500 |  | 
| 1501 |     If \a cs is Qt::CaseSensitive (default), the search is case | 
| 1502 |     sensitive; otherwise the search is case insensitive. | 
| 1503 |  | 
| 1504 |     \sa QString::endsWith(), endsWith() | 
| 1505 | */ | 
| 1506 | bool QStringRef::endsWith(QChar ch, Qt::CaseSensitivity cs) const | 
| 1507 | { | 
| 1508 |     return qt_ends_with(haystack: *this, needle: ch, cs); | 
| 1509 | } | 
| 1510 |  | 
| 1511 | /*! | 
| 1512 |     \since 4.8 | 
| 1513 |     \overload endsWith() | 
| 1514 |     \sa QString::endsWith(), endsWith() | 
| 1515 | */ | 
| 1516 | bool QStringRef::endsWith(QLatin1String str, Qt::CaseSensitivity cs) const | 
| 1517 | { | 
| 1518 |     return qt_ends_with(haystack: *this, needle: str, cs); | 
| 1519 | } | 
| 1520 |  | 
| 1521 | /*! | 
| 1522 |     \fn bool QStringRef::endsWith(QStringView str, Qt::CaseSensitivity cs) const | 
| 1523 |     \since 5.10 | 
| 1524 |     \overload endsWith() | 
| 1525 |     \sa QString::endsWith(), startsWith() | 
| 1526 | */ | 
| 1527 |  | 
| 1528 | /*! | 
| 1529 |     \since 4.8 | 
| 1530 |     \overload endsWith() | 
| 1531 |     \sa QString::endsWith(), endsWith() | 
| 1532 | */ | 
| 1533 | bool QStringRef::endsWith(const QStringRef &str, Qt::CaseSensitivity cs) const | 
| 1534 | { | 
| 1535 |     return qt_ends_with(haystack: *this, needle: str, cs); | 
| 1536 | } | 
| 1537 |  | 
| 1538 | /*! \fn bool QStringRef::contains(const QString &str, Qt::CaseSensitivity cs = Qt::CaseSensitive) const | 
| 1539 |  | 
| 1540 |     \since 4.8 | 
| 1541 |     Returns \c true if this string reference contains an occurrence of | 
| 1542 |     the string \a str; otherwise returns \c false. | 
| 1543 |  | 
| 1544 |     If \a cs is Qt::CaseSensitive (default), the search is | 
| 1545 |     case sensitive; otherwise the search is case insensitive. | 
| 1546 |  | 
| 1547 |     \sa indexOf(), count() | 
| 1548 | */ | 
| 1549 |  | 
| 1550 | /*! \fn bool QStringRef::contains(QChar ch, Qt::CaseSensitivity cs = Qt::CaseSensitive) const | 
| 1551 |  | 
| 1552 |     \overload contains() | 
| 1553 |     \since 4.8 | 
| 1554 |  | 
| 1555 |     Returns \c true if this string contains an occurrence of the | 
| 1556 |     character \a ch; otherwise returns \c false. | 
| 1557 |  | 
| 1558 |     If \a cs is Qt::CaseSensitive (default), the search is | 
| 1559 |     case sensitive; otherwise the search is case insensitive. | 
| 1560 |  | 
| 1561 | */ | 
| 1562 |  | 
| 1563 | /*! \fn bool QStringRef::contains(const QStringRef &str, Qt::CaseSensitivity cs = Qt::CaseSensitive) const | 
| 1564 |     \overload contains() | 
| 1565 |     \since 4.8 | 
| 1566 |  | 
| 1567 |     Returns \c true if this string reference contains an occurrence of | 
| 1568 |     the string reference \a str; otherwise returns \c false. | 
| 1569 |  | 
| 1570 |     If \a cs is Qt::CaseSensitive (default), the search is | 
| 1571 |     case sensitive; otherwise the search is case insensitive. | 
| 1572 |  | 
| 1573 |     \sa indexOf(), count() | 
| 1574 | */ | 
| 1575 |  | 
| 1576 | /*! \fn bool QStringRef::contains(QLatin1String str, Qt::CaseSensitivity cs) const | 
| 1577 |     \since 4.8 | 
| 1578 |     \overload contains() | 
| 1579 |  | 
| 1580 |     Returns \c true if this string reference contains an occurrence of | 
| 1581 |     the string \a str; otherwise returns \c false. | 
| 1582 |  | 
| 1583 |     If \a cs is Qt::CaseSensitive (default), the search is | 
| 1584 |     case sensitive; otherwise the search is case insensitive. | 
| 1585 |  | 
| 1586 |     \sa indexOf(), count() | 
| 1587 | */ | 
| 1588 |  | 
| 1589 | /*! \fn bool QStringRef::contains(QStringView str, Qt::CaseSensitivity cs = Qt::CaseSensitive) const | 
| 1590 |     \since 5.14 | 
| 1591 |     \overload contains() | 
| 1592 |  | 
| 1593 |     Returns \c true if this string reference contains an occurrence of | 
| 1594 |     the string view \a str; otherwise returns \c false. | 
| 1595 |  | 
| 1596 |     If \a cs is Qt::CaseSensitive (default), the search is | 
| 1597 |     case sensitive; otherwise the search is case insensitive. | 
| 1598 |  | 
| 1599 |     \sa indexOf(), count() | 
| 1600 | */ | 
| 1601 |  | 
| 1602 | template <typename Haystack, typename Needle> | 
| 1603 | bool qt_starts_with_impl(Haystack haystack, Needle needle, Qt::CaseSensitivity cs) noexcept | 
| 1604 | { | 
| 1605 |     if (haystack.isNull()) | 
| 1606 |         return needle.isNull(); // historical behavior, consider changing in ### Qt 6. | 
| 1607 |     const auto haystackLen = haystack.size(); | 
| 1608 |     const auto needleLen = needle.size(); | 
| 1609 |     if (haystackLen == 0) | 
| 1610 |         return needleLen == 0; | 
| 1611 |     if (needleLen > haystackLen) | 
| 1612 |         return false; | 
| 1613 |  | 
| 1614 |     return qt_compare_strings(haystack.left(needleLen), needle, cs) == 0; | 
| 1615 | } | 
| 1616 |  | 
| 1617 | static inline bool qt_starts_with(QStringView haystack, QStringView needle, Qt::CaseSensitivity cs) | 
| 1618 | { | 
| 1619 |     return qt_starts_with_impl(haystack, needle, cs); | 
| 1620 | } | 
| 1621 |  | 
| 1622 | static inline bool qt_starts_with(QStringView haystack, QLatin1String needle, Qt::CaseSensitivity cs) | 
| 1623 | { | 
| 1624 |     return qt_starts_with_impl(haystack, needle, cs); | 
| 1625 | } | 
| 1626 |  | 
| 1627 | static inline bool qt_starts_with(QStringView haystack, QChar needle, Qt::CaseSensitivity cs) | 
| 1628 | { | 
| 1629 |     return haystack.size() | 
| 1630 |            && (cs == Qt::CaseSensitive ? haystack.front() == needle | 
| 1631 |                                        : QCharPrivate::foldCase(ch: haystack.front()) == QCharPrivate::foldCase(ch: needle)); | 
| 1632 | } | 
| 1633 |  | 
| 1634 | template <typename Haystack, typename Needle> | 
| 1635 | bool qt_ends_with_impl(Haystack haystack, Needle needle, Qt::CaseSensitivity cs) noexcept | 
| 1636 | { | 
| 1637 |     if (haystack.isNull()) | 
| 1638 |         return needle.isNull(); // historical behavior, consider changing in ### Qt 6. | 
| 1639 |     const auto haystackLen = haystack.size(); | 
| 1640 |     const auto needleLen = needle.size(); | 
| 1641 |     if (haystackLen == 0) | 
| 1642 |         return needleLen == 0; | 
| 1643 |     if (haystackLen < needleLen) | 
| 1644 |         return false; | 
| 1645 |  | 
| 1646 |     return qt_compare_strings(haystack.right(needleLen), needle, cs) == 0; | 
| 1647 | } | 
| 1648 |  | 
| 1649 | static inline bool qt_ends_with(QStringView haystack, QStringView needle, Qt::CaseSensitivity cs) | 
| 1650 | { | 
| 1651 |     return qt_ends_with_impl(haystack, needle, cs); | 
| 1652 | } | 
| 1653 |  | 
| 1654 | static inline bool qt_ends_with(QStringView haystack, QLatin1String needle, Qt::CaseSensitivity cs) | 
| 1655 | { | 
| 1656 |     return qt_ends_with_impl(haystack, needle, cs); | 
| 1657 | } | 
| 1658 |  | 
| 1659 | static inline bool qt_ends_with(QStringView haystack, QChar needle, Qt::CaseSensitivity cs) | 
| 1660 | { | 
| 1661 |     return haystack.size() | 
| 1662 |            && (cs == Qt::CaseSensitive ? haystack.back() == needle | 
| 1663 |                                        : QCharPrivate::foldCase(ch: haystack.back()) == QCharPrivate::foldCase(ch: needle)); | 
| 1664 | } | 
| 1665 |  | 
| 1666 | /*! | 
| 1667 |     \internal | 
| 1668 |  | 
| 1669 |     Returns the index position of the first occurrence of the | 
| 1670 |     character \a ch in the string given by \a str and \a len, | 
| 1671 |     searching forward from index | 
| 1672 |     position \a from. Returns -1 if \a ch could not be found. | 
| 1673 | */ | 
| 1674 |  | 
| 1675 | static inline qsizetype qFindChar(QStringView str, QChar ch, qsizetype from, Qt::CaseSensitivity cs) noexcept | 
| 1676 | { | 
| 1677 |     if (from < 0) | 
| 1678 |         from = qMax(a: from + str.size(), b: qsizetype(0)); | 
| 1679 |     if (from < str.size()) { | 
| 1680 |         const char16_t *s = str.utf16(); | 
| 1681 |         char16_t c = ch.unicode(); | 
| 1682 |         const char16_t *n = s + from; | 
| 1683 |         const char16_t *e = s + str.size(); | 
| 1684 |         if (cs == Qt::CaseSensitive) { | 
| 1685 |             n = QtPrivate::qustrchr(str: QStringView(n, e), ch: c); | 
| 1686 |             if (n != e) | 
| 1687 |                 return n - s; | 
| 1688 |         } else { | 
| 1689 |             c = QCharPrivate::foldCase(ch: c); | 
| 1690 |             --n; | 
| 1691 |             while (++n != e) | 
| 1692 |                 if (QCharPrivate::foldCase(ch: *n) == c) | 
| 1693 |                     return n - s; | 
| 1694 |         } | 
| 1695 |     } | 
| 1696 |     return -1; | 
| 1697 | } | 
| 1698 |  | 
| 1699 | /*! | 
| 1700 |     \since 4.8 | 
| 1701 |  | 
| 1702 |     Returns a Latin-1 representation of the string as a QByteArray. | 
| 1703 |  | 
| 1704 |     The returned byte array is undefined if the string contains non-Latin1 | 
| 1705 |     characters. Those characters may be suppressed or replaced with a | 
| 1706 |     question mark. | 
| 1707 |  | 
| 1708 |     \sa toUtf8(), toLocal8Bit(), QStringEncoder | 
| 1709 | */ | 
| 1710 | QByteArray QStringRef::toLatin1() const | 
| 1711 | { | 
| 1712 |     return QStringView{ *this }.toLatin1(); | 
| 1713 | } | 
| 1714 |  | 
| 1715 | /*! | 
| 1716 |     \since 4.8 | 
| 1717 |  | 
| 1718 |     Returns the local 8-bit representation of the string as a | 
| 1719 |     QByteArray. The returned byte array is undefined if the string | 
| 1720 |     contains characters not supported by the local 8-bit encoding. | 
| 1721 |  | 
| 1722 |     On Unix systems this is equivalent to toUtf8(), on Windows the systems | 
| 1723 |     current code page is being used. | 
| 1724 |  | 
| 1725 |     If this string contains any characters that cannot be encoded in the | 
| 1726 |     locale, the returned byte array is undefined. Those characters may be | 
| 1727 |     suppressed or replaced by another. | 
| 1728 |  | 
| 1729 |     \sa toLatin1(), toUtf8(), QStringEncoder | 
| 1730 | */ | 
| 1731 | QByteArray QStringRef::toLocal8Bit() const | 
| 1732 | { | 
| 1733 |     return qt_convert_to_local_8bit(string: *this); | 
| 1734 | } | 
| 1735 |  | 
| 1736 | /*! | 
| 1737 |     \since 4.8 | 
| 1738 |  | 
| 1739 |     Returns a UTF-8 representation of the string as a QByteArray. | 
| 1740 |  | 
| 1741 |     UTF-8 is a Unicode codec and can represent all characters in a Unicode | 
| 1742 |     string like QString. | 
| 1743 |  | 
| 1744 |     \sa toLatin1(), toLocal8Bit(), QStringEncoder | 
| 1745 | */ | 
| 1746 | QByteArray QStringRef::toUtf8() const | 
| 1747 | { | 
| 1748 |     return qt_convert_to_utf8(str: *this); | 
| 1749 | } | 
| 1750 |  | 
| 1751 | /*! | 
| 1752 |     \since 4.8 | 
| 1753 |  | 
| 1754 |     Returns a UCS-4/UTF-32 representation of the string as a QList<uint>. | 
| 1755 |  | 
| 1756 |     UCS-4 is a Unicode codec and therefore it is lossless. All characters from | 
| 1757 |     this string will be encoded in UCS-4. Any invalid sequence of code units in | 
| 1758 |     this string is replaced by the Unicode's replacement character | 
| 1759 |     (QChar::ReplacementCharacter, which corresponds to \c{U+FFFD}). | 
| 1760 |  | 
| 1761 |     The returned list is not \\0'-terminated. | 
| 1762 |  | 
| 1763 |     \sa toUtf8(), toLatin1(), toLocal8Bit(), QStringEncoder | 
| 1764 | */ | 
| 1765 | QList<uint> QStringRef::toUcs4() const | 
| 1766 | { | 
| 1767 |     return qt_convert_to_ucs4(string: *this); | 
| 1768 | } | 
| 1769 |  | 
| 1770 | /*! | 
| 1771 |     Returns a string that has whitespace removed from the start and | 
| 1772 |     the end. | 
| 1773 |  | 
| 1774 |     Whitespace means any character for which QChar::isSpace() returns | 
| 1775 |     \c true. This includes the ASCII characters '\\t', '\\n', '\\v', | 
| 1776 |     '\\f', '\\r', and ' '. | 
| 1777 |  | 
| 1778 |     Unlike QString::simplified(), trimmed() leaves internal whitespace alone. | 
| 1779 |  | 
| 1780 |     \since 5.1 | 
| 1781 |  | 
| 1782 |     \sa QString::trimmed() | 
| 1783 | */ | 
| 1784 | QStringRef QStringRef::trimmed() const | 
| 1785 | { | 
| 1786 |     auto trimmed = QStringView(*this).trimmed(); | 
| 1787 |     auto begin = trimmed.cbegin(); | 
| 1788 |     auto end = trimmed.cend(); | 
| 1789 |     if (begin == cbegin() && end == cend()) | 
| 1790 |         return *this; | 
| 1791 |     int position = m_position + (begin - cbegin()); | 
| 1792 |     return QStringRef(m_string, position, end - begin); | 
| 1793 | } | 
| 1794 |  | 
| 1795 | /*! | 
| 1796 |     Returns the string converted to a \c{long long} using base \a | 
| 1797 |     base, which is 10 by default and must be between 2 and 36, or 0. | 
| 1798 |     Returns 0 if the conversion fails. | 
| 1799 |  | 
| 1800 |     If \a ok is not \nullptr, failure is reported by setting *\a{ok} | 
| 1801 |     to \c false, and success by setting *\a{ok} to \c true. | 
| 1802 |  | 
| 1803 |     If \a base is 0, the C language convention is used: If the string | 
| 1804 |     begins with "0x", base 16 is used; if the string begins with "0", | 
| 1805 |     base 8 is used; otherwise, base 10 is used. | 
| 1806 |  | 
| 1807 |     The string conversion will always happen in the 'C' locale. For locale | 
| 1808 |     dependent conversion use QLocale::toLongLong() | 
| 1809 |  | 
| 1810 |     \sa QString::toLongLong() | 
| 1811 |  | 
| 1812 |     \since 5.1 | 
| 1813 | */ | 
| 1814 | qint64 QStringRef::toLongLong(bool *ok, int base) const | 
| 1815 | { | 
| 1816 |     return QStringView{ *this }.toLongLong(ok, base); | 
| 1817 | } | 
| 1818 |  | 
| 1819 | /*! | 
| 1820 |     Returns the string converted to an \c{unsigned long long} using base \a | 
| 1821 |     base, which is 10 by default and must be between 2 and 36, or 0. | 
| 1822 |     Returns 0 if the conversion fails. | 
| 1823 |  | 
| 1824 |     If \a ok is not \nullptr, failure is reported by setting *\a{ok} | 
| 1825 |     to \c false, and success by setting *\a{ok} to \c true. | 
| 1826 |  | 
| 1827 |     If \a base is 0, the C language convention is used: If the string | 
| 1828 |     begins with "0x", base 16 is used; if the string begins with "0", | 
| 1829 |     base 8 is used; otherwise, base 10 is used. | 
| 1830 |  | 
| 1831 |     The string conversion will always happen in the 'C' locale. For locale | 
| 1832 |     dependent conversion use QLocale::toULongLong() | 
| 1833 |  | 
| 1834 |     \sa QString::toULongLong() | 
| 1835 |  | 
| 1836 |     \since 5.1 | 
| 1837 | */ | 
| 1838 | quint64 QStringRef::toULongLong(bool *ok, int base) const | 
| 1839 | { | 
| 1840 |     return QStringView{ *this }.toULongLong(ok, base); | 
| 1841 | } | 
| 1842 |  | 
| 1843 | /*! | 
| 1844 |     \fn long QStringRef::toLong(bool *ok, int base) const | 
| 1845 |  | 
| 1846 |     Returns the string converted to a \c long using base \a | 
| 1847 |     base, which is 10 by default and must be between 2 and 36, or 0. | 
| 1848 |     Returns 0 if the conversion fails. | 
| 1849 |  | 
| 1850 |     If \a ok is not \nullptr, failure is reported by setting *\a{ok} | 
| 1851 |     to \c false, and success by setting *\a{ok} to \c true. | 
| 1852 |  | 
| 1853 |     If \a base is 0, the C language convention is used: If the string | 
| 1854 |     begins with "0x", base 16 is used; if the string begins with "0", | 
| 1855 |     base 8 is used; otherwise, base 10 is used. | 
| 1856 |  | 
| 1857 |     The string conversion will always happen in the 'C' locale. For locale | 
| 1858 |     dependent conversion use QLocale::toLong() | 
| 1859 |  | 
| 1860 |     \sa QString::toLong() | 
| 1861 |  | 
| 1862 |     \since 5.1 | 
| 1863 | */ | 
| 1864 | long QStringRef::toLong(bool *ok, int base) const | 
| 1865 | { | 
| 1866 |     return QStringView{ *this }.toLong(ok, base); | 
| 1867 | } | 
| 1868 |  | 
| 1869 | /*! | 
| 1870 |     \fn ulong QStringRef::toULong(bool *ok, int base) const | 
| 1871 |  | 
| 1872 |     Returns the string converted to an \c{unsigned long} using base \a | 
| 1873 |     base, which is 10 by default and must be between 2 and 36, or 0. | 
| 1874 |     Returns 0 if the conversion fails. | 
| 1875 |  | 
| 1876 |     If \a ok is not \nullptr, failure is reported by setting *\a{ok} | 
| 1877 |     to \c false, and success by setting *\a{ok} to \c true. | 
| 1878 |  | 
| 1879 |     If \a base is 0, the C language convention is used: If the string | 
| 1880 |     begins with "0x", base 16 is used; if the string begins with "0", | 
| 1881 |     base 8 is used; otherwise, base 10 is used. | 
| 1882 |  | 
| 1883 |     The string conversion will always happen in the 'C' locale. For locale | 
| 1884 |     dependent conversion use QLocale::toULongLong() | 
| 1885 |  | 
| 1886 |     \sa QString::toULong() | 
| 1887 |  | 
| 1888 |     \since 5.1 | 
| 1889 | */ | 
| 1890 | ulong QStringRef::toULong(bool *ok, int base) const | 
| 1891 | { | 
| 1892 |    return QStringView{ *this }.toULong(ok, base); | 
| 1893 | } | 
| 1894 |  | 
| 1895 | /*! | 
| 1896 |     Returns the string converted to an \c int using base \a | 
| 1897 |     base, which is 10 by default and must be between 2 and 36, or 0. | 
| 1898 |     Returns 0 if the conversion fails. | 
| 1899 |  | 
| 1900 |     If \a ok is not \nullptr, failure is reported by setting *\a{ok} | 
| 1901 |     to \c false, and success by setting *\a{ok} to \c true. | 
| 1902 |  | 
| 1903 |     If \a base is 0, the C language convention is used: If the string | 
| 1904 |     begins with "0x", base 16 is used; if the string begins with "0", | 
| 1905 |     base 8 is used; otherwise, base 10 is used. | 
| 1906 |  | 
| 1907 |     The string conversion will always happen in the 'C' locale. For locale | 
| 1908 |     dependent conversion use QLocale::toInt() | 
| 1909 |  | 
| 1910 |     \sa QString::toInt() | 
| 1911 |  | 
| 1912 |     \since 5.1 | 
| 1913 | */ | 
| 1914 | int QStringRef::toInt(bool *ok, int base) const | 
| 1915 | { | 
| 1916 |     return QStringView{ *this }.toInt(ok, base); | 
| 1917 | } | 
| 1918 |  | 
| 1919 | /*! | 
| 1920 |     Returns the string converted to an \c{unsigned int} using base \a | 
| 1921 |     base, which is 10 by default and must be between 2 and 36, or 0. | 
| 1922 |     Returns 0 if the conversion fails. | 
| 1923 |  | 
| 1924 |     If \a ok is not \nullptr, failure is reported by setting *\a{ok} | 
| 1925 |     to \c false, and success by setting *\a{ok} to \c true. | 
| 1926 |  | 
| 1927 |     If \a base is 0, the C language convention is used: If the string | 
| 1928 |     begins with "0x", base 16 is used; if the string begins with "0", | 
| 1929 |     base 8 is used; otherwise, base 10 is used. | 
| 1930 |  | 
| 1931 |     The string conversion will always happen in the 'C' locale. For locale | 
| 1932 |     dependent conversion use QLocale::toUInt() | 
| 1933 |  | 
| 1934 |     \sa QString::toUInt() | 
| 1935 |  | 
| 1936 |     \since 5.1 | 
| 1937 | */ | 
| 1938 | uint QStringRef::toUInt(bool *ok, int base) const | 
| 1939 | { | 
| 1940 |     return QStringView{ *this }.toUInt(ok, base); | 
| 1941 | } | 
| 1942 |  | 
| 1943 | /*! | 
| 1944 |     Returns the string converted to a \c short using base \a | 
| 1945 |     base, which is 10 by default and must be between 2 and 36, or 0. | 
| 1946 |     Returns 0 if the conversion fails. | 
| 1947 |  | 
| 1948 |     If \a ok is not \nullptr, failure is reported by setting *\a{ok} | 
| 1949 |     to \c false, and success by setting *\a{ok} to \c true. | 
| 1950 |  | 
| 1951 |     If \a base is 0, the C language convention is used: If the string | 
| 1952 |     begins with "0x", base 16 is used; if the string begins with "0", | 
| 1953 |     base 8 is used; otherwise, base 10 is used. | 
| 1954 |  | 
| 1955 |     The string conversion will always happen in the 'C' locale. For locale | 
| 1956 |     dependent conversion use QLocale::toShort() | 
| 1957 |  | 
| 1958 |     \sa QString::toShort() | 
| 1959 |  | 
| 1960 |     \since 5.1 | 
| 1961 | */ | 
| 1962 | short QStringRef::toShort(bool *ok, int base) const | 
| 1963 | { | 
| 1964 |     return QStringView{ *this }.toShort(ok, base); | 
| 1965 | } | 
| 1966 |  | 
| 1967 | /*! | 
| 1968 |     Returns the string converted to an \c{unsigned short} using base \a | 
| 1969 |     base, which is 10 by default and must be between 2 and 36, or 0. | 
| 1970 |     Returns 0 if the conversion fails. | 
| 1971 |  | 
| 1972 |     If \a ok is not \nullptr, failure is reported by setting *\a{ok} | 
| 1973 |     to \c false, and success by setting *\a{ok} to \c true. | 
| 1974 |  | 
| 1975 |     If \a base is 0, the C language convention is used: If the string | 
| 1976 |     begins with "0x", base 16 is used; if the string begins with "0", | 
| 1977 |     base 8 is used; otherwise, base 10 is used. | 
| 1978 |  | 
| 1979 |     The string conversion will always happen in the 'C' locale. For locale | 
| 1980 |     dependent conversion use QLocale::toUShort() | 
| 1981 |  | 
| 1982 |     \sa QString::toUShort() | 
| 1983 |  | 
| 1984 |     \since 5.1 | 
| 1985 | */ | 
| 1986 | ushort QStringRef::toUShort(bool *ok, int base) const | 
| 1987 | { | 
| 1988 |     return QStringView{ *this }.toUShort(ok, base); | 
| 1989 | } | 
| 1990 |  | 
| 1991 | /*! | 
| 1992 |     Returns the string converted to a \c double value. | 
| 1993 |  | 
| 1994 |     Returns an infinity if the conversion overflows or 0.0 if the | 
| 1995 |     conversion fails for other reasons (e.g. underflow). | 
| 1996 |  | 
| 1997 |     If \a ok is not \nullptr, failure is reported by setting *\a{ok} | 
| 1998 |     to \c false, and success by setting *\a{ok} to \c true. | 
| 1999 |  | 
| 2000 |     The string conversion will always happen in the 'C' locale. For locale | 
| 2001 |     dependent conversion use QLocale::toDouble() | 
| 2002 |  | 
| 2003 |     For historic reasons, this function does not handle | 
| 2004 |     thousands group separators. If you need to convert such numbers, | 
| 2005 |     use QLocale::toDouble(). | 
| 2006 |  | 
| 2007 |     \sa QString::toDouble() | 
| 2008 |  | 
| 2009 |     \since 5.1 | 
| 2010 | */ | 
| 2011 | double QStringRef::toDouble(bool *ok) const | 
| 2012 | { | 
| 2013 |     return QStringView{ *this }.toDouble(ok); | 
| 2014 | } | 
| 2015 |  | 
| 2016 | /*! | 
| 2017 |     Returns the string converted to a \c float value. | 
| 2018 |  | 
| 2019 |     Returns an infinity if the conversion overflows or 0.0 if the | 
| 2020 |     conversion fails for other reasons (e.g. underflow). | 
| 2021 |  | 
| 2022 |     If \a ok is not \nullptr, failure is reported by setting *\a{ok} | 
| 2023 |     to \c false, and success by setting *\a{ok} to \c true. | 
| 2024 |  | 
| 2025 |     The string conversion will always happen in the 'C' locale. For locale | 
| 2026 |     dependent conversion use QLocale::toFloat() | 
| 2027 |  | 
| 2028 |     \sa QString::toFloat() | 
| 2029 |  | 
| 2030 |     \since 5.1 | 
| 2031 | */ | 
| 2032 | float QStringRef::toFloat(bool *ok) const | 
| 2033 | { | 
| 2034 |     return QStringView{ *this }.toFloat(ok); | 
| 2035 | } | 
| 2036 |  | 
| 2037 | /*! \fn size_t qHash(const QStringRef &key, size_t seed = 0) | 
| 2038 |     \relates QHash | 
| 2039 |     \since 5.0 | 
| 2040 |  | 
| 2041 |     Returns the hash value for the \a key, using \a seed to seed the calculation. | 
| 2042 | */ | 
| 2043 |  | 
| 2044 | QT_END_NAMESPACE | 
| 2045 |  |