| Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/corelib/tools/qstring.cpp |
| Source code | Switch to Preprocessed file |
| Line | Source | Count | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | /**************************************************************************** | - | ||||||||||||||||||
| 2 | ** | - | ||||||||||||||||||
| 3 | ** Copyright (C) 2015 The Qt Company Ltd. | - | ||||||||||||||||||
| 4 | ** Copyright (C) 2015 Intel Corporation | - | ||||||||||||||||||
| 5 | ** Contact: http://www.qt.io/licensing/ | - | ||||||||||||||||||
| 6 | ** | - | ||||||||||||||||||
| 7 | ** This file is part of the QtCore module of the Qt Toolkit. | - | ||||||||||||||||||
| 8 | ** | - | ||||||||||||||||||
| 9 | ** $QT_BEGIN_LICENSE:LGPL21$ | - | ||||||||||||||||||
| 10 | ** Commercial License Usage | - | ||||||||||||||||||
| 11 | ** Licensees holding valid commercial Qt licenses may use this file in | - | ||||||||||||||||||
| 12 | ** accordance with the commercial license agreement provided with the | - | ||||||||||||||||||
| 13 | ** Software or, alternatively, in accordance with the terms contained in | - | ||||||||||||||||||
| 14 | ** a written agreement between you and The Qt Company. For licensing terms | - | ||||||||||||||||||
| 15 | ** and conditions see http://www.qt.io/terms-conditions. For further | - | ||||||||||||||||||
| 16 | ** information use the contact form at http://www.qt.io/contact-us. | - | ||||||||||||||||||
| 17 | ** | - | ||||||||||||||||||
| 18 | ** GNU Lesser General Public License Usage | - | ||||||||||||||||||
| 19 | ** Alternatively, this file may be used under the terms of the GNU Lesser | - | ||||||||||||||||||
| 20 | ** General Public License version 2.1 or version 3 as published by the Free | - | ||||||||||||||||||
| 21 | ** Software Foundation and appearing in the file LICENSE.LGPLv21 and | - | ||||||||||||||||||
| 22 | ** LICENSE.LGPLv3 included in the packaging of this file. Please review the | - | ||||||||||||||||||
| 23 | ** following information to ensure the GNU Lesser General Public License | - | ||||||||||||||||||
| 24 | ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and | - | ||||||||||||||||||
| 25 | ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | - | ||||||||||||||||||
| 26 | ** | - | ||||||||||||||||||
| 27 | ** As a special exception, The Qt Company gives you certain additional | - | ||||||||||||||||||
| 28 | ** rights. These rights are described in The Qt Company LGPL Exception | - | ||||||||||||||||||
| 29 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | - | ||||||||||||||||||
| 30 | ** | - | ||||||||||||||||||
| 31 | ** $QT_END_LICENSE$ | - | ||||||||||||||||||
| 32 | ** | - | ||||||||||||||||||
| 33 | ****************************************************************************/ | - | ||||||||||||||||||
| 34 | - | |||||||||||||||||||
| 35 | #include "qstringlist.h" | - | ||||||||||||||||||
| 36 | #include "qregexp.h" | - | ||||||||||||||||||
| 37 | #include "qregularexpression.h" | - | ||||||||||||||||||
| 38 | #include "qunicodetables_p.h" | - | ||||||||||||||||||
| 39 | #ifndef QT_NO_TEXTCODEC | - | ||||||||||||||||||
| 40 | #include <qtextcodec.h> | - | ||||||||||||||||||
| 41 | #endif | - | ||||||||||||||||||
| 42 | #include <private/qutfcodec_p.h> | - | ||||||||||||||||||
| 43 | #include "qsimd_p.h" | - | ||||||||||||||||||
| 44 | #include <qnumeric.h> | - | ||||||||||||||||||
| 45 | #include <qdatastream.h> | - | ||||||||||||||||||
| 46 | #include <qlist.h> | - | ||||||||||||||||||
| 47 | #include "qlocale.h" | - | ||||||||||||||||||
| 48 | #include "qlocale_p.h" | - | ||||||||||||||||||
| 49 | #include "qstringbuilder.h" | - | ||||||||||||||||||
| 50 | #include "qstringmatcher.h" | - | ||||||||||||||||||
| 51 | #include "qvarlengtharray.h" | - | ||||||||||||||||||
| 52 | #include "qtools_p.h" | - | ||||||||||||||||||
| 53 | #include "qdebug.h" | - | ||||||||||||||||||
| 54 | #include "qendian.h" | - | ||||||||||||||||||
| 55 | #include "qcollator.h" | - | ||||||||||||||||||
| 56 | - | |||||||||||||||||||
| 57 | #ifdef Q_OS_MAC | - | ||||||||||||||||||
| 58 | #include <private/qcore_mac_p.h> | - | ||||||||||||||||||
| 59 | #endif | - | ||||||||||||||||||
| 60 | - | |||||||||||||||||||
| 61 | #include <private/qfunctions_p.h> | - | ||||||||||||||||||
| 62 | - | |||||||||||||||||||
| 63 | #include <limits.h> | - | ||||||||||||||||||
| 64 | #include <string.h> | - | ||||||||||||||||||
| 65 | #include <stdlib.h> | - | ||||||||||||||||||
| 66 | #include <stdio.h> | - | ||||||||||||||||||
| 67 | #include <stdarg.h> | - | ||||||||||||||||||
| 68 | - | |||||||||||||||||||
| 69 | #include "qchar.cpp" | - | ||||||||||||||||||
| 70 | #include "qstringmatcher.cpp" | - | ||||||||||||||||||
| 71 | #include "qstringiterator_p.h" | - | ||||||||||||||||||
| 72 | #include "qstringalgorithms_p.h" | - | ||||||||||||||||||
| 73 | #include "qthreadstorage.h" | - | ||||||||||||||||||
| 74 | - | |||||||||||||||||||
| 75 | #ifdef Q_OS_WIN | - | ||||||||||||||||||
| 76 | # include <qt_windows.h> | - | ||||||||||||||||||
| 77 | # ifdef Q_OS_WINCE | - | ||||||||||||||||||
| 78 | # include <winnls.h> | - | ||||||||||||||||||
| 79 | # endif | - | ||||||||||||||||||
| 80 | #endif | - | ||||||||||||||||||
| 81 | - | |||||||||||||||||||
| 82 | #ifdef truncate | - | ||||||||||||||||||
| 83 | # undef truncate | - | ||||||||||||||||||
| 84 | #endif | - | ||||||||||||||||||
| 85 | - | |||||||||||||||||||
| 86 | #ifndef LLONG_MAX | - | ||||||||||||||||||
| 87 | #define LLONG_MAX qint64_C(9223372036854775807) | - | ||||||||||||||||||
| 88 | #endif | - | ||||||||||||||||||
| 89 | #ifndef LLONG_MIN | - | ||||||||||||||||||
| 90 | #define LLONG_MIN (-LLONG_MAX - qint64_C(1)) | - | ||||||||||||||||||
| 91 | #endif | - | ||||||||||||||||||
| 92 | #ifndef ULLONG_MAX | - | ||||||||||||||||||
| 93 | #define ULLONG_MAX quint64_C(18446744073709551615) | - | ||||||||||||||||||
| 94 | #endif | - | ||||||||||||||||||
| 95 | - | |||||||||||||||||||
| 96 | #define IS_RAW_DATA(d) ((d)->offset != sizeof(QStringData)) | - | ||||||||||||||||||
| 97 | - | |||||||||||||||||||
| 98 | QT_BEGIN_NAMESPACE | - | ||||||||||||||||||
| 99 | - | |||||||||||||||||||
| 100 | /* | - | ||||||||||||||||||
| 101 | * Note on the use of SIMD in qstring.cpp: | - | ||||||||||||||||||
| 102 | * | - | ||||||||||||||||||
| 103 | * Several operations with strings are improved with the use of SIMD code, | - | ||||||||||||||||||
| 104 | * since they are repetitive. For MIPS, we have hand-written assembly code | - | ||||||||||||||||||
| 105 | * outside of qstring.cpp targeting MIPS DSP and MIPS DSPr2. For ARM and for | - | ||||||||||||||||||
| 106 | * x86, we can only use intrinsics and therefore everything is contained in | - | ||||||||||||||||||
| 107 | * qstring.cpp. We need to use intrinsics only for those platforms due to the | - | ||||||||||||||||||
| 108 | * different compilers and toolchains used, which have different syntax for | - | ||||||||||||||||||
| 109 | * assembly sources. | - | ||||||||||||||||||
| 110 | * | - | ||||||||||||||||||
| 111 | * ** SSE notes: ** | - | ||||||||||||||||||
| 112 | * | - | ||||||||||||||||||
| 113 | * Whenever multiple alternatives are equivalent or near so, we prefer the one | - | ||||||||||||||||||
| 114 | * using instructions from SSE2, since SSE2 is guaranteed to be enabled for all | - | ||||||||||||||||||
| 115 | * 64-bit builds and we enable it for 32-bit builds by default. Use of higher | - | ||||||||||||||||||
| 116 | * SSE versions should be done when there's a clear performance benefit and | - | ||||||||||||||||||
| 117 | * requires fallback code to SSE2, if it exists. | - | ||||||||||||||||||
| 118 | * | - | ||||||||||||||||||
| 119 | * Performance measurement in the past shows that most strings are short in | - | ||||||||||||||||||
| 120 | * size and, therefore, do not benefit from alignment prologues. That is, | - | ||||||||||||||||||
| 121 | * trying to find a 16-byte-aligned boundary to operate on is often more | - | ||||||||||||||||||
| 122 | * expensive than executing the unaligned operation directly. In addition, note | - | ||||||||||||||||||
| 123 | * that the QString private data is designed so that the data is stored on | - | ||||||||||||||||||
| 124 | * 16-byte boundaries if the system malloc() returns 16-byte aligned pointers | - | ||||||||||||||||||
| 125 | * on its own (64-bit glibc on Linux does; 32-bit glibc on Linux returns them | - | ||||||||||||||||||
| 126 | * 50% of the time), so skipping the alignment prologue is actually optimizing | - | ||||||||||||||||||
| 127 | * for the common case. | - | ||||||||||||||||||
| 128 | */ | - | ||||||||||||||||||
| 129 | - | |||||||||||||||||||
| 130 | #if defined(__mips_dsp) | - | ||||||||||||||||||
| 131 | // From qstring_mips_dsp_asm.S | - | ||||||||||||||||||
| 132 | extern "C" void qt_fromlatin1_mips_asm_unroll4 (ushort*, const char*, uint); | - | ||||||||||||||||||
| 133 | extern "C" void qt_fromlatin1_mips_asm_unroll8 (ushort*, const char*, uint); | - | ||||||||||||||||||
| 134 | extern "C" void qt_toLatin1_mips_dsp_asm(uchar *dst, const ushort *src, int length); | - | ||||||||||||||||||
| 135 | #endif | - | ||||||||||||||||||
| 136 | - | |||||||||||||||||||
| 137 | // internal | - | ||||||||||||||||||
| 138 | int qFindString(const QChar *haystack, int haystackLen, int from, | - | ||||||||||||||||||
| 139 | const QChar *needle, int needleLen, Qt::CaseSensitivity cs); | - | ||||||||||||||||||
| 140 | int qFindStringBoyerMoore(const QChar *haystack, int haystackLen, int from, | - | ||||||||||||||||||
| 141 | const QChar *needle, int needleLen, Qt::CaseSensitivity cs); | - | ||||||||||||||||||
| 142 | static inline int qt_last_index_of(const QChar *haystack, int haystackLen, QChar needle, | - | ||||||||||||||||||
| 143 | int from, Qt::CaseSensitivity cs); | - | ||||||||||||||||||
| 144 | static inline int qt_string_count(const QChar *haystack, int haystackLen, | - | ||||||||||||||||||
| 145 | const QChar *needle, int needleLen, | - | ||||||||||||||||||
| 146 | Qt::CaseSensitivity cs); | - | ||||||||||||||||||
| 147 | static inline int qt_string_count(const QChar *haystack, int haystackLen, | - | ||||||||||||||||||
| 148 | QChar needle, Qt::CaseSensitivity cs); | - | ||||||||||||||||||
| 149 | static inline int qt_find_latin1_string(const QChar *hay, int size, QLatin1String needle, | - | ||||||||||||||||||
| 150 | int from, Qt::CaseSensitivity cs); | - | ||||||||||||||||||
| 151 | static inline bool qt_starts_with(const QChar *haystack, int haystackLen, | - | ||||||||||||||||||
| 152 | const QChar *needle, int needleLen, Qt::CaseSensitivity cs); | - | ||||||||||||||||||
| 153 | static inline bool qt_starts_with(const QChar *haystack, int haystackLen, | - | ||||||||||||||||||
| 154 | QLatin1String needle, Qt::CaseSensitivity cs); | - | ||||||||||||||||||
| 155 | static inline bool qt_ends_with(const QChar *haystack, int haystackLen, | - | ||||||||||||||||||
| 156 | const QChar *needle, int needleLen, Qt::CaseSensitivity cs); | - | ||||||||||||||||||
| 157 | static inline bool qt_ends_with(const QChar *haystack, int haystackLen, | - | ||||||||||||||||||
| 158 | QLatin1String needle, Qt::CaseSensitivity cs); | - | ||||||||||||||||||
| 159 | - | |||||||||||||||||||
| 160 | #if defined(Q_COMPILER_LAMBDA) && !defined(__OPTIMIZE_SIZE__) | - | ||||||||||||||||||
| 161 | namespace { | - | ||||||||||||||||||
| 162 | template <uint MaxCount> struct UnrollTailLoop | - | ||||||||||||||||||
| 163 | { | - | ||||||||||||||||||
| 164 | template <typename RetType, typename Functor1, typename Functor2> | - | ||||||||||||||||||
| 165 | static inline RetType exec(int count, RetType returnIfExited, Functor1 loopCheck, Functor2 returnIfFailed, int i = 0) | - | ||||||||||||||||||
| 166 | { | - | ||||||||||||||||||
| 167 | /* equivalent to: | - | ||||||||||||||||||
| 168 | * while (count--) { | - | ||||||||||||||||||
| 169 | * if (loopCheck(i)) | - | ||||||||||||||||||
| 170 | * return returnIfFailed(i); | - | ||||||||||||||||||
| 171 | * } | - | ||||||||||||||||||
| 172 | * return returnIfExited; | - | ||||||||||||||||||
| 173 | */ | - | ||||||||||||||||||
| 174 | - | |||||||||||||||||||
| 175 | if (!count)
| 6490921-32903230 | ||||||||||||||||||
| 176 | return returnIfExited; executed 6490952 times by 720 tests: return returnIfExited;Executed by:
| 6490952 | ||||||||||||||||||
| 177 | - | |||||||||||||||||||
| 178 | bool check = loopCheck(i); | - | ||||||||||||||||||
| 179 | if (check) {
| 1381261-31522028 | ||||||||||||||||||
| 180 | const RetType &retval = returnIfFailed(i); | - | ||||||||||||||||||
| 181 | return retval; executed 1381261 times by 555 tests: return retval;Executed by:
| 1381261 | ||||||||||||||||||
| 182 | } | - | ||||||||||||||||||
| 183 | - | |||||||||||||||||||
| 184 | return UnrollTailLoop<MaxCount - 1>::exec(count - 1, returnIfExited, loopCheck, returnIfFailed, i + 1); executed 31510179 times by 807 tests: return UnrollTailLoop<MaxCount - 1>::exec(count - 1, returnIfExited, loopCheck, returnIfFailed, i + 1);Executed by:
| 31510179 | ||||||||||||||||||
| 185 | } | - | ||||||||||||||||||
| 186 | - | |||||||||||||||||||
| 187 | template <typename Functor> | - | ||||||||||||||||||
| 188 | static inline void exec(int count, Functor code) | - | ||||||||||||||||||
| 189 | { | - | ||||||||||||||||||
| 190 | /* equivalent to: | - | ||||||||||||||||||
| 191 | * for (int i = 0; i < count; ++i) | - | ||||||||||||||||||
| 192 | * code(i); | - | ||||||||||||||||||
| 193 | */ | - | ||||||||||||||||||
| 194 | exec(count, 0, [=](int i) -> bool { code(i); return false; }, [](int) { return 0; }); executed 15984012 times by 719 tests: return false;Executed by:
never executed: return 0; | 0-15984012 | ||||||||||||||||||
| 195 | } executed 2504564 times by 720 tests: end of blockExecuted by:
| 2504564 | ||||||||||||||||||
| 196 | }; | - | ||||||||||||||||||
| 197 | template <> template <typename RetType, typename Functor1, typename Functor2> | - | ||||||||||||||||||
| 198 | inline RetType UnrollTailLoop<0>::exec(int, RetType returnIfExited, Functor1, Functor2, int) | - | ||||||||||||||||||
| 199 | { | - | ||||||||||||||||||
| 200 | return returnIfExited; executed 523506 times by 484 tests: return returnIfExited;Executed by:
| 523506 | ||||||||||||||||||
| 201 | } | - | ||||||||||||||||||
| 202 | } | - | ||||||||||||||||||
| 203 | #endif | - | ||||||||||||||||||
| 204 | - | |||||||||||||||||||
| 205 | // conversion between Latin 1 and UTF-16 | - | ||||||||||||||||||
| 206 | void qt_from_latin1(ushort *dst, const char *str, size_t size) Q_DECL_NOTHROW | - | ||||||||||||||||||
| 207 | { | - | ||||||||||||||||||
| 208 | /* SIMD: | - | ||||||||||||||||||
| 209 | * Unpacking with SSE has been shown to improve performance on recent CPUs | - | ||||||||||||||||||
| 210 | * The same method gives no improvement with NEON. | - | ||||||||||||||||||
| 211 | */ | - | ||||||||||||||||||
| 212 | #if defined(__SSE2__) | - | ||||||||||||||||||
| 213 | const char *e = str + size; | - | ||||||||||||||||||
| 214 | qptrdiff offset = 0; | - | ||||||||||||||||||
| 215 | - | |||||||||||||||||||
| 216 | // we're going to read str[offset..offset+15] (16 bytes) | - | ||||||||||||||||||
| 217 | for ( ; str + offset + 15 < e; offset += 16) {
| 1567911-2214904 | ||||||||||||||||||
| 218 | const __m128i chunk = _mm_loadu_si128((const __m128i*)(str + offset)); // load | - | ||||||||||||||||||
| 219 | #ifdef __AVX2__ | - | ||||||||||||||||||
| 220 | // zero extend to an YMM register | - | ||||||||||||||||||
| 221 | const __m256i extended = _mm256_cvtepu8_epi16(chunk); | - | ||||||||||||||||||
| 222 | - | |||||||||||||||||||
| 223 | // store | - | ||||||||||||||||||
| 224 | _mm256_storeu_si256((__m256i*)(dst + offset), extended); | - | ||||||||||||||||||
| 225 | #else | - | ||||||||||||||||||
| 226 | const __m128i nullMask = _mm_set1_epi32(0); | - | ||||||||||||||||||
| 227 | - | |||||||||||||||||||
| 228 | // unpack the first 8 bytes, padding with zeros | - | ||||||||||||||||||
| 229 | const __m128i firstHalf = _mm_unpacklo_epi8(chunk, nullMask); | - | ||||||||||||||||||
| 230 | _mm_storeu_si128((__m128i*)(dst + offset), firstHalf); // store | - | ||||||||||||||||||
| 231 | - | |||||||||||||||||||
| 232 | // unpack the last 8 bytes, padding with zeros | - | ||||||||||||||||||
| 233 | const __m128i secondHalf = _mm_unpackhi_epi8 (chunk, nullMask); | - | ||||||||||||||||||
| 234 | _mm_storeu_si128((__m128i*)(dst + offset + 8), secondHalf); // store | - | ||||||||||||||||||
| 235 | #endif | - | ||||||||||||||||||
| 236 | } executed 1567911 times by 550 tests: end of blockExecuted by:
| 1567911 | ||||||||||||||||||
| 237 | - | |||||||||||||||||||
| 238 | size = size % 16; | - | ||||||||||||||||||
| 239 | dst += offset; | - | ||||||||||||||||||
| 240 | str += offset; | - | ||||||||||||||||||
| 241 | # if defined(Q_COMPILER_LAMBDA) && !defined(__OPTIMIZE_SIZE__) | - | ||||||||||||||||||
| 242 | return UnrollTailLoop<15>::exec(int(size), [=](int i) { dst[i] = (uchar)str[i]; }); executed 14559810 times by 719 tests: end of blockExecuted by:
executed 2214904 times by 720 tests: return UnrollTailLoop<15>::exec(int(size), [=](int i) { dst[i] = (uchar)str[i]; });Executed by:
| 2214904-14559810 | ||||||||||||||||||
| 243 | # endif | - | ||||||||||||||||||
| 244 | #endif | - | ||||||||||||||||||
| 245 | #if defined(__mips_dsp) | - | ||||||||||||||||||
| 246 | if (size > 20) | - | ||||||||||||||||||
| 247 | qt_fromlatin1_mips_asm_unroll8(dst, str, size); | - | ||||||||||||||||||
| 248 | else | - | ||||||||||||||||||
| 249 | qt_fromlatin1_mips_asm_unroll4(dst, str, size); | - | ||||||||||||||||||
| 250 | #else | - | ||||||||||||||||||
| 251 | while (size--) dead code: while (size--) *dst++ = (uchar)*str++; | - | ||||||||||||||||||
| 252 | *dst++ = (uchar)*str++; dead code: while (size--) *dst++ = (uchar)*str++; | - | ||||||||||||||||||
| 253 | #endif | - | ||||||||||||||||||
| 254 | } | - | ||||||||||||||||||
| 255 | - | |||||||||||||||||||
| 256 | #if defined(__SSE2__) | - | ||||||||||||||||||
| 257 | static inline __m128i mergeQuestionMarks(__m128i chunk) | - | ||||||||||||||||||
| 258 | { | - | ||||||||||||||||||
| 259 | const __m128i questionMark = _mm_set1_epi16('?'); | - | ||||||||||||||||||
| 260 | - | |||||||||||||||||||
| 261 | # ifdef __SSE4_2__ | - | ||||||||||||||||||
| 262 | // compare the unsigned shorts for the range 0x0100-0xFFFF | - | ||||||||||||||||||
| 263 | // note on the use of _mm_cmpestrm: | - | ||||||||||||||||||
| 264 | // The MSDN documentation online (http://technet.microsoft.com/en-us/library/bb514080.aspx) | - | ||||||||||||||||||
| 265 | // says for range search the following: | - | ||||||||||||||||||
| 266 | // For each character c in a, determine whether b0 <= c <= b1 or b2 <= c <= b3 | - | ||||||||||||||||||
| 267 | // | - | ||||||||||||||||||
| 268 | // However, all examples on the Internet, including from Intel | - | ||||||||||||||||||
| 269 | // (see http://software.intel.com/en-us/articles/xml-parsing-accelerator-with-intel-streaming-simd-extensions-4-intel-sse4/) | - | ||||||||||||||||||
| 270 | // put the range to be searched first | - | ||||||||||||||||||
| 271 | // | - | ||||||||||||||||||
| 272 | // Disassembly and instruction-level debugging with GCC and ICC show | - | ||||||||||||||||||
| 273 | // that they are doing the right thing. Inverting the arguments in the | - | ||||||||||||||||||
| 274 | // instruction does cause a bunch of test failures. | - | ||||||||||||||||||
| 275 | - | |||||||||||||||||||
| 276 | const __m128i rangeMatch = _mm_cvtsi32_si128(0xffff0100); | - | ||||||||||||||||||
| 277 | const __m128i offLimitMask = _mm_cmpestrm(rangeMatch, 2, chunk, 8, | - | ||||||||||||||||||
| 278 | _SIDD_UWORD_OPS | _SIDD_CMP_RANGES | _SIDD_UNIT_MASK); | - | ||||||||||||||||||
| 279 | - | |||||||||||||||||||
| 280 | // replace the non-Latin 1 characters in the chunk with question marks | - | ||||||||||||||||||
| 281 | chunk = _mm_blendv_epi8(chunk, questionMark, offLimitMask); | - | ||||||||||||||||||
| 282 | # else | - | ||||||||||||||||||
| 283 | // SSE has no compare instruction for unsigned comparison. | - | ||||||||||||||||||
| 284 | // The variables must be shiffted + 0x8000 to be compared | - | ||||||||||||||||||
| 285 | const __m128i signedBitOffset = _mm_set1_epi16(short(0x8000)); | - | ||||||||||||||||||
| 286 | const __m128i thresholdMask = _mm_set1_epi16(short(0xff + 0x8000)); | - | ||||||||||||||||||
| 287 | - | |||||||||||||||||||
| 288 | const __m128i signedChunk = _mm_add_epi16(chunk, signedBitOffset); | - | ||||||||||||||||||
| 289 | const __m128i offLimitMask = _mm_cmpgt_epi16(signedChunk, thresholdMask); | - | ||||||||||||||||||
| 290 | - | |||||||||||||||||||
| 291 | # ifdef __SSE4_1__ | - | ||||||||||||||||||
| 292 | // replace the non-Latin 1 characters in the chunk with question marks | - | ||||||||||||||||||
| 293 | chunk = _mm_blendv_epi8(chunk, questionMark, offLimitMask); | - | ||||||||||||||||||
| 294 | # else | - | ||||||||||||||||||
| 295 | // offLimitQuestionMark contains '?' for each 16 bits that was off-limit | - | ||||||||||||||||||
| 296 | // the 16 bits that were correct contains zeros | - | ||||||||||||||||||
| 297 | const __m128i offLimitQuestionMark = _mm_and_si128(offLimitMask, questionMark); | - | ||||||||||||||||||
| 298 | - | |||||||||||||||||||
| 299 | // correctBytes contains the bytes that were in limit | - | ||||||||||||||||||
| 300 | // the 16 bits that were off limits contains zeros | - | ||||||||||||||||||
| 301 | const __m128i correctBytes = _mm_andnot_si128(offLimitMask, chunk); | - | ||||||||||||||||||
| 302 | - | |||||||||||||||||||
| 303 | // merge offLimitQuestionMark and correctBytes to have the result | - | ||||||||||||||||||
| 304 | chunk = _mm_or_si128(correctBytes, offLimitQuestionMark); | - | ||||||||||||||||||
| 305 | # endif | - | ||||||||||||||||||
| 306 | # endif | - | ||||||||||||||||||
| 307 | return chunk; executed 767416 times by 380 tests: return chunk;Executed by:
| 767416 | ||||||||||||||||||
| 308 | } | - | ||||||||||||||||||
| 309 | #endif | - | ||||||||||||||||||
| 310 | - | |||||||||||||||||||
| 311 | static void qt_to_latin1(uchar *dst, const ushort *src, int length) | - | ||||||||||||||||||
| 312 | { | - | ||||||||||||||||||
| 313 | #if defined(__SSE2__) | - | ||||||||||||||||||
| 314 | uchar *e = dst + length; | - | ||||||||||||||||||
| 315 | qptrdiff offset = 0; | - | ||||||||||||||||||
| 316 | - | |||||||||||||||||||
| 317 | // we're going to write to dst[offset..offset+15] (16 bytes) | - | ||||||||||||||||||
| 318 | for ( ; dst + offset + 15 < e; offset += 16) {
| 289660-383708 | ||||||||||||||||||
| 319 | __m128i chunk1 = _mm_loadu_si128((const __m128i*)(src + offset)); // load | - | ||||||||||||||||||
| 320 | chunk1 = mergeQuestionMarks(chunk1); | - | ||||||||||||||||||
| 321 | - | |||||||||||||||||||
| 322 | __m128i chunk2 = _mm_loadu_si128((const __m128i*)(src + offset + 8)); // load | - | ||||||||||||||||||
| 323 | chunk2 = mergeQuestionMarks(chunk2); | - | ||||||||||||||||||
| 324 | - | |||||||||||||||||||
| 325 | // pack the two vector to 16 x 8bits elements | - | ||||||||||||||||||
| 326 | const __m128i result = _mm_packus_epi16(chunk1, chunk2); | - | ||||||||||||||||||
| 327 | _mm_storeu_si128((__m128i*)(dst + offset), result); // store | - | ||||||||||||||||||
| 328 | } executed 383708 times by 380 tests: end of blockExecuted by:
| 383708 | ||||||||||||||||||
| 329 | - | |||||||||||||||||||
| 330 | length = length % 16; | - | ||||||||||||||||||
| 331 | dst += offset; | - | ||||||||||||||||||
| 332 | src += offset; | - | ||||||||||||||||||
| 333 | - | |||||||||||||||||||
| 334 | # if defined(Q_COMPILER_LAMBDA) && !defined(__OPTIMIZE_SIZE__) | - | ||||||||||||||||||
| 335 | return UnrollTailLoop<15>::exec(length, [=](int i) { dst[i] = (src[i]>0xff) ? '?' : (uchar) src[i]; }); executed 1424202 times by 447 tests: end of blockExecuted by:
executed 289660 times by 448 tests: return UnrollTailLoop<15>::exec(length, [=](int i) { dst[i] = (src[i]>0xff) ? '?' : (uchar) src[i]; });Executed by:
| 11-1424202 | ||||||||||||||||||
| 336 | # endif | - | ||||||||||||||||||
| 337 | #elif defined(__ARM_NEON__) | - | ||||||||||||||||||
| 338 | // Refer to the documentation of the SSE2 implementation | - | ||||||||||||||||||
| 339 | // this use eactly the same method as for SSE except: | - | ||||||||||||||||||
| 340 | // 1) neon has unsigned comparison | - | ||||||||||||||||||
| 341 | // 2) packing is done to 64 bits (8 x 8bits component). | - | ||||||||||||||||||
| 342 | if (length >= 16) { | - | ||||||||||||||||||
| 343 | const int chunkCount = length >> 3; // divided by 8 | - | ||||||||||||||||||
| 344 | const uint16x8_t questionMark = vdupq_n_u16('?'); // set | - | ||||||||||||||||||
| 345 | const uint16x8_t thresholdMask = vdupq_n_u16(0xff); // set | - | ||||||||||||||||||
| 346 | for (int i = 0; i < chunkCount; ++i) { | - | ||||||||||||||||||
| 347 | uint16x8_t chunk = vld1q_u16((uint16_t *)src); // load | - | ||||||||||||||||||
| 348 | src += 8; | - | ||||||||||||||||||
| 349 | - | |||||||||||||||||||
| 350 | const uint16x8_t offLimitMask = vcgtq_u16(chunk, thresholdMask); // chunk > thresholdMask | - | ||||||||||||||||||
| 351 | const uint16x8_t offLimitQuestionMark = vandq_u16(offLimitMask, questionMark); // offLimitMask & questionMark | - | ||||||||||||||||||
| 352 | const uint16x8_t correctBytes = vbicq_u16(chunk, offLimitMask); // !offLimitMask & chunk | - | ||||||||||||||||||
| 353 | chunk = vorrq_u16(correctBytes, offLimitQuestionMark); // correctBytes | offLimitQuestionMark | - | ||||||||||||||||||
| 354 | const uint8x8_t result = vmovn_u16(chunk); // narrowing move->packing | - | ||||||||||||||||||
| 355 | vst1_u8(dst, result); // store | - | ||||||||||||||||||
| 356 | dst += 8; | - | ||||||||||||||||||
| 357 | } | - | ||||||||||||||||||
| 358 | length = length % 8; | - | ||||||||||||||||||
| 359 | } | - | ||||||||||||||||||
| 360 | #endif | - | ||||||||||||||||||
| 361 | #if defined(__mips_dsp) | - | ||||||||||||||||||
| 362 | qt_toLatin1_mips_dsp_asm(dst, src, length); | - | ||||||||||||||||||
| 363 | #else | - | ||||||||||||||||||
| 364 | while (length--) { dead code: while (length--) { *dst++ = (*src>0xff) ? '?' : (uchar) *src; ++src; } | - | ||||||||||||||||||
| 365 | *dst++ = (*src>0xff) ? '?' : (uchar) *src; dead code: while (length--) { *dst++ = (*src>0xff) ? '?' : (uchar) *src; ++src; } | - | ||||||||||||||||||
| 366 | ++src; dead code: while (length--) { *dst++ = (*src>0xff) ? '?' : (uchar) *src; ++src; } | - | ||||||||||||||||||
| 367 | } dead code: while (length--) { *dst++ = (*src>0xff) ? '?' : (uchar) *src; ++src; } | - | ||||||||||||||||||
| 368 | #endif | - | ||||||||||||||||||
| 369 | } | - | ||||||||||||||||||
| 370 | - | |||||||||||||||||||
| 371 | // Unicode case-insensitive comparison | - | ||||||||||||||||||
| 372 | static int ucstricmp(const ushort *a, const ushort *ae, const ushort *b, const ushort *be) | - | ||||||||||||||||||
| 373 | { | - | ||||||||||||||||||
| 374 | if (a == b)
| 4625-488665 | ||||||||||||||||||
| 375 | return (ae - be); executed 4625 times by 125 tests: return (ae - be);Executed by:
| 4625 | ||||||||||||||||||
| 376 | if (a == 0)
| 0-488665 | ||||||||||||||||||
| 377 | return 1; never executed: return 1; | 0 | ||||||||||||||||||
| 378 | if (b == 0)
| 0-488665 | ||||||||||||||||||
| 379 | return -1; never executed: return -1; | 0 | ||||||||||||||||||
| 380 | - | |||||||||||||||||||
| 381 | const ushort *e = ae; | - | ||||||||||||||||||
| 382 | if (be - b < ae - a)
| 226096-262569 | ||||||||||||||||||
| 383 | e = a + (be - b); executed 226096 times by 134 tests: e = a + (be - b);Executed by:
| 226096 | ||||||||||||||||||
| 384 | - | |||||||||||||||||||
| 385 | uint alast = 0; | - | ||||||||||||||||||
| 386 | uint blast = 0; | - | ||||||||||||||||||
| 387 | while (a < e) {
| 71226-1637572 | ||||||||||||||||||
| 388 | // qDebug() << hex << alast << blast; | - | ||||||||||||||||||
| 389 | // qDebug() << hex << "*a=" << *a << "alast=" << alast << "folded=" << foldCase (*a, alast); | - | ||||||||||||||||||
| 390 | // qDebug() << hex << "*b=" << *b << "blast=" << blast << "folded=" << foldCase (*b, blast); | - | ||||||||||||||||||
| 391 | int diff = foldCase(*a, alast) - foldCase(*b, blast); | - | ||||||||||||||||||
| 392 | if ((diff))
| 417439-1220133 | ||||||||||||||||||
| 393 | return diff; executed 417439 times by 154 tests: return diff;Executed by:
| 417439 | ||||||||||||||||||
| 394 | ++a; | - | ||||||||||||||||||
| 395 | ++b; | - | ||||||||||||||||||
| 396 | } executed 1220133 times by 163 tests: end of blockExecuted by:
| 1220133 | ||||||||||||||||||
| 397 | if (a == ae) {
| 4639-66587 | ||||||||||||||||||
| 398 | if (b == be)
| 9124-57463 | ||||||||||||||||||
| 399 | return 0; executed 57463 times by 162 tests: return 0;Executed by:
| 57463 | ||||||||||||||||||
| 400 | return -1; executed 9124 times by 126 tests: return -1;Executed by:
| 9124 | ||||||||||||||||||
| 401 | } | - | ||||||||||||||||||
| 402 | return 1; executed 4639 times by 126 tests: return 1;Executed by:
| 4639 | ||||||||||||||||||
| 403 | } | - | ||||||||||||||||||
| 404 | - | |||||||||||||||||||
| 405 | // Case-insensitive comparison between a Unicode string and a QLatin1String | - | ||||||||||||||||||
| 406 | static int ucstricmp(const ushort *a, const ushort *ae, const uchar *b, const uchar *be) | - | ||||||||||||||||||
| 407 | { | - | ||||||||||||||||||
| 408 | if (a == 0) {
| 0-16802 | ||||||||||||||||||
| 409 | if (b == 0)
| 0 | ||||||||||||||||||
| 410 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
| 411 | return 1; never executed: return 1; | 0 | ||||||||||||||||||
| 412 | } | - | ||||||||||||||||||
| 413 | if (b == 0)
| 0-16802 | ||||||||||||||||||
| 414 | return -1; never executed: return -1; | 0 | ||||||||||||||||||
| 415 | - | |||||||||||||||||||
| 416 | const ushort *e = ae; | - | ||||||||||||||||||
| 417 | if (be - b < ae - a)
| 3984-12818 | ||||||||||||||||||
| 418 | e = a + (be - b); executed 3984 times by 24 tests: e = a + (be - b);Executed by:
| 3984 | ||||||||||||||||||
| 419 | - | |||||||||||||||||||
| 420 | while (a < e) {
| 4472-68943 | ||||||||||||||||||
| 421 | int diff = foldCase(*a) - foldCase(*b); | - | ||||||||||||||||||
| 422 | if ((diff))
| 12330-56613 | ||||||||||||||||||
| 423 | return diff; executed 12330 times by 35 tests: return diff;Executed by:
| 12330 | ||||||||||||||||||
| 424 | ++a; | - | ||||||||||||||||||
| 425 | ++b; | - | ||||||||||||||||||
| 426 | } executed 56613 times by 41 tests: end of blockExecuted by:
| 56613 | ||||||||||||||||||
| 427 | if (a == ae) {
| 150-4322 | ||||||||||||||||||
| 428 | if (b == be)
| 569-3753 | ||||||||||||||||||
| 429 | return 0; executed 3753 times by 41 tests: return 0;Executed by:
| 3753 | ||||||||||||||||||
| 430 | return -1; executed 569 times by 14 tests: return -1;Executed by:
| 569 | ||||||||||||||||||
| 431 | } | - | ||||||||||||||||||
| 432 | return 1; executed 150 times by 13 tests: return 1;Executed by:
| 150 | ||||||||||||||||||
| 433 | } | - | ||||||||||||||||||
| 434 | - | |||||||||||||||||||
| 435 | #if defined(__mips_dsp) | - | ||||||||||||||||||
| 436 | // From qstring_mips_dsp_asm.S | - | ||||||||||||||||||
| 437 | extern "C" int qt_ucstrncmp_mips_dsp_asm(const ushort *a, | - | ||||||||||||||||||
| 438 | const ushort *b, | - | ||||||||||||||||||
| 439 | unsigned len); | - | ||||||||||||||||||
| 440 | #endif | - | ||||||||||||||||||
| 441 | - | |||||||||||||||||||
| 442 | // Unicode case-sensitive compare two same-sized strings | - | ||||||||||||||||||
| 443 | static int ucstrncmp(const QChar *a, const QChar *b, int l) | - | ||||||||||||||||||
| 444 | { | - | ||||||||||||||||||
| 445 | #if defined(__mips_dsp) | - | ||||||||||||||||||
| 446 | if (l >= 8) { | - | ||||||||||||||||||
| 447 | return qt_ucstrncmp_mips_dsp_asm(reinterpret_cast<const ushort*>(a), | - | ||||||||||||||||||
| 448 | reinterpret_cast<const ushort*>(b), | - | ||||||||||||||||||
| 449 | l); | - | ||||||||||||||||||
| 450 | } | - | ||||||||||||||||||
| 451 | #endif // __mips_dsp | - | ||||||||||||||||||
| 452 | #ifdef __SSE2__ | - | ||||||||||||||||||
| 453 | const char *ptr = reinterpret_cast<const char*>(a); | - | ||||||||||||||||||
| 454 | qptrdiff distance = reinterpret_cast<const char*>(b) - ptr; | - | ||||||||||||||||||
| 455 | a += l & ~7; | - | ||||||||||||||||||
| 456 | b += l & ~7; | - | ||||||||||||||||||
| 457 | l &= 7; | - | ||||||||||||||||||
| 458 | - | |||||||||||||||||||
| 459 | // we're going to read ptr[0..15] (16 bytes) | - | ||||||||||||||||||
| 460 | for ( ; ptr + 15 < reinterpret_cast<const char *>(a); ptr += 16) {
| 3882046-6243664 | ||||||||||||||||||
| 461 | __m128i a_data = _mm_loadu_si128((const __m128i*)ptr); | - | ||||||||||||||||||
| 462 | __m128i b_data = _mm_loadu_si128((const __m128i*)(ptr + distance)); | - | ||||||||||||||||||
| 463 | __m128i result = _mm_cmpeq_epi16(a_data, b_data); | - | ||||||||||||||||||
| 464 | uint mask = ~_mm_movemask_epi8(result); | - | ||||||||||||||||||
| 465 | if (ushort(mask)) {
| 1473564-4770100 | ||||||||||||||||||
| 466 | // found a different byte | - | ||||||||||||||||||
| 467 | uint idx = uint(_bit_scan_forward(mask)); | - | ||||||||||||||||||
| 468 | return reinterpret_cast<const QChar *>(ptr + idx)->unicode() executed 1473564 times by 468 tests: return reinterpret_cast<const QChar *>(ptr + idx)->unicode() - reinterpret_cast<const QChar *>(ptr + distance + idx)->unicode();Executed by:
| 1473564 | ||||||||||||||||||
| 469 | - reinterpret_cast<const QChar *>(ptr + distance + idx)->unicode(); executed 1473564 times by 468 tests: return reinterpret_cast<const QChar *>(ptr + idx)->unicode() - reinterpret_cast<const QChar *>(ptr + distance + idx)->unicode();Executed by:
| 1473564 | ||||||||||||||||||
| 470 | } | - | ||||||||||||||||||
| 471 | } executed 4770100 times by 601 tests: end of blockExecuted by:
| 4770100 | ||||||||||||||||||
| 472 | # if defined(Q_COMPILER_LAMBDA) && !defined(__OPTIMIZE_SIZE__) | - | ||||||||||||||||||
| 473 | const auto &lambda = [=](int i) -> int { | - | ||||||||||||||||||
| 474 | return reinterpret_cast<const QChar *>(ptr)[i].unicode() executed 13023200 times by 615 tests: return reinterpret_cast<const QChar *>(ptr)[i].unicode() - reinterpret_cast<const QChar *>(ptr + distance)[i].unicode();Executed by:
| 13023200 | ||||||||||||||||||
| 475 | - reinterpret_cast<const QChar *>(ptr + distance)[i].unicode(); executed 13023200 times by 615 tests: return reinterpret_cast<const QChar *>(ptr)[i].unicode() - reinterpret_cast<const QChar *>(ptr + distance)[i].unicode();Executed by:
| 13023200 | ||||||||||||||||||
| 476 | }; | - | ||||||||||||||||||
| 477 | return UnrollTailLoop<7>::exec(l, 0, lambda, lambda); executed 3882046 times by 616 tests: return UnrollTailLoop<7>::exec(l, 0, lambda, lambda);Executed by:
| 3882046 | ||||||||||||||||||
| 478 | # endif | - | ||||||||||||||||||
| 479 | #endif | - | ||||||||||||||||||
| 480 | if (!l) dead code: if (!l) return 0; | - | ||||||||||||||||||
| 481 | return 0; dead code: if (!l) return 0; | - | ||||||||||||||||||
| 482 | - | |||||||||||||||||||
| 483 | // check alignment | - | ||||||||||||||||||
| 484 | if ((reinterpret_cast<quintptr>(a) & 2) == (reinterpret_cast<quintptr>(b) & 2)) { dead code: if ((reinterpret_cast<quintptr>(a) & 2) == (reinterpret_cast<quintptr>(b) & 2)) { if (reinterpret_cast<quintptr>(a) & 2) { if (*a != *b) return a->unicode() - b->unicode(); --l; ++a; ++b; } const quint32 *da = reinterpret_cast<const quint32 *>(a); const q...e(); } } a = reinterpret_cast<const QChar *>(da); b = reinterpret_cast<const QChar *>(db); return (l & 1) ? a->unicode() - b->unicode() : 0; } else { const QChar *e = a + l; for ( ; a != e; ++a, ++b) { if (*a != *b) return a->unicode() - b->unicode(); } } | - | ||||||||||||||||||
| 485 | // both addresses have the same alignment dead code: if ((reinterpret_cast<quintptr>(a) & 2) == (reinterpret_cast<quintptr>(b) & 2)) { if (reinterpret_cast<quintptr>(a) & 2) { if (*a != *b) return a->unicode() - b->unicode(); --l; ++a; ++b; } const quint32 *da = reinterpret_cast<const quint32 *>(a); const q...e(); } } a = reinterpret_cast<const QChar *>(da); b = reinterpret_cast<const QChar *>(db); return (l & 1) ? a->unicode() - b->unicode() : 0; } else { const QChar *e = a + l; for ( ; a != e; ++a, ++b) { if (*a != *b) return a->unicode() - b->unicode(); } } | - | ||||||||||||||||||
| 486 | if (reinterpret_cast<quintptr>(a) & 2) { dead code: if ((reinterpret_cast<quintptr>(a) & 2) == (reinterpret_cast<quintptr>(b) & 2)) { if (reinterpret_cast<quintptr>(a) & 2) { if (*a != *b) return a->unicode() - b->unicode(); --l; ++a; ++b; } const quint32 *da = reinterpret_cast<const quint32 *>(a); const q...e(); } } a = reinterpret_cast<const QChar *>(da); b = reinterpret_cast<const QChar *>(db); return (l & 1) ? a->unicode() - b->unicode() : 0; } else { const QChar *e = a + l; for ( ; a != e; ++a, ++b) { if (*a != *b) return a->unicode() - b->unicode(); } } | - | ||||||||||||||||||
| 487 | // both addresses are not aligned to 4-bytes boundaries dead code: if ((reinterpret_cast<quintptr>(a) & 2) == (reinterpret_cast<quintptr>(b) & 2)) { if (reinterpret_cast<quintptr>(a) & 2) { if (*a != *b) return a->unicode() - b->unicode(); --l; ++a; ++b; } const quint32 *da = reinterpret_cast<const quint32 *>(a); const q...e(); } } a = reinterpret_cast<const QChar *>(da); b = reinterpret_cast<const QChar *>(db); return (l & 1) ? a->unicode() - b->unicode() : 0; } else { const QChar *e = a + l; for ( ; a != e; ++a, ++b) { if (*a != *b) return a->unicode() - b->unicode(); } } | - | ||||||||||||||||||
| 488 | // compare the first character dead code: if ((reinterpret_cast<quintptr>(a) & 2) == (reinterpret_cast<quintptr>(b) & 2)) { if (reinterpret_cast<quintptr>(a) & 2) { if (*a != *b) return a->unicode() - b->unicode(); --l; ++a; ++b; } const quint32 *da = reinterpret_cast<const quint32 *>(a); const q...e(); } } a = reinterpret_cast<const QChar *>(da); b = reinterpret_cast<const QChar *>(db); return (l & 1) ? a->unicode() - b->unicode() : 0; } else { const QChar *e = a + l; for ( ; a != e; ++a, ++b) { if (*a != *b) return a->unicode() - b->unicode(); } } | - | ||||||||||||||||||
| 489 | if (*a != *b) dead code: if ((reinterpret_cast<quintptr>(a) & 2) == (reinterpret_cast<quintptr>(b) & 2)) { if (reinterpret_cast<quintptr>(a) & 2) { if (*a != *b) return a->unicode() - b->unicode(); --l; ++a; ++b; } const quint32 *da = reinterpret_cast<const quint32 *>(a); const q...e(); } } a = reinterpret_cast<const QChar *>(da); b = reinterpret_cast<const QChar *>(db); return (l & 1) ? a->unicode() - b->unicode() : 0; } else { const QChar *e = a + l; for ( ; a != e; ++a, ++b) { if (*a != *b) return a->unicode() - b->unicode(); } } | - | ||||||||||||||||||
| 490 | return a->unicode() - b->unicode(); dead code: if ((reinterpret_cast<quintptr>(a) & 2) == (reinterpret_cast<quintptr>(b) & 2)) { if (reinterpret_cast<quintptr>(a) & 2) { if (*a != *b) return a->unicode() - b->unicode(); --l; ++a; ++b; } const quint32 *da = reinterpret_cast<const quint32 *>(a); const q...e(); } } a = reinterpret_cast<const QChar *>(da); b = reinterpret_cast<const QChar *>(db); return (l & 1) ? a->unicode() - b->unicode() : 0; } else { const QChar *e = a + l; for ( ; a != e; ++a, ++b) { if (*a != *b) return a->unicode() - b->unicode(); } } | - | ||||||||||||||||||
| 491 | --l; dead code: if ((reinterpret_cast<quintptr>(a) & 2) == (reinterpret_cast<quintptr>(b) & 2)) { if (reinterpret_cast<quintptr>(a) & 2) { if (*a != *b) return a->unicode() - b->unicode(); --l; ++a; ++b; } const quint32 *da = reinterpret_cast<const quint32 *>(a); const q...e(); } } a = reinterpret_cast<const QChar *>(da); b = reinterpret_cast<const QChar *>(db); return (l & 1) ? a->unicode() - b->unicode() : 0; } else { const QChar *e = a + l; for ( ; a != e; ++a, ++b) { if (*a != *b) return a->unicode() - b->unicode(); } } | - | ||||||||||||||||||
| 492 | ++a; dead code: if ((reinterpret_cast<quintptr>(a) & 2) == (reinterpret_cast<quintptr>(b) & 2)) { if (reinterpret_cast<quintptr>(a) & 2) { if (*a != *b) return a->unicode() - b->unicode(); --l; ++a; ++b; } const quint32 *da = reinterpret_cast<const quint32 *>(a); const q...e(); } } a = reinterpret_cast<const QChar *>(da); b = reinterpret_cast<const QChar *>(db); return (l & 1) ? a->unicode() - b->unicode() : 0; } else { const QChar *e = a + l; for ( ; a != e; ++a, ++b) { if (*a != *b) return a->unicode() - b->unicode(); } } | - | ||||||||||||||||||
| 493 | ++b; dead code: if ((reinterpret_cast<quintptr>(a) & 2) == (reinterpret_cast<quintptr>(b) & 2)) { if (reinterpret_cast<quintptr>(a) & 2) { if (*a != *b) return a->unicode() - b->unicode(); --l; ++a; ++b; } const quint32 *da = reinterpret_cast<const quint32 *>(a); const q...e(); } } a = reinterpret_cast<const QChar *>(da); b = reinterpret_cast<const QChar *>(db); return (l & 1) ? a->unicode() - b->unicode() : 0; } else { const QChar *e = a + l; for ( ; a != e; ++a, ++b) { if (*a != *b) return a->unicode() - b->unicode(); } } | - | ||||||||||||||||||
| 494 | - | |||||||||||||||||||
| 495 | // now both addresses are 4-bytes aligned dead code: if ((reinterpret_cast<quintptr>(a) & 2) == (reinterpret_cast<quintptr>(b) & 2)) { if (reinterpret_cast<quintptr>(a) & 2) { if (*a != *b) return a->unicode() - b->unicode(); --l; ++a; ++b; } const quint32 *da = reinterpret_cast<const quint32 *>(a); const q...e(); } } a = reinterpret_cast<const QChar *>(da); b = reinterpret_cast<const QChar *>(db); return (l & 1) ? a->unicode() - b->unicode() : 0; } else { const QChar *e = a + l; for ( ; a != e; ++a, ++b) { if (*a != *b) return a->unicode() - b->unicode(); } } | - | ||||||||||||||||||
| 496 | } dead code: if ((reinterpret_cast<quintptr>(a) & 2) == (reinterpret_cast<quintptr>(b) & 2)) { if (reinterpret_cast<quintptr>(a) & 2) { if (*a != *b) return a->unicode() - b->unicode(); --l; ++a; ++b; } const quint32 *da = reinterpret_cast<const quint32 *>(a); const q...e(); } } a = reinterpret_cast<const QChar *>(da); b = reinterpret_cast<const QChar *>(db); return (l & 1) ? a->unicode() - b->unicode() : 0; } else { const QChar *e = a + l; for ( ; a != e; ++a, ++b) { if (*a != *b) return a->unicode() - b->unicode(); } } | - | ||||||||||||||||||
| 497 | - | |||||||||||||||||||
| 498 | // both addresses are 4-bytes aligned dead code: if ((reinterpret_cast<quintptr>(a) & 2) == (reinterpret_cast<quintptr>(b) & 2)) { if (reinterpret_cast<quintptr>(a) & 2) { if (*a != *b) return a->unicode() - b->unicode(); --l; ++a; ++b; } const quint32 *da = reinterpret_cast<const quint32 *>(a); const q...e(); } } a = reinterpret_cast<const QChar *>(da); b = reinterpret_cast<const QChar *>(db); return (l & 1) ? a->unicode() - b->unicode() : 0; } else { const QChar *e = a + l; for ( ; a != e; ++a, ++b) { if (*a != *b) return a->unicode() - b->unicode(); } } | - | ||||||||||||||||||
| 499 | // do a fast 32-bit comparison dead code: if ((reinterpret_cast<quintptr>(a) & 2) == (reinterpret_cast<quintptr>(b) & 2)) { if (reinterpret_cast<quintptr>(a) & 2) { if (*a != *b) return a->unicode() - b->unicode(); --l; ++a; ++b; } const quint32 *da = reinterpret_cast<const quint32 *>(a); const q...e(); } } a = reinterpret_cast<const QChar *>(da); b = reinterpret_cast<const QChar *>(db); return (l & 1) ? a->unicode() - b->unicode() : 0; } else { const QChar *e = a + l; for ( ; a != e; ++a, ++b) { if (*a != *b) return a->unicode() - b->unicode(); } } | - | ||||||||||||||||||
| 500 | const quint32 *da = reinterpret_cast<const quint32 *>(a); dead code: if ((reinterpret_cast<quintptr>(a) & 2) == (reinterpret_cast<quintptr>(b) & 2)) { if (reinterpret_cast<quintptr>(a) & 2) { if (*a != *b) return a->unicode() - b->unicode(); --l; ++a; ++b; } const quint32 *da = reinterpret_cast<const quint32 *>(a); const q...e(); } } a = reinterpret_cast<const QChar *>(da); b = reinterpret_cast<const QChar *>(db); return (l & 1) ? a->unicode() - b->unicode() : 0; } else { const QChar *e = a + l; for ( ; a != e; ++a, ++b) { if (*a != *b) return a->unicode() - b->unicode(); } } | - | ||||||||||||||||||
| 501 | const quint32 *db = reinterpret_cast<const quint32 *>(b); dead code: if ((reinterpret_cast<quintptr>(a) & 2) == (reinterpret_cast<quintptr>(b) & 2)) { if (reinterpret_cast<quintptr>(a) & 2) { if (*a != *b) return a->unicode() - b->unicode(); --l; ++a; ++b; } const quint32 *da = reinterpret_cast<const quint32 *>(a); const q...e(); } } a = reinterpret_cast<const QChar *>(da); b = reinterpret_cast<const QChar *>(db); return (l & 1) ? a->unicode() - b->unicode() : 0; } else { const QChar *e = a + l; for ( ; a != e; ++a, ++b) { if (*a != *b) return a->unicode() - b->unicode(); } } | - | ||||||||||||||||||
| 502 | const quint32 *e = da + (l >> 1); dead code: if ((reinterpret_cast<quintptr>(a) & 2) == (reinterpret_cast<quintptr>(b) & 2)) { if (reinterpret_cast<quintptr>(a) & 2) { if (*a != *b) return a->unicode() - b->unicode(); --l; ++a; ++b; } const quint32 *da = reinterpret_cast<const quint32 *>(a); const q...e(); } } a = reinterpret_cast<const QChar *>(da); b = reinterpret_cast<const QChar *>(db); return (l & 1) ? a->unicode() - b->unicode() : 0; } else { const QChar *e = a + l; for ( ; a != e; ++a, ++b) { if (*a != *b) return a->unicode() - b->unicode(); } } | - | ||||||||||||||||||
| 503 | for ( ; da != e; ++da, ++db) { dead code: if ((reinterpret_cast<quintptr>(a) & 2) == (reinterpret_cast<quintptr>(b) & 2)) { if (reinterpret_cast<quintptr>(a) & 2) { if (*a != *b) return a->unicode() - b->unicode(); --l; ++a; ++b; } const quint32 *da = reinterpret_cast<const quint32 *>(a); const q...e(); } } a = reinterpret_cast<const QChar *>(da); b = reinterpret_cast<const QChar *>(db); return (l & 1) ? a->unicode() - b->unicode() : 0; } else { const QChar *e = a + l; for ( ; a != e; ++a, ++b) { if (*a != *b) return a->unicode() - b->unicode(); } } | - | ||||||||||||||||||
| 504 | if (*da != *db) { dead code: if ((reinterpret_cast<quintptr>(a) & 2) == (reinterpret_cast<quintptr>(b) & 2)) { if (reinterpret_cast<quintptr>(a) & 2) { if (*a != *b) return a->unicode() - b->unicode(); --l; ++a; ++b; } const quint32 *da = reinterpret_cast<const quint32 *>(a); const q...e(); } } a = reinterpret_cast<const QChar *>(da); b = reinterpret_cast<const QChar *>(db); return (l & 1) ? a->unicode() - b->unicode() : 0; } else { const QChar *e = a + l; for ( ; a != e; ++a, ++b) { if (*a != *b) return a->unicode() - b->unicode(); } } | - | ||||||||||||||||||
| 505 | a = reinterpret_cast<const QChar *>(da); dead code: if ((reinterpret_cast<quintptr>(a) & 2) == (reinterpret_cast<quintptr>(b) & 2)) { if (reinterpret_cast<quintptr>(a) & 2) { if (*a != *b) return a->unicode() - b->unicode(); --l; ++a; ++b; } const quint32 *da = reinterpret_cast<const quint32 *>(a); const q...e(); } } a = reinterpret_cast<const QChar *>(da); b = reinterpret_cast<const QChar *>(db); return (l & 1) ? a->unicode() - b->unicode() : 0; } else { const QChar *e = a + l; for ( ; a != e; ++a, ++b) { if (*a != *b) return a->unicode() - b->unicode(); } } | - | ||||||||||||||||||
| 506 | b = reinterpret_cast<const QChar *>(db); dead code: if ((reinterpret_cast<quintptr>(a) & 2) == (reinterpret_cast<quintptr>(b) & 2)) { if (reinterpret_cast<quintptr>(a) & 2) { if (*a != *b) return a->unicode() - b->unicode(); --l; ++a; ++b; } const quint32 *da = reinterpret_cast<const quint32 *>(a); const q...e(); } } a = reinterpret_cast<const QChar *>(da); b = reinterpret_cast<const QChar *>(db); return (l & 1) ? a->unicode() - b->unicode() : 0; } else { const QChar *e = a + l; for ( ; a != e; ++a, ++b) { if (*a != *b) return a->unicode() - b->unicode(); } } | - | ||||||||||||||||||
| 507 | if (*a != *b) dead code: if ((reinterpret_cast<quintptr>(a) & 2) == (reinterpret_cast<quintptr>(b) & 2)) { if (reinterpret_cast<quintptr>(a) & 2) { if (*a != *b) return a->unicode() - b->unicode(); --l; ++a; ++b; } const quint32 *da = reinterpret_cast<const quint32 *>(a); const q...e(); } } a = reinterpret_cast<const QChar *>(da); b = reinterpret_cast<const QChar *>(db); return (l & 1) ? a->unicode() - b->unicode() : 0; } else { const QChar *e = a + l; for ( ; a != e; ++a, ++b) { if (*a != *b) return a->unicode() - b->unicode(); } } | - | ||||||||||||||||||
| 508 | return a->unicode() - b->unicode(); dead code: if ((reinterpret_cast<quintptr>(a) & 2) == (reinterpret_cast<quintptr>(b) & 2)) { if (reinterpret_cast<quintptr>(a) & 2) { if (*a != *b) return a->unicode() - b->unicode(); --l; ++a; ++b; } const quint32 *da = reinterpret_cast<const quint32 *>(a); const q...e(); } } a = reinterpret_cast<const QChar *>(da); b = reinterpret_cast<const QChar *>(db); return (l & 1) ? a->unicode() - b->unicode() : 0; } else { const QChar *e = a + l; for ( ; a != e; ++a, ++b) { if (*a != *b) return a->unicode() - b->unicode(); } } | - | ||||||||||||||||||
| 509 | return a[1].unicode() - b[1].unicode(); dead code: if ((reinterpret_cast<quintptr>(a) & 2) == (reinterpret_cast<quintptr>(b) & 2)) { if (reinterpret_cast<quintptr>(a) & 2) { if (*a != *b) return a->unicode() - b->unicode(); --l; ++a; ++b; } const quint32 *da = reinterpret_cast<const quint32 *>(a); const q...e(); } } a = reinterpret_cast<const QChar *>(da); b = reinterpret_cast<const QChar *>(db); return (l & 1) ? a->unicode() - b->unicode() : 0; } else { const QChar *e = a + l; for ( ; a != e; ++a, ++b) { if (*a != *b) return a->unicode() - b->unicode(); } } | - | ||||||||||||||||||
| 510 | } dead code: if ((reinterpret_cast<quintptr>(a) & 2) == (reinterpret_cast<quintptr>(b) & 2)) { if (reinterpret_cast<quintptr>(a) & 2) { if (*a != *b) return a->unicode() - b->unicode(); --l; ++a; ++b; } const quint32 *da = reinterpret_cast<const quint32 *>(a); const q...e(); } } a = reinterpret_cast<const QChar *>(da); b = reinterpret_cast<const QChar *>(db); return (l & 1) ? a->unicode() - b->unicode() : 0; } else { const QChar *e = a + l; for ( ; a != e; ++a, ++b) { if (*a != *b) return a->unicode() - b->unicode(); } } | - | ||||||||||||||||||
| 511 | } dead code: if ((reinterpret_cast<quintptr>(a) & 2) == (reinterpret_cast<quintptr>(b) & 2)) { if (reinterpret_cast<quintptr>(a) & 2) { if (*a != *b) return a->unicode() - b->unicode(); --l; ++a; ++b; } const quint32 *da = reinterpret_cast<const quint32 *>(a); const q...e(); } } a = reinterpret_cast<const QChar *>(da); b = reinterpret_cast<const QChar *>(db); return (l & 1) ? a->unicode() - b->unicode() : 0; } else { const QChar *e = a + l; for ( ; a != e; ++a, ++b) { if (*a != *b) return a->unicode() - b->unicode(); } } | - | ||||||||||||||||||
| 512 | - | |||||||||||||||||||
| 513 | // do we have a tail? dead code: if ((reinterpret_cast<quintptr>(a) & 2) == (reinterpret_cast<quintptr>(b) & 2)) { if (reinterpret_cast<quintptr>(a) & 2) { if (*a != *b) return a->unicode() - b->unicode(); --l; ++a; ++b; } const quint32 *da = reinterpret_cast<const quint32 *>(a); const q...e(); } } a = reinterpret_cast<const QChar *>(da); b = reinterpret_cast<const QChar *>(db); return (l & 1) ? a->unicode() - b->unicode() : 0; } else { const QChar *e = a + l; for ( ; a != e; ++a, ++b) { if (*a != *b) return a->unicode() - b->unicode(); } } | - | ||||||||||||||||||
| 514 | a = reinterpret_cast<const QChar *>(da); dead code: if ((reinterpret_cast<quintptr>(a) & 2) == (reinterpret_cast<quintptr>(b) & 2)) { if (reinterpret_cast<quintptr>(a) & 2) { if (*a != *b) return a->unicode() - b->unicode(); --l; ++a; ++b; } const quint32 *da = reinterpret_cast<const quint32 *>(a); const q...e(); } } a = reinterpret_cast<const QChar *>(da); b = reinterpret_cast<const QChar *>(db); return (l & 1) ? a->unicode() - b->unicode() : 0; } else { const QChar *e = a + l; for ( ; a != e; ++a, ++b) { if (*a != *b) return a->unicode() - b->unicode(); } } | - | ||||||||||||||||||
| 515 | b = reinterpret_cast<const QChar *>(db); dead code: if ((reinterpret_cast<quintptr>(a) & 2) == (reinterpret_cast<quintptr>(b) & 2)) { if (reinterpret_cast<quintptr>(a) & 2) { if (*a != *b) return a->unicode() - b->unicode(); --l; ++a; ++b; } const quint32 *da = reinterpret_cast<const quint32 *>(a); const q...e(); } } a = reinterpret_cast<const QChar *>(da); b = reinterpret_cast<const QChar *>(db); return (l & 1) ? a->unicode() - b->unicode() : 0; } else { const QChar *e = a + l; for ( ; a != e; ++a, ++b) { if (*a != *b) return a->unicode() - b->unicode(); } } | - | ||||||||||||||||||
| 516 | return (l & 1) ? a->unicode() - b->unicode() : 0; dead code: if ((reinterpret_cast<quintptr>(a) & 2) == (reinterpret_cast<quintptr>(b) & 2)) { if (reinterpret_cast<quintptr>(a) & 2) { if (*a != *b) return a->unicode() - b->unicode(); --l; ++a; ++b; } const quint32 *da = reinterpret_cast<const quint32 *>(a); const q...e(); } } a = reinterpret_cast<const QChar *>(da); b = reinterpret_cast<const QChar *>(db); return (l & 1) ? a->unicode() - b->unicode() : 0; } else { const QChar *e = a + l; for ( ; a != e; ++a, ++b) { if (*a != *b) return a->unicode() - b->unicode(); } } | - | ||||||||||||||||||
| 517 | } else { dead code: if ((reinterpret_cast<quintptr>(a) & 2) == (reinterpret_cast<quintptr>(b) & 2)) { if (reinterpret_cast<quintptr>(a) & 2) { if (*a != *b) return a->unicode() - b->unicode(); --l; ++a; ++b; } const quint32 *da = reinterpret_cast<const quint32 *>(a); const q...e(); } } a = reinterpret_cast<const QChar *>(da); b = reinterpret_cast<const QChar *>(db); return (l & 1) ? a->unicode() - b->unicode() : 0; } else { const QChar *e = a + l; for ( ; a != e; ++a, ++b) { if (*a != *b) return a->unicode() - b->unicode(); } } | - | ||||||||||||||||||
| 518 | // one of the addresses isn't 4-byte aligned but the other is dead code: if ((reinterpret_cast<quintptr>(a) & 2) == (reinterpret_cast<quintptr>(b) & 2)) { if (reinterpret_cast<quintptr>(a) & 2) { if (*a != *b) return a->unicode() - b->unicode(); --l; ++a; ++b; } const quint32 *da = reinterpret_cast<const quint32 *>(a); const q...e(); } } a = reinterpret_cast<const QChar *>(da); b = reinterpret_cast<const QChar *>(db); return (l & 1) ? a->unicode() - b->unicode() : 0; } else { const QChar *e = a + l; for ( ; a != e; ++a, ++b) { if (*a != *b) return a->unicode() - b->unicode(); } } | - | ||||||||||||||||||
| 519 | const QChar *e = a + l; dead code: if ((reinterpret_cast<quintptr>(a) & 2) == (reinterpret_cast<quintptr>(b) & 2)) { if (reinterpret_cast<quintptr>(a) & 2) { if (*a != *b) return a->unicode() - b->unicode(); --l; ++a; ++b; } const quint32 *da = reinterpret_cast<const quint32 *>(a); const q...e(); } } a = reinterpret_cast<const QChar *>(da); b = reinterpret_cast<const QChar *>(db); return (l & 1) ? a->unicode() - b->unicode() : 0; } else { const QChar *e = a + l; for ( ; a != e; ++a, ++b) { if (*a != *b) return a->unicode() - b->unicode(); } } | - | ||||||||||||||||||
| 520 | for ( ; a != e; ++a, ++b) { dead code: if ((reinterpret_cast<quintptr>(a) & 2) == (reinterpret_cast<quintptr>(b) & 2)) { if (reinterpret_cast<quintptr>(a) & 2) { if (*a != *b) return a->unicode() - b->unicode(); --l; ++a; ++b; } const quint32 *da = reinterpret_cast<const quint32 *>(a); const q...e(); } } a = reinterpret_cast<const QChar *>(da); b = reinterpret_cast<const QChar *>(db); return (l & 1) ? a->unicode() - b->unicode() : 0; } else { const QChar *e = a + l; for ( ; a != e; ++a, ++b) { if (*a != *b) return a->unicode() - b->unicode(); } } | - | ||||||||||||||||||
| 521 | if (*a != *b) dead code: if ((reinterpret_cast<quintptr>(a) & 2) == (reinterpret_cast<quintptr>(b) & 2)) { if (reinterpret_cast<quintptr>(a) & 2) { if (*a != *b) return a->unicode() - b->unicode(); --l; ++a; ++b; } const quint32 *da = reinterpret_cast<const quint32 *>(a); const q...e(); } } a = reinterpret_cast<const QChar *>(da); b = reinterpret_cast<const QChar *>(db); return (l & 1) ? a->unicode() - b->unicode() : 0; } else { const QChar *e = a + l; for ( ; a != e; ++a, ++b) { if (*a != *b) return a->unicode() - b->unicode(); } } | - | ||||||||||||||||||
| 522 | return a->unicode() - b->unicode(); dead code: if ((reinterpret_cast<quintptr>(a) & 2) == (reinterpret_cast<quintptr>(b) & 2)) { if (reinterpret_cast<quintptr>(a) & 2) { if (*a != *b) return a->unicode() - b->unicode(); --l; ++a; ++b; } const quint32 *da = reinterpret_cast<const quint32 *>(a); const q...e(); } } a = reinterpret_cast<const QChar *>(da); b = reinterpret_cast<const QChar *>(db); return (l & 1) ? a->unicode() - b->unicode() : 0; } else { const QChar *e = a + l; for ( ; a != e; ++a, ++b) { if (*a != *b) return a->unicode() - b->unicode(); } } | - | ||||||||||||||||||
| 523 | } dead code: if ((reinterpret_cast<quintptr>(a) & 2) == (reinterpret_cast<quintptr>(b) & 2)) { if (reinterpret_cast<quintptr>(a) & 2) { if (*a != *b) return a->unicode() - b->unicode(); --l; ++a; ++b; } const quint32 *da = reinterpret_cast<const quint32 *>(a); const q...e(); } } a = reinterpret_cast<const QChar *>(da); b = reinterpret_cast<const QChar *>(db); return (l & 1) ? a->unicode() - b->unicode() : 0; } else { const QChar *e = a + l; for ( ; a != e; ++a, ++b) { if (*a != *b) return a->unicode() - b->unicode(); } } | - | ||||||||||||||||||
| 524 | } dead code: if ((reinterpret_cast<quintptr>(a) & 2) == (reinterpret_cast<quintptr>(b) & 2)) { if (reinterpret_cast<quintptr>(a) & 2) { if (*a != *b) return a->unicode() - b->unicode(); --l; ++a; ++b; } const quint32 *da = reinterpret_cast<const quint32 *>(a); const q...e(); } } a = reinterpret_cast<const QChar *>(da); b = reinterpret_cast<const QChar *>(db); return (l & 1) ? a->unicode() - b->unicode() : 0; } else { const QChar *e = a + l; for ( ; a != e; ++a, ++b) { if (*a != *b) return a->unicode() - b->unicode(); } } | - | ||||||||||||||||||
| 525 | return 0; dead code: return 0; | - | ||||||||||||||||||
| 526 | } | - | ||||||||||||||||||
| 527 | - | |||||||||||||||||||
| 528 | static int ucstrncmp(const QChar *a, const uchar *c, int l) | - | ||||||||||||||||||
| 529 | { | - | ||||||||||||||||||
| 530 | const ushort *uc = reinterpret_cast<const ushort *>(a); | - | ||||||||||||||||||
| 531 | const ushort *e = uc + l; | - | ||||||||||||||||||
| 532 | - | |||||||||||||||||||
| 533 | #ifdef __SSE2__ | - | ||||||||||||||||||
| 534 | __m128i nullmask = _mm_setzero_si128(); | - | ||||||||||||||||||
| 535 | qptrdiff offset = 0; | - | ||||||||||||||||||
| 536 | - | |||||||||||||||||||
| 537 | // we're going to read uc[offset..offset+15] (32 bytes) | - | ||||||||||||||||||
| 538 | // and c[offset..offset+15] (16 bytes) | - | ||||||||||||||||||
| 539 | for ( ; uc + offset + 15 < e; offset += 16) {
| 49948-1099422 | ||||||||||||||||||
| 540 | // similar to fromLatin1_helper: | - | ||||||||||||||||||
| 541 | // load 16 bytes of Latin 1 data | - | ||||||||||||||||||
| 542 | __m128i chunk = _mm_loadu_si128((const __m128i*)(c + offset)); | - | ||||||||||||||||||
| 543 | - | |||||||||||||||||||
| 544 | # ifdef __AVX2__ | - | ||||||||||||||||||
| 545 | // expand Latin 1 data via zero extension | - | ||||||||||||||||||
| 546 | __m256i ldata = _mm256_cvtepu8_epi16(chunk); | - | ||||||||||||||||||
| 547 | - | |||||||||||||||||||
| 548 | // load UTF-16 data and compare | - | ||||||||||||||||||
| 549 | __m256i ucdata = _mm256_loadu_si256((const __m256i*)(uc + offset)); | - | ||||||||||||||||||
| 550 | __m256i result = _mm256_cmpeq_epi16(ldata, ucdata); | - | ||||||||||||||||||
| 551 | - | |||||||||||||||||||
| 552 | uint mask = ~_mm256_movemask_epi8(result); | - | ||||||||||||||||||
| 553 | # else | - | ||||||||||||||||||
| 554 | // expand via unpacking | - | ||||||||||||||||||
| 555 | __m128i firstHalf = _mm_unpacklo_epi8(chunk, nullmask); | - | ||||||||||||||||||
| 556 | __m128i secondHalf = _mm_unpackhi_epi8(chunk, nullmask); | - | ||||||||||||||||||
| 557 | - | |||||||||||||||||||
| 558 | // load UTF-16 data and compare | - | ||||||||||||||||||
| 559 | __m128i ucdata1 = _mm_loadu_si128((const __m128i*)(uc + offset)); | - | ||||||||||||||||||
| 560 | __m128i ucdata2 = _mm_loadu_si128((const __m128i*)(uc + offset + 8)); | - | ||||||||||||||||||
| 561 | __m128i result1 = _mm_cmpeq_epi16(firstHalf, ucdata1); | - | ||||||||||||||||||
| 562 | __m128i result2 = _mm_cmpeq_epi16(secondHalf, ucdata2); | - | ||||||||||||||||||
| 563 | - | |||||||||||||||||||
| 564 | uint mask = ~(_mm_movemask_epi8(result1) | _mm_movemask_epi8(result2) << 16); | - | ||||||||||||||||||
| 565 | # endif | - | ||||||||||||||||||
| 566 | if (mask) {
| 19712-30236 | ||||||||||||||||||
| 567 | // found a different character | - | ||||||||||||||||||
| 568 | uint idx = uint(_bit_scan_forward(mask)); | - | ||||||||||||||||||
| 569 | return uc[offset + idx / 2] - c[offset + idx / 2]; executed 19712 times by 60 tests: return uc[offset + idx / 2] - c[offset + idx / 2];Executed by:
| 19712 | ||||||||||||||||||
| 570 | } | - | ||||||||||||||||||
| 571 | } executed 30236 times by 342 tests: end of blockExecuted by:
| 30236 | ||||||||||||||||||
| 572 | - | |||||||||||||||||||
| 573 | # ifdef Q_PROCESSOR_X86_64 | - | ||||||||||||||||||
| 574 | enum { MaxTailLength = 7 }; | - | ||||||||||||||||||
| 575 | // we'll read uc[offset..offset+7] (16 bytes) and c[offset..offset+7] (8 bytes) | - | ||||||||||||||||||
| 576 | if (uc + offset + 7 < e) {
| 361043-738379 | ||||||||||||||||||
| 577 | // same, but we're using an 8-byte load | - | ||||||||||||||||||
| 578 | __m128i chunk = _mm_cvtsi64_si128(qFromUnaligned<long long>(c + offset)); | - | ||||||||||||||||||
| 579 | __m128i secondHalf = _mm_unpacklo_epi8(chunk, nullmask); | - | ||||||||||||||||||
| 580 | - | |||||||||||||||||||
| 581 | __m128i ucdata = _mm_loadu_si128((const __m128i*)(uc + offset)); | - | ||||||||||||||||||
| 582 | __m128i result = _mm_cmpeq_epi16(secondHalf, ucdata); | - | ||||||||||||||||||
| 583 | uint mask = ~_mm_movemask_epi8(result); | - | ||||||||||||||||||
| 584 | if (ushort(mask)) {
| 80759-280284 | ||||||||||||||||||
| 585 | // found a different character | - | ||||||||||||||||||
| 586 | uint idx = uint(_bit_scan_forward(mask)); | - | ||||||||||||||||||
| 587 | return uc[offset + idx / 2] - c[offset + idx / 2]; executed 80759 times by 228 tests: return uc[offset + idx / 2] - c[offset + idx / 2];Executed by:
| 80759 | ||||||||||||||||||
| 588 | } | - | ||||||||||||||||||
| 589 | - | |||||||||||||||||||
| 590 | // still matched | - | ||||||||||||||||||
| 591 | offset += 8; | - | ||||||||||||||||||
| 592 | } executed 280284 times by 244 tests: end of blockExecuted by:
| 280284 | ||||||||||||||||||
| 593 | # else | - | ||||||||||||||||||
| 594 | // 32-bit, we can't do MOVQ to load 8 bytes | - | ||||||||||||||||||
| 595 | Q_UNUSED(nullmask); | - | ||||||||||||||||||
| 596 | enum { MaxTailLength = 15 }; | - | ||||||||||||||||||
| 597 | # endif | - | ||||||||||||||||||
| 598 | - | |||||||||||||||||||
| 599 | // reset uc and c | - | ||||||||||||||||||
| 600 | uc += offset; | - | ||||||||||||||||||
| 601 | c += offset; | - | ||||||||||||||||||
| 602 | - | |||||||||||||||||||
| 603 | # if defined(Q_COMPILER_LAMBDA) && !defined(__OPTIMIZE_SIZE__) | - | ||||||||||||||||||
| 604 | const auto &lambda = [=](int i) { return uc[i] - ushort(c[i]); }; executed 2969312 times by 459 tests: return uc[i] - ushort(c[i]);Executed by:
| 2969312 | ||||||||||||||||||
| 605 | return UnrollTailLoop<MaxTailLength>::exec(e - uc, 0, lambda, lambda); executed 1018663 times by 459 tests: return UnrollTailLoop<MaxTailLength>::exec(e - uc, 0, lambda, lambda);Executed by:
| 1018663 | ||||||||||||||||||
| 606 | # endif | - | ||||||||||||||||||
| 607 | #endif | - | ||||||||||||||||||
| 608 | - | |||||||||||||||||||
| 609 | while (uc < e) { dead code: while (uc < e) { int diff = *uc - *c; if (diff) return diff; uc++, c++; } | - | ||||||||||||||||||
| 610 | int diff = *uc - *c; dead code: while (uc < e) { int diff = *uc - *c; if (diff) return diff; uc++, c++; } | - | ||||||||||||||||||
| 611 | if (diff) dead code: while (uc < e) { int diff = *uc - *c; if (diff) return diff; uc++, c++; } | - | ||||||||||||||||||
| 612 | return diff; dead code: while (uc < e) { int diff = *uc - *c; if (diff) return diff; uc++, c++; } | - | ||||||||||||||||||
| 613 | uc++, c++; dead code: while (uc < e) { int diff = *uc - *c; if (diff) return diff; uc++, c++; } | - | ||||||||||||||||||
| 614 | } dead code: while (uc < e) { int diff = *uc - *c; if (diff) return diff; uc++, c++; } | - | ||||||||||||||||||
| 615 | - | |||||||||||||||||||
| 616 | return 0; dead code: return 0; | - | ||||||||||||||||||
| 617 | } | - | ||||||||||||||||||
| 618 | - | |||||||||||||||||||
| 619 | // Unicode case-sensitive comparison | - | ||||||||||||||||||
| 620 | static int ucstrcmp(const QChar *a, int alen, const QChar *b, int blen) | - | ||||||||||||||||||
| 621 | { | - | ||||||||||||||||||
| 622 | if (a == b && alen == blen)
| 1-2253452 | ||||||||||||||||||
| 623 | return 0; executed 80469 times by 428 tests: return 0;Executed by:
| 80469 | ||||||||||||||||||
| 624 | int l = qMin(alen, blen); | - | ||||||||||||||||||
| 625 | int cmp = ucstrncmp(a, b, l); | - | ||||||||||||||||||
| 626 | return cmp ? cmp : (alen-blen); executed 2253777 times by 463 tests: return cmp ? cmp : (alen-blen);Executed by:
| 181672-2253777 | ||||||||||||||||||
| 627 | } | - | ||||||||||||||||||
| 628 | - | |||||||||||||||||||
| 629 | // Unicode case-insensitive compare two same-sized strings | - | ||||||||||||||||||
| 630 | static int ucstrnicmp(const ushort *a, const ushort *b, int l) | - | ||||||||||||||||||
| 631 | { | - | ||||||||||||||||||
| 632 | return ucstricmp(a, a + l, b, b + l); executed 1171 times by 13 tests: return ucstricmp(a, a + l, b, b + l);Executed by:
| 1171 | ||||||||||||||||||
| 633 | } | - | ||||||||||||||||||
| 634 | - | |||||||||||||||||||
| 635 | static bool qMemEquals(const quint16 *a, const quint16 *b, int length) | - | ||||||||||||||||||
| 636 | { | - | ||||||||||||||||||
| 637 | if (a == b || !length)
| 220559-3030930 | ||||||||||||||||||
| 638 | return true; executed 1142005 times by 474 tests: return true;Executed by:
| 1142005 | ||||||||||||||||||
| 639 | - | |||||||||||||||||||
| 640 | return ucstrncmp(reinterpret_cast<const QChar *>(a), reinterpret_cast<const QChar *>(b), length) == 0; executed 2810371 times by 399 tests: return ucstrncmp(reinterpret_cast<const QChar *>(a), reinterpret_cast<const QChar *>(b), length) == 0;Executed by:
| 2810371 | ||||||||||||||||||
| 641 | } | - | ||||||||||||||||||
| 642 | - | |||||||||||||||||||
| 643 | static int ucstrcmp(const QChar *a, int alen, const uchar *b, int blen) | - | ||||||||||||||||||
| 644 | { | - | ||||||||||||||||||
| 645 | int l = qMin(alen, blen); | - | ||||||||||||||||||
| 646 | int cmp = ucstrncmp(a, b, l); | - | ||||||||||||||||||
| 647 | return cmp ? cmp : (alen-blen); executed 518239 times by 443 tests: return cmp ? cmp : (alen-blen);Executed by:
| 222479-518239 | ||||||||||||||||||
| 648 | } | - | ||||||||||||||||||
| 649 | - | |||||||||||||||||||
| 650 | /*! | - | ||||||||||||||||||
| 651 | \internal | - | ||||||||||||||||||
| 652 | - | |||||||||||||||||||
| 653 | Returns the index position of the first occurrence of the | - | ||||||||||||||||||
| 654 | character \a ch in the string given by \a str and \a len, | - | ||||||||||||||||||
| 655 | searching forward from index | - | ||||||||||||||||||
| 656 | position \a from. Returns -1 if \a ch could not be found. | - | ||||||||||||||||||
| 657 | */ | - | ||||||||||||||||||
| 658 | static int findChar(const QChar *str, int len, QChar ch, int from, | - | ||||||||||||||||||
| 659 | Qt::CaseSensitivity cs) | - | ||||||||||||||||||
| 660 | { | - | ||||||||||||||||||
| 661 | const ushort *s = (const ushort *)str; | - | ||||||||||||||||||
| 662 | ushort c = ch.unicode(); | - | ||||||||||||||||||
| 663 | if (from < 0)
| 1-1387889 | ||||||||||||||||||
| 664 | from = qMax(from + len, 0); executed 1 time by 1 test: from = qMax(from + len, 0);Executed by:
| 1 | ||||||||||||||||||
| 665 | if (from < len) {
| 3491-1384399 | ||||||||||||||||||
| 666 | const ushort *n = s + from; | - | ||||||||||||||||||
| 667 | const ushort *e = s + len; | - | ||||||||||||||||||
| 668 | if (cs == Qt::CaseSensitive) {
| 461-1383938 | ||||||||||||||||||
| 669 | #ifdef __SSE2__ | - | ||||||||||||||||||
| 670 | __m128i mch = _mm_set1_epi32(c | (c << 16)); | - | ||||||||||||||||||
| 671 | - | |||||||||||||||||||
| 672 | // we're going to read n[0..7] (16 bytes) | - | ||||||||||||||||||
| 673 | for (const ushort *next = n + 8; next <= e; n = next, next += 8) {
| 992185-1050720 | ||||||||||||||||||
| 674 | __m128i data = _mm_loadu_si128((const __m128i*)n); | - | ||||||||||||||||||
| 675 | __m128i result = _mm_cmpeq_epi16(data, mch); | - | ||||||||||||||||||
| 676 | uint mask = _mm_movemask_epi8(result); | - | ||||||||||||||||||
| 677 | if (ushort(mask)) {
| 391753-658967 | ||||||||||||||||||
| 678 | // found a match | - | ||||||||||||||||||
| 679 | // same as: return n - s + _bit_scan_forward(mask) / 2 | - | ||||||||||||||||||
| 680 | return (reinterpret_cast<const char *>(n) - reinterpret_cast<const char *>(s) executed 391753 times by 270 tests: return (reinterpret_cast<const char *>(n) - reinterpret_cast<const char *>(s) + __bsfd(mask)) >> 1;Executed by:
| 391753 | ||||||||||||||||||
| 681 | + _bit_scan_forward(mask)) >> 1; executed 391753 times by 270 tests: return (reinterpret_cast<const char *>(n) - reinterpret_cast<const char *>(s) + __bsfd(mask)) >> 1;Executed by:
| 391753 | ||||||||||||||||||
| 682 | } | - | ||||||||||||||||||
| 683 | } executed 658967 times by 297 tests: end of blockExecuted by:
| 658967 | ||||||||||||||||||
| 684 | - | |||||||||||||||||||
| 685 | # if defined(Q_COMPILER_LAMBDA) && !defined(__OPTIMIZE_SIZE__) | - | ||||||||||||||||||
| 686 | return UnrollTailLoop<7>::exec(e - n, -1, executed 992185 times by 309 tests: return UnrollTailLoop<7>::exec(e - n, -1, [=](int i) { return n[i] == c; }, [=](int i) { return n - s + i; });Executed by:
| 992185 | ||||||||||||||||||
| 687 | [=](int i) { return n[i] == c; }, executed 992185 times by 309 tests: return UnrollTailLoop<7>::exec(e - n, -1, [=](int i) { return n[i] == c; }, [=](int i) { return n - s + i; });Executed by:
executed 2236993 times by 307 tests: return n[i] == c;Executed by:
| 992185-2236993 | ||||||||||||||||||
| 688 | [=](int i) { return n - s + i; }); executed 992185 times by 309 tests: return UnrollTailLoop<7>::exec(e - n, -1, [=](int i) { return n[i] == c; }, [=](int i) { return n - s + i; });Executed by:
executed 71033 times by 138 tests: return n - s + i;Executed by:
| 71033-992185 | ||||||||||||||||||
| 689 | # endif | - | ||||||||||||||||||
| 690 | #endif | - | ||||||||||||||||||
| 691 | --n; dead code: --n; | - | ||||||||||||||||||
| 692 | while (++n != e) dead code: while (++n != e) if (*n == c) return n - s; | - | ||||||||||||||||||
| 693 | if (*n == c) dead code: while (++n != e) if (*n == c) return n - s; | - | ||||||||||||||||||
| 694 | return n - s; dead code: while (++n != e) if (*n == c) return n - s; | - | ||||||||||||||||||
| 695 | } else { | - | ||||||||||||||||||
| 696 | c = foldCase(c); | - | ||||||||||||||||||
| 697 | --n; | - | ||||||||||||||||||
| 698 | while (++n != e)
| 125-800 | ||||||||||||||||||
| 699 | if (foldCase(*n) == c)
| 336-464 | ||||||||||||||||||
| 700 | return n - s; executed 336 times by 6 tests: return n - s;Executed by:
| 336 | ||||||||||||||||||
| 701 | } executed 125 times by 4 tests: end of blockExecuted by:
| 125 | ||||||||||||||||||
| 702 | } | - | ||||||||||||||||||
| 703 | return -1; executed 3616 times by 66 tests: return -1;Executed by:
| 3616 | ||||||||||||||||||
| 704 | } | - | ||||||||||||||||||
| 705 | - | |||||||||||||||||||
| 706 | #define REHASH(a) \ | - | ||||||||||||||||||
| 707 | if (sl_minus_1 < sizeof(uint) * CHAR_BIT) \ | - | ||||||||||||||||||
| 708 | hashHaystack -= uint(a) << sl_minus_1; \ | - | ||||||||||||||||||
| 709 | hashHaystack <<= 1 | - | ||||||||||||||||||
| 710 | - | |||||||||||||||||||
| 711 | inline bool qIsUpper(char ch) | - | ||||||||||||||||||
| 712 | { | - | ||||||||||||||||||
| 713 | return ch >= 'A' && ch <= 'Z'; executed 114903 times by 50 tests: return ch >= 'A' && ch <= 'Z';Executed by:
| 0-114903 | ||||||||||||||||||
| 714 | } | - | ||||||||||||||||||
| 715 | - | |||||||||||||||||||
| 716 | inline bool qIsDigit(char ch) | - | ||||||||||||||||||
| 717 | { | - | ||||||||||||||||||
| 718 | return ch >= '0' && ch <= '9'; executed 420370 times by 110 tests: return ch >= '0' && ch <= '9';Executed by:
| 9369-420370 | ||||||||||||||||||
| 719 | } | - | ||||||||||||||||||
| 720 | - | |||||||||||||||||||
| 721 | inline char qToLower(char ch) | - | ||||||||||||||||||
| 722 | { | - | ||||||||||||||||||
| 723 | if (ch >= 'A' && ch <= 'Z')
| 0-114903 | ||||||||||||||||||
| 724 | return ch - 'A' + 'a'; executed 4992 times by 1 test: return ch - 'A' + 'a';Executed by:
| 4992 | ||||||||||||||||||
| 725 | else | - | ||||||||||||||||||
| 726 | return ch; executed 109911 times by 50 tests: return ch;Executed by:
| 109911 | ||||||||||||||||||
| 727 | } | - | ||||||||||||||||||
| 728 | - | |||||||||||||||||||
| 729 | - | |||||||||||||||||||
| 730 | const QString::Null QString::null = { }; | - | ||||||||||||||||||
| 731 | - | |||||||||||||||||||
| 732 | /*! | - | ||||||||||||||||||
| 733 | \macro QT_RESTRICTED_CAST_FROM_ASCII | - | ||||||||||||||||||
| 734 | \relates QString | - | ||||||||||||||||||
| 735 | - | |||||||||||||||||||
| 736 | Defining this macro disables most automatic conversions from source | - | ||||||||||||||||||
| 737 | literals and 8-bit data to unicode QStrings, but allows the use of | - | ||||||||||||||||||
| 738 | the \c{QChar(char)} and \c{QString(const char (&ch)[N]} constructors, | - | ||||||||||||||||||
| 739 | and the \c{QString::operator=(const char (&ch)[N])} assignment operator | - | ||||||||||||||||||
| 740 | giving most of the type-safety benefits of QT_NO_CAST_FROM_ASCII | - | ||||||||||||||||||
| 741 | but does not require user code to wrap character and string literals | - | ||||||||||||||||||
| 742 | with QLatin1Char, QLatin1String or similar. | - | ||||||||||||||||||
| 743 | - | |||||||||||||||||||
| 744 | Using this macro together with source strings outside the 7-bit range, | - | ||||||||||||||||||
| 745 | non-literals, or literals with embedded NUL characters is undefined. | - | ||||||||||||||||||
| 746 | - | |||||||||||||||||||
| 747 | \sa QT_NO_CAST_FROM_ASCII, QT_NO_CAST_TO_ASCII | - | ||||||||||||||||||
| 748 | */ | - | ||||||||||||||||||
| 749 | - | |||||||||||||||||||
| 750 | /*! | - | ||||||||||||||||||
| 751 | \macro QT_NO_CAST_FROM_ASCII | - | ||||||||||||||||||
| 752 | \relates QString | - | ||||||||||||||||||
| 753 | - | |||||||||||||||||||
| 754 | Disables automatic conversions from 8-bit strings (char *) to unicode QStrings | - | ||||||||||||||||||
| 755 | - | |||||||||||||||||||
| 756 | \sa QT_NO_CAST_TO_ASCII, QT_RESTRICTED_CAST_FROM_ASCII, QT_NO_CAST_FROM_BYTEARRAY | - | ||||||||||||||||||
| 757 | */ | - | ||||||||||||||||||
| 758 | - | |||||||||||||||||||
| 759 | /*! | - | ||||||||||||||||||
| 760 | \macro QT_NO_CAST_TO_ASCII | - | ||||||||||||||||||
| 761 | \relates QString | - | ||||||||||||||||||
| 762 | - | |||||||||||||||||||
| 763 | disables automatic conversion from QString to 8-bit strings (char *) | - | ||||||||||||||||||
| 764 | - | |||||||||||||||||||
| 765 | \sa QT_NO_CAST_FROM_ASCII, QT_RESTRICTED_CAST_FROM_ASCII, QT_NO_CAST_FROM_BYTEARRAY | - | ||||||||||||||||||
| 766 | */ | - | ||||||||||||||||||
| 767 | - | |||||||||||||||||||
| 768 | /*! | - | ||||||||||||||||||
| 769 | \macro QT_ASCII_CAST_WARNINGS | - | ||||||||||||||||||
| 770 | \internal | - | ||||||||||||||||||
| 771 | \relates QString | - | ||||||||||||||||||
| 772 | - | |||||||||||||||||||
| 773 | This macro can be defined to force a warning whenever a function is | - | ||||||||||||||||||
| 774 | called that automatically converts between unicode and 8-bit encodings. | - | ||||||||||||||||||
| 775 | - | |||||||||||||||||||
| 776 | Note: This only works for compilers that support warnings for | - | ||||||||||||||||||
| 777 | deprecated API. | - | ||||||||||||||||||
| 778 | - | |||||||||||||||||||
| 779 | \sa QT_NO_CAST_TO_ASCII, QT_NO_CAST_FROM_ASCII, QT_RESTRICTED_CAST_FROM_ASCII | - | ||||||||||||||||||
| 780 | */ | - | ||||||||||||||||||
| 781 | - | |||||||||||||||||||
| 782 | /*! | - | ||||||||||||||||||
| 783 | \class QCharRef | - | ||||||||||||||||||
| 784 | \inmodule QtCore | - | ||||||||||||||||||
| 785 | \reentrant | - | ||||||||||||||||||
| 786 | \brief The QCharRef class is a helper class for QString. | - | ||||||||||||||||||
| 787 | - | |||||||||||||||||||
| 788 | \internal | - | ||||||||||||||||||
| 789 | - | |||||||||||||||||||
| 790 | \ingroup string-processing | - | ||||||||||||||||||
| 791 | - | |||||||||||||||||||
| 792 | When you get an object of type QCharRef, if you can assign to it, | - | ||||||||||||||||||
| 793 | the assignment will apply to the character in the string from | - | ||||||||||||||||||
| 794 | which you got the reference. That is its whole purpose in life. | - | ||||||||||||||||||
| 795 | The QCharRef becomes invalid once modifications are made to the | - | ||||||||||||||||||
| 796 | string: if you want to keep the character, copy it into a QChar. | - | ||||||||||||||||||
| 797 | - | |||||||||||||||||||
| 798 | Most of the QChar member functions also exist in QCharRef. | - | ||||||||||||||||||
| 799 | However, they are not explicitly documented here. | - | ||||||||||||||||||
| 800 | - | |||||||||||||||||||
| 801 | \sa QString::operator[](), QString::at(), QChar | - | ||||||||||||||||||
| 802 | */ | - | ||||||||||||||||||
| 803 | - | |||||||||||||||||||
| 804 | /*! | - | ||||||||||||||||||
| 805 | \class QString | - | ||||||||||||||||||
| 806 | \inmodule QtCore | - | ||||||||||||||||||
| 807 | \reentrant | - | ||||||||||||||||||
| 808 | - | |||||||||||||||||||
| 809 | \brief The QString class provides a Unicode character string. | - | ||||||||||||||||||
| 810 | - | |||||||||||||||||||
| 811 | \ingroup tools | - | ||||||||||||||||||
| 812 | \ingroup shared | - | ||||||||||||||||||
| 813 | \ingroup string-processing | - | ||||||||||||||||||
| 814 | - | |||||||||||||||||||
| 815 | QString stores a string of 16-bit \l{QChar}s, where each QChar | - | ||||||||||||||||||
| 816 | corresponds one Unicode 4.0 character. (Unicode characters | - | ||||||||||||||||||
| 817 | with code values above 65535 are stored using surrogate pairs, | - | ||||||||||||||||||
| 818 | i.e., two consecutive \l{QChar}s.) | - | ||||||||||||||||||
| 819 | - | |||||||||||||||||||
| 820 | \l{Unicode} is an international standard that supports most of the | - | ||||||||||||||||||
| 821 | writing systems in use today. It is a superset of US-ASCII (ANSI | - | ||||||||||||||||||
| 822 | X3.4-1986) and Latin-1 (ISO 8859-1), and all the US-ASCII/Latin-1 | - | ||||||||||||||||||
| 823 | characters are available at the same code positions. | - | ||||||||||||||||||
| 824 | - | |||||||||||||||||||
| 825 | Behind the scenes, QString uses \l{implicit sharing} | - | ||||||||||||||||||
| 826 | (copy-on-write) to reduce memory usage and to avoid the needless | - | ||||||||||||||||||
| 827 | copying of data. This also helps reduce the inherent overhead of | - | ||||||||||||||||||
| 828 | storing 16-bit characters instead of 8-bit characters. | - | ||||||||||||||||||
| 829 | - | |||||||||||||||||||
| 830 | In addition to QString, Qt also provides the QByteArray class to | - | ||||||||||||||||||
| 831 | store raw bytes and traditional 8-bit '\\0'-terminated strings. | - | ||||||||||||||||||
| 832 | For most purposes, QString is the class you want to use. It is | - | ||||||||||||||||||
| 833 | used throughout the Qt API, and the Unicode support ensures that | - | ||||||||||||||||||
| 834 | your applications will be easy to translate if you want to expand | - | ||||||||||||||||||
| 835 | your application's market at some point. The two main cases where | - | ||||||||||||||||||
| 836 | QByteArray is appropriate are when you need to store raw binary | - | ||||||||||||||||||
| 837 | data, and when memory conservation is critical (like in embedded | - | ||||||||||||||||||
| 838 | systems). | - | ||||||||||||||||||
| 839 | - | |||||||||||||||||||
| 840 | \tableofcontents | - | ||||||||||||||||||
| 841 | - | |||||||||||||||||||
| 842 | \section1 Initializing a String | - | ||||||||||||||||||
| 843 | - | |||||||||||||||||||
| 844 | One way to initialize a QString is simply to pass a \c{const char | - | ||||||||||||||||||
| 845 | *} to its constructor. For example, the following code creates a | - | ||||||||||||||||||
| 846 | QString of size 5 containing the data "Hello": | - | ||||||||||||||||||
| 847 | - | |||||||||||||||||||
| 848 | \snippet qstring/main.cpp 0 | - | ||||||||||||||||||
| 849 | - | |||||||||||||||||||
| 850 | QString converts the \c{const char *} data into Unicode using the | - | ||||||||||||||||||
| 851 | fromUtf8() function. | - | ||||||||||||||||||
| 852 | - | |||||||||||||||||||
| 853 | In all of the QString functions that take \c{const char *} | - | ||||||||||||||||||
| 854 | parameters, the \c{const char *} is interpreted as a classic | - | ||||||||||||||||||
| 855 | C-style '\\0'-terminated string encoded in UTF-8. It is legal for | - | ||||||||||||||||||
| 856 | the \c{const char *} parameter to be 0. | - | ||||||||||||||||||
| 857 | - | |||||||||||||||||||
| 858 | You can also provide string data as an array of \l{QChar}s: | - | ||||||||||||||||||
| 859 | - | |||||||||||||||||||
| 860 | \snippet qstring/main.cpp 1 | - | ||||||||||||||||||
| 861 | - | |||||||||||||||||||
| 862 | QString makes a deep copy of the QChar data, so you can modify it | - | ||||||||||||||||||
| 863 | later without experiencing side effects. (If for performance | - | ||||||||||||||||||
| 864 | reasons you don't want to take a deep copy of the character data, | - | ||||||||||||||||||
| 865 | use QString::fromRawData() instead.) | - | ||||||||||||||||||
| 866 | - | |||||||||||||||||||
| 867 | Another approach is to set the size of the string using resize() | - | ||||||||||||||||||
| 868 | and to initialize the data character per character. QString uses | - | ||||||||||||||||||
| 869 | 0-based indexes, just like C++ arrays. To access the character at | - | ||||||||||||||||||
| 870 | a particular index position, you can use \l operator[](). On | - | ||||||||||||||||||
| 871 | non-const strings, \l operator[]() returns a reference to a | - | ||||||||||||||||||
| 872 | character that can be used on the left side of an assignment. For | - | ||||||||||||||||||
| 873 | example: | - | ||||||||||||||||||
| 874 | - | |||||||||||||||||||
| 875 | \snippet qstring/main.cpp 2 | - | ||||||||||||||||||
| 876 | - | |||||||||||||||||||
| 877 | For read-only access, an alternative syntax is to use the at() | - | ||||||||||||||||||
| 878 | function: | - | ||||||||||||||||||
| 879 | - | |||||||||||||||||||
| 880 | \snippet qstring/main.cpp 3 | - | ||||||||||||||||||
| 881 | - | |||||||||||||||||||
| 882 | The at() function can be faster than \l operator[](), because it | - | ||||||||||||||||||
| 883 | never causes a \l{deep copy} to occur. Alternatively, use the | - | ||||||||||||||||||
| 884 | left(), right(), or mid() functions to extract several characters | - | ||||||||||||||||||
| 885 | at a time. | - | ||||||||||||||||||
| 886 | - | |||||||||||||||||||
| 887 | A QString can embed '\\0' characters (QChar::Null). The size() | - | ||||||||||||||||||
| 888 | function always returns the size of the whole string, including | - | ||||||||||||||||||
| 889 | embedded '\\0' characters. | - | ||||||||||||||||||
| 890 | - | |||||||||||||||||||
| 891 | After a call to the resize() function, newly allocated characters | - | ||||||||||||||||||
| 892 | have undefined values. To set all the characters in the string to | - | ||||||||||||||||||
| 893 | a particular value, use the fill() function. | - | ||||||||||||||||||
| 894 | - | |||||||||||||||||||
| 895 | QString provides dozens of overloads designed to simplify string | - | ||||||||||||||||||
| 896 | usage. For example, if you want to compare a QString with a string | - | ||||||||||||||||||
| 897 | literal, you can write code like this and it will work as expected: | - | ||||||||||||||||||
| 898 | - | |||||||||||||||||||
| 899 | \snippet qstring/main.cpp 4 | - | ||||||||||||||||||
| 900 | - | |||||||||||||||||||
| 901 | You can also pass string literals to functions that take QStrings | - | ||||||||||||||||||
| 902 | as arguments, invoking the QString(const char *) | - | ||||||||||||||||||
| 903 | constructor. Similarly, you can pass a QString to a function that | - | ||||||||||||||||||
| 904 | takes a \c{const char *} argument using the \l qPrintable() macro | - | ||||||||||||||||||
| 905 | which returns the given QString as a \c{const char *}. This is | - | ||||||||||||||||||
| 906 | equivalent to calling <QString>.toLocal8Bit().constData(). | - | ||||||||||||||||||
| 907 | - | |||||||||||||||||||
| 908 | \section1 Manipulating String Data | - | ||||||||||||||||||
| 909 | - | |||||||||||||||||||
| 910 | QString provides the following basic functions for modifying the | - | ||||||||||||||||||
| 911 | character data: append(), prepend(), insert(), replace(), and | - | ||||||||||||||||||
| 912 | remove(). For example: | - | ||||||||||||||||||
| 913 | - | |||||||||||||||||||
| 914 | \snippet qstring/main.cpp 5 | - | ||||||||||||||||||
| 915 | - | |||||||||||||||||||
| 916 | If you are building a QString gradually and know in advance | - | ||||||||||||||||||
| 917 | approximately how many characters the QString will contain, you | - | ||||||||||||||||||
| 918 | can call reserve(), asking QString to preallocate a certain amount | - | ||||||||||||||||||
| 919 | of memory. You can also call capacity() to find out how much | - | ||||||||||||||||||
| 920 | memory QString actually allocated. | - | ||||||||||||||||||
| 921 | - | |||||||||||||||||||
| 922 | The replace() and remove() functions' first two arguments are the | - | ||||||||||||||||||
| 923 | position from which to start erasing and the number of characters | - | ||||||||||||||||||
| 924 | that should be erased. If you want to replace all occurrences of | - | ||||||||||||||||||
| 925 | a particular substring with another, use one of the two-parameter | - | ||||||||||||||||||
| 926 | replace() overloads. | - | ||||||||||||||||||
| 927 | - | |||||||||||||||||||
| 928 | A frequent requirement is to remove whitespace characters from a | - | ||||||||||||||||||
| 929 | string ('\\n', '\\t', ' ', etc.). If you want to remove whitespace | - | ||||||||||||||||||
| 930 | from both ends of a QString, use the trimmed() function. If you | - | ||||||||||||||||||
| 931 | want to remove whitespace from both ends and replace multiple | - | ||||||||||||||||||
| 932 | consecutive whitespaces with a single space character within the | - | ||||||||||||||||||
| 933 | string, use simplified(). | - | ||||||||||||||||||
| 934 | - | |||||||||||||||||||
| 935 | If you want to find all occurrences of a particular character or | - | ||||||||||||||||||
| 936 | substring in a QString, use the indexOf() or lastIndexOf() | - | ||||||||||||||||||
| 937 | functions. The former searches forward starting from a given index | - | ||||||||||||||||||
| 938 | position, the latter searches backward. Both return the index | - | ||||||||||||||||||
| 939 | position of the character or substring if they find it; otherwise, | - | ||||||||||||||||||
| 940 | they return -1. For example, here's a typical loop that finds all | - | ||||||||||||||||||
| 941 | occurrences of a particular substring: | - | ||||||||||||||||||
| 942 | - | |||||||||||||||||||
| 943 | \snippet qstring/main.cpp 6 | - | ||||||||||||||||||
| 944 | - | |||||||||||||||||||
| 945 | QString provides many functions for converting numbers into | - | ||||||||||||||||||
| 946 | strings and strings into numbers. See the arg() functions, the | - | ||||||||||||||||||
| 947 | setNum() functions, the number() static functions, and the | - | ||||||||||||||||||
| 948 | toInt(), toDouble(), and similar functions. | - | ||||||||||||||||||
| 949 | - | |||||||||||||||||||
| 950 | To get an upper- or lowercase version of a string use toUpper() or | - | ||||||||||||||||||
| 951 | toLower(). | - | ||||||||||||||||||
| 952 | - | |||||||||||||||||||
| 953 | Lists of strings are handled by the QStringList class. You can | - | ||||||||||||||||||
| 954 | split a string into a list of strings using the split() function, | - | ||||||||||||||||||
| 955 | and join a list of strings into a single string with an optional | - | ||||||||||||||||||
| 956 | separator using QStringList::join(). You can obtain a list of | - | ||||||||||||||||||
| 957 | strings from a string list that contain a particular substring or | - | ||||||||||||||||||
| 958 | that match a particular QRegExp using the QStringList::filter() | - | ||||||||||||||||||
| 959 | function. | - | ||||||||||||||||||
| 960 | - | |||||||||||||||||||
| 961 | \section1 Querying String Data | - | ||||||||||||||||||
| 962 | - | |||||||||||||||||||
| 963 | If you want to see if a QString starts or ends with a particular | - | ||||||||||||||||||
| 964 | substring use startsWith() or endsWith(). If you simply want to | - | ||||||||||||||||||
| 965 | check whether a QString contains a particular character or | - | ||||||||||||||||||
| 966 | substring, use the contains() function. If you want to find out | - | ||||||||||||||||||
| 967 | how many times a particular character or substring occurs in the | - | ||||||||||||||||||
| 968 | string, use count(). | - | ||||||||||||||||||
| 969 | - | |||||||||||||||||||
| 970 | QStrings can be compared using overloaded operators such as \l | - | ||||||||||||||||||
| 971 | operator<(), \l operator<=(), \l operator==(), \l operator>=(), | - | ||||||||||||||||||
| 972 | and so on. Note that the comparison is based exclusively on the | - | ||||||||||||||||||
| 973 | numeric Unicode values of the characters. It is very fast, but is | - | ||||||||||||||||||
| 974 | not what a human would expect; the QString::localeAwareCompare() | - | ||||||||||||||||||
| 975 | function is a better choice for sorting user-interface strings. | - | ||||||||||||||||||
| 976 | - | |||||||||||||||||||
| 977 | To obtain a pointer to the actual character data, call data() or | - | ||||||||||||||||||
| 978 | constData(). These functions return a pointer to the beginning of | - | ||||||||||||||||||
| 979 | the QChar data. The pointer is guaranteed to remain valid until a | - | ||||||||||||||||||
| 980 | non-const function is called on the QString. | - | ||||||||||||||||||
| 981 | - | |||||||||||||||||||
| 982 | \section1 Converting Between 8-Bit Strings and Unicode Strings | - | ||||||||||||||||||
| 983 | - | |||||||||||||||||||
| 984 | QString provides the following three functions that return a | - | ||||||||||||||||||
| 985 | \c{const char *} version of the string as QByteArray: toUtf8(), | - | ||||||||||||||||||
| 986 | toLatin1(), and toLocal8Bit(). | - | ||||||||||||||||||
| 987 | - | |||||||||||||||||||
| 988 | \list | - | ||||||||||||||||||
| 989 | \li toLatin1() returns a Latin-1 (ISO 8859-1) encoded 8-bit string. | - | ||||||||||||||||||
| 990 | \li toUtf8() returns a UTF-8 encoded 8-bit string. UTF-8 is a | - | ||||||||||||||||||
| 991 | superset of US-ASCII (ANSI X3.4-1986) that supports the entire | - | ||||||||||||||||||
| 992 | Unicode character set through multibyte sequences. | - | ||||||||||||||||||
| 993 | \li toLocal8Bit() returns an 8-bit string using the system's local | - | ||||||||||||||||||
| 994 | encoding. | - | ||||||||||||||||||
| 995 | \endlist | - | ||||||||||||||||||
| 996 | - | |||||||||||||||||||
| 997 | To convert from one of these encodings, QString provides | - | ||||||||||||||||||
| 998 | fromLatin1(), fromUtf8(), and fromLocal8Bit(). Other | - | ||||||||||||||||||
| 999 | encodings are supported through the QTextCodec class. | - | ||||||||||||||||||
| 1000 | - | |||||||||||||||||||
| 1001 | As mentioned above, QString provides a lot of functions and | - | ||||||||||||||||||
| 1002 | operators that make it easy to interoperate with \c{const char *} | - | ||||||||||||||||||
| 1003 | strings. But this functionality is a double-edged sword: It makes | - | ||||||||||||||||||
| 1004 | QString more convenient to use if all strings are US-ASCII or | - | ||||||||||||||||||
| 1005 | Latin-1, but there is always the risk that an implicit conversion | - | ||||||||||||||||||
| 1006 | from or to \c{const char *} is done using the wrong 8-bit | - | ||||||||||||||||||
| 1007 | encoding. To minimize these risks, you can turn off these implicit | - | ||||||||||||||||||
| 1008 | conversions by defining the following two preprocessor symbols: | - | ||||||||||||||||||
| 1009 | - | |||||||||||||||||||
| 1010 | \list | - | ||||||||||||||||||
| 1011 | \li \c QT_NO_CAST_FROM_ASCII disables automatic conversions from | - | ||||||||||||||||||
| 1012 | C string literals and pointers to Unicode. | - | ||||||||||||||||||
| 1013 | \li \c QT_RESTRICTED_CAST_FROM_ASCII allows automatic conversions | - | ||||||||||||||||||
| 1014 | from C characters and character arrays, but disables automatic | - | ||||||||||||||||||
| 1015 | conversions from character pointers to Unicode. | - | ||||||||||||||||||
| 1016 | \li \c QT_NO_CAST_TO_ASCII disables automatic conversion from QString | - | ||||||||||||||||||
| 1017 | to C strings. | - | ||||||||||||||||||
| 1018 | \endlist | - | ||||||||||||||||||
| 1019 | - | |||||||||||||||||||
| 1020 | One way to define these preprocessor symbols globally for your | - | ||||||||||||||||||
| 1021 | application is to add the following entry to your \l {Creating Project Files}{qmake project file}: | - | ||||||||||||||||||
| 1022 | - | |||||||||||||||||||
| 1023 | \snippet code/src_corelib_tools_qstring.cpp 0 | - | ||||||||||||||||||
| 1024 | - | |||||||||||||||||||
| 1025 | You then need to explicitly call fromUtf8(), fromLatin1(), | - | ||||||||||||||||||
| 1026 | or fromLocal8Bit() to construct a QString from an | - | ||||||||||||||||||
| 1027 | 8-bit string, or use the lightweight QLatin1String class, for | - | ||||||||||||||||||
| 1028 | example: | - | ||||||||||||||||||
| 1029 | - | |||||||||||||||||||
| 1030 | \snippet code/src_corelib_tools_qstring.cpp 1 | - | ||||||||||||||||||
| 1031 | - | |||||||||||||||||||
| 1032 | Similarly, you must call toLatin1(), toUtf8(), or | - | ||||||||||||||||||
| 1033 | toLocal8Bit() explicitly to convert the QString to an 8-bit | - | ||||||||||||||||||
| 1034 | string. (Other encodings are supported through the QTextCodec | - | ||||||||||||||||||
| 1035 | class.) | - | ||||||||||||||||||
| 1036 | - | |||||||||||||||||||
| 1037 | \table 100 % | - | ||||||||||||||||||
| 1038 | \header | - | ||||||||||||||||||
| 1039 | \li Note for C Programmers | - | ||||||||||||||||||
| 1040 | - | |||||||||||||||||||
| 1041 | \row | - | ||||||||||||||||||
| 1042 | \li | - | ||||||||||||||||||
| 1043 | Due to C++'s type system and the fact that QString is | - | ||||||||||||||||||
| 1044 | \l{implicitly shared}, QStrings may be treated like \c{int}s or | - | ||||||||||||||||||
| 1045 | other basic types. For example: | - | ||||||||||||||||||
| 1046 | - | |||||||||||||||||||
| 1047 | \snippet qstring/main.cpp 7 | - | ||||||||||||||||||
| 1048 | - | |||||||||||||||||||
| 1049 | The \c result variable, is a normal variable allocated on the | - | ||||||||||||||||||
| 1050 | stack. When \c return is called, and because we're returning by | - | ||||||||||||||||||
| 1051 | value, the copy constructor is called and a copy of the string is | - | ||||||||||||||||||
| 1052 | returned. No actual copying takes place thanks to the implicit | - | ||||||||||||||||||
| 1053 | sharing. | - | ||||||||||||||||||
| 1054 | - | |||||||||||||||||||
| 1055 | \endtable | - | ||||||||||||||||||
| 1056 | - | |||||||||||||||||||
| 1057 | \section1 Distinction Between Null and Empty Strings | - | ||||||||||||||||||
| 1058 | - | |||||||||||||||||||
| 1059 | For historical reasons, QString distinguishes between a null | - | ||||||||||||||||||
| 1060 | string and an empty string. A \e null string is a string that is | - | ||||||||||||||||||
| 1061 | initialized using QString's default constructor or by passing | - | ||||||||||||||||||
| 1062 | (const char *)0 to the constructor. An \e empty string is any | - | ||||||||||||||||||
| 1063 | string with size 0. A null string is always empty, but an empty | - | ||||||||||||||||||
| 1064 | string isn't necessarily null: | - | ||||||||||||||||||
| 1065 | - | |||||||||||||||||||
| 1066 | \snippet qstring/main.cpp 8 | - | ||||||||||||||||||
| 1067 | - | |||||||||||||||||||
| 1068 | All functions except isNull() treat null strings the same as empty | - | ||||||||||||||||||
| 1069 | strings. For example, toUtf8().constData() returns a pointer to a | - | ||||||||||||||||||
| 1070 | '\\0' character for a null string (\e not a null pointer), and | - | ||||||||||||||||||
| 1071 | QString() compares equal to QString(""). We recommend that you | - | ||||||||||||||||||
| 1072 | always use the isEmpty() function and avoid isNull(). | - | ||||||||||||||||||
| 1073 | - | |||||||||||||||||||
| 1074 | \section1 Argument Formats | - | ||||||||||||||||||
| 1075 | - | |||||||||||||||||||
| 1076 | In member functions where an argument \e format can be specified | - | ||||||||||||||||||
| 1077 | (e.g., arg(), number()), the argument \e format can be one of the | - | ||||||||||||||||||
| 1078 | following: | - | ||||||||||||||||||
| 1079 | - | |||||||||||||||||||
| 1080 | \table | - | ||||||||||||||||||
| 1081 | \header \li Format \li Meaning | - | ||||||||||||||||||
| 1082 | \row \li \c e \li format as [-]9.9e[+|-]999 | - | ||||||||||||||||||
| 1083 | \row \li \c E \li format as [-]9.9E[+|-]999 | - | ||||||||||||||||||
| 1084 | \row \li \c f \li format as [-]9.9 | - | ||||||||||||||||||
| 1085 | \row \li \c g \li use \c e or \c f format, whichever is the most concise | - | ||||||||||||||||||
| 1086 | \row \li \c G \li use \c E or \c f format, whichever is the most concise | - | ||||||||||||||||||
| 1087 | \endtable | - | ||||||||||||||||||
| 1088 | - | |||||||||||||||||||
| 1089 | A \e precision is also specified with the argument \e format. For | - | ||||||||||||||||||
| 1090 | the 'e', 'E', and 'f' formats, the \e precision represents the | - | ||||||||||||||||||
| 1091 | number of digits \e after the decimal point. For the 'g' and 'G' | - | ||||||||||||||||||
| 1092 | formats, the \e precision represents the maximum number of | - | ||||||||||||||||||
| 1093 | significant digits (trailing zeroes are omitted). | - | ||||||||||||||||||
| 1094 | - | |||||||||||||||||||
| 1095 | \section1 More Efficient String Construction | - | ||||||||||||||||||
| 1096 | - | |||||||||||||||||||
| 1097 | Many strings are known at compile time. But the trivial | - | ||||||||||||||||||
| 1098 | constructor QString("Hello"), will copy the contents of the string, | - | ||||||||||||||||||
| 1099 | treating the contents as Latin-1. To avoid this one can use the | - | ||||||||||||||||||
| 1100 | QStringLiteral macro to directly create the required data at compile | - | ||||||||||||||||||
| 1101 | time. Constructing a QString out of the literal does then not cause | - | ||||||||||||||||||
| 1102 | any overhead at runtime. | - | ||||||||||||||||||
| 1103 | - | |||||||||||||||||||
| 1104 | A slightly less efficient way is to use QLatin1String. This class wraps | - | ||||||||||||||||||
| 1105 | a C string literal, precalculates it length at compile time and can | - | ||||||||||||||||||
| 1106 | then be used for faster comparison with QStrings and conversion to | - | ||||||||||||||||||
| 1107 | QStrings than a regular C string literal. | - | ||||||||||||||||||
| 1108 | - | |||||||||||||||||||
| 1109 | Using the QString \c{'+'} operator, it is easy to construct a | - | ||||||||||||||||||
| 1110 | complex string from multiple substrings. You will often write code | - | ||||||||||||||||||
| 1111 | like this: | - | ||||||||||||||||||
| 1112 | - | |||||||||||||||||||
| 1113 | \snippet qstring/stringbuilder.cpp 0 | - | ||||||||||||||||||
| 1114 | - | |||||||||||||||||||
| 1115 | There is nothing wrong with either of these string constructions, | - | ||||||||||||||||||
| 1116 | but there are a few hidden inefficiencies. Beginning with Qt 4.6, | - | ||||||||||||||||||
| 1117 | you can eliminate them. | - | ||||||||||||||||||
| 1118 | - | |||||||||||||||||||
| 1119 | First, multiple uses of the \c{'+'} operator usually means | - | ||||||||||||||||||
| 1120 | multiple memory allocations. When concatenating \e{n} substrings, | - | ||||||||||||||||||
| 1121 | where \e{n > 2}, there can be as many as \e{n - 1} calls to the | - | ||||||||||||||||||
| 1122 | memory allocator. | - | ||||||||||||||||||
| 1123 | - | |||||||||||||||||||
| 1124 | In 4.6, an internal template class \c{QStringBuilder} has been | - | ||||||||||||||||||
| 1125 | added along with a few helper functions. This class is marked | - | ||||||||||||||||||
| 1126 | internal and does not appear in the documentation, because you | - | ||||||||||||||||||
| 1127 | aren't meant to instantiate it in your code. Its use will be | - | ||||||||||||||||||
| 1128 | automatic, as described below. The class is found in | - | ||||||||||||||||||
| 1129 | \c {src/corelib/tools/qstringbuilder.cpp} if you want to have a | - | ||||||||||||||||||
| 1130 | look at it. | - | ||||||||||||||||||
| 1131 | - | |||||||||||||||||||
| 1132 | \c{QStringBuilder} uses expression templates and reimplements the | - | ||||||||||||||||||
| 1133 | \c{'%'} operator so that when you use \c{'%'} for string | - | ||||||||||||||||||
| 1134 | concatenation instead of \c{'+'}, multiple substring | - | ||||||||||||||||||
| 1135 | concatenations will be postponed until the final result is about | - | ||||||||||||||||||
| 1136 | to be assigned to a QString. At this point, the amount of memory | - | ||||||||||||||||||
| 1137 | required for the final result is known. The memory allocator is | - | ||||||||||||||||||
| 1138 | then called \e{once} to get the required space, and the substrings | - | ||||||||||||||||||
| 1139 | are copied into it one by one. | - | ||||||||||||||||||
| 1140 | - | |||||||||||||||||||
| 1141 | Additional efficiency is gained by inlining and reduced reference | - | ||||||||||||||||||
| 1142 | counting (the QString created from a \c{QStringBuilder} typically | - | ||||||||||||||||||
| 1143 | has a ref count of 1, whereas QString::append() needs an extra | - | ||||||||||||||||||
| 1144 | test). | - | ||||||||||||||||||
| 1145 | - | |||||||||||||||||||
| 1146 | There are three ways you can access this improved method of string | - | ||||||||||||||||||
| 1147 | construction. The straightforward way is to include | - | ||||||||||||||||||
| 1148 | \c{QStringBuilder} wherever you want to use it, and use the | - | ||||||||||||||||||
| 1149 | \c{'%'} operator instead of \c{'+'} when concatenating strings: | - | ||||||||||||||||||
| 1150 | - | |||||||||||||||||||
| 1151 | \snippet qstring/stringbuilder.cpp 5 | - | ||||||||||||||||||
| 1152 | - | |||||||||||||||||||
| 1153 | A more global approach which is the most convenient but | - | ||||||||||||||||||
| 1154 | not entirely source compatible, is to this define in your | - | ||||||||||||||||||
| 1155 | .pro file: | - | ||||||||||||||||||
| 1156 | - | |||||||||||||||||||
| 1157 | \snippet qstring/stringbuilder.cpp 3 | - | ||||||||||||||||||
| 1158 | - | |||||||||||||||||||
| 1159 | and the \c{'+'} will automatically be performed as the | - | ||||||||||||||||||
| 1160 | \c{QStringBuilder} \c{'%'} everywhere. | - | ||||||||||||||||||
| 1161 | - | |||||||||||||||||||
| 1162 | \sa fromRawData(), QChar, QLatin1String, QByteArray, QStringRef | - | ||||||||||||||||||
| 1163 | */ | - | ||||||||||||||||||
| 1164 | - | |||||||||||||||||||
| 1165 | /*! | - | ||||||||||||||||||
| 1166 | \enum QString::SplitBehavior | - | ||||||||||||||||||
| 1167 | - | |||||||||||||||||||
| 1168 | This enum specifies how the split() function should behave with | - | ||||||||||||||||||
| 1169 | respect to empty strings. | - | ||||||||||||||||||
| 1170 | - | |||||||||||||||||||
| 1171 | \value KeepEmptyParts If a field is empty, keep it in the result. | - | ||||||||||||||||||
| 1172 | \value SkipEmptyParts If a field is empty, don't include it in the result. | - | ||||||||||||||||||
| 1173 | - | |||||||||||||||||||
| 1174 | \sa split() | - | ||||||||||||||||||
| 1175 | */ | - | ||||||||||||||||||
| 1176 | - | |||||||||||||||||||
| 1177 | /*! \typedef QString::ConstIterator | - | ||||||||||||||||||
| 1178 | - | |||||||||||||||||||
| 1179 | Qt-style synonym for QString::const_iterator. | - | ||||||||||||||||||
| 1180 | */ | - | ||||||||||||||||||
| 1181 | - | |||||||||||||||||||
| 1182 | /*! \typedef QString::Iterator | - | ||||||||||||||||||
| 1183 | - | |||||||||||||||||||
| 1184 | Qt-style synonym for QString::iterator. | - | ||||||||||||||||||
| 1185 | */ | - | ||||||||||||||||||
| 1186 | - | |||||||||||||||||||
| 1187 | /*! \typedef QString::const_iterator | - | ||||||||||||||||||
| 1188 | - | |||||||||||||||||||
| 1189 | This typedef provides an STL-style const iterator for QString. | - | ||||||||||||||||||
| 1190 | - | |||||||||||||||||||
| 1191 | \sa QString::iterator | - | ||||||||||||||||||
| 1192 | */ | - | ||||||||||||||||||
| 1193 | - | |||||||||||||||||||
| 1194 | /*! \typedef QString::iterator | - | ||||||||||||||||||
| 1195 | - | |||||||||||||||||||
| 1196 | The QString::iterator typedef provides an STL-style non-const | - | ||||||||||||||||||
| 1197 | iterator for QString. | - | ||||||||||||||||||
| 1198 | - | |||||||||||||||||||
| 1199 | \sa QString::const_iterator | - | ||||||||||||||||||
| 1200 | */ | - | ||||||||||||||||||
| 1201 | - | |||||||||||||||||||
| 1202 | /*! \typedef QString::const_reverse_iterator | - | ||||||||||||||||||
| 1203 | \since 5.6 | - | ||||||||||||||||||
| 1204 | - | |||||||||||||||||||
| 1205 | This typedef provides an STL-style const reverse iterator for QString. | - | ||||||||||||||||||
| 1206 | - | |||||||||||||||||||
| 1207 | \sa QString::reverse_iterator, QString::const_iterator | - | ||||||||||||||||||
| 1208 | */ | - | ||||||||||||||||||
| 1209 | - | |||||||||||||||||||
| 1210 | /*! \typedef QString::reverse_iterator | - | ||||||||||||||||||
| 1211 | \since 5.6 | - | ||||||||||||||||||
| 1212 | - | |||||||||||||||||||
| 1213 | This typedef provides an STL-style non-const reverse iterator for QString. | - | ||||||||||||||||||
| 1214 | - | |||||||||||||||||||
| 1215 | \sa QString::const_reverse_iterator, QString::iterator | - | ||||||||||||||||||
| 1216 | */ | - | ||||||||||||||||||
| 1217 | - | |||||||||||||||||||
| 1218 | /*! | - | ||||||||||||||||||
| 1219 | \typedef QString::size_type | - | ||||||||||||||||||
| 1220 | - | |||||||||||||||||||
| 1221 | The QString::size_type typedef provides an STL-style type for sizes (int). | - | ||||||||||||||||||
| 1222 | */ | - | ||||||||||||||||||
| 1223 | - | |||||||||||||||||||
| 1224 | /*! | - | ||||||||||||||||||
| 1225 | \typedef QString::difference_type | - | ||||||||||||||||||
| 1226 | - | |||||||||||||||||||
| 1227 | The QString::size_type typedef provides an STL-style type for difference between pointers. | - | ||||||||||||||||||
| 1228 | */ | - | ||||||||||||||||||
| 1229 | - | |||||||||||||||||||
| 1230 | /*! | - | ||||||||||||||||||
| 1231 | \typedef QString::const_reference | - | ||||||||||||||||||
| 1232 | - | |||||||||||||||||||
| 1233 | This typedef provides an STL-style const reference for a QString element (QChar). | - | ||||||||||||||||||
| 1234 | */ | - | ||||||||||||||||||
| 1235 | /*! | - | ||||||||||||||||||
| 1236 | \typedef QString::reference | - | ||||||||||||||||||
| 1237 | - | |||||||||||||||||||
| 1238 | This typedef provides an STL-style | - | ||||||||||||||||||
| 1239 | reference for a QString element (QChar). | - | ||||||||||||||||||
| 1240 | */ | - | ||||||||||||||||||
| 1241 | - | |||||||||||||||||||
| 1242 | /*! | - | ||||||||||||||||||
| 1243 | \typedef QString::const_pointer | - | ||||||||||||||||||
| 1244 | - | |||||||||||||||||||
| 1245 | The QString::const_pointer typedef provides an STL-style | - | ||||||||||||||||||
| 1246 | const pointer to a QString element (QChar). | - | ||||||||||||||||||
| 1247 | */ | - | ||||||||||||||||||
| 1248 | /*! | - | ||||||||||||||||||
| 1249 | \typedef QString::pointer | - | ||||||||||||||||||
| 1250 | - | |||||||||||||||||||
| 1251 | The QString::const_pointer typedef provides an STL-style | - | ||||||||||||||||||
| 1252 | pointer to a QString element (QChar). | - | ||||||||||||||||||
| 1253 | */ | - | ||||||||||||||||||
| 1254 | - | |||||||||||||||||||
| 1255 | /*! | - | ||||||||||||||||||
| 1256 | \typedef QString::value_type | - | ||||||||||||||||||
| 1257 | - | |||||||||||||||||||
| 1258 | This typedef provides an STL-style value type for QString. | - | ||||||||||||||||||
| 1259 | */ | - | ||||||||||||||||||
| 1260 | - | |||||||||||||||||||
| 1261 | /*! \fn QString::iterator QString::begin() | - | ||||||||||||||||||
| 1262 | - | |||||||||||||||||||
| 1263 | Returns an \l{STL-style iterators}{STL-style iterator} pointing to the first character in | - | ||||||||||||||||||
| 1264 | the string. | - | ||||||||||||||||||
| 1265 | - | |||||||||||||||||||
| 1266 | \sa constBegin(), end() | - | ||||||||||||||||||
| 1267 | */ | - | ||||||||||||||||||
| 1268 | - | |||||||||||||||||||
| 1269 | /*! \fn QString::const_iterator QString::begin() const | - | ||||||||||||||||||
| 1270 | - | |||||||||||||||||||
| 1271 | \overload begin() | - | ||||||||||||||||||
| 1272 | */ | - | ||||||||||||||||||
| 1273 | - | |||||||||||||||||||
| 1274 | /*! \fn QString::const_iterator QString::cbegin() const | - | ||||||||||||||||||
| 1275 | \since 5.0 | - | ||||||||||||||||||
| 1276 | - | |||||||||||||||||||
| 1277 | Returns a const \l{STL-style iterators}{STL-style iterator} pointing to the first character | - | ||||||||||||||||||
| 1278 | in the string. | - | ||||||||||||||||||
| 1279 | - | |||||||||||||||||||
| 1280 | \sa begin(), cend() | - | ||||||||||||||||||
| 1281 | */ | - | ||||||||||||||||||
| 1282 | - | |||||||||||||||||||
| 1283 | /*! \fn QString::const_iterator QString::constBegin() const | - | ||||||||||||||||||
| 1284 | - | |||||||||||||||||||
| 1285 | Returns a const \l{STL-style iterators}{STL-style iterator} pointing to the first character | - | ||||||||||||||||||
| 1286 | in the string. | - | ||||||||||||||||||
| 1287 | - | |||||||||||||||||||
| 1288 | \sa begin(), constEnd() | - | ||||||||||||||||||
| 1289 | */ | - | ||||||||||||||||||
| 1290 | - | |||||||||||||||||||
| 1291 | /*! \fn QString::iterator QString::end() | - | ||||||||||||||||||
| 1292 | - | |||||||||||||||||||
| 1293 | Returns an \l{STL-style iterators}{STL-style iterator} pointing to the imaginary character | - | ||||||||||||||||||
| 1294 | after the last character in the string. | - | ||||||||||||||||||
| 1295 | - | |||||||||||||||||||
| 1296 | \sa begin(), constEnd() | - | ||||||||||||||||||
| 1297 | */ | - | ||||||||||||||||||
| 1298 | - | |||||||||||||||||||
| 1299 | /*! \fn QString::const_iterator QString::end() const | - | ||||||||||||||||||
| 1300 | - | |||||||||||||||||||
| 1301 | \overload end() | - | ||||||||||||||||||
| 1302 | */ | - | ||||||||||||||||||
| 1303 | - | |||||||||||||||||||
| 1304 | /*! \fn QString::const_iterator QString::cend() const | - | ||||||||||||||||||
| 1305 | \since 5.0 | - | ||||||||||||||||||
| 1306 | - | |||||||||||||||||||
| 1307 | Returns a const \l{STL-style iterators}{STL-style iterator} pointing to the imaginary | - | ||||||||||||||||||
| 1308 | character after the last character in the list. | - | ||||||||||||||||||
| 1309 | - | |||||||||||||||||||
| 1310 | \sa cbegin(), end() | - | ||||||||||||||||||
| 1311 | */ | - | ||||||||||||||||||
| 1312 | - | |||||||||||||||||||
| 1313 | /*! \fn QString::const_iterator QString::constEnd() const | - | ||||||||||||||||||
| 1314 | - | |||||||||||||||||||
| 1315 | Returns a const \l{STL-style iterators}{STL-style iterator} pointing to the imaginary | - | ||||||||||||||||||
| 1316 | character after the last character in the list. | - | ||||||||||||||||||
| 1317 | - | |||||||||||||||||||
| 1318 | \sa constBegin(), end() | - | ||||||||||||||||||
| 1319 | */ | - | ||||||||||||||||||
| 1320 | - | |||||||||||||||||||
| 1321 | /*! \fn QString::reverse_iterator QString::rbegin() | - | ||||||||||||||||||
| 1322 | \since 5.6 | - | ||||||||||||||||||
| 1323 | - | |||||||||||||||||||
| 1324 | Returns a \l{STL-style iterators}{STL-style} reverse iterator pointing to the first | - | ||||||||||||||||||
| 1325 | character in the string, in reverse order. | - | ||||||||||||||||||
| 1326 | - | |||||||||||||||||||
| 1327 | \sa begin(), crbegin(), rend() | - | ||||||||||||||||||
| 1328 | */ | - | ||||||||||||||||||
| 1329 | - | |||||||||||||||||||
| 1330 | /*! \fn QString::const_reverse_iterator QString::rbegin() const | - | ||||||||||||||||||
| 1331 | \since 5.6 | - | ||||||||||||||||||
| 1332 | \overload | - | ||||||||||||||||||
| 1333 | */ | - | ||||||||||||||||||
| 1334 | - | |||||||||||||||||||
| 1335 | /*! \fn QString::const_reverse_iterator QString::crbegin() const | - | ||||||||||||||||||
| 1336 | \since 5.6 | - | ||||||||||||||||||
| 1337 | - | |||||||||||||||||||
| 1338 | Returns a const \l{STL-style iterators}{STL-style} reverse iterator pointing to the first | - | ||||||||||||||||||
| 1339 | character in the string, in reverse order. | - | ||||||||||||||||||
| 1340 | - | |||||||||||||||||||
| 1341 | \sa begin(), rbegin(), rend() | - | ||||||||||||||||||
| 1342 | */ | - | ||||||||||||||||||
| 1343 | - | |||||||||||||||||||
| 1344 | /*! \fn QString::reverse_iterator QString::rend() | - | ||||||||||||||||||
| 1345 | \since 5.6 | - | ||||||||||||||||||
| 1346 | - | |||||||||||||||||||
| 1347 | Returns a \l{STL-style iterators}{STL-style} reverse iterator pointing to one past | - | ||||||||||||||||||
| 1348 | the last character in the string, in reverse order. | - | ||||||||||||||||||
| 1349 | - | |||||||||||||||||||
| 1350 | \sa end(), crend(), rbegin() | - | ||||||||||||||||||
| 1351 | */ | - | ||||||||||||||||||
| 1352 | - | |||||||||||||||||||
| 1353 | /*! \fn QString::const_reverse_iterator QString::rend() const | - | ||||||||||||||||||
| 1354 | \since 5.6 | - | ||||||||||||||||||
| 1355 | \overload | - | ||||||||||||||||||
| 1356 | */ | - | ||||||||||||||||||
| 1357 | - | |||||||||||||||||||
| 1358 | /*! \fn QString::const_reverse_iterator QString::crend() const | - | ||||||||||||||||||
| 1359 | \since 5.6 | - | ||||||||||||||||||
| 1360 | - | |||||||||||||||||||
| 1361 | Returns a const \l{STL-style iterators}{STL-style} reverse iterator pointing to one | - | ||||||||||||||||||
| 1362 | past the last character in the string, in reverse order. | - | ||||||||||||||||||
| 1363 | - | |||||||||||||||||||
| 1364 | \sa end(), rend(), rbegin() | - | ||||||||||||||||||
| 1365 | */ | - | ||||||||||||||||||
| 1366 | - | |||||||||||||||||||
| 1367 | /*! | - | ||||||||||||||||||
| 1368 | \fn QString::QString() | - | ||||||||||||||||||
| 1369 | - | |||||||||||||||||||
| 1370 | Constructs a null string. Null strings are also empty. | - | ||||||||||||||||||
| 1371 | - | |||||||||||||||||||
| 1372 | \sa isEmpty() | - | ||||||||||||||||||
| 1373 | */ | - | ||||||||||||||||||
| 1374 | - | |||||||||||||||||||
| 1375 | /*! | - | ||||||||||||||||||
| 1376 | \fn QString::QString(QString &&other) | - | ||||||||||||||||||
| 1377 | - | |||||||||||||||||||
| 1378 | Move-constructs a QString instance, making it point at the same | - | ||||||||||||||||||
| 1379 | object that \a other was pointing to. | - | ||||||||||||||||||
| 1380 | - | |||||||||||||||||||
| 1381 | \since 5.2 | - | ||||||||||||||||||
| 1382 | */ | - | ||||||||||||||||||
| 1383 | - | |||||||||||||||||||
| 1384 | /*! \fn QString::QString(const char *str) | - | ||||||||||||||||||
| 1385 | - | |||||||||||||||||||
| 1386 | Constructs a string initialized with the 8-bit string \a str. The | - | ||||||||||||||||||
| 1387 | given const char pointer is converted to Unicode using the | - | ||||||||||||||||||
| 1388 | fromUtf8() function. | - | ||||||||||||||||||
| 1389 | - | |||||||||||||||||||
| 1390 | You can disable this constructor by defining \c | - | ||||||||||||||||||
| 1391 | QT_NO_CAST_FROM_ASCII when you compile your applications. This | - | ||||||||||||||||||
| 1392 | can be useful if you want to ensure that all user-visible strings | - | ||||||||||||||||||
| 1393 | go through QObject::tr(), for example. | - | ||||||||||||||||||
| 1394 | - | |||||||||||||||||||
| 1395 | \note Defining QT_RESTRICTED_CAST_FROM_ASCII also disables | - | ||||||||||||||||||
| 1396 | this constructor, but enables a \c{QString(const char (&ch)[N])} | - | ||||||||||||||||||
| 1397 | constructor instead. Using non-literal input, or input with | - | ||||||||||||||||||
| 1398 | embedded NUL characters, or non-7-bit characters is undefined | - | ||||||||||||||||||
| 1399 | in this case. | - | ||||||||||||||||||
| 1400 | - | |||||||||||||||||||
| 1401 | \sa fromLatin1(), fromLocal8Bit(), fromUtf8() | - | ||||||||||||||||||
| 1402 | */ | - | ||||||||||||||||||
| 1403 | - | |||||||||||||||||||
| 1404 | /*! \fn QString QString::fromStdString(const std::string &str) | - | ||||||||||||||||||
| 1405 | - | |||||||||||||||||||
| 1406 | Returns a copy of the \a str string. The given string is converted | - | ||||||||||||||||||
| 1407 | to Unicode using the fromUtf8() function. | - | ||||||||||||||||||
| 1408 | - | |||||||||||||||||||
| 1409 | \sa fromLatin1(), fromLocal8Bit(), fromUtf8(), QByteArray::fromStdString() | - | ||||||||||||||||||
| 1410 | */ | - | ||||||||||||||||||
| 1411 | - | |||||||||||||||||||
| 1412 | /*! \fn QString QString::fromStdWString(const std::wstring &str) | - | ||||||||||||||||||
| 1413 | - | |||||||||||||||||||
| 1414 | Returns a copy of the \a str string. The given string is assumed | - | ||||||||||||||||||
| 1415 | to be encoded in utf16 if the size of wchar_t is 2 bytes (e.g. on | - | ||||||||||||||||||
| 1416 | windows) and ucs4 if the size of wchar_t is 4 bytes (most Unix | - | ||||||||||||||||||
| 1417 | systems). | - | ||||||||||||||||||
| 1418 | - | |||||||||||||||||||
| 1419 | \sa fromUtf16(), fromLatin1(), fromLocal8Bit(), fromUtf8(), fromUcs4(), fromStdU16String(), fromStdU32String() | - | ||||||||||||||||||
| 1420 | */ | - | ||||||||||||||||||
| 1421 | - | |||||||||||||||||||
| 1422 | /*! \fn QString QString::fromWCharArray(const wchar_t *string, int size) | - | ||||||||||||||||||
| 1423 | \since 4.2 | - | ||||||||||||||||||
| 1424 | - | |||||||||||||||||||
| 1425 | Returns a copy of the \a string, where the encoding of \a string depends on | - | ||||||||||||||||||
| 1426 | the size of wchar. If wchar is 4 bytes, the \a string is interpreted as UCS-4, | - | ||||||||||||||||||
| 1427 | if wchar is 2 bytes it is interpreted as UTF-16. | - | ||||||||||||||||||
| 1428 | - | |||||||||||||||||||
| 1429 | If \a size is -1 (default), the \a string has to be 0 terminated. | - | ||||||||||||||||||
| 1430 | - | |||||||||||||||||||
| 1431 | \sa fromUtf16(), fromLatin1(), fromLocal8Bit(), fromUtf8(), fromUcs4(), fromStdWString() | - | ||||||||||||||||||
| 1432 | */ | - | ||||||||||||||||||
| 1433 | - | |||||||||||||||||||
| 1434 | /*! \fn std::wstring QString::toStdWString() const | - | ||||||||||||||||||
| 1435 | - | |||||||||||||||||||
| 1436 | Returns a std::wstring object with the data contained in this | - | ||||||||||||||||||
| 1437 | QString. The std::wstring is encoded in utf16 on platforms where | - | ||||||||||||||||||
| 1438 | wchar_t is 2 bytes wide (e.g. windows) and in ucs4 on platforms | - | ||||||||||||||||||
| 1439 | where wchar_t is 4 bytes wide (most Unix systems). | - | ||||||||||||||||||
| 1440 | - | |||||||||||||||||||
| 1441 | This method is mostly useful to pass a QString to a function | - | ||||||||||||||||||
| 1442 | that accepts a std::wstring object. | - | ||||||||||||||||||
| 1443 | - | |||||||||||||||||||
| 1444 | \sa utf16(), toLatin1(), toUtf8(), toLocal8Bit(), toStdU16String(), toStdU32String() | - | ||||||||||||||||||
| 1445 | */ | - | ||||||||||||||||||
| 1446 | - | |||||||||||||||||||
| 1447 | int QString::toUcs4_helper(const ushort *uc, int length, uint *out) | - | ||||||||||||||||||
| 1448 | { | - | ||||||||||||||||||
| 1449 | int count = 0; | - | ||||||||||||||||||
| 1450 | - | |||||||||||||||||||
| 1451 | QStringIterator i(reinterpret_cast<const QChar *>(uc), reinterpret_cast<const QChar *>(uc + length)); | - | ||||||||||||||||||
| 1452 | while (i.hasNext())
| 12-44 | ||||||||||||||||||
| 1453 | out[count++] = i.next(); executed 44 times by 1 test: out[count++] = i.next();Executed by:
| 44 | ||||||||||||||||||
| 1454 | - | |||||||||||||||||||
| 1455 | return count; executed 12 times by 1 test: return count;Executed by:
| 12 | ||||||||||||||||||
| 1456 | } | - | ||||||||||||||||||
| 1457 | - | |||||||||||||||||||
| 1458 | /*! \fn int QString::toWCharArray(wchar_t *array) const | - | ||||||||||||||||||
| 1459 | \since 4.2 | - | ||||||||||||||||||
| 1460 | - | |||||||||||||||||||
| 1461 | Fills the \a array with the data contained in this QString object. | - | ||||||||||||||||||
| 1462 | The array is encoded in UTF-16 on platforms where | - | ||||||||||||||||||
| 1463 | wchar_t is 2 bytes wide (e.g. windows) and in UCS-4 on platforms | - | ||||||||||||||||||
| 1464 | where wchar_t is 4 bytes wide (most Unix systems). | - | ||||||||||||||||||
| 1465 | - | |||||||||||||||||||
| 1466 | \a array has to be allocated by the caller and contain enough space to | - | ||||||||||||||||||
| 1467 | hold the complete string (allocating the array with the same length as the | - | ||||||||||||||||||
| 1468 | string is always sufficient). | - | ||||||||||||||||||
| 1469 | - | |||||||||||||||||||
| 1470 | This function returns the actual length of the string in \a array. | - | ||||||||||||||||||
| 1471 | - | |||||||||||||||||||
| 1472 | \note This function does not append a null character to the array. | - | ||||||||||||||||||
| 1473 | - | |||||||||||||||||||
| 1474 | \sa utf16(), toUcs4(), toLatin1(), toUtf8(), toLocal8Bit(), toStdWString() | - | ||||||||||||||||||
| 1475 | */ | - | ||||||||||||||||||
| 1476 | - | |||||||||||||||||||
| 1477 | /*! \fn QString::QString(const QString &other) | - | ||||||||||||||||||
| 1478 | - | |||||||||||||||||||
| 1479 | Constructs a copy of \a other. | - | ||||||||||||||||||
| 1480 | - | |||||||||||||||||||
| 1481 | This operation takes \l{constant time}, because QString is | - | ||||||||||||||||||
| 1482 | \l{implicitly shared}. This makes returning a QString from a | - | ||||||||||||||||||
| 1483 | function very fast. If a shared instance is modified, it will be | - | ||||||||||||||||||
| 1484 | copied (copy-on-write), and that takes \l{linear time}. | - | ||||||||||||||||||
| 1485 | - | |||||||||||||||||||
| 1486 | \sa operator=() | - | ||||||||||||||||||
| 1487 | */ | - | ||||||||||||||||||
| 1488 | - | |||||||||||||||||||
| 1489 | /*! | - | ||||||||||||||||||
| 1490 | Constructs a string initialized with the first \a size characters | - | ||||||||||||||||||
| 1491 | of the QChar array \a unicode. | - | ||||||||||||||||||
| 1492 | - | |||||||||||||||||||
| 1493 | If \a unicode is 0, a null string is constructed. | - | ||||||||||||||||||
| 1494 | - | |||||||||||||||||||
| 1495 | If \a size is negative, \a unicode is assumed to point to a nul-terminated | - | ||||||||||||||||||
| 1496 | array and its length is determined dynamically. The terminating | - | ||||||||||||||||||
| 1497 | nul-character is not considered part of the string. | - | ||||||||||||||||||
| 1498 | - | |||||||||||||||||||
| 1499 | QString makes a deep copy of the string data. The unicode data is copied as | - | ||||||||||||||||||
| 1500 | is and the Byte Order Mark is preserved if present. | - | ||||||||||||||||||
| 1501 | - | |||||||||||||||||||
| 1502 | \sa fromRawData() | - | ||||||||||||||||||
| 1503 | */ | - | ||||||||||||||||||
| 1504 | QString::QString(const QChar *unicode, int size) | - | ||||||||||||||||||
| 1505 | { | - | ||||||||||||||||||
| 1506 | if (!unicode) {
| 3143-13159949 | ||||||||||||||||||
| 1507 | d = Data::sharedNull(); | - | ||||||||||||||||||
| 1508 | } else { executed 3143 times by 9 tests: end of blockExecuted by:
| 3143 | ||||||||||||||||||
| 1509 | if (size < 0) {
| 101050-13058899 | ||||||||||||||||||
| 1510 | size = 0; | - | ||||||||||||||||||
| 1511 | while (!unicode[size].isNull())
| 101050-3080963 | ||||||||||||||||||
| 1512 | ++size; executed 3080963 times by 9 tests: ++size;Executed by:
| 3080963 | ||||||||||||||||||
| 1513 | } executed 101050 times by 9 tests: end of blockExecuted by:
| 101050 | ||||||||||||||||||
| 1514 | if (!size) {
| 421779-12738170 | ||||||||||||||||||
| 1515 | d = Data::allocate(0); | - | ||||||||||||||||||
| 1516 | } else { executed 421779 times by 400 tests: end of blockExecuted by:
| 421779 | ||||||||||||||||||
| 1517 | d = Data::allocate(size + 1); | - | ||||||||||||||||||
| 1518 | Q_CHECK_PTR(d); never executed: qBadAlloc();
| 0-12738170 | ||||||||||||||||||
| 1519 | d->size = size; | - | ||||||||||||||||||
| 1520 | memcpy(d->data(), unicode, size * sizeof(QChar)); | - | ||||||||||||||||||
| 1521 | d->data()[size] = '\0'; | - | ||||||||||||||||||
| 1522 | } executed 12738170 times by 421 tests: end of blockExecuted by:
| 12738170 | ||||||||||||||||||
| 1523 | } | - | ||||||||||||||||||
| 1524 | } | - | ||||||||||||||||||
| 1525 | - | |||||||||||||||||||
| 1526 | /*! | - | ||||||||||||||||||
| 1527 | Constructs a string of the given \a size with every character set | - | ||||||||||||||||||
| 1528 | to \a ch. | - | ||||||||||||||||||
| 1529 | - | |||||||||||||||||||
| 1530 | \sa fill() | - | ||||||||||||||||||
| 1531 | */ | - | ||||||||||||||||||
| 1532 | QString::QString(int size, QChar ch) | - | ||||||||||||||||||
| 1533 | { | - | ||||||||||||||||||
| 1534 | if (size <= 0) {
| 201-249846 | ||||||||||||||||||
| 1535 | d = Data::allocate(0); | - | ||||||||||||||||||
| 1536 | } else { executed 201 times by 3 tests: end of blockExecuted by:
| 201 | ||||||||||||||||||
| 1537 | d = Data::allocate(size + 1); | - | ||||||||||||||||||
| 1538 | Q_CHECK_PTR(d); never executed: qBadAlloc();
| 0-249846 | ||||||||||||||||||
| 1539 | d->size = size; | - | ||||||||||||||||||
| 1540 | d->data()[size] = '\0'; | - | ||||||||||||||||||
| 1541 | ushort *i = d->data() + size; | - | ||||||||||||||||||
| 1542 | ushort *b = d->data(); | - | ||||||||||||||||||
| 1543 | const ushort value = ch.unicode(); | - | ||||||||||||||||||
| 1544 | while (i != b)
| 249846-404828 | ||||||||||||||||||
| 1545 | *--i = value; executed 404828 times by 43 tests: *--i = value;Executed by:
| 404828 | ||||||||||||||||||
| 1546 | } executed 249846 times by 43 tests: end of blockExecuted by:
| 249846 | ||||||||||||||||||
| 1547 | } | - | ||||||||||||||||||
| 1548 | - | |||||||||||||||||||
| 1549 | /*! \fn QString::QString(int size, Qt::Initialization) | - | ||||||||||||||||||
| 1550 | \internal | - | ||||||||||||||||||
| 1551 | - | |||||||||||||||||||
| 1552 | Constructs a string of the given \a size without initializing the | - | ||||||||||||||||||
| 1553 | characters. This is only used in \c QStringBuilder::toString(). | - | ||||||||||||||||||
| 1554 | */ | - | ||||||||||||||||||
| 1555 | QString::QString(int size, Qt::Initialization) | - | ||||||||||||||||||
| 1556 | { | - | ||||||||||||||||||
| 1557 | d = Data::allocate(size + 1); | - | ||||||||||||||||||
| 1558 | Q_CHECK_PTR(d); never executed: qBadAlloc();
| 0-60792734 | ||||||||||||||||||
| 1559 | d->size = size; | - | ||||||||||||||||||
| 1560 | d->data()[size] = '\0'; | - | ||||||||||||||||||
| 1561 | } executed 60792734 times by 594 tests: end of blockExecuted by:
| 60792734 | ||||||||||||||||||
| 1562 | - | |||||||||||||||||||
| 1563 | /*! \fn QString::QString(QLatin1String str) | - | ||||||||||||||||||
| 1564 | - | |||||||||||||||||||
| 1565 | Constructs a copy of the Latin-1 string \a str. | - | ||||||||||||||||||
| 1566 | - | |||||||||||||||||||
| 1567 | \sa fromLatin1() | - | ||||||||||||||||||
| 1568 | */ | - | ||||||||||||||||||
| 1569 | - | |||||||||||||||||||
| 1570 | /*! | - | ||||||||||||||||||
| 1571 | Constructs a string of size 1 containing the character \a ch. | - | ||||||||||||||||||
| 1572 | */ | - | ||||||||||||||||||
| 1573 | QString::QString(QChar ch) | - | ||||||||||||||||||
| 1574 | { | - | ||||||||||||||||||
| 1575 | d = Data::allocate(2); | - | ||||||||||||||||||
| 1576 | Q_CHECK_PTR(d); never executed: qBadAlloc();
| 0-488750 | ||||||||||||||||||
| 1577 | d->size = 1; | - | ||||||||||||||||||
| 1578 | d->data()[0] = ch.unicode(); | - | ||||||||||||||||||
| 1579 | d->data()[1] = '\0'; | - | ||||||||||||||||||
| 1580 | } executed 488750 times by 265 tests: end of blockExecuted by:
| 488750 | ||||||||||||||||||
| 1581 | - | |||||||||||||||||||
| 1582 | /*! \fn QString::QString(const QByteArray &ba) | - | ||||||||||||||||||
| 1583 | - | |||||||||||||||||||
| 1584 | Constructs a string initialized with the byte array \a ba. The | - | ||||||||||||||||||
| 1585 | given byte array is converted to Unicode using fromUtf8(). Stops | - | ||||||||||||||||||
| 1586 | copying at the first 0 character, otherwise copies the entire byte | - | ||||||||||||||||||
| 1587 | array. | - | ||||||||||||||||||
| 1588 | - | |||||||||||||||||||
| 1589 | You can disable this constructor by defining \c | - | ||||||||||||||||||
| 1590 | QT_NO_CAST_FROM_ASCII when you compile your applications. This | - | ||||||||||||||||||
| 1591 | can be useful if you want to ensure that all user-visible strings | - | ||||||||||||||||||
| 1592 | go through QObject::tr(), for example. | - | ||||||||||||||||||
| 1593 | - | |||||||||||||||||||
| 1594 | \sa fromLatin1(), fromLocal8Bit(), fromUtf8() | - | ||||||||||||||||||
| 1595 | */ | - | ||||||||||||||||||
| 1596 | - | |||||||||||||||||||
| 1597 | /*! \fn QString::QString(const Null &) | - | ||||||||||||||||||
| 1598 | \internal | - | ||||||||||||||||||
| 1599 | */ | - | ||||||||||||||||||
| 1600 | - | |||||||||||||||||||
| 1601 | /*! \fn QString::QString(QStringDataPtr) | - | ||||||||||||||||||
| 1602 | \internal | - | ||||||||||||||||||
| 1603 | */ | - | ||||||||||||||||||
| 1604 | - | |||||||||||||||||||
| 1605 | /*! \fn QString &QString::operator=(const Null &) | - | ||||||||||||||||||
| 1606 | \internal | - | ||||||||||||||||||
| 1607 | */ | - | ||||||||||||||||||
| 1608 | - | |||||||||||||||||||
| 1609 | /*! | - | ||||||||||||||||||
| 1610 | \fn QString::~QString() | - | ||||||||||||||||||
| 1611 | - | |||||||||||||||||||
| 1612 | Destroys the string. | - | ||||||||||||||||||
| 1613 | */ | - | ||||||||||||||||||
| 1614 | - | |||||||||||||||||||
| 1615 | - | |||||||||||||||||||
| 1616 | /*! \fn void QString::swap(QString &other) | - | ||||||||||||||||||
| 1617 | \since 4.8 | - | ||||||||||||||||||
| 1618 | - | |||||||||||||||||||
| 1619 | Swaps string \a other with this string. This operation is very fast and | - | ||||||||||||||||||
| 1620 | never fails. | - | ||||||||||||||||||
| 1621 | */ | - | ||||||||||||||||||
| 1622 | - | |||||||||||||||||||
| 1623 | /*! \fn void QString::detach() | - | ||||||||||||||||||
| 1624 | - | |||||||||||||||||||
| 1625 | \internal | - | ||||||||||||||||||
| 1626 | */ | - | ||||||||||||||||||
| 1627 | - | |||||||||||||||||||
| 1628 | /*! \fn bool QString::isDetached() const | - | ||||||||||||||||||
| 1629 | - | |||||||||||||||||||
| 1630 | \internal | - | ||||||||||||||||||
| 1631 | */ | - | ||||||||||||||||||
| 1632 | - | |||||||||||||||||||
| 1633 | /*! \fn bool QString::isSharedWith(const QString &other) const | - | ||||||||||||||||||
| 1634 | - | |||||||||||||||||||
| 1635 | \internal | - | ||||||||||||||||||
| 1636 | */ | - | ||||||||||||||||||
| 1637 | - | |||||||||||||||||||
| 1638 | /*! | - | ||||||||||||||||||
| 1639 | Sets the size of the string to \a size characters. | - | ||||||||||||||||||
| 1640 | - | |||||||||||||||||||
| 1641 | If \a size is greater than the current size, the string is | - | ||||||||||||||||||
| 1642 | extended to make it \a size characters long with the extra | - | ||||||||||||||||||
| 1643 | characters added to the end. The new characters are uninitialized. | - | ||||||||||||||||||
| 1644 | - | |||||||||||||||||||
| 1645 | If \a size is less than the current size, characters are removed | - | ||||||||||||||||||
| 1646 | from the end. | - | ||||||||||||||||||
| 1647 | - | |||||||||||||||||||
| 1648 | Example: | - | ||||||||||||||||||
| 1649 | - | |||||||||||||||||||
| 1650 | \snippet qstring/main.cpp 45 | - | ||||||||||||||||||
| 1651 | - | |||||||||||||||||||
| 1652 | If you want to append a certain number of identical characters to | - | ||||||||||||||||||
| 1653 | the string, use \l operator+=() as follows rather than resize(): | - | ||||||||||||||||||
| 1654 | - | |||||||||||||||||||
| 1655 | \snippet qstring/main.cpp 46 | - | ||||||||||||||||||
| 1656 | - | |||||||||||||||||||
| 1657 | If you want to expand the string so that it reaches a certain | - | ||||||||||||||||||
| 1658 | width and fill the new positions with a particular character, use | - | ||||||||||||||||||
| 1659 | the leftJustified() function: | - | ||||||||||||||||||
| 1660 | - | |||||||||||||||||||
| 1661 | If \a size is negative, it is equivalent to passing zero. | - | ||||||||||||||||||
| 1662 | - | |||||||||||||||||||
| 1663 | \snippet qstring/main.cpp 47 | - | ||||||||||||||||||
| 1664 | - | |||||||||||||||||||
| 1665 | \sa truncate(), reserve() | - | ||||||||||||||||||
| 1666 | */ | - | ||||||||||||||||||
| 1667 | - | |||||||||||||||||||
| 1668 | void QString::resize(int size) | - | ||||||||||||||||||
| 1669 | { | - | ||||||||||||||||||
| 1670 | if (size < 0)
| 28-87220402 | ||||||||||||||||||
| 1671 | size = 0; executed 28 times by 4 tests: size = 0;Executed by:
| 28 | ||||||||||||||||||
| 1672 | - | |||||||||||||||||||
| 1673 | if (IS_RAW_DATA(d) && !d->ref.isShared() && size < d->size) {
| 0-87220520 | ||||||||||||||||||
| 1674 | d->size = size; | - | ||||||||||||||||||
| 1675 | return; executed 2 times by 2 tests: return;Executed by:
| 2 | ||||||||||||||||||
| 1676 | } | - | ||||||||||||||||||
| 1677 | - | |||||||||||||||||||
| 1678 | if (d->ref.isShared() || uint(size) + 1u > d->alloc)
| 227704-85442319 | ||||||||||||||||||
| 1679 | reallocData(uint(size) + 1u, true); executed 2005907 times by 460 tests: reallocData(uint(size) + 1u, true);Executed by:
| 2005907 | ||||||||||||||||||
| 1680 | if (d->alloc) {
| 0-87220522 | ||||||||||||||||||
| 1681 | d->size = size; | - | ||||||||||||||||||
| 1682 | d->data()[size] = '\0'; | - | ||||||||||||||||||
| 1683 | } executed 87220522 times by 559 tests: end of blockExecuted by:
| 87220522 | ||||||||||||||||||
| 1684 | } executed 87220522 times by 559 tests: end of blockExecuted by:
| 87220522 | ||||||||||||||||||
| 1685 | - | |||||||||||||||||||
| 1686 | /*! \fn int QString::capacity() const | - | ||||||||||||||||||
| 1687 | - | |||||||||||||||||||
| 1688 | Returns the maximum number of characters that can be stored in | - | ||||||||||||||||||
| 1689 | the string without forcing a reallocation. | - | ||||||||||||||||||
| 1690 | - | |||||||||||||||||||
| 1691 | The sole purpose of this function is to provide a means of fine | - | ||||||||||||||||||
| 1692 | tuning QString's memory usage. In general, you will rarely ever | - | ||||||||||||||||||
| 1693 | need to call this function. If you want to know how many | - | ||||||||||||||||||
| 1694 | characters are in the string, call size(). | - | ||||||||||||||||||
| 1695 | - | |||||||||||||||||||
| 1696 | \sa reserve(), squeeze() | - | ||||||||||||||||||
| 1697 | */ | - | ||||||||||||||||||
| 1698 | - | |||||||||||||||||||
| 1699 | /*! | - | ||||||||||||||||||
| 1700 | \fn void QString::reserve(int size) | - | ||||||||||||||||||
| 1701 | - | |||||||||||||||||||
| 1702 | Attempts to allocate memory for at least \a size characters. If | - | ||||||||||||||||||
| 1703 | you know in advance how large the string will be, you can call | - | ||||||||||||||||||
| 1704 | this function, and if you resize the string often you are likely | - | ||||||||||||||||||
| 1705 | to get better performance. If \a size is an underestimate, the | - | ||||||||||||||||||
| 1706 | worst that will happen is that the QString will be a bit slower. | - | ||||||||||||||||||
| 1707 | - | |||||||||||||||||||
| 1708 | The sole purpose of this function is to provide a means of fine | - | ||||||||||||||||||
| 1709 | tuning QString's memory usage. In general, you will rarely ever | - | ||||||||||||||||||
| 1710 | need to call this function. If you want to change the size of the | - | ||||||||||||||||||
| 1711 | string, call resize(). | - | ||||||||||||||||||
| 1712 | - | |||||||||||||||||||
| 1713 | This function is useful for code that needs to build up a long | - | ||||||||||||||||||
| 1714 | string and wants to avoid repeated reallocation. In this example, | - | ||||||||||||||||||
| 1715 | we want to add to the string until some condition is \c true, and | - | ||||||||||||||||||
| 1716 | we're fairly sure that size is large enough to make a call to | - | ||||||||||||||||||
| 1717 | reserve() worthwhile: | - | ||||||||||||||||||
| 1718 | - | |||||||||||||||||||
| 1719 | \snippet qstring/main.cpp 44 | - | ||||||||||||||||||
| 1720 | - | |||||||||||||||||||
| 1721 | \sa squeeze(), capacity() | - | ||||||||||||||||||
| 1722 | */ | - | ||||||||||||||||||
| 1723 | - | |||||||||||||||||||
| 1724 | /*! | - | ||||||||||||||||||
| 1725 | \fn void QString::squeeze() | - | ||||||||||||||||||
| 1726 | - | |||||||||||||||||||
| 1727 | Releases any memory not required to store the character data. | - | ||||||||||||||||||
| 1728 | - | |||||||||||||||||||
| 1729 | The sole purpose of this function is to provide a means of fine | - | ||||||||||||||||||
| 1730 | tuning QString's memory usage. In general, you will rarely ever | - | ||||||||||||||||||
| 1731 | need to call this function. | - | ||||||||||||||||||
| 1732 | - | |||||||||||||||||||
| 1733 | \sa reserve(), capacity() | - | ||||||||||||||||||
| 1734 | */ | - | ||||||||||||||||||
| 1735 | - | |||||||||||||||||||
| 1736 | void QString::reallocData(uint alloc, bool grow) | - | ||||||||||||||||||
| 1737 | { | - | ||||||||||||||||||
| 1738 | if (grow) {
| 1038742-3837956 | ||||||||||||||||||
| 1739 | if (alloc > (uint(MaxAllocSize) - sizeof(Data)) / sizeof(QChar))
| 0-3837956 | ||||||||||||||||||
| 1740 | qBadAlloc(); never executed: qBadAlloc(); | 0 | ||||||||||||||||||
| 1741 | alloc = qAllocMore(alloc * sizeof(QChar), sizeof(Data)) / sizeof(QChar); | - | ||||||||||||||||||
| 1742 | } executed 3837956 times by 541 tests: end of blockExecuted by:
| 3837956 | ||||||||||||||||||
| 1743 | - | |||||||||||||||||||
| 1744 | if (d->ref.isShared() || IS_RAW_DATA(d)) {
| 8376-3633906 | ||||||||||||||||||
| 1745 | Data::AllocationOptions allocOptions(d->capacityReserved ? Data::CapacityReserved : 0); | - | ||||||||||||||||||
| 1746 | Data *x = Data::allocate(alloc, allocOptions); | - | ||||||||||||||||||
| 1747 | Q_CHECK_PTR(x); never executed: qBadAlloc();
| 0-3642282 | ||||||||||||||||||
| 1748 | x->size = qMin(int(alloc) - 1, d->size); | - | ||||||||||||||||||
| 1749 | ::memcpy(x->data(), d->data(), x->size * sizeof(QChar)); | - | ||||||||||||||||||
| 1750 | x->data()[x->size] = 0; | - | ||||||||||||||||||
| 1751 | if (!d->ref.deref())
| 8376-3633906 | ||||||||||||||||||
| 1752 | Data::deallocate(d); executed 8376 times by 14 tests: Data::deallocate(d);Executed by:
| 8376 | ||||||||||||||||||
| 1753 | d = x; | - | ||||||||||||||||||
| 1754 | } else { executed 3642282 times by 538 tests: end of blockExecuted by:
| 3642282 | ||||||||||||||||||
| 1755 | Data *p = static_cast<Data *>(::realloc(d, sizeof(Data) + alloc * sizeof(QChar))); | - | ||||||||||||||||||
| 1756 | Q_CHECK_PTR(p); never executed: qBadAlloc();
| 0-1234416 | ||||||||||||||||||
| 1757 | d = p; | - | ||||||||||||||||||
| 1758 | d->alloc = alloc; | - | ||||||||||||||||||
| 1759 | d->offset = sizeof(QStringData); | - | ||||||||||||||||||
| 1760 | } executed 1234416 times by 503 tests: end of blockExecuted by:
| 1234416 | ||||||||||||||||||
| 1761 | } | - | ||||||||||||||||||
| 1762 | - | |||||||||||||||||||
| 1763 | void QString::expand(int i) | - | ||||||||||||||||||
| 1764 | { | - | ||||||||||||||||||
| 1765 | int sz = d->size; | - | ||||||||||||||||||
| 1766 | resize(qMax(i + 1, sz)); | - | ||||||||||||||||||
| 1767 | if (d->size - 1 > sz) {
| 699856-780777 | ||||||||||||||||||
| 1768 | ushort *n = d->data() + d->size - 1; | - | ||||||||||||||||||
| 1769 | ushort *e = d->data() + sz; | - | ||||||||||||||||||
| 1770 | while (n != e)
| 699856-5687733 | ||||||||||||||||||
| 1771 | * --n = ' '; executed 5687733 times by 100 tests: * --n = ' ';Executed by:
| 5687733 | ||||||||||||||||||
| 1772 | } executed 699856 times by 100 tests: end of blockExecuted by:
| 699856 | ||||||||||||||||||
| 1773 | } executed 1480633 times by 440 tests: end of blockExecuted by:
| 1480633 | ||||||||||||||||||
| 1774 | - | |||||||||||||||||||
| 1775 | /*! \fn void QString::clear() | - | ||||||||||||||||||
| 1776 | - | |||||||||||||||||||
| 1777 | Clears the contents of the string and makes it null. | - | ||||||||||||||||||
| 1778 | - | |||||||||||||||||||
| 1779 | \sa resize(), isNull() | - | ||||||||||||||||||
| 1780 | */ | - | ||||||||||||||||||
| 1781 | - | |||||||||||||||||||
| 1782 | /*! \fn QString &QString::operator=(const QString &other) | - | ||||||||||||||||||
| 1783 | - | |||||||||||||||||||
| 1784 | Assigns \a other to this string and returns a reference to this | - | ||||||||||||||||||
| 1785 | string. | - | ||||||||||||||||||
| 1786 | */ | - | ||||||||||||||||||
| 1787 | - | |||||||||||||||||||
| 1788 | QString &QString::operator=(const QString &other) Q_DECL_NOTHROW | - | ||||||||||||||||||
| 1789 | { | - | ||||||||||||||||||
| 1790 | other.d->ref.ref(); | - | ||||||||||||||||||
| 1791 | if (!d->ref.deref())
| 849156-7023579 | ||||||||||||||||||
| 1792 | Data::deallocate(d); executed 849156 times by 263 tests: Data::deallocate(d);Executed by:
| 849156 | ||||||||||||||||||
| 1793 | d = other.d; | - | ||||||||||||||||||
| 1794 | return *this; executed 7872735 times by 454 tests: return *this;Executed by:
| 7872735 | ||||||||||||||||||
| 1795 | } | - | ||||||||||||||||||
| 1796 | - | |||||||||||||||||||
| 1797 | /*! | - | ||||||||||||||||||
| 1798 | \fn QString &QString::operator=(QString &&other) | - | ||||||||||||||||||
| 1799 | - | |||||||||||||||||||
| 1800 | Move-assigns \a other to this QString instance. | - | ||||||||||||||||||
| 1801 | - | |||||||||||||||||||
| 1802 | \since 5.2 | - | ||||||||||||||||||
| 1803 | */ | - | ||||||||||||||||||
| 1804 | - | |||||||||||||||||||
| 1805 | /*! \fn QString &QString::operator=(QLatin1String str) | - | ||||||||||||||||||
| 1806 | - | |||||||||||||||||||
| 1807 | \overload operator=() | - | ||||||||||||||||||
| 1808 | - | |||||||||||||||||||
| 1809 | Assigns the Latin-1 string \a str to this string. | - | ||||||||||||||||||
| 1810 | */ | - | ||||||||||||||||||
| 1811 | QString &QString::operator=(QLatin1String other) | - | ||||||||||||||||||
| 1812 | { | - | ||||||||||||||||||
| 1813 | if (isDetached() && other.size() <= capacity()) { // assumes d->alloc == 0 → !isDetached() (sharedNull)
| 4919-199496 | ||||||||||||||||||
| 1814 | d->size = other.size(); | - | ||||||||||||||||||
| 1815 | d->data()[other.size()] = 0; | - | ||||||||||||||||||
| 1816 | qt_from_latin1(d->data(), other.latin1(), other.size()); | - | ||||||||||||||||||
| 1817 | } else { executed 147839 times by 492 tests: end of blockExecuted by:
| 147839 | ||||||||||||||||||
| 1818 | *this = fromLatin1(other.latin1(), other.size()); | - | ||||||||||||||||||
| 1819 | } executed 204415 times by 690 tests: end of blockExecuted by:
| 204415 | ||||||||||||||||||
| 1820 | return *this; executed 352254 times by 690 tests: return *this;Executed by:
| 352254 | ||||||||||||||||||
| 1821 | } | - | ||||||||||||||||||
| 1822 | - | |||||||||||||||||||
| 1823 | /*! \fn QString &QString::operator=(const QByteArray &ba) | - | ||||||||||||||||||
| 1824 | - | |||||||||||||||||||
| 1825 | \overload operator=() | - | ||||||||||||||||||
| 1826 | - | |||||||||||||||||||
| 1827 | Assigns \a ba to this string. The byte array is converted to Unicode | - | ||||||||||||||||||
| 1828 | using the fromUtf8() function. This function stops conversion at the | - | ||||||||||||||||||
| 1829 | first NUL character found, or the end of the \a ba byte array. | - | ||||||||||||||||||
| 1830 | - | |||||||||||||||||||
| 1831 | You can disable this operator by defining \c | - | ||||||||||||||||||
| 1832 | QT_NO_CAST_FROM_ASCII when you compile your applications. This | - | ||||||||||||||||||
| 1833 | can be useful if you want to ensure that all user-visible strings | - | ||||||||||||||||||
| 1834 | go through QObject::tr(), for example. | - | ||||||||||||||||||
| 1835 | */ | - | ||||||||||||||||||
| 1836 | - | |||||||||||||||||||
| 1837 | /*! \fn QString &QString::operator=(const char *str) | - | ||||||||||||||||||
| 1838 | - | |||||||||||||||||||
| 1839 | \overload operator=() | - | ||||||||||||||||||
| 1840 | - | |||||||||||||||||||
| 1841 | Assigns \a str to this string. The const char pointer is converted | - | ||||||||||||||||||
| 1842 | to Unicode using the fromUtf8() function. | - | ||||||||||||||||||
| 1843 | - | |||||||||||||||||||
| 1844 | You can disable this operator by defining \c QT_NO_CAST_FROM_ASCII | - | ||||||||||||||||||
| 1845 | or \c QT_RESTRICTED_CAST_FROM_ASCII when you compile your applications. | - | ||||||||||||||||||
| 1846 | This can be useful if you want to ensure that all user-visible strings | - | ||||||||||||||||||
| 1847 | go through QObject::tr(), for example. | - | ||||||||||||||||||
| 1848 | - | |||||||||||||||||||
| 1849 | */ | - | ||||||||||||||||||
| 1850 | - | |||||||||||||||||||
| 1851 | /*! \fn QString &QString::operator=(char ch) | - | ||||||||||||||||||
| 1852 | - | |||||||||||||||||||
| 1853 | \overload operator=() | - | ||||||||||||||||||
| 1854 | - | |||||||||||||||||||
| 1855 | Assigns character \a ch to this string. Note that the character is | - | ||||||||||||||||||
| 1856 | converted to Unicode using the fromLatin1() function, unlike other 8-bit | - | ||||||||||||||||||
| 1857 | functions that operate on UTF-8 data. | - | ||||||||||||||||||
| 1858 | - | |||||||||||||||||||
| 1859 | You can disable this operator by defining \c | - | ||||||||||||||||||
| 1860 | QT_NO_CAST_FROM_ASCII when you compile your applications. This | - | ||||||||||||||||||
| 1861 | can be useful if you want to ensure that all user-visible strings | - | ||||||||||||||||||
| 1862 | go through QObject::tr(), for example. | - | ||||||||||||||||||
| 1863 | */ | - | ||||||||||||||||||
| 1864 | - | |||||||||||||||||||
| 1865 | /*! | - | ||||||||||||||||||
| 1866 | \overload operator=() | - | ||||||||||||||||||
| 1867 | - | |||||||||||||||||||
| 1868 | Sets the string to contain the single character \a ch. | - | ||||||||||||||||||
| 1869 | */ | - | ||||||||||||||||||
| 1870 | QString &QString::operator=(QChar ch) | - | ||||||||||||||||||
| 1871 | { | - | ||||||||||||||||||
| 1872 | if (isDetached() && capacity() >= 1) { // assumes d->alloc == 0 → !isDetached() (sharedNull)
| 1-75330 | ||||||||||||||||||
| 1873 | // re-use existing capacity: | - | ||||||||||||||||||
| 1874 | ushort *dat = d->data(); | - | ||||||||||||||||||
| 1875 | dat[0] = ch.unicode(); | - | ||||||||||||||||||
| 1876 | dat[1] = 0; | - | ||||||||||||||||||
| 1877 | d->size = 1; | - | ||||||||||||||||||
| 1878 | } else { executed 696 times by 162 tests: end of blockExecuted by:
| 696 | ||||||||||||||||||
| 1879 | operator=(QString(ch)); | - | ||||||||||||||||||
| 1880 | } executed 75331 times by 107 tests: end of blockExecuted by:
| 75331 | ||||||||||||||||||
| 1881 | return *this; executed 76027 times by 218 tests: return *this;Executed by:
| 76027 | ||||||||||||||||||
| 1882 | } | - | ||||||||||||||||||
| 1883 | - | |||||||||||||||||||
| 1884 | /*! | - | ||||||||||||||||||
| 1885 | \fn QString& QString::insert(int position, const QString &str) | - | ||||||||||||||||||
| 1886 | - | |||||||||||||||||||
| 1887 | Inserts the string \a str at the given index \a position and | - | ||||||||||||||||||
| 1888 | returns a reference to this string. | - | ||||||||||||||||||
| 1889 | - | |||||||||||||||||||
| 1890 | Example: | - | ||||||||||||||||||
| 1891 | - | |||||||||||||||||||
| 1892 | \snippet qstring/main.cpp 26 | - | ||||||||||||||||||
| 1893 | - | |||||||||||||||||||
| 1894 | If the given \a position is greater than size(), the array is | - | ||||||||||||||||||
| 1895 | first extended using resize(). | - | ||||||||||||||||||
| 1896 | - | |||||||||||||||||||
| 1897 | \sa append(), prepend(), replace(), remove() | - | ||||||||||||||||||
| 1898 | */ | - | ||||||||||||||||||
| 1899 | - | |||||||||||||||||||
| 1900 | - | |||||||||||||||||||
| 1901 | /*! | - | ||||||||||||||||||
| 1902 | \fn QString& QString::insert(int position, const QStringRef &str) | - | ||||||||||||||||||
| 1903 | \since 5.5 | - | ||||||||||||||||||
| 1904 | \overload insert() | - | ||||||||||||||||||
| 1905 | - | |||||||||||||||||||
| 1906 | Inserts the string reference \a str at the given index \a position and | - | ||||||||||||||||||
| 1907 | returns a reference to this string. | - | ||||||||||||||||||
| 1908 | - | |||||||||||||||||||
| 1909 | If the given \a position is greater than size(), the array is | - | ||||||||||||||||||
| 1910 | first extended using resize(). | - | ||||||||||||||||||
| 1911 | */ | - | ||||||||||||||||||
| 1912 | - | |||||||||||||||||||
| 1913 | - | |||||||||||||||||||
| 1914 | /*! | - | ||||||||||||||||||
| 1915 | \fn QString& QString::insert(int position, const char *str) | - | ||||||||||||||||||
| 1916 | \since 5.5 | - | ||||||||||||||||||
| 1917 | \overload insert() | - | ||||||||||||||||||
| 1918 | - | |||||||||||||||||||
| 1919 | Inserts the C string \a str at the given index \a position and | - | ||||||||||||||||||
| 1920 | returns a reference to this string. | - | ||||||||||||||||||
| 1921 | - | |||||||||||||||||||
| 1922 | If the given \a position is greater than size(), the array is | - | ||||||||||||||||||
| 1923 | first extended using resize(). | - | ||||||||||||||||||
| 1924 | - | |||||||||||||||||||
| 1925 | This function is not available when QT_NO_CAST_FROM_ASCII is | - | ||||||||||||||||||
| 1926 | defined. | - | ||||||||||||||||||
| 1927 | */ | - | ||||||||||||||||||
| 1928 | - | |||||||||||||||||||
| 1929 | - | |||||||||||||||||||
| 1930 | /*! | - | ||||||||||||||||||
| 1931 | \fn QString& QString::insert(int position, const QByteArray &str) | - | ||||||||||||||||||
| 1932 | \since 5.5 | - | ||||||||||||||||||
| 1933 | \overload insert() | - | ||||||||||||||||||
| 1934 | - | |||||||||||||||||||
| 1935 | Inserts the byte array \a str at the given index \a position and | - | ||||||||||||||||||
| 1936 | returns a reference to this string. | - | ||||||||||||||||||
| 1937 | - | |||||||||||||||||||
| 1938 | If the given \a position is greater than size(), the array is | - | ||||||||||||||||||
| 1939 | first extended using resize(). | - | ||||||||||||||||||
| 1940 | - | |||||||||||||||||||
| 1941 | This function is not available when QT_NO_CAST_FROM_ASCII is | - | ||||||||||||||||||
| 1942 | defined. | - | ||||||||||||||||||
| 1943 | */ | - | ||||||||||||||||||
| 1944 | - | |||||||||||||||||||
| 1945 | - | |||||||||||||||||||
| 1946 | /*! | - | ||||||||||||||||||
| 1947 | \fn QString &QString::insert(int position, QLatin1String str) | - | ||||||||||||||||||
| 1948 | \overload insert() | - | ||||||||||||||||||
| 1949 | - | |||||||||||||||||||
| 1950 | Inserts the Latin-1 string \a str at the given index \a position. | - | ||||||||||||||||||
| 1951 | */ | - | ||||||||||||||||||
| 1952 | QString &QString::insert(int i, QLatin1String str) | - | ||||||||||||||||||
| 1953 | { | - | ||||||||||||||||||
| 1954 | const char *s = str.latin1(); | - | ||||||||||||||||||
| 1955 | if (i < 0 || !s || !(*s))
| 0-18042 | ||||||||||||||||||
| 1956 | return *this; executed 16 times by 1 test: return *this;Executed by:
| 16 | ||||||||||||||||||
| 1957 | - | |||||||||||||||||||
| 1958 | int len = str.size(); | - | ||||||||||||||||||
| 1959 | expand(qMax(d->size, i) + len - 1); | - | ||||||||||||||||||
| 1960 | - | |||||||||||||||||||
| 1961 | ::memmove(d->data() + i + len, d->data() + i, (d->size - i - len) * sizeof(QChar)); | - | ||||||||||||||||||
| 1962 | qt_from_latin1(d->data() + i, s, uint(len)); | - | ||||||||||||||||||
| 1963 | return *this; executed 18026 times by 56 tests: return *this;Executed by:
| 18026 | ||||||||||||||||||
| 1964 | } | - | ||||||||||||||||||
| 1965 | - | |||||||||||||||||||
| 1966 | /*! | - | ||||||||||||||||||
| 1967 | \fn QString& QString::insert(int position, const QChar *unicode, int size) | - | ||||||||||||||||||
| 1968 | \overload insert() | - | ||||||||||||||||||
| 1969 | - | |||||||||||||||||||
| 1970 | Inserts the first \a size characters of the QChar array \a unicode | - | ||||||||||||||||||
| 1971 | at the given index \a position in the string. | - | ||||||||||||||||||
| 1972 | */ | - | ||||||||||||||||||
| 1973 | QString& QString::insert(int i, const QChar *unicode, int size) | - | ||||||||||||||||||
| 1974 | { | - | ||||||||||||||||||
| 1975 | if (i < 0 || size <= 0)
| 0-984787 | ||||||||||||||||||
| 1976 | return *this; executed 279220 times by 45 tests: return *this;Executed by:
| 279220 | ||||||||||||||||||
| 1977 | - | |||||||||||||||||||
| 1978 | const ushort *s = (const ushort *)unicode; | - | ||||||||||||||||||
| 1979 | if (s >= d->data() && s < d->data() + d->alloc) {
| 3-555253 | ||||||||||||||||||
| 1980 | // Part of me - take a copy | - | ||||||||||||||||||
| 1981 | ushort *tmp = static_cast<ushort *>(::malloc(size * sizeof(QChar))); | - | ||||||||||||||||||
| 1982 | Q_CHECK_PTR(tmp); never executed: qBadAlloc();
| 0-3 | ||||||||||||||||||
| 1983 | memcpy(tmp, s, size * sizeof(QChar)); | - | ||||||||||||||||||
| 1984 | insert(i, reinterpret_cast<const QChar *>(tmp), size); | - | ||||||||||||||||||
| 1985 | ::free(tmp); | - | ||||||||||||||||||
| 1986 | return *this; executed 3 times by 2 tests: return *this;Executed by:
| 3 | ||||||||||||||||||
| 1987 | } | - | ||||||||||||||||||
| 1988 | - | |||||||||||||||||||
| 1989 | expand(qMax(d->size, i) + size - 1); | - | ||||||||||||||||||
| 1990 | - | |||||||||||||||||||
| 1991 | ::memmove(d->data() + i + size, d->data() + i, (d->size - i - size) * sizeof(QChar)); | - | ||||||||||||||||||
| 1992 | memcpy(d->data() + i, s, size * sizeof(QChar)); | - | ||||||||||||||||||
| 1993 | return *this; executed 705564 times by 68 tests: return *this;Executed by:
| 705564 | ||||||||||||||||||
| 1994 | } | - | ||||||||||||||||||
| 1995 | - | |||||||||||||||||||
| 1996 | /*! | - | ||||||||||||||||||
| 1997 | \fn QString& QString::insert(int position, QChar ch) | - | ||||||||||||||||||
| 1998 | \overload insert() | - | ||||||||||||||||||
| 1999 | - | |||||||||||||||||||
| 2000 | Inserts \a ch at the given index \a position in the string. | - | ||||||||||||||||||
| 2001 | */ | - | ||||||||||||||||||
| 2002 | - | |||||||||||||||||||
| 2003 | QString& QString::insert(int i, QChar ch) | - | ||||||||||||||||||
| 2004 | { | - | ||||||||||||||||||
| 2005 | if (i < 0)
| 0-730500 | ||||||||||||||||||
| 2006 | i += d->size; never executed: i += d->size; | 0 | ||||||||||||||||||
| 2007 | if (i < 0)
| 0-730500 | ||||||||||||||||||
| 2008 | return *this; never executed: return *this; | 0 | ||||||||||||||||||
| 2009 | expand(qMax(i, d->size)); | - | ||||||||||||||||||
| 2010 | ::memmove(d->data() + i + 1, d->data() + i, (d->size - i - 1) * sizeof(QChar)); | - | ||||||||||||||||||
| 2011 | d->data()[i] = ch.unicode(); | - | ||||||||||||||||||
| 2012 | return *this; executed 730500 times by 421 tests: return *this;Executed by:
| 730500 | ||||||||||||||||||
| 2013 | } | - | ||||||||||||||||||
| 2014 | - | |||||||||||||||||||
| 2015 | /*! | - | ||||||||||||||||||
| 2016 | Appends the string \a str onto the end of this string. | - | ||||||||||||||||||
| 2017 | - | |||||||||||||||||||
| 2018 | Example: | - | ||||||||||||||||||
| 2019 | - | |||||||||||||||||||
| 2020 | \snippet qstring/main.cpp 9 | - | ||||||||||||||||||
| 2021 | - | |||||||||||||||||||
| 2022 | This is the same as using the insert() function: | - | ||||||||||||||||||
| 2023 | - | |||||||||||||||||||
| 2024 | \snippet qstring/main.cpp 10 | - | ||||||||||||||||||
| 2025 | - | |||||||||||||||||||
| 2026 | The append() function is typically very fast (\l{constant time}), | - | ||||||||||||||||||
| 2027 | because QString preallocates extra space at the end of the string | - | ||||||||||||||||||
| 2028 | data so it can grow without reallocating the entire string each | - | ||||||||||||||||||
| 2029 | time. | - | ||||||||||||||||||
| 2030 | - | |||||||||||||||||||
| 2031 | \sa operator+=(), prepend(), insert() | - | ||||||||||||||||||
| 2032 | */ | - | ||||||||||||||||||
| 2033 | QString &QString::append(const QString &str) | - | ||||||||||||||||||
| 2034 | { | - | ||||||||||||||||||
| 2035 | if (str.d != Data::sharedNull()) {
| 41338-44864085 | ||||||||||||||||||
| 2036 | if (d == Data::sharedNull()) {
| 560528-44303557 | ||||||||||||||||||
| 2037 | operator=(str); | - | ||||||||||||||||||
| 2038 | } else { executed 560528 times by 266 tests: end of blockExecuted by:
| 560528 | ||||||||||||||||||
| 2039 | if (d->ref.isShared() || uint(d->size + str.d->size) + 1u > d->alloc)
| 474489-43829068 | ||||||||||||||||||
| 2040 | reallocData(uint(d->size + str.d->size) + 1u, true); executed 1116781 times by 499 tests: reallocData(uint(d->size + str.d->size) + 1u, true);Executed by:
| 1116781 | ||||||||||||||||||
| 2041 | memcpy(d->data() + d->size, str.d->data(), str.d->size * sizeof(QChar)); | - | ||||||||||||||||||
| 2042 | d->size += str.d->size; | - | ||||||||||||||||||
| 2043 | d->data()[d->size] = '\0'; | - | ||||||||||||||||||
| 2044 | } executed 44303557 times by 510 tests: end of blockExecuted by:
| 44303557 | ||||||||||||||||||
| 2045 | } | - | ||||||||||||||||||
| 2046 | return *this; executed 44905423 times by 528 tests: return *this;Executed by:
| 44905423 | ||||||||||||||||||
| 2047 | } | - | ||||||||||||||||||
| 2048 | - | |||||||||||||||||||
| 2049 | /*! | - | ||||||||||||||||||
| 2050 | \overload append() | - | ||||||||||||||||||
| 2051 | \since 5.0 | - | ||||||||||||||||||
| 2052 | - | |||||||||||||||||||
| 2053 | Appends \a len characters from the QChar array \a str to this string. | - | ||||||||||||||||||
| 2054 | */ | - | ||||||||||||||||||
| 2055 | QString &QString::append(const QChar *str, int len) | - | ||||||||||||||||||
| 2056 | { | - | ||||||||||||||||||
| 2057 | if (str && len > 0) {
| 1-261951 | ||||||||||||||||||
| 2058 | if (d->ref.isShared() || uint(d->size + len) + 1u > d->alloc)
| 36484-204935 | ||||||||||||||||||
| 2059 | reallocData(uint(d->size + len) + 1u, true); executed 90694 times by 86 tests: reallocData(uint(d->size + len) + 1u, true);Executed by:
| 90694 | ||||||||||||||||||
| 2060 | memcpy(d->data() + d->size, str, len * sizeof(QChar)); | - | ||||||||||||||||||
| 2061 | d->size += len; | - | ||||||||||||||||||
| 2062 | d->data()[d->size] = '\0'; | - | ||||||||||||||||||
| 2063 | } executed 259145 times by 99 tests: end of blockExecuted by:
| 259145 | ||||||||||||||||||
| 2064 | return *this; executed 261952 times by 99 tests: return *this;Executed by:
| 261952 | ||||||||||||||||||
| 2065 | } | - | ||||||||||||||||||
| 2066 | - | |||||||||||||||||||
| 2067 | /*! | - | ||||||||||||||||||
| 2068 | \overload append() | - | ||||||||||||||||||
| 2069 | - | |||||||||||||||||||
| 2070 | Appends the Latin-1 string \a str to this string. | - | ||||||||||||||||||
| 2071 | */ | - | ||||||||||||||||||
| 2072 | QString &QString::append(QLatin1String str) | - | ||||||||||||||||||
| 2073 | { | - | ||||||||||||||||||
| 2074 | const char *s = str.latin1(); | - | ||||||||||||||||||
| 2075 | if (s) {
| 57-116300 | ||||||||||||||||||
| 2076 | int len = str.size(); | - | ||||||||||||||||||
| 2077 | if (d->ref.isShared() || uint(d->size + len) + 1u > d->alloc)
| 12945-103355 | ||||||||||||||||||
| 2078 | reallocData(uint(d->size + len) + 1u, true); executed 38183 times by 142 tests: reallocData(uint(d->size + len) + 1u, true);Executed by:
| 38183 | ||||||||||||||||||
| 2079 | ushort *i = d->data() + d->size; | - | ||||||||||||||||||
| 2080 | qt_from_latin1(i, s, uint(len)); | - | ||||||||||||||||||
| 2081 | i[len] = '\0'; | - | ||||||||||||||||||
| 2082 | d->size += len; | - | ||||||||||||||||||
| 2083 | } executed 116300 times by 149 tests: end of blockExecuted by:
| 116300 | ||||||||||||||||||
| 2084 | return *this; executed 116357 times by 149 tests: return *this;Executed by:
| 116357 | ||||||||||||||||||
| 2085 | } | - | ||||||||||||||||||
| 2086 | - | |||||||||||||||||||
| 2087 | /*! \fn QString &QString::append(const QByteArray &ba) | - | ||||||||||||||||||
| 2088 | - | |||||||||||||||||||
| 2089 | \overload append() | - | ||||||||||||||||||
| 2090 | - | |||||||||||||||||||
| 2091 | Appends the byte array \a ba to this string. The given byte array | - | ||||||||||||||||||
| 2092 | is converted to Unicode using the fromUtf8() function. | - | ||||||||||||||||||
| 2093 | - | |||||||||||||||||||
| 2094 | You can disable this function by defining \c QT_NO_CAST_FROM_ASCII | - | ||||||||||||||||||
| 2095 | when you compile your applications. This can be useful if you want | - | ||||||||||||||||||
| 2096 | to ensure that all user-visible strings go through QObject::tr(), | - | ||||||||||||||||||
| 2097 | for example. | - | ||||||||||||||||||
| 2098 | */ | - | ||||||||||||||||||
| 2099 | - | |||||||||||||||||||
| 2100 | /*! \fn QString &QString::append(const char *str) | - | ||||||||||||||||||
| 2101 | - | |||||||||||||||||||
| 2102 | \overload append() | - | ||||||||||||||||||
| 2103 | - | |||||||||||||||||||
| 2104 | Appends the string \a str to this string. The given const char | - | ||||||||||||||||||
| 2105 | pointer is converted to Unicode using the fromUtf8() function. | - | ||||||||||||||||||
| 2106 | - | |||||||||||||||||||
| 2107 | You can disable this function by defining \c QT_NO_CAST_FROM_ASCII | - | ||||||||||||||||||
| 2108 | when you compile your applications. This can be useful if you want | - | ||||||||||||||||||
| 2109 | to ensure that all user-visible strings go through QObject::tr(), | - | ||||||||||||||||||
| 2110 | for example. | - | ||||||||||||||||||
| 2111 | */ | - | ||||||||||||||||||
| 2112 | - | |||||||||||||||||||
| 2113 | /*! | - | ||||||||||||||||||
| 2114 | \overload append() | - | ||||||||||||||||||
| 2115 | - | |||||||||||||||||||
| 2116 | Appends the character \a ch to this string. | - | ||||||||||||||||||
| 2117 | */ | - | ||||||||||||||||||
| 2118 | QString &QString::append(QChar ch) | - | ||||||||||||||||||
| 2119 | { | - | ||||||||||||||||||
| 2120 | if (d->ref.isShared() || uint(d->size) + 2u > d->alloc)
| 36013-428586 | ||||||||||||||||||
| 2121 | reallocData(uint(d->size) + 2u, true); executed 182094 times by 202 tests: reallocData(uint(d->size) + 2u, true);Executed by:
| 182094 | ||||||||||||||||||
| 2122 | d->data()[d->size++] = ch.unicode(); | - | ||||||||||||||||||
| 2123 | d->data()[d->size] = '\0'; | - | ||||||||||||||||||
| 2124 | return *this; executed 574667 times by 221 tests: return *this;Executed by:
| 574667 | ||||||||||||||||||
| 2125 | } | - | ||||||||||||||||||
| 2126 | - | |||||||||||||||||||
| 2127 | /*! \fn QString &QString::prepend(const QString &str) | - | ||||||||||||||||||
| 2128 | - | |||||||||||||||||||
| 2129 | Prepends the string \a str to the beginning of this string and | - | ||||||||||||||||||
| 2130 | returns a reference to this string. | - | ||||||||||||||||||
| 2131 | - | |||||||||||||||||||
| 2132 | Example: | - | ||||||||||||||||||
| 2133 | - | |||||||||||||||||||
| 2134 | \snippet qstring/main.cpp 36 | - | ||||||||||||||||||
| 2135 | - | |||||||||||||||||||
| 2136 | \sa append(), insert() | - | ||||||||||||||||||
| 2137 | */ | - | ||||||||||||||||||
| 2138 | - | |||||||||||||||||||
| 2139 | /*! \fn QString &QString::prepend(QLatin1String str) | - | ||||||||||||||||||
| 2140 | - | |||||||||||||||||||
| 2141 | \overload prepend() | - | ||||||||||||||||||
| 2142 | - | |||||||||||||||||||
| 2143 | Prepends the Latin-1 string \a str to this string. | - | ||||||||||||||||||
| 2144 | */ | - | ||||||||||||||||||
| 2145 | - | |||||||||||||||||||
| 2146 | /*! \fn QString &QString::prepend(const QChar *str, int len) | - | ||||||||||||||||||
| 2147 | \since 5.5 | - | ||||||||||||||||||
| 2148 | \overload prepend() | - | ||||||||||||||||||
| 2149 | - | |||||||||||||||||||
| 2150 | Prepends \a len characters from the QChar array \a str to this string and | - | ||||||||||||||||||
| 2151 | returns a reference to this string. | - | ||||||||||||||||||
| 2152 | */ | - | ||||||||||||||||||
| 2153 | - | |||||||||||||||||||
| 2154 | /*! \fn QString &QString::prepend(const QStringRef &str) | - | ||||||||||||||||||
| 2155 | \since 5.5 | - | ||||||||||||||||||
| 2156 | \overload prepend() | - | ||||||||||||||||||
| 2157 | - | |||||||||||||||||||
| 2158 | Prepends the string reference \a str to the beginning of this string and | - | ||||||||||||||||||
| 2159 | returns a reference to this string. | - | ||||||||||||||||||
| 2160 | */ | - | ||||||||||||||||||
| 2161 | - | |||||||||||||||||||
| 2162 | /*! \fn QString &QString::prepend(const QByteArray &ba) | - | ||||||||||||||||||
| 2163 | - | |||||||||||||||||||
| 2164 | \overload prepend() | - | ||||||||||||||||||
| 2165 | - | |||||||||||||||||||
| 2166 | Prepends the byte array \a ba to this string. The byte array is | - | ||||||||||||||||||
| 2167 | converted to Unicode using the fromUtf8() function. | - | ||||||||||||||||||
| 2168 | - | |||||||||||||||||||
| 2169 | You can disable this function by defining \c | - | ||||||||||||||||||
| 2170 | QT_NO_CAST_FROM_ASCII when you compile your applications. This | - | ||||||||||||||||||
| 2171 | can be useful if you want to ensure that all user-visible strings | - | ||||||||||||||||||
| 2172 | go through QObject::tr(), for example. | - | ||||||||||||||||||
| 2173 | */ | - | ||||||||||||||||||
| 2174 | - | |||||||||||||||||||
| 2175 | /*! \fn QString &QString::prepend(const char *str) | - | ||||||||||||||||||
| 2176 | - | |||||||||||||||||||
| 2177 | \overload prepend() | - | ||||||||||||||||||
| 2178 | - | |||||||||||||||||||
| 2179 | Prepends the string \a str to this string. The const char pointer | - | ||||||||||||||||||
| 2180 | is converted to Unicode using the fromUtf8() function. | - | ||||||||||||||||||
| 2181 | - | |||||||||||||||||||
| 2182 | You can disable this function by defining \c | - | ||||||||||||||||||
| 2183 | QT_NO_CAST_FROM_ASCII when you compile your applications. This | - | ||||||||||||||||||
| 2184 | can be useful if you want to ensure that all user-visible strings | - | ||||||||||||||||||
| 2185 | go through QObject::tr(), for example. | - | ||||||||||||||||||
| 2186 | */ | - | ||||||||||||||||||
| 2187 | - | |||||||||||||||||||
| 2188 | /*! \fn QString &QString::prepend(QChar ch) | - | ||||||||||||||||||
| 2189 | - | |||||||||||||||||||
| 2190 | \overload prepend() | - | ||||||||||||||||||
| 2191 | - | |||||||||||||||||||
| 2192 | Prepends the character \a ch to this string. | - | ||||||||||||||||||
| 2193 | */ | - | ||||||||||||||||||
| 2194 | - | |||||||||||||||||||
| 2195 | /*! | - | ||||||||||||||||||
| 2196 | \fn QString &QString::remove(int position, int n) | - | ||||||||||||||||||
| 2197 | - | |||||||||||||||||||
| 2198 | Removes \a n characters from the string, starting at the given \a | - | ||||||||||||||||||
| 2199 | position index, and returns a reference to the string. | - | ||||||||||||||||||
| 2200 | - | |||||||||||||||||||
| 2201 | If the specified \a position index is within the string, but \a | - | ||||||||||||||||||
| 2202 | position + \a n is beyond the end of the string, the string is | - | ||||||||||||||||||
| 2203 | truncated at the specified \a position. | - | ||||||||||||||||||
| 2204 | - | |||||||||||||||||||
| 2205 | \snippet qstring/main.cpp 37 | - | ||||||||||||||||||
| 2206 | - | |||||||||||||||||||
| 2207 | \sa insert(), replace() | - | ||||||||||||||||||
| 2208 | */ | - | ||||||||||||||||||
| 2209 | QString &QString::remove(int pos, int len) | - | ||||||||||||||||||
| 2210 | { | - | ||||||||||||||||||
| 2211 | if (pos < 0) // count from end of string
| 0-173831 | ||||||||||||||||||
| 2212 | pos += d->size; never executed: pos += d->size; | 0 | ||||||||||||||||||
| 2213 | if (uint(pos) >= uint(d->size)) {
| 0-173739 | ||||||||||||||||||
| 2214 | // range problems | - | ||||||||||||||||||
| 2215 | } else if (len >= d->size - pos) { never executed: end of block
| 0-123802 | ||||||||||||||||||
| 2216 | resize(pos); // truncate | - | ||||||||||||||||||
| 2217 | } else if (len > 0) { executed 50029 times by 24 tests: end of blockExecuted by:
| 1-123801 | ||||||||||||||||||
| 2218 | detach(); | - | ||||||||||||||||||
| 2219 | memmove(d->data() + pos, d->data() + pos + len, | - | ||||||||||||||||||
| 2220 | (d->size - pos - len + 1) * sizeof(ushort)); | - | ||||||||||||||||||
| 2221 | d->size -= len; | - | ||||||||||||||||||
| 2222 | } executed 123801 times by 149 tests: end of blockExecuted by:
| 123801 | ||||||||||||||||||
| 2223 | return *this; executed 173831 times by 149 tests: return *this;Executed by:
| 173831 | ||||||||||||||||||
| 2224 | } | - | ||||||||||||||||||
| 2225 | - | |||||||||||||||||||
| 2226 | /*! | - | ||||||||||||||||||
| 2227 | Removes every occurrence of the given \a str string in this | - | ||||||||||||||||||
| 2228 | string, and returns a reference to this string. | - | ||||||||||||||||||
| 2229 | - | |||||||||||||||||||
| 2230 | If \a cs is Qt::CaseSensitive (default), the search is | - | ||||||||||||||||||
| 2231 | case sensitive; otherwise the search is case insensitive. | - | ||||||||||||||||||
| 2232 | - | |||||||||||||||||||
| 2233 | This is the same as \c replace(str, "", cs). | - | ||||||||||||||||||
| 2234 | - | |||||||||||||||||||
| 2235 | \sa replace() | - | ||||||||||||||||||
| 2236 | */ | - | ||||||||||||||||||
| 2237 | QString &QString::remove(const QString &str, Qt::CaseSensitivity cs) | - | ||||||||||||||||||
| 2238 | { | - | ||||||||||||||||||
| 2239 | if (str.d->size) {
| 4-24569 | ||||||||||||||||||
| 2240 | int i = 0; | - | ||||||||||||||||||
| 2241 | while ((i = indexOf(str, i, cs)) != -1)
| 18-24569 | ||||||||||||||||||
| 2242 | remove(i, str.d->size); executed 18 times by 2 tests: remove(i, str.d->size);Executed by:
| 18 | ||||||||||||||||||
| 2243 | } executed 24569 times by 12 tests: end of blockExecuted by:
| 24569 | ||||||||||||||||||
| 2244 | return *this; executed 24573 times by 12 tests: return *this;Executed by:
| 24573 | ||||||||||||||||||
| 2245 | } | - | ||||||||||||||||||
| 2246 | - | |||||||||||||||||||
| 2247 | /*! | - | ||||||||||||||||||
| 2248 | Removes every occurrence of the character \a ch in this string, and | - | ||||||||||||||||||
| 2249 | returns a reference to this string. | - | ||||||||||||||||||
| 2250 | - | |||||||||||||||||||
| 2251 | If \a cs is Qt::CaseSensitive (default), the search is case | - | ||||||||||||||||||
| 2252 | sensitive; otherwise the search is case insensitive. | - | ||||||||||||||||||
| 2253 | - | |||||||||||||||||||
| 2254 | Example: | - | ||||||||||||||||||
| 2255 | - | |||||||||||||||||||
| 2256 | \snippet qstring/main.cpp 38 | - | ||||||||||||||||||
| 2257 | - | |||||||||||||||||||
| 2258 | This is the same as \c replace(ch, "", cs). | - | ||||||||||||||||||
| 2259 | - | |||||||||||||||||||
| 2260 | \sa replace() | - | ||||||||||||||||||
| 2261 | */ | - | ||||||||||||||||||
| 2262 | QString &QString::remove(QChar ch, Qt::CaseSensitivity cs) | - | ||||||||||||||||||
| 2263 | { | - | ||||||||||||||||||
| 2264 | int i = 0; | - | ||||||||||||||||||
| 2265 | ushort c = ch.unicode(); | - | ||||||||||||||||||
| 2266 | if (cs == Qt::CaseSensitive) {
| 11-30147 | ||||||||||||||||||
| 2267 | while (i < d->size)
| 30147-760913 | ||||||||||||||||||
| 2268 | if (d->data()[i] == ch)
| 48434-712479 | ||||||||||||||||||
| 2269 | remove(i, 1); executed 48434 times by 11 tests: remove(i, 1);Executed by:
| 48434 | ||||||||||||||||||
| 2270 | else | - | ||||||||||||||||||
| 2271 | i++; executed 712479 times by 25 tests: i++;Executed by:
| 712479 | ||||||||||||||||||
| 2272 | } else { executed 30147 times by 26 tests: end of blockExecuted by:
| 30147 | ||||||||||||||||||
| 2273 | c = foldCase(c); | - | ||||||||||||||||||
| 2274 | while (i < d->size)
| 11-36 | ||||||||||||||||||
| 2275 | if (foldCase(d->data()[i]) == c)
| 14-22 | ||||||||||||||||||
| 2276 | remove(i, 1); executed 14 times by 1 test: remove(i, 1);Executed by:
| 14 | ||||||||||||||||||
| 2277 | else | - | ||||||||||||||||||
| 2278 | i++; executed 22 times by 1 test: i++;Executed by:
| 22 | ||||||||||||||||||
| 2279 | } executed 11 times by 1 test: end of blockExecuted by:
| 11 | ||||||||||||||||||
| 2280 | return *this; executed 30158 times by 26 tests: return *this;Executed by:
| 30158 | ||||||||||||||||||
| 2281 | } | - | ||||||||||||||||||
| 2282 | - | |||||||||||||||||||
| 2283 | /*! | - | ||||||||||||||||||
| 2284 | \fn QString &QString::remove(const QRegExp &rx) | - | ||||||||||||||||||
| 2285 | - | |||||||||||||||||||
| 2286 | Removes every occurrence of the regular expression \a rx in the | - | ||||||||||||||||||
| 2287 | string, and returns a reference to the string. For example: | - | ||||||||||||||||||
| 2288 | - | |||||||||||||||||||
| 2289 | \snippet qstring/main.cpp 39 | - | ||||||||||||||||||
| 2290 | - | |||||||||||||||||||
| 2291 | \sa indexOf(), lastIndexOf(), replace() | - | ||||||||||||||||||
| 2292 | */ | - | ||||||||||||||||||
| 2293 | - | |||||||||||||||||||
| 2294 | /*! | - | ||||||||||||||||||
| 2295 | \fn QString &QString::remove(const QRegularExpression &re) | - | ||||||||||||||||||
| 2296 | \since 5.0 | - | ||||||||||||||||||
| 2297 | - | |||||||||||||||||||
| 2298 | Removes every occurrence of the regular expression \a re in the | - | ||||||||||||||||||
| 2299 | string, and returns a reference to the string. For example: | - | ||||||||||||||||||
| 2300 | - | |||||||||||||||||||
| 2301 | \snippet qstring/main.cpp 96 | - | ||||||||||||||||||
| 2302 | - | |||||||||||||||||||
| 2303 | \sa indexOf(), lastIndexOf(), replace() | - | ||||||||||||||||||
| 2304 | */ | - | ||||||||||||||||||
| 2305 | - | |||||||||||||||||||
| 2306 | /*! | - | ||||||||||||||||||
| 2307 | \fn QString &QString::replace(int position, int n, const QString &after) | - | ||||||||||||||||||
| 2308 | - | |||||||||||||||||||
| 2309 | Replaces \a n characters beginning at index \a position with | - | ||||||||||||||||||
| 2310 | the string \a after and returns a reference to this string. | - | ||||||||||||||||||
| 2311 | - | |||||||||||||||||||
| 2312 | \note If the specified \a position index is within the string, | - | ||||||||||||||||||
| 2313 | but \a position + \a n goes outside the strings range, | - | ||||||||||||||||||
| 2314 | then \a n will be adjusted to stop at the end of the string. | - | ||||||||||||||||||
| 2315 | - | |||||||||||||||||||
| 2316 | Example: | - | ||||||||||||||||||
| 2317 | - | |||||||||||||||||||
| 2318 | \snippet qstring/main.cpp 40 | - | ||||||||||||||||||
| 2319 | - | |||||||||||||||||||
| 2320 | \sa insert(), remove() | - | ||||||||||||||||||
| 2321 | */ | - | ||||||||||||||||||
| 2322 | QString &QString::replace(int pos, int len, const QString &after) | - | ||||||||||||||||||
| 2323 | { | - | ||||||||||||||||||
| 2324 | QString copy = after; | - | ||||||||||||||||||
| 2325 | return replace(pos, len, copy.constData(), copy.length()); executed 2003365 times by 18 tests: return replace(pos, len, copy.constData(), copy.length());Executed by:
| 2003365 | ||||||||||||||||||
| 2326 | } | - | ||||||||||||||||||
| 2327 | - | |||||||||||||||||||
| 2328 | /*! | - | ||||||||||||||||||
| 2329 | \fn QString &QString::replace(int position, int n, const QChar *unicode, int size) | - | ||||||||||||||||||
| 2330 | \overload replace() | - | ||||||||||||||||||
| 2331 | Replaces \a n characters beginning at index \a position with the | - | ||||||||||||||||||
| 2332 | first \a size characters of the QChar array \a unicode and returns a | - | ||||||||||||||||||
| 2333 | reference to this string. | - | ||||||||||||||||||
| 2334 | */ | - | ||||||||||||||||||
| 2335 | QString &QString::replace(int pos, int len, const QChar *unicode, int size) | - | ||||||||||||||||||
| 2336 | { | - | ||||||||||||||||||
| 2337 | if (uint(pos) > uint(d->size))
| 0-2109496 | ||||||||||||||||||
| 2338 | return *this; never executed: return *this; | 0 | ||||||||||||||||||
| 2339 | if (len > d->size - pos)
| 25-2109471 | ||||||||||||||||||
| 2340 | len = d->size - pos; executed 25 times by 1 test: len = d->size - pos;Executed by:
| 25 | ||||||||||||||||||
| 2341 | - | |||||||||||||||||||
| 2342 | uint index = pos; | - | ||||||||||||||||||
| 2343 | replace_helper(&index, 1, len, unicode, size); | - | ||||||||||||||||||
| 2344 | return *this; executed 2109496 times by 23 tests: return *this;Executed by:
| 2109496 | ||||||||||||||||||
| 2345 | } | - | ||||||||||||||||||
| 2346 | - | |||||||||||||||||||
| 2347 | /*! | - | ||||||||||||||||||
| 2348 | \fn QString &QString::replace(int position, int n, QChar after) | - | ||||||||||||||||||
| 2349 | \overload replace() | - | ||||||||||||||||||
| 2350 | - | |||||||||||||||||||
| 2351 | Replaces \a n characters beginning at index \a position with the | - | ||||||||||||||||||
| 2352 | character \a after and returns a reference to this string. | - | ||||||||||||||||||
| 2353 | */ | - | ||||||||||||||||||
| 2354 | QString &QString::replace(int pos, int len, QChar after) | - | ||||||||||||||||||
| 2355 | { | - | ||||||||||||||||||
| 2356 | return replace(pos, len, &after, 1); executed 12 times by 3 tests: return replace(pos, len, &after, 1);Executed by:
| 12 | ||||||||||||||||||
| 2357 | } | - | ||||||||||||||||||
| 2358 | - | |||||||||||||||||||
| 2359 | /*! | - | ||||||||||||||||||
| 2360 | \overload replace() | - | ||||||||||||||||||
| 2361 | Replaces every occurrence of the string \a before with the string \a | - | ||||||||||||||||||
| 2362 | after and returns a reference to this string. | - | ||||||||||||||||||
| 2363 | - | |||||||||||||||||||
| 2364 | If \a cs is Qt::CaseSensitive (default), the search is case | - | ||||||||||||||||||
| 2365 | sensitive; otherwise the search is case insensitive. | - | ||||||||||||||||||
| 2366 | - | |||||||||||||||||||
| 2367 | Example: | - | ||||||||||||||||||
| 2368 | - | |||||||||||||||||||
| 2369 | \snippet qstring/main.cpp 41 | - | ||||||||||||||||||
| 2370 | - | |||||||||||||||||||
| 2371 | \note The replacement text is not rescanned after it is inserted. | - | ||||||||||||||||||
| 2372 | - | |||||||||||||||||||
| 2373 | Example: | - | ||||||||||||||||||
| 2374 | - | |||||||||||||||||||
| 2375 | \snippet qstring/main.cpp 86 | - | ||||||||||||||||||
| 2376 | */ | - | ||||||||||||||||||
| 2377 | QString &QString::replace(const QString &before, const QString &after, Qt::CaseSensitivity cs) | - | ||||||||||||||||||
| 2378 | { | - | ||||||||||||||||||
| 2379 | return replace(before.constData(), before.size(), after.constData(), after.size(), cs); executed 164573 times by 19 tests: return replace(before.constData(), before.size(), after.constData(), after.size(), cs);Executed by:
| 164573 | ||||||||||||||||||
| 2380 | } | - | ||||||||||||||||||
| 2381 | - | |||||||||||||||||||
| 2382 | namespace { // helpers for replace and its helper: | - | ||||||||||||||||||
| 2383 | QChar *textCopy(const QChar *start, int len) | - | ||||||||||||||||||
| 2384 | { | - | ||||||||||||||||||
| 2385 | const size_t size = len * sizeof(QChar); | - | ||||||||||||||||||
| 2386 | QChar *const copy = static_cast<QChar *>(::malloc(size)); | - | ||||||||||||||||||
| 2387 | Q_CHECK_PTR(copy); never executed: qBadAlloc();
| 0-25 | ||||||||||||||||||
| 2388 | ::memcpy(copy, start, size); | - | ||||||||||||||||||
| 2389 | return copy; executed 25 times by 4 tests: return copy;Executed by:
| 25 | ||||||||||||||||||
| 2390 | } | - | ||||||||||||||||||
| 2391 | - | |||||||||||||||||||
| 2392 | bool pointsIntoRange(const QChar *ptr, const ushort *base, int len) | - | ||||||||||||||||||
| 2393 | { | - | ||||||||||||||||||
| 2394 | const QChar *const start = reinterpret_cast<const QChar *>(base); | - | ||||||||||||||||||
| 2395 | return start <= ptr && ptr < start + len; executed 2111196 times by 51 tests: return start <= ptr && ptr < start + len;Executed by:
| 25-2111196 | ||||||||||||||||||
| 2396 | } | - | ||||||||||||||||||
| 2397 | } // end namespace | - | ||||||||||||||||||
| 2398 | - | |||||||||||||||||||
| 2399 | /*! | - | ||||||||||||||||||
| 2400 | \internal | - | ||||||||||||||||||
| 2401 | */ | - | ||||||||||||||||||
| 2402 | void QString::replace_helper(uint *indices, int nIndices, int blen, const QChar *after, int alen) | - | ||||||||||||||||||
| 2403 | { | - | ||||||||||||||||||
| 2404 | // Copy after if it lies inside our own d->data() area (which we could | - | ||||||||||||||||||
| 2405 | // possibly invalidate via a realloc or modify by replacement). | - | ||||||||||||||||||
| 2406 | QChar *afterBuffer = 0; | - | ||||||||||||||||||
| 2407 | if (pointsIntoRange(after, d->data(), d->size)) // Use copy in place of vulnerable original:
| 23-2111171 | ||||||||||||||||||
| 2408 | after = afterBuffer = textCopy(after, alen); executed 23 times by 4 tests: after = afterBuffer = textCopy(after, alen);Executed by:
| 23 | ||||||||||||||||||
| 2409 | - | |||||||||||||||||||
| 2410 | QT_TRY { | - | ||||||||||||||||||
| 2411 | if (blen == alen) {
| 96920-2014274 | ||||||||||||||||||
| 2412 | // replace in place | - | ||||||||||||||||||
| 2413 | detach(); | - | ||||||||||||||||||
| 2414 | for (int i = 0; i < nIndices; ++i)
| 2014274-2014281 | ||||||||||||||||||
| 2415 | memcpy(d->data() + indices[i], after, alen * sizeof(QChar)); executed 2014281 times by 21 tests: memcpy(d->data() + indices[i], after, alen * sizeof(QChar));Executed by:
| 2014281 | ||||||||||||||||||
| 2416 | } else if (alen < blen) { executed 2014274 times by 21 tests: end of blockExecuted by:
| 10370-2014274 | ||||||||||||||||||
| 2417 | // replace from front | - | ||||||||||||||||||
| 2418 | detach(); | - | ||||||||||||||||||
| 2419 | uint to = indices[0]; | - | ||||||||||||||||||
| 2420 | if (alen)
| 32-10338 | ||||||||||||||||||
| 2421 | memcpy(d->data()+to, after, alen*sizeof(QChar)); executed 10338 times by 16 tests: memcpy(d->data()+to, after, alen*sizeof(QChar));Executed by:
| 10338 | ||||||||||||||||||
| 2422 | to += alen; | - | ||||||||||||||||||
| 2423 | uint movestart = indices[0] + blen; | - | ||||||||||||||||||
| 2424 | for (int i = 1; i < nIndices; ++i) {
| 1031-10370 | ||||||||||||||||||
| 2425 | int msize = indices[i] - movestart; | - | ||||||||||||||||||
| 2426 | if (msize > 0) {
| 2-1029 | ||||||||||||||||||
| 2427 | memmove(d->data() + to, d->data() + movestart, msize * sizeof(QChar)); | - | ||||||||||||||||||
| 2428 | to += msize; | - | ||||||||||||||||||
| 2429 | } executed 1029 times by 1 test: end of blockExecuted by:
| 1029 | ||||||||||||||||||
| 2430 | if (alen) {
| 5-1026 | ||||||||||||||||||
| 2431 | memcpy(d->data() + to, after, alen * sizeof(QChar)); | - | ||||||||||||||||||
| 2432 | to += alen; | - | ||||||||||||||||||
| 2433 | } executed 1026 times by 1 test: end of blockExecuted by:
| 1026 | ||||||||||||||||||
| 2434 | movestart = indices[i] + blen; | - | ||||||||||||||||||
| 2435 | } executed 1031 times by 1 test: end of blockExecuted by:
| 1031 | ||||||||||||||||||
| 2436 | int msize = d->size - movestart; | - | ||||||||||||||||||
| 2437 | if (msize > 0)
| 1283-9087 | ||||||||||||||||||
| 2438 | memmove(d->data() + to, d->data() + movestart, msize * sizeof(QChar)); executed 1283 times by 11 tests: memmove(d->data() + to, d->data() + movestart, msize * sizeof(QChar));Executed by:
| 1283 | ||||||||||||||||||
| 2439 | resize(d->size - nIndices*(blen-alen)); | - | ||||||||||||||||||
| 2440 | } else { executed 10370 times by 16 tests: end of blockExecuted by:
| 10370 | ||||||||||||||||||
| 2441 | // replace from back | - | ||||||||||||||||||
| 2442 | int adjust = nIndices*(alen-blen); | - | ||||||||||||||||||
| 2443 | int newLen = d->size + adjust; | - | ||||||||||||||||||
| 2444 | int moveend = d->size; | - | ||||||||||||||||||
| 2445 | resize(newLen); | - | ||||||||||||||||||
| 2446 | - | |||||||||||||||||||
| 2447 | while (nIndices) {
| 86550-86666 | ||||||||||||||||||
| 2448 | --nIndices; | - | ||||||||||||||||||
| 2449 | int movestart = indices[nIndices] + blen; | - | ||||||||||||||||||
| 2450 | int insertstart = indices[nIndices] + nIndices*(alen-blen); | - | ||||||||||||||||||
| 2451 | int moveto = insertstart + alen; | - | ||||||||||||||||||
| 2452 | memmove(d->data() + moveto, d->data() + movestart, | - | ||||||||||||||||||
| 2453 | (moveend - movestart)*sizeof(QChar)); | - | ||||||||||||||||||
| 2454 | memcpy(d->data() + insertstart, after, alen * sizeof(QChar)); | - | ||||||||||||||||||
| 2455 | moveend = movestart-blen; | - | ||||||||||||||||||
| 2456 | } executed 86666 times by 33 tests: end of blockExecuted by:
| 86666 | ||||||||||||||||||
| 2457 | } executed 86550 times by 33 tests: end of blockExecuted by:
| 86550 | ||||||||||||||||||
| 2458 | } QT_CATCH(const std::bad_alloc &) { | - | ||||||||||||||||||
| 2459 | ::free(afterBuffer); | - | ||||||||||||||||||
| 2460 | QT_RETHROW; never executed: throw; | 0 | ||||||||||||||||||
| 2461 | } | - | ||||||||||||||||||
| 2462 | ::free(afterBuffer); | - | ||||||||||||||||||
| 2463 | } executed 2111194 times by 51 tests: end of blockExecuted by:
| 2111194 | ||||||||||||||||||
| 2464 | - | |||||||||||||||||||
| 2465 | /*! | - | ||||||||||||||||||
| 2466 | \since 4.5 | - | ||||||||||||||||||
| 2467 | \overload replace() | - | ||||||||||||||||||
| 2468 | - | |||||||||||||||||||
| 2469 | Replaces each occurrence in this string of the first \a blen | - | ||||||||||||||||||
| 2470 | characters of \a before with the first \a alen characters of \a | - | ||||||||||||||||||
| 2471 | after and returns a reference to this string. | - | ||||||||||||||||||
| 2472 | - | |||||||||||||||||||
| 2473 | If \a cs is Qt::CaseSensitive (default), the search is case | - | ||||||||||||||||||
| 2474 | sensitive; otherwise the search is case insensitive. | - | ||||||||||||||||||
| 2475 | */ | - | ||||||||||||||||||
| 2476 | QString &QString::replace(const QChar *before, int blen, | - | ||||||||||||||||||
| 2477 | const QChar *after, int alen, | - | ||||||||||||||||||
| 2478 | Qt::CaseSensitivity cs) | - | ||||||||||||||||||
| 2479 | { | - | ||||||||||||||||||
| 2480 | if (d->size == 0) {
| 1574-174176 | ||||||||||||||||||
| 2481 | if (blen)
| 6-1568 | ||||||||||||||||||
| 2482 | return *this; executed 1568 times by 17 tests: return *this;Executed by:
| 1568 | ||||||||||||||||||
| 2483 | } else { executed 6 times by 1 test: end of blockExecuted by:
| 6 | ||||||||||||||||||
| 2484 | if (cs == Qt::CaseSensitive && before == after && blen == alen)
| 0-174161 | ||||||||||||||||||
| 2485 | return *this; executed 2 times by 1 test: return *this;Executed by:
| 2 | ||||||||||||||||||
| 2486 | } executed 174174 times by 73 tests: end of blockExecuted by:
| 174174 | ||||||||||||||||||
| 2487 | if (alen == 0 && blen == 0)
| 4-174159 | ||||||||||||||||||
| 2488 | return *this; executed 4 times by 1 test: return *this;Executed by:
| 4 | ||||||||||||||||||
| 2489 | - | |||||||||||||||||||
| 2490 | QStringMatcher matcher(before, blen, cs); | - | ||||||||||||||||||
| 2491 | QChar *beforeBuffer = 0, *afterBuffer = 0; | - | ||||||||||||||||||
| 2492 | - | |||||||||||||||||||
| 2493 | int index = 0; | - | ||||||||||||||||||
| 2494 | while (1) { | - | ||||||||||||||||||
| 2495 | uint indices[1024]; | - | ||||||||||||||||||
| 2496 | uint pos = 0; | - | ||||||||||||||||||
| 2497 | while (pos < 1024) {
| 1-176988 | ||||||||||||||||||
| 2498 | index = matcher.indexIn(*this, index); | - | ||||||||||||||||||
| 2499 | if (index == -1)
| 2812-174176 | ||||||||||||||||||
| 2500 | break; executed 174176 times by 73 tests: break;Executed by:
| 174176 | ||||||||||||||||||
| 2501 | indices[pos++] = index; | - | ||||||||||||||||||
| 2502 | if (blen) // Step over before:
| 10-2802 | ||||||||||||||||||
| 2503 | index += blen; executed 2802 times by 32 tests: index += blen;Executed by:
| 2802 | ||||||||||||||||||
| 2504 | else // Only count one instance of empty between any two characters: | - | ||||||||||||||||||
| 2505 | index++; executed 10 times by 1 test: index++;Executed by:
| 10 | ||||||||||||||||||
| 2506 | } | - | ||||||||||||||||||
| 2507 | if (!pos) // Nothing to replace
| 1673-172504 | ||||||||||||||||||
| 2508 | break; executed 172504 times by 61 tests: break;Executed by:
| 172504 | ||||||||||||||||||
| 2509 | - | |||||||||||||||||||
| 2510 | if (Q_UNLIKELY(index != -1)) {
| 1-1672 | ||||||||||||||||||
| 2511 | /* | - | ||||||||||||||||||
| 2512 | We're about to change data, that before and after might point | - | ||||||||||||||||||
| 2513 | into, and we'll need that data for our next batch of indices. | - | ||||||||||||||||||
| 2514 | */ | - | ||||||||||||||||||
| 2515 | if (!afterBuffer && pointsIntoRange(after, d->data(), d->size))
| 0-1 | ||||||||||||||||||
| 2516 | after = afterBuffer = textCopy(after, alen); executed 1 time by 1 test: after = afterBuffer = textCopy(after, alen);Executed by:
| 1 | ||||||||||||||||||
| 2517 | - | |||||||||||||||||||
| 2518 | if (!beforeBuffer && pointsIntoRange(before, d->data(), d->size)) {
| 0-1 | ||||||||||||||||||
| 2519 | beforeBuffer = textCopy(before, blen); | - | ||||||||||||||||||
| 2520 | matcher = QStringMatcher(beforeBuffer, blen, cs); | - | ||||||||||||||||||
| 2521 | } executed 1 time by 1 test: end of blockExecuted by:
| 1 | ||||||||||||||||||
| 2522 | } executed 1 time by 1 test: end of blockExecuted by:
| 1 | ||||||||||||||||||
| 2523 | - | |||||||||||||||||||
| 2524 | replace_helper(indices, pos, blen, after, alen); | - | ||||||||||||||||||
| 2525 | - | |||||||||||||||||||
| 2526 | if (Q_LIKELY(index == -1)) // Nothing left to replace
| 1-1672 | ||||||||||||||||||
| 2527 | break; executed 1672 times by 32 tests: break;Executed by:
| 1672 | ||||||||||||||||||
| 2528 | // The call to replace_helper just moved what index points at: | - | ||||||||||||||||||
| 2529 | index += pos*(alen-blen); | - | ||||||||||||||||||
| 2530 | } executed 1 time by 1 test: end of blockExecuted by:
| 1 | ||||||||||||||||||
| 2531 | ::free(afterBuffer); | - | ||||||||||||||||||
| 2532 | ::free(beforeBuffer); | - | ||||||||||||||||||
| 2533 | - | |||||||||||||||||||
| 2534 | return *this; executed 174176 times by 73 tests: return *this;Executed by:
| 174176 | ||||||||||||||||||
| 2535 | } | - | ||||||||||||||||||
| 2536 | - | |||||||||||||||||||
| 2537 | /*! | - | ||||||||||||||||||
| 2538 | \overload replace() | - | ||||||||||||||||||
| 2539 | Replaces every occurrence of the character \a ch in the string with | - | ||||||||||||||||||
| 2540 | \a after and returns a reference to this string. | - | ||||||||||||||||||
| 2541 | - | |||||||||||||||||||
| 2542 | If \a cs is Qt::CaseSensitive (default), the search is case | - | ||||||||||||||||||
| 2543 | sensitive; otherwise the search is case insensitive. | - | ||||||||||||||||||
| 2544 | */ | - | ||||||||||||||||||
| 2545 | QString& QString::replace(QChar ch, const QString &after, Qt::CaseSensitivity cs) | - | ||||||||||||||||||
| 2546 | { | - | ||||||||||||||||||
| 2547 | if (after.d->size == 0)
| 37-14856 | ||||||||||||||||||
| 2548 | return remove(ch, cs); executed 37 times by 1 test: return remove(ch, cs);Executed by:
| 37 | ||||||||||||||||||
| 2549 | - | |||||||||||||||||||
| 2550 | if (after.d->size == 1)
| 22-14834 | ||||||||||||||||||
| 2551 | return replace(ch, after.d->data()[0], cs); executed 22 times by 1 test: return replace(ch, after.d->data()[0], cs);Executed by:
| 22 | ||||||||||||||||||
| 2552 | - | |||||||||||||||||||
| 2553 | if (d->size == 0)
| 1154-13680 | ||||||||||||||||||
| 2554 | return *this; executed 1154 times by 11 tests: return *this;Executed by:
| 1154 | ||||||||||||||||||
| 2555 | - | |||||||||||||||||||
| 2556 | ushort cc = (cs == Qt::CaseSensitive ? ch.unicode() : ch.toCaseFolded().unicode());
| 4-13676 | ||||||||||||||||||
| 2557 | - | |||||||||||||||||||
| 2558 | int index = 0; | - | ||||||||||||||||||
| 2559 | while (1) { | - | ||||||||||||||||||
| 2560 | uint indices[1024]; | - | ||||||||||||||||||
| 2561 | uint pos = 0; | - | ||||||||||||||||||
| 2562 | if (cs == Qt::CaseSensitive) {
| 7-13698 | ||||||||||||||||||
| 2563 | while (pos < 1024 && index < d->size) {
| 0-416523 | ||||||||||||||||||
| 2564 | if (d->data()[index] == cc)
| 32-402793 | ||||||||||||||||||
| 2565 | indices[pos++] = index; executed 32 times by 5 tests: indices[pos++] = index;Executed by:
| 32 | ||||||||||||||||||
| 2566 | index++; | - | ||||||||||||||||||
| 2567 | } executed 402825 times by 42 tests: end of blockExecuted by:
| 402825 | ||||||||||||||||||
| 2568 | } else { executed 13698 times by 42 tests: end of blockExecuted by:
| 13698 | ||||||||||||||||||
| 2569 | while (pos < 1024 && index < d->size) {
| 0-29 | ||||||||||||||||||
| 2570 | if (QChar::toCaseFolded(d->data()[index]) == cc)
| 8-14 | ||||||||||||||||||
| 2571 | indices[pos++] = index; executed 8 times by 1 test: indices[pos++] = index;Executed by:
| 8 | ||||||||||||||||||
| 2572 | index++; | - | ||||||||||||||||||
| 2573 | } executed 22 times by 1 test: end of blockExecuted by:
| 22 | ||||||||||||||||||
| 2574 | } executed 7 times by 1 test: end of blockExecuted by:
| 7 | ||||||||||||||||||
| 2575 | if (!pos) // Nothing to replace
| 25-13680 | ||||||||||||||||||
| 2576 | break; executed 13680 times by 42 tests: break;Executed by:
| 13680 | ||||||||||||||||||
| 2577 | - | |||||||||||||||||||
| 2578 | replace_helper(indices, pos, 1, after.constData(), after.d->size); | - | ||||||||||||||||||
| 2579 | - | |||||||||||||||||||
| 2580 | if (Q_LIKELY(index == -1)) // Nothing left to replace
| 0-25 | ||||||||||||||||||
| 2581 | break; never executed: break; | 0 | ||||||||||||||||||
| 2582 | // The call to replace_helper just moved what index points at: | - | ||||||||||||||||||
| 2583 | index += pos*(after.d->size - 1); | - | ||||||||||||||||||
| 2584 | } executed 25 times by 5 tests: end of blockExecuted by:
| 25 | ||||||||||||||||||
| 2585 | return *this; executed 13680 times by 42 tests: return *this;Executed by:
| 13680 | ||||||||||||||||||
| 2586 | } | - | ||||||||||||||||||
| 2587 | - | |||||||||||||||||||
| 2588 | /*! | - | ||||||||||||||||||
| 2589 | \overload replace() | - | ||||||||||||||||||
| 2590 | Replaces every occurrence of the character \a before with the | - | ||||||||||||||||||
| 2591 | character \a after and returns a reference to this string. | - | ||||||||||||||||||
| 2592 | - | |||||||||||||||||||
| 2593 | If \a cs is Qt::CaseSensitive (default), the search is case | - | ||||||||||||||||||
| 2594 | sensitive; otherwise the search is case insensitive. | - | ||||||||||||||||||
| 2595 | */ | - | ||||||||||||||||||
| 2596 | QString& QString::replace(QChar before, QChar after, Qt::CaseSensitivity cs) | - | ||||||||||||||||||
| 2597 | { | - | ||||||||||||||||||
| 2598 | ushort a = after.unicode(); | - | ||||||||||||||||||
| 2599 | ushort b = before.unicode(); | - | ||||||||||||||||||
| 2600 | if (d->size) {
| 1311-136058 | ||||||||||||||||||
| 2601 | detach(); | - | ||||||||||||||||||
| 2602 | ushort *i = d->data(); | - | ||||||||||||||||||
| 2603 | const ushort *e = i + d->size; | - | ||||||||||||||||||
| 2604 | if (cs == Qt::CaseSensitive) {
| 22-136036 | ||||||||||||||||||
| 2605 | for (; i != e; ++i)
| 136036-1107344 | ||||||||||||||||||
| 2606 | if (*i == b)
| 9865-1097479 | ||||||||||||||||||
| 2607 | *i = a; executed 9865 times by 25 tests: *i = a;Executed by:
| 9865 | ||||||||||||||||||
| 2608 | } else { executed 136036 times by 64 tests: end of blockExecuted by:
| 136036 | ||||||||||||||||||
| 2609 | b = foldCase(b); | - | ||||||||||||||||||
| 2610 | for (; i != e; ++i)
| 22-58 | ||||||||||||||||||
| 2611 | if (foldCase(*i) == b)
| 28-30 | ||||||||||||||||||
| 2612 | *i = a; executed 30 times by 1 test: *i = a;Executed by:
| 30 | ||||||||||||||||||
| 2613 | } executed 22 times by 1 test: end of blockExecuted by:
| 22 | ||||||||||||||||||
| 2614 | } | - | ||||||||||||||||||
| 2615 | return *this; executed 137369 times by 64 tests: return *this;Executed by:
| 137369 | ||||||||||||||||||
| 2616 | } | - | ||||||||||||||||||
| 2617 | - | |||||||||||||||||||
| 2618 | /*! | - | ||||||||||||||||||
| 2619 | \since 4.5 | - | ||||||||||||||||||
| 2620 | \overload replace() | - | ||||||||||||||||||
| 2621 | - | |||||||||||||||||||
| 2622 | Replaces every occurrence of the string \a before with the string \a | - | ||||||||||||||||||
| 2623 | after and returns a reference to this string. | - | ||||||||||||||||||
| 2624 | - | |||||||||||||||||||
| 2625 | If \a cs is Qt::CaseSensitive (default), the search is case | - | ||||||||||||||||||
| 2626 | sensitive; otherwise the search is case insensitive. | - | ||||||||||||||||||
| 2627 | - | |||||||||||||||||||
| 2628 | \note The text is not rescanned after a replacement. | - | ||||||||||||||||||
| 2629 | */ | - | ||||||||||||||||||
| 2630 | QString &QString::replace(QLatin1String before, QLatin1String after, Qt::CaseSensitivity cs) | - | ||||||||||||||||||
| 2631 | { | - | ||||||||||||||||||
| 2632 | int alen = after.size(); | - | ||||||||||||||||||
| 2633 | int blen = before.size(); | - | ||||||||||||||||||
| 2634 | QVarLengthArray<ushort> a(alen); | - | ||||||||||||||||||
| 2635 | QVarLengthArray<ushort> b(blen); | - | ||||||||||||||||||
| 2636 | qt_from_latin1(a.data(), after.latin1(), alen); | - | ||||||||||||||||||
| 2637 | qt_from_latin1(b.data(), before.latin1(), blen); | - | ||||||||||||||||||
| 2638 | return replace((const QChar *)b.data(), blen, (const QChar *)a.data(), alen, cs); executed 1016 times by 43 tests: return replace((const QChar *)b.data(), blen, (const QChar *)a.data(), alen, cs);Executed by:
| 1016 | ||||||||||||||||||
| 2639 | } | - | ||||||||||||||||||
| 2640 | - | |||||||||||||||||||
| 2641 | /*! | - | ||||||||||||||||||
| 2642 | \since 4.5 | - | ||||||||||||||||||
| 2643 | \overload replace() | - | ||||||||||||||||||
| 2644 | - | |||||||||||||||||||
| 2645 | Replaces every occurrence of the string \a before with the string \a | - | ||||||||||||||||||
| 2646 | after and returns a reference to this string. | - | ||||||||||||||||||
| 2647 | - | |||||||||||||||||||
| 2648 | If \a cs is Qt::CaseSensitive (default), the search is case | - | ||||||||||||||||||
| 2649 | sensitive; otherwise the search is case insensitive. | - | ||||||||||||||||||
| 2650 | - | |||||||||||||||||||
| 2651 | \note The text is not rescanned after a replacement. | - | ||||||||||||||||||
| 2652 | */ | - | ||||||||||||||||||
| 2653 | QString &QString::replace(QLatin1String before, const QString &after, Qt::CaseSensitivity cs) | - | ||||||||||||||||||
| 2654 | { | - | ||||||||||||||||||
| 2655 | int blen = before.size(); | - | ||||||||||||||||||
| 2656 | QVarLengthArray<ushort> b(blen); | - | ||||||||||||||||||
| 2657 | qt_from_latin1(b.data(), before.latin1(), blen); | - | ||||||||||||||||||
| 2658 | return replace((const QChar *)b.data(), blen, after.constData(), after.d->size, cs); executed 210 times by 3 tests: return replace((const QChar *)b.data(), blen, after.constData(), after.d->size, cs);Executed by:
| 210 | ||||||||||||||||||
| 2659 | } | - | ||||||||||||||||||
| 2660 | - | |||||||||||||||||||
| 2661 | /*! | - | ||||||||||||||||||
| 2662 | \since 4.5 | - | ||||||||||||||||||
| 2663 | \overload replace() | - | ||||||||||||||||||
| 2664 | - | |||||||||||||||||||
| 2665 | Replaces every occurrence of the string \a before with the string \a | - | ||||||||||||||||||
| 2666 | after and returns a reference to this string. | - | ||||||||||||||||||
| 2667 | - | |||||||||||||||||||
| 2668 | If \a cs is Qt::CaseSensitive (default), the search is case | - | ||||||||||||||||||
| 2669 | sensitive; otherwise the search is case insensitive. | - | ||||||||||||||||||
| 2670 | - | |||||||||||||||||||
| 2671 | \note The text is not rescanned after a replacement. | - | ||||||||||||||||||
| 2672 | */ | - | ||||||||||||||||||
| 2673 | QString &QString::replace(const QString &before, QLatin1String after, Qt::CaseSensitivity cs) | - | ||||||||||||||||||
| 2674 | { | - | ||||||||||||||||||
| 2675 | int alen = after.size(); | - | ||||||||||||||||||
| 2676 | QVarLengthArray<ushort> a(alen); | - | ||||||||||||||||||
| 2677 | qt_from_latin1(a.data(), after.latin1(), alen); | - | ||||||||||||||||||
| 2678 | return replace(before.constData(), before.d->size, (const QChar *)a.data(), alen, cs); never executed: return replace(before.constData(), before.d->size, (const QChar *)a.data(), alen, cs); | 0 | ||||||||||||||||||
| 2679 | } | - | ||||||||||||||||||
| 2680 | - | |||||||||||||||||||
| 2681 | /*! | - | ||||||||||||||||||
| 2682 | \since 4.5 | - | ||||||||||||||||||
| 2683 | \overload replace() | - | ||||||||||||||||||
| 2684 | - | |||||||||||||||||||
| 2685 | Replaces every occurrence of the character \a c with the string \a | - | ||||||||||||||||||
| 2686 | after and returns a reference to this string. | - | ||||||||||||||||||
| 2687 | - | |||||||||||||||||||
| 2688 | If \a cs is Qt::CaseSensitive (default), the search is case | - | ||||||||||||||||||
| 2689 | sensitive; otherwise the search is case insensitive. | - | ||||||||||||||||||
| 2690 | - | |||||||||||||||||||
| 2691 | \note The text is not rescanned after a replacement. | - | ||||||||||||||||||
| 2692 | */ | - | ||||||||||||||||||
| 2693 | QString &QString::replace(QChar c, QLatin1String after, Qt::CaseSensitivity cs) | - | ||||||||||||||||||
| 2694 | { | - | ||||||||||||||||||
| 2695 | int alen = after.size(); | - | ||||||||||||||||||
| 2696 | QVarLengthArray<ushort> a(alen); | - | ||||||||||||||||||
| 2697 | qt_from_latin1(a.data(), after.latin1(), alen); | - | ||||||||||||||||||
| 2698 | return replace(&c, 1, (const QChar *)a.data(), alen, cs); executed 9949 times by 35 tests: return replace(&c, 1, (const QChar *)a.data(), alen, cs);Executed by:
| 9949 | ||||||||||||||||||
| 2699 | } | - | ||||||||||||||||||
| 2700 | - | |||||||||||||||||||
| 2701 | - | |||||||||||||||||||
| 2702 | /*! | - | ||||||||||||||||||
| 2703 | \relates QString | - | ||||||||||||||||||
| 2704 | Returns \c true if string \a s1 is equal to string \a s2; otherwise | - | ||||||||||||||||||
| 2705 | returns \c false. | - | ||||||||||||||||||
| 2706 | - | |||||||||||||||||||
| 2707 | The comparison is based exclusively on the numeric Unicode values of | - | ||||||||||||||||||
| 2708 | the characters and is very fast, but is not what a human would | - | ||||||||||||||||||
| 2709 | expect. Consider sorting user-interface strings with | - | ||||||||||||||||||
| 2710 | localeAwareCompare(). | - | ||||||||||||||||||
| 2711 | */ | - | ||||||||||||||||||
| 2712 | bool operator==(const QString &s1, const QString &s2) | - | ||||||||||||||||||
| 2713 | { | - | ||||||||||||||||||
| 2714 | if (s1.d->size != s2.d->size)
| 435387-2823015 | ||||||||||||||||||
| 2715 | return false; executed 435387 times by 306 tests: return false;Executed by:
| 435387 | ||||||||||||||||||
| 2716 | - | |||||||||||||||||||
| 2717 | return qMemEquals(s1.d->data(), s2.d->data(), s1.d->size); executed 2823015 times by 525 tests: return qMemEquals(s1.d->data(), s2.d->data(), s1.d->size);Executed by:
| 2823015 | ||||||||||||||||||
| 2718 | } | - | ||||||||||||||||||
| 2719 | - | |||||||||||||||||||
| 2720 | /*! | - | ||||||||||||||||||
| 2721 | \overload operator==() | - | ||||||||||||||||||
| 2722 | Returns \c true if this string is equal to \a other; otherwise | - | ||||||||||||||||||
| 2723 | returns \c false. | - | ||||||||||||||||||
| 2724 | */ | - | ||||||||||||||||||
| 2725 | bool QString::operator==(QLatin1String other) const | - | ||||||||||||||||||
| 2726 | { | - | ||||||||||||||||||
| 2727 | if (d->size != other.size())
| 281771-1241903 | ||||||||||||||||||
| 2728 | return false; executed 1241903 times by 341 tests: return false;Executed by:
| 1241903 | ||||||||||||||||||
| 2729 | - | |||||||||||||||||||
| 2730 | if (!other.size())
| 4-281767 | ||||||||||||||||||
| 2731 | return isEmpty(); executed 4 times by 1 test: return isEmpty();Executed by:
| 4 | ||||||||||||||||||
| 2732 | - | |||||||||||||||||||
| 2733 | return compare_helper(data(), size(), other, Qt::CaseSensitive) == 0; executed 281767 times by 442 tests: return compare_helper(data(), size(), other, Qt::CaseSensitive) == 0;Executed by:
| 281767 | ||||||||||||||||||
| 2734 | } | - | ||||||||||||||||||
| 2735 | - | |||||||||||||||||||
| 2736 | /*! \fn bool QString::operator==(const QByteArray &other) const | - | ||||||||||||||||||
| 2737 | - | |||||||||||||||||||
| 2738 | \overload operator==() | - | ||||||||||||||||||
| 2739 | - | |||||||||||||||||||
| 2740 | The \a other byte array is converted to a QString using the | - | ||||||||||||||||||
| 2741 | fromUtf8() function. This function stops conversion at the | - | ||||||||||||||||||
| 2742 | first NUL character found, or the end of the byte array. | - | ||||||||||||||||||
| 2743 | - | |||||||||||||||||||
| 2744 | You can disable this operator by defining \c | - | ||||||||||||||||||
| 2745 | QT_NO_CAST_FROM_ASCII when you compile your applications. This | - | ||||||||||||||||||
| 2746 | can be useful if you want to ensure that all user-visible strings | - | ||||||||||||||||||
| 2747 | go through QObject::tr(), for example. | - | ||||||||||||||||||
| 2748 | - | |||||||||||||||||||
| 2749 | Returns \c true if this string is lexically equal to the parameter | - | ||||||||||||||||||
| 2750 | string \a other. Otherwise returns \c false. | - | ||||||||||||||||||
| 2751 | */ | - | ||||||||||||||||||
| 2752 | - | |||||||||||||||||||
| 2753 | /*! \fn bool QString::operator==(const char *other) const | - | ||||||||||||||||||
| 2754 | - | |||||||||||||||||||
| 2755 | \overload operator==() | - | ||||||||||||||||||
| 2756 | - | |||||||||||||||||||
| 2757 | The \a other const char pointer is converted to a QString using | - | ||||||||||||||||||
| 2758 | the fromUtf8() function. | - | ||||||||||||||||||
| 2759 | - | |||||||||||||||||||
| 2760 | You can disable this operator by defining \c | - | ||||||||||||||||||
| 2761 | QT_NO_CAST_FROM_ASCII when you compile your applications. This | - | ||||||||||||||||||
| 2762 | can be useful if you want to ensure that all user-visible strings | - | ||||||||||||||||||
| 2763 | go through QObject::tr(), for example. | - | ||||||||||||||||||
| 2764 | */ | - | ||||||||||||||||||
| 2765 | - | |||||||||||||||||||
| 2766 | /*! | - | ||||||||||||||||||
| 2767 | \relates QString | - | ||||||||||||||||||
| 2768 | Returns \c true if string \a s1 is lexically less than string | - | ||||||||||||||||||
| 2769 | \a s2; otherwise returns \c false. | - | ||||||||||||||||||
| 2770 | - | |||||||||||||||||||
| 2771 | The comparison is based exclusively on the numeric Unicode values | - | ||||||||||||||||||
| 2772 | of the characters and is very fast, but is not what a human would | - | ||||||||||||||||||
| 2773 | expect. Consider sorting user-interface strings using the | - | ||||||||||||||||||
| 2774 | QString::localeAwareCompare() function. | - | ||||||||||||||||||
| 2775 | */ | - | ||||||||||||||||||
| 2776 | bool operator<(const QString &s1, const QString &s2) | - | ||||||||||||||||||
| 2777 | { | - | ||||||||||||||||||
| 2778 | return ucstrcmp(s1.constData(), s1.length(), s2.constData(), s2.length()) < 0; executed 1722682 times by 419 tests: return ucstrcmp(s1.constData(), s1.length(), s2.constData(), s2.length()) < 0;Executed by:
| 1722682 | ||||||||||||||||||
| 2779 | } | - | ||||||||||||||||||
| 2780 | /*! | - | ||||||||||||||||||
| 2781 | \overload operator<() | - | ||||||||||||||||||
| 2782 | - | |||||||||||||||||||
| 2783 | Returns \c true if this string is lexically less than the parameter | - | ||||||||||||||||||
| 2784 | string called \a other; otherwise returns \c false. | - | ||||||||||||||||||
| 2785 | */ | - | ||||||||||||||||||
| 2786 | bool QString::operator<(QLatin1String other) const | - | ||||||||||||||||||
| 2787 | { | - | ||||||||||||||||||
| 2788 | const uchar *c = (const uchar *) other.latin1(); | - | ||||||||||||||||||
| 2789 | if (!c || *c == 0)
| 5-2322 | ||||||||||||||||||
| 2790 | return false; executed 12 times by 1 test: return false;Executed by:
| 12 | ||||||||||||||||||
| 2791 | - | |||||||||||||||||||
| 2792 | return compare_helper(data(), size(), other, Qt::CaseSensitive) < 0; executed 2315 times by 19 tests: return compare_helper(data(), size(), other, Qt::CaseSensitive) < 0;Executed by:
| 2315 | ||||||||||||||||||
| 2793 | } | - | ||||||||||||||||||
| 2794 | - | |||||||||||||||||||
| 2795 | /*! \fn bool QString::operator<(const QByteArray &other) const | - | ||||||||||||||||||
| 2796 | - | |||||||||||||||||||
| 2797 | \overload operator<() | - | ||||||||||||||||||
| 2798 | - | |||||||||||||||||||
| 2799 | The \a other byte array is converted to a QString using the | - | ||||||||||||||||||
| 2800 | fromUtf8() function. If any NUL characters ('\\0') are embedded | - | ||||||||||||||||||
| 2801 | in the byte array, they will be included in the transformation. | - | ||||||||||||||||||
| 2802 | - | |||||||||||||||||||
| 2803 | You can disable this operator by defining \c | - | ||||||||||||||||||
| 2804 | QT_NO_CAST_FROM_ASCII when you compile your applications. This | - | ||||||||||||||||||
| 2805 | can be useful if you want to ensure that all user-visible strings | - | ||||||||||||||||||
| 2806 | go through QObject::tr(), for example. | - | ||||||||||||||||||
| 2807 | */ | - | ||||||||||||||||||
| 2808 | - | |||||||||||||||||||
| 2809 | /*! \fn bool QString::operator<(const char *other) const | - | ||||||||||||||||||
| 2810 | - | |||||||||||||||||||
| 2811 | Returns \c true if this string is lexically less than string \a other. | - | ||||||||||||||||||
| 2812 | Otherwise returns \c false. | - | ||||||||||||||||||
| 2813 | - | |||||||||||||||||||
| 2814 | \overload operator<() | - | ||||||||||||||||||
| 2815 | - | |||||||||||||||||||
| 2816 | The \a other const char pointer is converted to a QString using | - | ||||||||||||||||||
| 2817 | the fromUtf8() function. | - | ||||||||||||||||||
| 2818 | - | |||||||||||||||||||
| 2819 | You can disable this operator by defining \c | - | ||||||||||||||||||
| 2820 | QT_NO_CAST_FROM_ASCII when you compile your applications. This | - | ||||||||||||||||||
| 2821 | can be useful if you want to ensure that all user-visible strings | - | ||||||||||||||||||
| 2822 | go through QObject::tr(), for example. | - | ||||||||||||||||||
| 2823 | */ | - | ||||||||||||||||||
| 2824 | - | |||||||||||||||||||
| 2825 | /*! \fn bool operator<=(const QString &s1, const QString &s2) | - | ||||||||||||||||||
| 2826 | - | |||||||||||||||||||
| 2827 | \relates QString | - | ||||||||||||||||||
| 2828 | - | |||||||||||||||||||
| 2829 | Returns \c true if string \a s1 is lexically less than or equal to | - | ||||||||||||||||||
| 2830 | string \a s2; otherwise returns \c false. | - | ||||||||||||||||||
| 2831 | - | |||||||||||||||||||
| 2832 | The comparison is based exclusively on the numeric Unicode values | - | ||||||||||||||||||
| 2833 | of the characters and is very fast, but is not what a human would | - | ||||||||||||||||||
| 2834 | expect. Consider sorting user-interface strings with | - | ||||||||||||||||||
| 2835 | localeAwareCompare(). | - | ||||||||||||||||||
| 2836 | */ | - | ||||||||||||||||||
| 2837 | - | |||||||||||||||||||
| 2838 | /*! \fn bool QString::operator<=(QLatin1String other) const | - | ||||||||||||||||||
| 2839 | - | |||||||||||||||||||
| 2840 | Returns \c true if this string is lexically less than or equal to | - | ||||||||||||||||||
| 2841 | parameter string \a other. Otherwise returns \c false. | - | ||||||||||||||||||
| 2842 | - | |||||||||||||||||||
| 2843 | \overload operator<=() | - | ||||||||||||||||||
| 2844 | */ | - | ||||||||||||||||||
| 2845 | - | |||||||||||||||||||
| 2846 | /*! \fn bool QString::operator<=(const QByteArray &other) const | - | ||||||||||||||||||
| 2847 | - | |||||||||||||||||||
| 2848 | \overload operator<=() | - | ||||||||||||||||||
| 2849 | - | |||||||||||||||||||
| 2850 | The \a other byte array is converted to a QString using the | - | ||||||||||||||||||
| 2851 | fromUtf8() function. If any NUL characters ('\\0') are embedded | - | ||||||||||||||||||
| 2852 | in the byte array, they will be included in the transformation. | - | ||||||||||||||||||
| 2853 | - | |||||||||||||||||||
| 2854 | You can disable this operator by defining \c | - | ||||||||||||||||||
| 2855 | QT_NO_CAST_FROM_ASCII when you compile your applications. This | - | ||||||||||||||||||
| 2856 | can be useful if you want to ensure that all user-visible strings | - | ||||||||||||||||||
| 2857 | go through QObject::tr(), for example. | - | ||||||||||||||||||
| 2858 | */ | - | ||||||||||||||||||
| 2859 | - | |||||||||||||||||||
| 2860 | /*! \fn bool QString::operator<=(const char *other) const | - | ||||||||||||||||||
| 2861 | - | |||||||||||||||||||
| 2862 | \overload operator<=() | - | ||||||||||||||||||
| 2863 | - | |||||||||||||||||||
| 2864 | The \a other const char pointer is converted to a QString using | - | ||||||||||||||||||
| 2865 | the fromUtf8() function. | - | ||||||||||||||||||
| 2866 | - | |||||||||||||||||||
| 2867 | You can disable this operator by defining \c | - | ||||||||||||||||||
| 2868 | QT_NO_CAST_FROM_ASCII when you compile your applications. This | - | ||||||||||||||||||
| 2869 | can be useful if you want to ensure that all user-visible strings | - | ||||||||||||||||||
| 2870 | go through QObject::tr(), for example. | - | ||||||||||||||||||
| 2871 | */ | - | ||||||||||||||||||
| 2872 | - | |||||||||||||||||||
| 2873 | /*! \fn bool operator>(const QString &s1, const QString &s2) | - | ||||||||||||||||||
| 2874 | \relates QString | - | ||||||||||||||||||
| 2875 | - | |||||||||||||||||||
| 2876 | Returns \c true if string \a s1 is lexically greater than string \a s2; | - | ||||||||||||||||||
| 2877 | otherwise returns \c false. | - | ||||||||||||||||||
| 2878 | - | |||||||||||||||||||
| 2879 | The comparison is based exclusively on the numeric Unicode values | - | ||||||||||||||||||
| 2880 | of the characters and is very fast, but is not what a human would | - | ||||||||||||||||||
| 2881 | expect. Consider sorting user-interface strings with | - | ||||||||||||||||||
| 2882 | localeAwareCompare(). | - | ||||||||||||||||||
| 2883 | */ | - | ||||||||||||||||||
| 2884 | - | |||||||||||||||||||
| 2885 | /*! | - | ||||||||||||||||||
| 2886 | \overload operator>() | - | ||||||||||||||||||
| 2887 | - | |||||||||||||||||||
| 2888 | Returns \c true if this string is lexically greater than the parameter | - | ||||||||||||||||||
| 2889 | string \a other; otherwise returns \c false. | - | ||||||||||||||||||
| 2890 | */ | - | ||||||||||||||||||
| 2891 | bool QString::operator>(QLatin1String other) const | - | ||||||||||||||||||
| 2892 | { | - | ||||||||||||||||||
| 2893 | const uchar *c = (const uchar *) other.latin1(); | - | ||||||||||||||||||
| 2894 | if (!c || *c == '\0')
| 5-232374 | ||||||||||||||||||
| 2895 | return !isEmpty(); executed 12 times by 1 test: return !isEmpty();Executed by:
| 12 | ||||||||||||||||||
| 2896 | - | |||||||||||||||||||
| 2897 | return compare_helper(data(), size(), other, Qt::CaseSensitive) > 0; executed 232367 times by 129 tests: return compare_helper(data(), size(), other, Qt::CaseSensitive) > 0;Executed by:
| 232367 | ||||||||||||||||||
| 2898 | } | - | ||||||||||||||||||
| 2899 | - | |||||||||||||||||||
| 2900 | /*! \fn bool QString::operator>(const QByteArray &other) const | - | ||||||||||||||||||
| 2901 | - | |||||||||||||||||||
| 2902 | \overload operator>() | - | ||||||||||||||||||
| 2903 | - | |||||||||||||||||||
| 2904 | The \a other byte array is converted to a QString using the | - | ||||||||||||||||||
| 2905 | fromUtf8() function. If any NUL characters ('\\0') are embedded | - | ||||||||||||||||||
| 2906 | in the byte array, they will be included in the transformation. | - | ||||||||||||||||||
| 2907 | - | |||||||||||||||||||
| 2908 | You can disable this operator by defining \c | - | ||||||||||||||||||
| 2909 | QT_NO_CAST_FROM_ASCII when you compile your applications. This | - | ||||||||||||||||||
| 2910 | can be useful if you want to ensure that all user-visible strings | - | ||||||||||||||||||
| 2911 | go through QObject::tr(), for example. | - | ||||||||||||||||||
| 2912 | */ | - | ||||||||||||||||||
| 2913 | - | |||||||||||||||||||
| 2914 | /*! \fn bool QString::operator>(const char *other) const | - | ||||||||||||||||||
| 2915 | - | |||||||||||||||||||
| 2916 | \overload operator>() | - | ||||||||||||||||||
| 2917 | - | |||||||||||||||||||
| 2918 | The \a other const char pointer is converted to a QString using | - | ||||||||||||||||||
| 2919 | the fromUtf8() function. | - | ||||||||||||||||||
| 2920 | - | |||||||||||||||||||
| 2921 | You can disable this operator by defining \c QT_NO_CAST_FROM_ASCII | - | ||||||||||||||||||
| 2922 | when you compile your applications. This can be useful if you want | - | ||||||||||||||||||
| 2923 | to ensure that all user-visible strings go through QObject::tr(), | - | ||||||||||||||||||
| 2924 | for example. | - | ||||||||||||||||||
| 2925 | */ | - | ||||||||||||||||||
| 2926 | - | |||||||||||||||||||
| 2927 | /*! \fn bool operator>=(const QString &s1, const QString &s2) | - | ||||||||||||||||||
| 2928 | \relates QString | - | ||||||||||||||||||
| 2929 | - | |||||||||||||||||||
| 2930 | Returns \c true if string \a s1 is lexically greater than or equal to | - | ||||||||||||||||||
| 2931 | string \a s2; otherwise returns \c false. | - | ||||||||||||||||||
| 2932 | - | |||||||||||||||||||
| 2933 | The comparison is based exclusively on the numeric Unicode values | - | ||||||||||||||||||
| 2934 | of the characters and is very fast, but is not what a human would | - | ||||||||||||||||||
| 2935 | expect. Consider sorting user-interface strings with | - | ||||||||||||||||||
| 2936 | localeAwareCompare(). | - | ||||||||||||||||||
| 2937 | */ | - | ||||||||||||||||||
| 2938 | - | |||||||||||||||||||
| 2939 | /*! \fn bool QString::operator>=(QLatin1String other) const | - | ||||||||||||||||||
| 2940 | - | |||||||||||||||||||
| 2941 | Returns \c true if this string is lexically greater than or equal to parameter | - | ||||||||||||||||||
| 2942 | string \a other. Otherwise returns \c false. | - | ||||||||||||||||||
| 2943 | - | |||||||||||||||||||
| 2944 | \overload operator>=() | - | ||||||||||||||||||
| 2945 | */ | - | ||||||||||||||||||
| 2946 | - | |||||||||||||||||||
| 2947 | /*! \fn bool QString::operator>=(const QByteArray &other) const | - | ||||||||||||||||||
| 2948 | - | |||||||||||||||||||
| 2949 | \overload operator>=() | - | ||||||||||||||||||
| 2950 | - | |||||||||||||||||||
| 2951 | The \a other byte array is converted to a QString using the | - | ||||||||||||||||||
| 2952 | fromUtf8() function. If any NUL characters ('\\0') are embedded in | - | ||||||||||||||||||
| 2953 | the byte array, they will be included in the transformation. | - | ||||||||||||||||||
| 2954 | - | |||||||||||||||||||
| 2955 | You can disable this operator by defining \c QT_NO_CAST_FROM_ASCII | - | ||||||||||||||||||
| 2956 | when you compile your applications. This can be useful if you want | - | ||||||||||||||||||
| 2957 | to ensure that all user-visible strings go through QObject::tr(), | - | ||||||||||||||||||
| 2958 | for example. | - | ||||||||||||||||||
| 2959 | */ | - | ||||||||||||||||||
| 2960 | - | |||||||||||||||||||
| 2961 | /*! \fn bool QString::operator>=(const char *other) const | - | ||||||||||||||||||
| 2962 | - | |||||||||||||||||||
| 2963 | \overload operator>=() | - | ||||||||||||||||||
| 2964 | - | |||||||||||||||||||
| 2965 | The \a other const char pointer is converted to a QString using | - | ||||||||||||||||||
| 2966 | the fromUtf8() function. | - | ||||||||||||||||||
| 2967 | - | |||||||||||||||||||
| 2968 | You can disable this operator by defining \c QT_NO_CAST_FROM_ASCII | - | ||||||||||||||||||
| 2969 | when you compile your applications. This can be useful if you want | - | ||||||||||||||||||
| 2970 | to ensure that all user-visible strings go through QObject::tr(), | - | ||||||||||||||||||
| 2971 | for example. | - | ||||||||||||||||||
| 2972 | */ | - | ||||||||||||||||||
| 2973 | - | |||||||||||||||||||
| 2974 | /*! \fn bool operator!=(const QString &s1, const QString &s2) | - | ||||||||||||||||||
| 2975 | \relates QString | - | ||||||||||||||||||
| 2976 | - | |||||||||||||||||||
| 2977 | Returns \c true if string \a s1 is not equal to string \a s2; | - | ||||||||||||||||||
| 2978 | otherwise returns \c false. | - | ||||||||||||||||||
| 2979 | - | |||||||||||||||||||
| 2980 | The comparison is based exclusively on the numeric Unicode values | - | ||||||||||||||||||
| 2981 | of the characters and is very fast, but is not what a human would | - | ||||||||||||||||||
| 2982 | expect. Consider sorting user-interface strings with | - | ||||||||||||||||||
| 2983 | localeAwareCompare(). | - | ||||||||||||||||||
| 2984 | */ | - | ||||||||||||||||||
| 2985 | - | |||||||||||||||||||
| 2986 | /*! \fn bool QString::operator!=(QLatin1String other) const | - | ||||||||||||||||||
| 2987 | - | |||||||||||||||||||
| 2988 | Returns \c true if this string is not equal to parameter string \a other. | - | ||||||||||||||||||
| 2989 | Otherwise returns \c false. | - | ||||||||||||||||||
| 2990 | - | |||||||||||||||||||
| 2991 | \overload operator!=() | - | ||||||||||||||||||
| 2992 | */ | - | ||||||||||||||||||
| 2993 | - | |||||||||||||||||||
| 2994 | /*! \fn bool QString::operator!=(const QByteArray &other) const | - | ||||||||||||||||||
| 2995 | - | |||||||||||||||||||
| 2996 | \overload operator!=() | - | ||||||||||||||||||
| 2997 | - | |||||||||||||||||||
| 2998 | The \a other byte array is converted to a QString using the | - | ||||||||||||||||||
| 2999 | fromUtf8() function. If any NUL characters ('\\0') are embedded | - | ||||||||||||||||||
| 3000 | in the byte array, they will be included in the transformation. | - | ||||||||||||||||||
| 3001 | - | |||||||||||||||||||
| 3002 | You can disable this operator by defining \c QT_NO_CAST_FROM_ASCII | - | ||||||||||||||||||
| 3003 | when you compile your applications. This can be useful if you want | - | ||||||||||||||||||
| 3004 | to ensure that all user-visible strings go through QObject::tr(), | - | ||||||||||||||||||
| 3005 | for example. | - | ||||||||||||||||||
| 3006 | */ | - | ||||||||||||||||||
| 3007 | - | |||||||||||||||||||
| 3008 | /*! \fn bool QString::operator!=(const char *other) const | - | ||||||||||||||||||
| 3009 | - | |||||||||||||||||||
| 3010 | \overload operator!=() | - | ||||||||||||||||||
| 3011 | - | |||||||||||||||||||
| 3012 | The \a other const char pointer is converted to a QString using | - | ||||||||||||||||||
| 3013 | the fromUtf8() function. | - | ||||||||||||||||||
| 3014 | - | |||||||||||||||||||
| 3015 | You can disable this operator by defining \c | - | ||||||||||||||||||
| 3016 | QT_NO_CAST_FROM_ASCII when you compile your applications. This | - | ||||||||||||||||||
| 3017 | can be useful if you want to ensure that all user-visible strings | - | ||||||||||||||||||
| 3018 | go through QObject::tr(), for example. | - | ||||||||||||||||||
| 3019 | */ | - | ||||||||||||||||||
| 3020 | - | |||||||||||||||||||
| 3021 | /*! | - | ||||||||||||||||||
| 3022 | Returns the index position of the first occurrence of the string \a | - | ||||||||||||||||||
| 3023 | str in this string, searching forward from index position \a | - | ||||||||||||||||||
| 3024 | from. Returns -1 if \a str is not found. | - | ||||||||||||||||||
| 3025 | - | |||||||||||||||||||
| 3026 | If \a cs is Qt::CaseSensitive (default), the search is case | - | ||||||||||||||||||
| 3027 | sensitive; otherwise the search is case insensitive. | - | ||||||||||||||||||
| 3028 | - | |||||||||||||||||||
| 3029 | Example: | - | ||||||||||||||||||
| 3030 | - | |||||||||||||||||||
| 3031 | \snippet qstring/main.cpp 24 | - | ||||||||||||||||||
| 3032 | - | |||||||||||||||||||
| 3033 | If \a from is -1, the search starts at the last character; if it is | - | ||||||||||||||||||
| 3034 | -2, at the next to last character and so on. | - | ||||||||||||||||||
| 3035 | - | |||||||||||||||||||
| 3036 | \sa lastIndexOf(), contains(), count() | - | ||||||||||||||||||
| 3037 | */ | - | ||||||||||||||||||
| 3038 | int QString::indexOf(const QString &str, int from, Qt::CaseSensitivity cs) const | - | ||||||||||||||||||
| 3039 | { | - | ||||||||||||||||||
| 3040 | return qFindString(unicode(), length(), from, str.unicode(), str.length(), cs); executed 902450 times by 89 tests: return qFindString(unicode(), length(), from, str.unicode(), str.length(), cs);Executed by:
| 902450 | ||||||||||||||||||
| 3041 | } | - | ||||||||||||||||||
| 3042 | - | |||||||||||||||||||
| 3043 | /*! | - | ||||||||||||||||||
| 3044 | \since 4.5 | - | ||||||||||||||||||
| 3045 | Returns the index position of the first occurrence of the string \a | - | ||||||||||||||||||
| 3046 | str in this string, searching forward from index position \a | - | ||||||||||||||||||
| 3047 | from. Returns -1 if \a str is not found. | - | ||||||||||||||||||
| 3048 | - | |||||||||||||||||||
| 3049 | If \a cs is Qt::CaseSensitive (default), the search is case | - | ||||||||||||||||||
| 3050 | sensitive; otherwise the search is case insensitive. | - | ||||||||||||||||||
| 3051 | - | |||||||||||||||||||
| 3052 | Example: | - | ||||||||||||||||||
| 3053 | - | |||||||||||||||||||
| 3054 | \snippet qstring/main.cpp 24 | - | ||||||||||||||||||
| 3055 | - | |||||||||||||||||||
| 3056 | If \a from is -1, the search starts at the last character; if it is | - | ||||||||||||||||||
| 3057 | -2, at the next to last character and so on. | - | ||||||||||||||||||
| 3058 | - | |||||||||||||||||||
| 3059 | \sa lastIndexOf(), contains(), count() | - | ||||||||||||||||||
| 3060 | */ | - | ||||||||||||||||||
| 3061 | - | |||||||||||||||||||
| 3062 | int QString::indexOf(QLatin1String str, int from, Qt::CaseSensitivity cs) const | - | ||||||||||||||||||
| 3063 | { | - | ||||||||||||||||||
| 3064 | return qt_find_latin1_string(unicode(), size(), str, from, cs); executed 14855 times by 185 tests: return qt_find_latin1_string(unicode(), size(), str, from, cs);Executed by:
| 14855 | ||||||||||||||||||
| 3065 | } | - | ||||||||||||||||||
| 3066 | - | |||||||||||||||||||
| 3067 | int qFindString( | - | ||||||||||||||||||
| 3068 | const QChar *haystack0, int haystackLen, int from, | - | ||||||||||||||||||
| 3069 | const QChar *needle0, int needleLen, Qt::CaseSensitivity cs) | - | ||||||||||||||||||
| 3070 | { | - | ||||||||||||||||||
| 3071 | const int l = haystackLen; | - | ||||||||||||||||||
| 3072 | const int sl = needleLen; | - | ||||||||||||||||||
| 3073 | if (from < 0)
| 0-1478944 | ||||||||||||||||||
| 3074 | from += l; never executed: from += l; | 0 | ||||||||||||||||||
| 3075 | if (uint(sl + from) > (uint)l)
| 47215-1431729 | ||||||||||||||||||
| 3076 | return -1; executed 47215 times by 89 tests: return -1;Executed by:
| 47215 | ||||||||||||||||||
| 3077 | if (!sl)
| 392-1431337 | ||||||||||||||||||
| 3078 | return from; executed 392 times by 12 tests: return from;Executed by:
| 392 | ||||||||||||||||||
| 3079 | if (!l)
| 0-1431337 | ||||||||||||||||||
| 3080 | return -1; never executed: return -1; | 0 | ||||||||||||||||||
| 3081 | - | |||||||||||||||||||
| 3082 | if (sl == 1)
| 526085-905252 | ||||||||||||||||||
| 3083 | return findChar(haystack0, haystackLen, needle0[0], from, cs); executed 526085 times by 271 tests: return findChar(haystack0, haystackLen, needle0[0], from, cs);Executed by:
| 526085 | ||||||||||||||||||
| 3084 | - | |||||||||||||||||||
| 3085 | /* | - | ||||||||||||||||||
| 3086 | We use the Boyer-Moore algorithm in cases where the overhead | - | ||||||||||||||||||
| 3087 | for the skip table should pay off, otherwise we use a simple | - | ||||||||||||||||||
| 3088 | hash function. | - | ||||||||||||||||||
| 3089 | */ | - | ||||||||||||||||||
| 3090 | if (l > 500 && sl > 5)
| 19-905057 | ||||||||||||||||||
| 3091 | return qFindStringBoyerMoore(haystack0, haystackLen, from, executed 176 times by 12 tests: return qFindStringBoyerMoore(haystack0, haystackLen, from, needle0, needleLen, cs);Executed by:
| 176 | ||||||||||||||||||
| 3092 | needle0, needleLen, cs); executed 176 times by 12 tests: return qFindStringBoyerMoore(haystack0, haystackLen, from, needle0, needleLen, cs);Executed by:
| 176 | ||||||||||||||||||
| 3093 | - | |||||||||||||||||||
| 3094 | /* | - | ||||||||||||||||||
| 3095 | We use some hashing for efficiency's sake. Instead of | - | ||||||||||||||||||
| 3096 | comparing strings, we compare the hash value of str with that | - | ||||||||||||||||||
| 3097 | of a part of this QString. Only if that matches, we call | - | ||||||||||||||||||
| 3098 | ucstrncmp() or ucstrnicmp(). | - | ||||||||||||||||||
| 3099 | */ | - | ||||||||||||||||||
| 3100 | const ushort *needle = (const ushort *)needle0; | - | ||||||||||||||||||
| 3101 | const ushort *haystack = (const ushort *)haystack0 + from; | - | ||||||||||||||||||
| 3102 | const ushort *end = (const ushort *)haystack0 + (l-sl); | - | ||||||||||||||||||
| 3103 | const uint sl_minus_1 = sl - 1; | - | ||||||||||||||||||
| 3104 | uint hashNeedle = 0, hashHaystack = 0; | - | ||||||||||||||||||
| 3105 | int idx; | - | ||||||||||||||||||
| 3106 | - | |||||||||||||||||||
| 3107 | if (cs == Qt::CaseSensitive) {
| 1319-903757 | ||||||||||||||||||
| 3108 | for (idx = 0; idx < sl; ++idx) {
| 903757-4496626 | ||||||||||||||||||
| 3109 | hashNeedle = ((hashNeedle<<1) + needle[idx]); | - | ||||||||||||||||||
| 3110 | hashHaystack = ((hashHaystack<<1) + haystack[idx]); | - | ||||||||||||||||||
| 3111 | } executed 4496626 times by 206 tests: end of blockExecuted by:
| 4496626 | ||||||||||||||||||
| 3112 | hashHaystack -= haystack[sl_minus_1]; | - | ||||||||||||||||||
| 3113 | - | |||||||||||||||||||
| 3114 | while (haystack <= end) {
| 612526-5110418 | ||||||||||||||||||
| 3115 | hashHaystack += haystack[sl_minus_1]; | - | ||||||||||||||||||
| 3116 | if (hashHaystack == hashNeedle
| 291391-4819027 | ||||||||||||||||||
| 3117 | && ucstrncmp((const QChar *)needle, (const QChar *)haystack, sl) == 0)
| 160-291231 | ||||||||||||||||||
| 3118 | return haystack - (const ushort *)haystack0; executed 291231 times by 67 tests: return haystack - (const ushort *)haystack0;Executed by:
| 291231 | ||||||||||||||||||
| 3119 | - | |||||||||||||||||||
| 3120 | REHASH(*haystack); executed 4817693 times by 205 tests: hashHaystack -= uint(*haystack) << sl_minus_1;Executed by:
| 1494-4817693 | ||||||||||||||||||
| 3121 | ++haystack; | - | ||||||||||||||||||
| 3122 | } executed 4819187 times by 205 tests: end of blockExecuted by:
| 4819187 | ||||||||||||||||||
| 3123 | } else { executed 612526 times by 193 tests: end of blockExecuted by:
| 612526 | ||||||||||||||||||
| 3124 | const ushort *haystack_start = (const ushort *)haystack0; | - | ||||||||||||||||||
| 3125 | for (idx = 0; idx < sl; ++idx) {
| 1319-4382 | ||||||||||||||||||
| 3126 | hashNeedle = (hashNeedle<<1) + foldCase(needle + idx, needle); | - | ||||||||||||||||||
| 3127 | hashHaystack = (hashHaystack<<1) + foldCase(haystack + idx, haystack_start); | - | ||||||||||||||||||
| 3128 | } executed 4382 times by 19 tests: end of blockExecuted by:
| 4382 | ||||||||||||||||||
| 3129 | hashHaystack -= foldCase(haystack + sl_minus_1, haystack_start); | - | ||||||||||||||||||
| 3130 | - | |||||||||||||||||||
| 3131 | while (haystack <= end) {
| 220-3269 | ||||||||||||||||||
| 3132 | hashHaystack += foldCase(haystack + sl_minus_1, haystack_start); | - | ||||||||||||||||||
| 3133 | if (hashHaystack == hashNeedle && ucstrnicmp(needle, haystack, sl) == 0)
| 3-2167 | ||||||||||||||||||
| 3134 | return haystack - (const ushort *)haystack0; executed 1099 times by 13 tests: return haystack - (const ushort *)haystack0;Executed by:
| 1099 | ||||||||||||||||||
| 3135 | - | |||||||||||||||||||
| 3136 | REHASH(foldCase(haystack, haystack_start)); executed 1985 times by 18 tests: hashHaystack -= uint(foldCase(haystack, haystack_start)) << sl_minus_1;Executed by:
| 185-1985 | ||||||||||||||||||
| 3137 | ++haystack; | - | ||||||||||||||||||
| 3138 | } executed 2170 times by 18 tests: end of blockExecuted by:
| 2170 | ||||||||||||||||||
| 3139 | } executed 220 times by 18 tests: end of blockExecuted by:
| 220 | ||||||||||||||||||
| 3140 | return -1; executed 612746 times by 198 tests: return -1;Executed by:
| 612746 | ||||||||||||||||||
| 3141 | } | - | ||||||||||||||||||
| 3142 | - | |||||||||||||||||||
| 3143 | /*! | - | ||||||||||||||||||
| 3144 | \overload indexOf() | - | ||||||||||||||||||
| 3145 | - | |||||||||||||||||||
| 3146 | Returns the index position of the first occurrence of the | - | ||||||||||||||||||
| 3147 | character \a ch in the string, searching forward from index | - | ||||||||||||||||||
| 3148 | position \a from. Returns -1 if \a ch could not be found. | - | ||||||||||||||||||
| 3149 | */ | - | ||||||||||||||||||
| 3150 | int QString::indexOf(QChar ch, int from, Qt::CaseSensitivity cs) const | - | ||||||||||||||||||
| 3151 | { | - | ||||||||||||||||||
| 3152 | return findChar(unicode(), length(), ch, from, cs); executed 810642 times by 282 tests: return findChar(unicode(), length(), ch, from, cs);Executed by:
| 810642 | ||||||||||||||||||
| 3153 | } | - | ||||||||||||||||||
| 3154 | - | |||||||||||||||||||
| 3155 | /*! | - | ||||||||||||||||||
| 3156 | \since 4.8 | - | ||||||||||||||||||
| 3157 | - | |||||||||||||||||||
| 3158 | \overload indexOf() | - | ||||||||||||||||||
| 3159 | - | |||||||||||||||||||
| 3160 | Returns the index position of the first occurrence of the string | - | ||||||||||||||||||
| 3161 | reference \a str in this string, searching forward from index | - | ||||||||||||||||||
| 3162 | position \a from. Returns -1 if \a str is not found. | - | ||||||||||||||||||
| 3163 | - | |||||||||||||||||||
| 3164 | If \a cs is Qt::CaseSensitive (default), the search is case | - | ||||||||||||||||||
| 3165 | sensitive; otherwise the search is case insensitive. | - | ||||||||||||||||||
| 3166 | */ | - | ||||||||||||||||||
| 3167 | int QString::indexOf(const QStringRef &str, int from, Qt::CaseSensitivity cs) const | - | ||||||||||||||||||
| 3168 | { | - | ||||||||||||||||||
| 3169 | return qFindString(unicode(), length(), from, str.unicode(), str.length(), cs); executed 392 times by 2 tests: return qFindString(unicode(), length(), from, str.unicode(), str.length(), cs);Executed by:
| 392 | ||||||||||||||||||
| 3170 | } | - | ||||||||||||||||||
| 3171 | - | |||||||||||||||||||
| 3172 | static int lastIndexOfHelper(const ushort *haystack, int from, const ushort *needle, int sl, Qt::CaseSensitivity cs) | - | ||||||||||||||||||
| 3173 | { | - | ||||||||||||||||||
| 3174 | /* | - | ||||||||||||||||||
| 3175 | See indexOf() for explanations. | - | ||||||||||||||||||
| 3176 | */ | - | ||||||||||||||||||
| 3177 | - | |||||||||||||||||||
| 3178 | const ushort *end = haystack; | - | ||||||||||||||||||
| 3179 | haystack += from; | - | ||||||||||||||||||
| 3180 | const uint sl_minus_1 = sl - 1; | - | ||||||||||||||||||
| 3181 | const ushort *n = needle+sl_minus_1; | - | ||||||||||||||||||
| 3182 | const ushort *h = haystack+sl_minus_1; | - | ||||||||||||||||||
| 3183 | uint hashNeedle = 0, hashHaystack = 0; | - | ||||||||||||||||||
| 3184 | int idx; | - | ||||||||||||||||||
| 3185 | - | |||||||||||||||||||
| 3186 | if (cs == Qt::CaseSensitive) {
| 85-103 | ||||||||||||||||||
| 3187 | for (idx = 0; idx < sl; ++idx) {
| 85-1125 | ||||||||||||||||||
| 3188 | hashNeedle = ((hashNeedle<<1) + *(n-idx)); | - | ||||||||||||||||||
| 3189 | hashHaystack = ((hashHaystack<<1) + *(h-idx)); | - | ||||||||||||||||||
| 3190 | } executed 1125 times by 8 tests: end of blockExecuted by:
| 1125 | ||||||||||||||||||
| 3191 | hashHaystack -= *haystack; | - | ||||||||||||||||||
| 3192 | - | |||||||||||||||||||
| 3193 | while (haystack >= end) {
| 18-668 | ||||||||||||||||||
| 3194 | hashHaystack += *haystack; | - | ||||||||||||||||||
| 3195 | if (hashHaystack == hashNeedle
| 71-597 | ||||||||||||||||||
| 3196 | && ucstrncmp((const QChar *)needle, (const QChar *)haystack, sl) == 0)
| 4-67 | ||||||||||||||||||
| 3197 | return haystack - end; executed 67 times by 8 tests: return haystack - end;Executed by:
| 67 | ||||||||||||||||||
| 3198 | --haystack; | - | ||||||||||||||||||
| 3199 | REHASH(haystack[sl]); executed 465 times by 5 tests: hashHaystack -= uint(haystack[sl]) << sl_minus_1;Executed by:
| 136-465 | ||||||||||||||||||
| 3200 | } executed 601 times by 5 tests: end of blockExecuted by:
| 601 | ||||||||||||||||||
| 3201 | } else { executed 18 times by 4 tests: end of blockExecuted by:
| 18 | ||||||||||||||||||
| 3202 | for (idx = 0; idx < sl; ++idx) {
| 103-1106 | ||||||||||||||||||
| 3203 | hashNeedle = ((hashNeedle<<1) + foldCase(n-idx, needle)); | - | ||||||||||||||||||
| 3204 | hashHaystack = ((hashHaystack<<1) + foldCase(h-idx, end)); | - | ||||||||||||||||||
| 3205 | } executed 1106 times by 3 tests: end of blockExecuted by:
| 1106 | ||||||||||||||||||
| 3206 | hashHaystack -= foldCase(haystack, end); | - | ||||||||||||||||||
| 3207 | - | |||||||||||||||||||
| 3208 | while (haystack >= end) {
| 38-675 | ||||||||||||||||||
| 3209 | hashHaystack += foldCase(haystack, end); | - | ||||||||||||||||||
| 3210 | if (hashHaystack == hashNeedle && ucstrnicmp(needle, haystack, sl) == 0)
| 4-606 | ||||||||||||||||||
| 3211 | return haystack - end; executed 65 times by 3 tests: return haystack - end;Executed by:
| 65 | ||||||||||||||||||
| 3212 | --haystack; | - | ||||||||||||||||||
| 3213 | REHASH(foldCase(haystack + sl, end)); executed 474 times by 3 tests: hashHaystack -= uint(foldCase(haystack + sl, end)) << sl_minus_1;Executed by:
| 136-474 | ||||||||||||||||||
| 3214 | } executed 610 times by 3 tests: end of blockExecuted by:
| 610 | ||||||||||||||||||
| 3215 | } executed 38 times by 3 tests: end of blockExecuted by:
| 38 | ||||||||||||||||||
| 3216 | return -1; executed 56 times by 4 tests: return -1;Executed by:
| 56 | ||||||||||||||||||
| 3217 | } | - | ||||||||||||||||||
| 3218 | - | |||||||||||||||||||
| 3219 | /*! | - | ||||||||||||||||||
| 3220 | Returns the index position of the last occurrence of the string \a | - | ||||||||||||||||||
| 3221 | str in this string, searching backward from index position \a | - | ||||||||||||||||||
| 3222 | from. If \a from is -1 (default), the search starts at the last | - | ||||||||||||||||||
| 3223 | character; if \a from is -2, at the next to last character and so | - | ||||||||||||||||||
| 3224 | on. Returns -1 if \a str is not found. | - | ||||||||||||||||||
| 3225 | - | |||||||||||||||||||
| 3226 | If \a cs is Qt::CaseSensitive (default), the search is case | - | ||||||||||||||||||
| 3227 | sensitive; otherwise the search is case insensitive. | - | ||||||||||||||||||
| 3228 | - | |||||||||||||||||||
| 3229 | Example: | - | ||||||||||||||||||
| 3230 | - | |||||||||||||||||||
| 3231 | \snippet qstring/main.cpp 29 | - | ||||||||||||||||||
| 3232 | - | |||||||||||||||||||
| 3233 | \sa indexOf(), contains(), count() | - | ||||||||||||||||||
| 3234 | */ | - | ||||||||||||||||||
| 3235 | int QString::lastIndexOf(const QString &str, int from, Qt::CaseSensitivity cs) const | - | ||||||||||||||||||
| 3236 | { | - | ||||||||||||||||||
| 3237 | const int sl = str.d->size; | - | ||||||||||||||||||
| 3238 | if (sl == 1)
| 95-3232 | ||||||||||||||||||
| 3239 | return lastIndexOf(QChar(str.d->data()[0]), from, cs); executed 3232 times by 3 tests: return lastIndexOf(QChar(str.d->data()[0]), from, cs);Executed by:
| 3232 | ||||||||||||||||||
| 3240 | - | |||||||||||||||||||
| 3241 | const int l = d->size; | - | ||||||||||||||||||
| 3242 | if (from < 0)
| 31-64 | ||||||||||||||||||
| 3243 | from += l; executed 64 times by 5 tests: from += l;Executed by:
| 64 | ||||||||||||||||||
| 3244 | int delta = l-sl; | - | ||||||||||||||||||
| 3245 | if (from == l && sl == 0)
| 3-89 | ||||||||||||||||||
| 3246 | return from; executed 3 times by 1 test: return from;Executed by:
| 3 | ||||||||||||||||||
| 3247 | if (uint(from) >= uint(l) || delta < 0)
| 9-76 | ||||||||||||||||||
| 3248 | return -1; executed 25 times by 1 test: return -1;Executed by:
| 25 | ||||||||||||||||||
| 3249 | if (from > delta)
| 19-48 | ||||||||||||||||||
| 3250 | from = delta; executed 48 times by 5 tests: from = delta;Executed by:
| 48 | ||||||||||||||||||
| 3251 | - | |||||||||||||||||||
| 3252 | return lastIndexOfHelper(d->data(), from, str.d->data(), str.d->size, cs); executed 67 times by 5 tests: return lastIndexOfHelper(d->data(), from, str.d->data(), str.d->size, cs);Executed by:
| 67 | ||||||||||||||||||
| 3253 | } | - | ||||||||||||||||||
| 3254 | - | |||||||||||||||||||
| 3255 | /*! | - | ||||||||||||||||||
| 3256 | \since 4.5 | - | ||||||||||||||||||
| 3257 | \overload lastIndexOf() | - | ||||||||||||||||||
| 3258 | - | |||||||||||||||||||
| 3259 | Returns the index position of the last occurrence of the string \a | - | ||||||||||||||||||
| 3260 | str in this string, searching backward from index position \a | - | ||||||||||||||||||
| 3261 | from. If \a from is -1 (default), the search starts at the last | - | ||||||||||||||||||
| 3262 | character; if \a from is -2, at the next to last character and so | - | ||||||||||||||||||
| 3263 | on. Returns -1 if \a str is not found. | - | ||||||||||||||||||
| 3264 | - | |||||||||||||||||||
| 3265 | If \a cs is Qt::CaseSensitive (default), the search is case | - | ||||||||||||||||||
| 3266 | sensitive; otherwise the search is case insensitive. | - | ||||||||||||||||||
| 3267 | - | |||||||||||||||||||
| 3268 | Example: | - | ||||||||||||||||||
| 3269 | - | |||||||||||||||||||
| 3270 | \snippet qstring/main.cpp 29 | - | ||||||||||||||||||
| 3271 | - | |||||||||||||||||||
| 3272 | \sa indexOf(), contains(), count() | - | ||||||||||||||||||
| 3273 | */ | - | ||||||||||||||||||
| 3274 | int QString::lastIndexOf(QLatin1String str, int from, Qt::CaseSensitivity cs) const | - | ||||||||||||||||||
| 3275 | { | - | ||||||||||||||||||
| 3276 | const int sl = str.size(); | - | ||||||||||||||||||
| 3277 | if (sl == 1)
| 0-13 | ||||||||||||||||||
| 3278 | return lastIndexOf(QLatin1Char(str.latin1()[0]), from, cs); never executed: return lastIndexOf(QLatin1Char(str.latin1()[0]), from, cs); | 0 | ||||||||||||||||||
| 3279 | - | |||||||||||||||||||
| 3280 | const int l = d->size; | - | ||||||||||||||||||
| 3281 | if (from < 0)
| 0-13 | ||||||||||||||||||
| 3282 | from += l; never executed: from += l; | 0 | ||||||||||||||||||
| 3283 | int delta = l-sl; | - | ||||||||||||||||||
| 3284 | if (from == l && sl == 0)
| 0-13 | ||||||||||||||||||
| 3285 | return from; never executed: return from; | 0 | ||||||||||||||||||
| 3286 | if (uint(from) >= uint(l) || delta < 0)
| 0-13 | ||||||||||||||||||
| 3287 | return -1; never executed: return -1; | 0 | ||||||||||||||||||
| 3288 | if (from > delta)
| 0-13 | ||||||||||||||||||
| 3289 | from = delta; executed 13 times by 2 tests: from = delta;Executed by:
| 13 | ||||||||||||||||||
| 3290 | - | |||||||||||||||||||
| 3291 | QVarLengthArray<ushort> s(sl); | - | ||||||||||||||||||
| 3292 | qt_from_latin1(s.data(), str.latin1(), sl); | - | ||||||||||||||||||
| 3293 | - | |||||||||||||||||||
| 3294 | return lastIndexOfHelper(d->data(), from, s.data(), sl, cs); executed 13 times by 2 tests: return lastIndexOfHelper(d->data(), from, s.data(), sl, cs);Executed by:
| 13 | ||||||||||||||||||
| 3295 | } | - | ||||||||||||||||||
| 3296 | - | |||||||||||||||||||
| 3297 | /*! | - | ||||||||||||||||||
| 3298 | \overload lastIndexOf() | - | ||||||||||||||||||
| 3299 | - | |||||||||||||||||||
| 3300 | Returns the index position of the last occurrence of the character | - | ||||||||||||||||||
| 3301 | \a ch, searching backward from position \a from. | - | ||||||||||||||||||
| 3302 | */ | - | ||||||||||||||||||
| 3303 | int QString::lastIndexOf(QChar ch, int from, Qt::CaseSensitivity cs) const | - | ||||||||||||||||||
| 3304 | { | - | ||||||||||||||||||
| 3305 | return qt_last_index_of(unicode(), size(), ch, from, cs); executed 259457 times by 303 tests: return qt_last_index_of(unicode(), size(), ch, from, cs);Executed by:
| 259457 | ||||||||||||||||||
| 3306 | } | - | ||||||||||||||||||
| 3307 | - | |||||||||||||||||||
| 3308 | /*! | - | ||||||||||||||||||
| 3309 | \since 4.8 | - | ||||||||||||||||||
| 3310 | \overload lastIndexOf() | - | ||||||||||||||||||
| 3311 | - | |||||||||||||||||||
| 3312 | Returns the index position of the last occurrence of the string | - | ||||||||||||||||||
| 3313 | reference \a str in this string, searching backward from index | - | ||||||||||||||||||
| 3314 | position \a from. If \a from is -1 (default), the search starts at | - | ||||||||||||||||||
| 3315 | the last character; if \a from is -2, at the next to last character | - | ||||||||||||||||||
| 3316 | and so on. Returns -1 if \a str is not found. | - | ||||||||||||||||||
| 3317 | - | |||||||||||||||||||
| 3318 | If \a cs is Qt::CaseSensitive (default), the search is case | - | ||||||||||||||||||
| 3319 | sensitive; otherwise the search is case insensitive. | - | ||||||||||||||||||
| 3320 | - | |||||||||||||||||||
| 3321 | \sa indexOf(), contains(), count() | - | ||||||||||||||||||
| 3322 | */ | - | ||||||||||||||||||
| 3323 | int QString::lastIndexOf(const QStringRef &str, int from, Qt::CaseSensitivity cs) const | - | ||||||||||||||||||
| 3324 | { | - | ||||||||||||||||||
| 3325 | const int sl = str.size(); | - | ||||||||||||||||||
| 3326 | if (sl == 1)
| 62-86 | ||||||||||||||||||
| 3327 | return lastIndexOf(str.at(0), from, cs); executed 86 times by 2 tests: return lastIndexOf(str.at(0), from, cs);Executed by:
| 86 | ||||||||||||||||||
| 3328 | - | |||||||||||||||||||
| 3329 | const int l = d->size; | - | ||||||||||||||||||
| 3330 | if (from < 0)
| 14-48 | ||||||||||||||||||
| 3331 | from += l; executed 48 times by 2 tests: from += l;Executed by:
| 48 | ||||||||||||||||||
| 3332 | int delta = l - sl; | - | ||||||||||||||||||
| 3333 | if (from == l && sl == 0)
| 2-58 | ||||||||||||||||||
| 3334 | return from; executed 2 times by 2 tests: return from;Executed by:
| 2 | ||||||||||||||||||
| 3335 | if (uint(from) >= uint(l) || delta < 0)
| 8-48 | ||||||||||||||||||
| 3336 | return -1; executed 20 times by 2 tests: return -1;Executed by:
| 20 | ||||||||||||||||||
| 3337 | if (from > delta)
| 10-30 | ||||||||||||||||||
| 3338 | from = delta; executed 30 times by 2 tests: from = delta;Executed by:
| 30 | ||||||||||||||||||
| 3339 | - | |||||||||||||||||||
| 3340 | return lastIndexOfHelper(d->data(), from, reinterpret_cast<const ushort*>(str.unicode()), executed 40 times by 2 tests: return lastIndexOfHelper(d->data(), from, reinterpret_cast<const ushort*>(str.unicode()), str.size(), cs);Executed by:
| 40 | ||||||||||||||||||
| 3341 | str.size(), cs); executed 40 times by 2 tests: return lastIndexOfHelper(d->data(), from, reinterpret_cast<const ushort*>(str.unicode()), str.size(), cs);Executed by:
| 40 | ||||||||||||||||||
| 3342 | } | - | ||||||||||||||||||
| 3343 | - | |||||||||||||||||||
| 3344 | - | |||||||||||||||||||
| 3345 | #if !(defined(QT_NO_REGEXP) && defined(QT_NO_REGULAREXPRESSION)) | - | ||||||||||||||||||
| 3346 | struct QStringCapture | - | ||||||||||||||||||
| 3347 | { | - | ||||||||||||||||||
| 3348 | int pos; | - | ||||||||||||||||||
| 3349 | int len; | - | ||||||||||||||||||
| 3350 | int no; | - | ||||||||||||||||||
| 3351 | }; | - | ||||||||||||||||||
| 3352 | Q_DECLARE_TYPEINFO(QStringCapture, Q_PRIMITIVE_TYPE); | - | ||||||||||||||||||
| 3353 | #endif | - | ||||||||||||||||||
| 3354 | - | |||||||||||||||||||
| 3355 | #ifndef QT_NO_REGEXP | - | ||||||||||||||||||
| 3356 | - | |||||||||||||||||||
| 3357 | /*! | - | ||||||||||||||||||
| 3358 | \overload replace() | - | ||||||||||||||||||
| 3359 | - | |||||||||||||||||||
| 3360 | Replaces every occurrence of the regular expression \a rx in the | - | ||||||||||||||||||
| 3361 | string with \a after. Returns a reference to the string. For | - | ||||||||||||||||||
| 3362 | example: | - | ||||||||||||||||||
| 3363 | - | |||||||||||||||||||
| 3364 | \snippet qstring/main.cpp 42 | - | ||||||||||||||||||
| 3365 | - | |||||||||||||||||||
| 3366 | For regular expressions containing \l{capturing parentheses}, | - | ||||||||||||||||||
| 3367 | occurrences of \b{\\1}, \b{\\2}, ..., in \a after are replaced | - | ||||||||||||||||||
| 3368 | with \a{rx}.cap(1), cap(2), ... | - | ||||||||||||||||||
| 3369 | - | |||||||||||||||||||
| 3370 | \snippet qstring/main.cpp 43 | - | ||||||||||||||||||
| 3371 | - | |||||||||||||||||||
| 3372 | \sa indexOf(), lastIndexOf(), remove(), QRegExp::cap() | - | ||||||||||||||||||
| 3373 | */ | - | ||||||||||||||||||
| 3374 | QString& QString::replace(const QRegExp &rx, const QString &after) | - | ||||||||||||||||||
| 3375 | { | - | ||||||||||||||||||
| 3376 | QRegExp rx2(rx); | - | ||||||||||||||||||
| 3377 | - | |||||||||||||||||||
| 3378 | if (isEmpty() && rx2.indexIn(*this) == -1)
| 18-90586 | ||||||||||||||||||
| 3379 | return *this; executed 51961 times by 2 tests: return *this;Executed by:
| 51961 | ||||||||||||||||||
| 3380 | - | |||||||||||||||||||
| 3381 | reallocData(uint(d->size) + 1u); | - | ||||||||||||||||||
| 3382 | - | |||||||||||||||||||
| 3383 | int index = 0; | - | ||||||||||||||||||
| 3384 | int numCaptures = rx2.captureCount(); | - | ||||||||||||||||||
| 3385 | int al = after.length(); | - | ||||||||||||||||||
| 3386 | QRegExp::CaretMode caretMode = QRegExp::CaretAtZero; | - | ||||||||||||||||||
| 3387 | - | |||||||||||||||||||
| 3388 | if (numCaptures > 0) {
| 27-90577 | ||||||||||||||||||
| 3389 | const QChar *uc = after.unicode(); | - | ||||||||||||||||||
| 3390 | int numBackRefs = 0; | - | ||||||||||||||||||
| 3391 | - | |||||||||||||||||||
| 3392 | for (int i = 0; i < al - 1; i++) {
| 27-173 | ||||||||||||||||||
| 3393 | if (uc[i] == QLatin1Char('\\')) {
| 76-97 | ||||||||||||||||||
| 3394 | int no = uc[i + 1].digitValue(); | - | ||||||||||||||||||
| 3395 | if (no > 0 && no <= numCaptures)
| 2-68 | ||||||||||||||||||
| 3396 | numBackRefs++; executed 66 times by 3 tests: numBackRefs++;Executed by:
| 66 | ||||||||||||||||||
| 3397 | } executed 76 times by 3 tests: end of blockExecuted by:
| 76 | ||||||||||||||||||
| 3398 | } executed 173 times by 3 tests: end of blockExecuted by:
| 173 | ||||||||||||||||||
| 3399 | - | |||||||||||||||||||
| 3400 | /* | - | ||||||||||||||||||
| 3401 | This is the harder case where we have back-references. | - | ||||||||||||||||||
| 3402 | */ | - | ||||||||||||||||||
| 3403 | if (numBackRefs > 0) {
| 6-21 | ||||||||||||||||||
| 3404 | QVarLengthArray<QStringCapture, 16> captures(numBackRefs); | - | ||||||||||||||||||
| 3405 | int j = 0; | - | ||||||||||||||||||
| 3406 | - | |||||||||||||||||||
| 3407 | for (int i = 0; i < al - 1; i++) {
| 21-164 | ||||||||||||||||||
| 3408 | if (uc[i] == QLatin1Char('\\')) {
| 72-92 | ||||||||||||||||||
| 3409 | int no = uc[i + 1].digitValue(); | - | ||||||||||||||||||
| 3410 | if (no > 0 && no <= numCaptures) {
| 1-67 | ||||||||||||||||||
| 3411 | QStringCapture capture; | - | ||||||||||||||||||
| 3412 | capture.pos = i; | - | ||||||||||||||||||
| 3413 | capture.len = 2; | - | ||||||||||||||||||
| 3414 | - | |||||||||||||||||||
| 3415 | if (i < al - 2) {
| 10-56 | ||||||||||||||||||
| 3416 | int secondDigit = uc[i + 2].digitValue(); | - | ||||||||||||||||||
| 3417 | if (secondDigit != -1 && ((no * 10) + secondDigit) <= numCaptures) {
| 6-28 | ||||||||||||||||||
| 3418 | no = (no * 10) + secondDigit; | - | ||||||||||||||||||
| 3419 | ++capture.len; | - | ||||||||||||||||||
| 3420 | } executed 6 times by 1 test: end of blockExecuted by:
| 6 | ||||||||||||||||||
| 3421 | } executed 56 times by 3 tests: end of blockExecuted by:
| 56 | ||||||||||||||||||
| 3422 | - | |||||||||||||||||||
| 3423 | capture.no = no; | - | ||||||||||||||||||
| 3424 | captures[j++] = capture; | - | ||||||||||||||||||
| 3425 | } executed 66 times by 3 tests: end of blockExecuted by:
| 66 | ||||||||||||||||||
| 3426 | } executed 72 times by 3 tests: end of blockExecuted by:
| 72 | ||||||||||||||||||
| 3427 | } executed 164 times by 3 tests: end of blockExecuted by:
| 164 | ||||||||||||||||||
| 3428 | - | |||||||||||||||||||
| 3429 | while (index <= length()) {
| 0-46 | ||||||||||||||||||
| 3430 | index = rx2.indexIn(*this, index, caretMode); | - | ||||||||||||||||||
| 3431 | if (index == -1)
| 21-25 | ||||||||||||||||||
| 3432 | break; executed 21 times by 3 tests: break;Executed by:
| 21 | ||||||||||||||||||
| 3433 | - | |||||||||||||||||||
| 3434 | QString after2(after); | - | ||||||||||||||||||
| 3435 | for (j = numBackRefs - 1; j >= 0; j--) {
| 25-64 | ||||||||||||||||||
| 3436 | const QStringCapture &capture = captures[j]; | - | ||||||||||||||||||
| 3437 | after2.replace(capture.pos, capture.len, rx2.cap(capture.no)); | - | ||||||||||||||||||
| 3438 | } executed 64 times by 3 tests: end of blockExecuted by:
| 64 | ||||||||||||||||||
| 3439 | - | |||||||||||||||||||
| 3440 | replace(index, rx2.matchedLength(), after2); | - | ||||||||||||||||||
| 3441 | index += after2.length(); | - | ||||||||||||||||||
| 3442 | - | |||||||||||||||||||
| 3443 | // avoid infinite loop on 0-length matches (e.g., QRegExp("[a-z]*")) | - | ||||||||||||||||||
| 3444 | if (rx2.matchedLength() == 0)
| 0-25 | ||||||||||||||||||
| 3445 | ++index; never executed: ++index; | 0 | ||||||||||||||||||
| 3446 | - | |||||||||||||||||||
| 3447 | caretMode = QRegExp::CaretWontMatch; | - | ||||||||||||||||||
| 3448 | } executed 25 times by 3 tests: end of blockExecuted by:
| 25 | ||||||||||||||||||
| 3449 | return *this; executed 21 times by 3 tests: return *this;Executed by:
| 21 | ||||||||||||||||||
| 3450 | } | - | ||||||||||||||||||
| 3451 | } executed 6 times by 2 tests: end of blockExecuted by:
| 6 | ||||||||||||||||||
| 3452 | - | |||||||||||||||||||
| 3453 | /* | - | ||||||||||||||||||
| 3454 | This is the simple and optimized case where we don't have | - | ||||||||||||||||||
| 3455 | back-references. | - | ||||||||||||||||||
| 3456 | */ | - | ||||||||||||||||||
| 3457 | while (index != -1) {
| 3642-90583 | ||||||||||||||||||
| 3458 | struct { | - | ||||||||||||||||||
| 3459 | int pos; | - | ||||||||||||||||||
| 3460 | int length; | - | ||||||||||||||||||
| 3461 | } replacements[2048]; | - | ||||||||||||||||||
| 3462 | - | |||||||||||||||||||
| 3463 | int pos = 0; | - | ||||||||||||||||||
| 3464 | int adjust = 0; | - | ||||||||||||||||||
| 3465 | while (pos < 2047) {
| 0-99581 | ||||||||||||||||||
| 3466 | index = rx2.indexIn(*this, index, caretMode); | - | ||||||||||||||||||
| 3467 | if (index == -1)
| 8998-90583 | ||||||||||||||||||
| 3468 | break; executed 90583 times by 15 tests: break;Executed by:
| 90583 | ||||||||||||||||||
| 3469 | int ml = rx2.matchedLength(); | - | ||||||||||||||||||
| 3470 | replacements[pos].pos = index; | - | ||||||||||||||||||
| 3471 | replacements[pos++].length = ml; | - | ||||||||||||||||||
| 3472 | index += ml; | - | ||||||||||||||||||
| 3473 | adjust += al - ml; | - | ||||||||||||||||||
| 3474 | // avoid infinite loop | - | ||||||||||||||||||
| 3475 | if (!ml)
| 46-8952 | ||||||||||||||||||
| 3476 | index++; executed 46 times by 3 tests: index++;Executed by:
| 46 | ||||||||||||||||||
| 3477 | } executed 8998 times by 12 tests: end of blockExecuted by:
| 8998 | ||||||||||||||||||
| 3478 | if (!pos)
| 3642-86941 | ||||||||||||||||||
| 3479 | break; executed 86941 times by 9 tests: break;Executed by:
| 86941 | ||||||||||||||||||
| 3480 | replacements[pos].pos = d->size; | - | ||||||||||||||||||
| 3481 | int newlen = d->size + adjust; | - | ||||||||||||||||||
| 3482 | - | |||||||||||||||||||
| 3483 | // to continue searching at the right position after we did | - | ||||||||||||||||||
| 3484 | // the first round of replacements | - | ||||||||||||||||||
| 3485 | if (index != -1)
| 0-3642 | ||||||||||||||||||
| 3486 | index += adjust; never executed: index += adjust; | 0 | ||||||||||||||||||
| 3487 | QString newstring; | - | ||||||||||||||||||
| 3488 | newstring.reserve(newlen + 1); | - | ||||||||||||||||||
| 3489 | QChar *newuc = newstring.data(); | - | ||||||||||||||||||
| 3490 | QChar *uc = newuc; | - | ||||||||||||||||||
| 3491 | int copystart = 0; | - | ||||||||||||||||||
| 3492 | int i = 0; | - | ||||||||||||||||||
| 3493 | while (i < pos) {
| 3642-8998 | ||||||||||||||||||
| 3494 | int copyend = replacements[i].pos; | - | ||||||||||||||||||
| 3495 | int size = copyend - copystart; | - | ||||||||||||||||||
| 3496 | memcpy(uc, d->data() + copystart, size * sizeof(QChar)); | - | ||||||||||||||||||
| 3497 | uc += size; | - | ||||||||||||||||||
| 3498 | memcpy(uc, after.d->data(), al * sizeof(QChar)); | - | ||||||||||||||||||
| 3499 | uc += al; | - | ||||||||||||||||||
| 3500 | copystart = copyend + replacements[i].length; | - | ||||||||||||||||||
| 3501 | i++; | - | ||||||||||||||||||
| 3502 | } executed 8998 times by 12 tests: end of blockExecuted by:
| 8998 | ||||||||||||||||||
| 3503 | memcpy(uc, d->data() + copystart, (d->size - copystart) * sizeof(QChar)); | - | ||||||||||||||||||
| 3504 | newstring.resize(newlen); | - | ||||||||||||||||||
| 3505 | *this = newstring; | - | ||||||||||||||||||
| 3506 | caretMode = QRegExp::CaretWontMatch; | - | ||||||||||||||||||
| 3507 | } executed 3642 times by 12 tests: end of blockExecuted by:
| 3642 | ||||||||||||||||||
| 3508 | return *this; executed 90583 times by 15 tests: return *this;Executed by:
| 90583 | ||||||||||||||||||
| 3509 | } | - | ||||||||||||||||||
| 3510 | #endif | - | ||||||||||||||||||
| 3511 | - | |||||||||||||||||||
| 3512 | #ifndef QT_NO_REGULAREXPRESSION | - | ||||||||||||||||||
| 3513 | #ifndef QT_BOOTSTRAPPED | - | ||||||||||||||||||
| 3514 | /*! | - | ||||||||||||||||||
| 3515 | \overload replace() | - | ||||||||||||||||||
| 3516 | \since 5.0 | - | ||||||||||||||||||
| 3517 | - | |||||||||||||||||||
| 3518 | Replaces every occurrence of the regular expression \a re in the | - | ||||||||||||||||||
| 3519 | string with \a after. Returns a reference to the string. For | - | ||||||||||||||||||
| 3520 | example: | - | ||||||||||||||||||
| 3521 | - | |||||||||||||||||||
| 3522 | \snippet qstring/main.cpp 87 | - | ||||||||||||||||||
| 3523 | - | |||||||||||||||||||
| 3524 | For regular expressions containing capturing groups, | - | ||||||||||||||||||
| 3525 | occurrences of \b{\\1}, \b{\\2}, ..., in \a after are replaced | - | ||||||||||||||||||
| 3526 | with the string captured by the corresponding capturing group. | - | ||||||||||||||||||
| 3527 | - | |||||||||||||||||||
| 3528 | \snippet qstring/main.cpp 88 | - | ||||||||||||||||||
| 3529 | - | |||||||||||||||||||
| 3530 | \sa indexOf(), lastIndexOf(), remove(), QRegularExpression, QRegularExpressionMatch | - | ||||||||||||||||||
| 3531 | */ | - | ||||||||||||||||||
| 3532 | QString &QString::replace(const QRegularExpression &re, const QString &after) | - | ||||||||||||||||||
| 3533 | { | - | ||||||||||||||||||
| 3534 | if (!re.isValid()) {
| 2-153 | ||||||||||||||||||
| 3535 | qWarning("QString::replace: invalid QRegularExpression object"); | - | ||||||||||||||||||
| 3536 | return *this; executed 2 times by 1 test: return *this;Executed by:
| 2 | ||||||||||||||||||
| 3537 | } | - | ||||||||||||||||||
| 3538 | - | |||||||||||||||||||
| 3539 | const QString copy(*this); | - | ||||||||||||||||||
| 3540 | QRegularExpressionMatchIterator iterator = re.globalMatch(copy); | - | ||||||||||||||||||
| 3541 | if (!iterator.hasNext()) // no matches at all
| 12-141 | ||||||||||||||||||
| 3542 | return *this; executed 12 times by 2 tests: return *this;Executed by:
| 12 | ||||||||||||||||||
| 3543 | - | |||||||||||||||||||
| 3544 | reallocData(uint(d->size) + 1u); | - | ||||||||||||||||||
| 3545 | - | |||||||||||||||||||
| 3546 | int numCaptures = re.captureCount(); | - | ||||||||||||||||||
| 3547 | - | |||||||||||||||||||
| 3548 | // 1. build the backreferences vector, holding where the backreferences | - | ||||||||||||||||||
| 3549 | // are in the replacement string | - | ||||||||||||||||||
| 3550 | QVector<QStringCapture> backReferences; | - | ||||||||||||||||||
| 3551 | const int al = after.length(); | - | ||||||||||||||||||
| 3552 | const QChar *ac = after.unicode(); | - | ||||||||||||||||||
| 3553 | - | |||||||||||||||||||
| 3554 | for (int i = 0; i < al - 1; i++) {
| 138-141 | ||||||||||||||||||
| 3555 | if (ac[i] == QLatin1Char('\\')) {
| 55-83 | ||||||||||||||||||
| 3556 | int no = ac[i + 1].digitValue(); | - | ||||||||||||||||||
| 3557 | if (no > 0 && no <= numCaptures) {
| 3-51 | ||||||||||||||||||
| 3558 | QStringCapture backReference; | - | ||||||||||||||||||
| 3559 | backReference.pos = i; | - | ||||||||||||||||||
| 3560 | backReference.len = 2; | - | ||||||||||||||||||
| 3561 | - | |||||||||||||||||||
| 3562 | if (i < al - 2) {
| 5-43 | ||||||||||||||||||
| 3563 | int secondDigit = ac[i + 2].digitValue(); | - | ||||||||||||||||||
| 3564 | if (secondDigit != -1 && ((no * 10) + secondDigit) <= numCaptures) {
| 6-28 | ||||||||||||||||||
| 3565 | no = (no * 10) + secondDigit; | - | ||||||||||||||||||
| 3566 | ++backReference.len; | - | ||||||||||||||||||
| 3567 | } executed 6 times by 1 test: end of blockExecuted by:
| 6 | ||||||||||||||||||
| 3568 | } executed 43 times by 2 tests: end of blockExecuted by:
| 43 | ||||||||||||||||||
| 3569 | - | |||||||||||||||||||
| 3570 | backReference.no = no; | - | ||||||||||||||||||
| 3571 | backReferences.append(backReference); | - | ||||||||||||||||||
| 3572 | } executed 48 times by 2 tests: end of blockExecuted by:
| 48 | ||||||||||||||||||
| 3573 | } executed 55 times by 2 tests: end of blockExecuted by:
| 55 | ||||||||||||||||||
| 3574 | } executed 138 times by 2 tests: end of blockExecuted by:
| 138 | ||||||||||||||||||
| 3575 | - | |||||||||||||||||||
| 3576 | // 2. iterate on the matches. For every match, copy in chunks | - | ||||||||||||||||||
| 3577 | // - the part before the match | - | ||||||||||||||||||
| 3578 | // - the after string, with the proper replacements for the backreferences | - | ||||||||||||||||||
| 3579 | - | |||||||||||||||||||
| 3580 | int newLength = 0; // length of the new string, with all the replacements | - | ||||||||||||||||||
| 3581 | int lastEnd = 0; | - | ||||||||||||||||||
| 3582 | QVector<QStringRef> chunks; | - | ||||||||||||||||||
| 3583 | while (iterator.hasNext()) {
| 141-158 | ||||||||||||||||||
| 3584 | QRegularExpressionMatch match = iterator.next(); | - | ||||||||||||||||||
| 3585 | int len; | - | ||||||||||||||||||
| 3586 | // add the part before the match | - | ||||||||||||||||||
| 3587 | len = match.capturedStart() - lastEnd; | - | ||||||||||||||||||
| 3588 | if (len > 0) {
| 4-154 | ||||||||||||||||||
| 3589 | chunks << copy.midRef(lastEnd, len); | - | ||||||||||||||||||
| 3590 | newLength += len; | - | ||||||||||||||||||
| 3591 | } executed 4 times by 1 test: end of blockExecuted by:
| 4 | ||||||||||||||||||
| 3592 | - | |||||||||||||||||||
| 3593 | lastEnd = 0; | - | ||||||||||||||||||
| 3594 | // add the after string, with replacements for the backreferences | - | ||||||||||||||||||
| 3595 | foreach (const QStringCapture &backReference, backReferences) { | - | ||||||||||||||||||
| 3596 | // part of "after" before the backreference | - | ||||||||||||||||||
| 3597 | len = backReference.pos - lastEnd; | - | ||||||||||||||||||
| 3598 | if (len > 0) {
| 28-30 | ||||||||||||||||||
| 3599 | chunks << after.midRef(lastEnd, len); | - | ||||||||||||||||||
| 3600 | newLength += len; | - | ||||||||||||||||||
| 3601 | } executed 28 times by 2 tests: end of blockExecuted by:
| 28 | ||||||||||||||||||
| 3602 | - | |||||||||||||||||||
| 3603 | // backreference itself | - | ||||||||||||||||||
| 3604 | len = match.capturedLength(backReference.no); | - | ||||||||||||||||||
| 3605 | if (len > 0) {
| 1-57 | ||||||||||||||||||
| 3606 | chunks << copy.midRef(match.capturedStart(backReference.no), len); | - | ||||||||||||||||||
| 3607 | newLength += len; | - | ||||||||||||||||||
| 3608 | } executed 57 times by 2 tests: end of blockExecuted by:
| 57 | ||||||||||||||||||
| 3609 | - | |||||||||||||||||||
| 3610 | lastEnd = backReference.pos + backReference.len; | - | ||||||||||||||||||
| 3611 | } executed 58 times by 2 tests: end of blockExecuted by:
| 58 | ||||||||||||||||||
| 3612 | - | |||||||||||||||||||
| 3613 | // add the last part of the after string | - | ||||||||||||||||||
| 3614 | len = after.length() - lastEnd; | - | ||||||||||||||||||
| 3615 | if (len > 0) {
| 27-131 | ||||||||||||||||||
| 3616 | chunks << after.midRef(lastEnd, len); | - | ||||||||||||||||||
| 3617 | newLength += len; | - | ||||||||||||||||||
| 3618 | } executed 27 times by 2 tests: end of blockExecuted by:
| 27 | ||||||||||||||||||
| 3619 | - | |||||||||||||||||||
| 3620 | lastEnd = match.capturedEnd(); | - | ||||||||||||||||||
| 3621 | } executed 158 times by 3 tests: end of blockExecuted by:
| 158 | ||||||||||||||||||
| 3622 | - | |||||||||||||||||||
| 3623 | // 3. trailing string after the last match | - | ||||||||||||||||||
| 3624 | if (copy.length() > lastEnd) {
| 14-127 | ||||||||||||||||||
| 3625 | chunks << copy.midRef(lastEnd); | - | ||||||||||||||||||
| 3626 | newLength += copy.length() - lastEnd; | - | ||||||||||||||||||
| 3627 | } executed 127 times by 3 tests: end of blockExecuted by:
| 127 | ||||||||||||||||||
| 3628 | - | |||||||||||||||||||
| 3629 | // 4. assemble the chunks together | - | ||||||||||||||||||
| 3630 | resize(newLength); | - | ||||||||||||||||||
| 3631 | int i = 0; | - | ||||||||||||||||||
| 3632 | QChar *uc = data(); | - | ||||||||||||||||||
| 3633 | foreach (const QStringRef &chunk, chunks) { | - | ||||||||||||||||||
| 3634 | int len = chunk.length(); | - | ||||||||||||||||||
| 3635 | memcpy(uc + i, chunk.unicode(), len * sizeof(QChar)); | - | ||||||||||||||||||
| 3636 | i += len; | - | ||||||||||||||||||
| 3637 | } executed 243 times by 3 tests: end of blockExecuted by:
| 243 | ||||||||||||||||||
| 3638 | - | |||||||||||||||||||
| 3639 | return *this; executed 141 times by 3 tests: return *this;Executed by:
| 141 | ||||||||||||||||||
| 3640 | } | - | ||||||||||||||||||
| 3641 | #endif // QT_BOOTSTRAPPED | - | ||||||||||||||||||
| 3642 | #endif // QT_NO_REGULAREXPRESSION | - | ||||||||||||||||||
| 3643 | - | |||||||||||||||||||
| 3644 | /*! | - | ||||||||||||||||||
| 3645 | Returns the number of (potentially overlapping) occurrences of | - | ||||||||||||||||||
| 3646 | the string \a str in this string. | - | ||||||||||||||||||
| 3647 | - | |||||||||||||||||||
| 3648 | If \a cs is Qt::CaseSensitive (default), the search is | - | ||||||||||||||||||
| 3649 | case sensitive; otherwise the search is case insensitive. | - | ||||||||||||||||||
| 3650 | - | |||||||||||||||||||
| 3651 | \sa contains(), indexOf() | - | ||||||||||||||||||
| 3652 | */ | - | ||||||||||||||||||
| 3653 | - | |||||||||||||||||||
| 3654 | int QString::count(const QString &str, Qt::CaseSensitivity cs) const | - | ||||||||||||||||||
| 3655 | { | - | ||||||||||||||||||
| 3656 | return qt_string_count(unicode(), size(), str.unicode(), str.size(), cs); executed 12 times by 4 tests: return qt_string_count(unicode(), size(), str.unicode(), str.size(), cs);Executed by:
| 12 | ||||||||||||||||||
| 3657 | } | - | ||||||||||||||||||
| 3658 | - | |||||||||||||||||||
| 3659 | /*! | - | ||||||||||||||||||
| 3660 | \overload count() | - | ||||||||||||||||||
| 3661 | - | |||||||||||||||||||
| 3662 | Returns the number of occurrences of character \a ch in the string. | - | ||||||||||||||||||
| 3663 | - | |||||||||||||||||||
| 3664 | If \a cs is Qt::CaseSensitive (default), the search is | - | ||||||||||||||||||
| 3665 | case sensitive; otherwise the search is case insensitive. | - | ||||||||||||||||||
| 3666 | - | |||||||||||||||||||
| 3667 | \sa contains(), indexOf() | - | ||||||||||||||||||
| 3668 | */ | - | ||||||||||||||||||
| 3669 | - | |||||||||||||||||||
| 3670 | int QString::count(QChar ch, Qt::CaseSensitivity cs) const | - | ||||||||||||||||||
| 3671 | { | - | ||||||||||||||||||
| 3672 | return qt_string_count(unicode(), size(), ch, cs); executed 10950 times by 11 tests: return qt_string_count(unicode(), size(), ch, cs);Executed by:
| 10950 | ||||||||||||||||||
| 3673 | } | - | ||||||||||||||||||
| 3674 | - | |||||||||||||||||||
| 3675 | /*! | - | ||||||||||||||||||
| 3676 | \since 4.8 | - | ||||||||||||||||||
| 3677 | \overload count() | - | ||||||||||||||||||
| 3678 | Returns the number of (potentially overlapping) occurrences of the | - | ||||||||||||||||||
| 3679 | string reference \a str in this string. | - | ||||||||||||||||||
| 3680 | - | |||||||||||||||||||
| 3681 | If \a cs is Qt::CaseSensitive (default), the search is | - | ||||||||||||||||||
| 3682 | case sensitive; otherwise the search is case insensitive. | - | ||||||||||||||||||
| 3683 | - | |||||||||||||||||||
| 3684 | \sa contains(), indexOf() | - | ||||||||||||||||||
| 3685 | */ | - | ||||||||||||||||||
| 3686 | int QString::count(const QStringRef &str, Qt::CaseSensitivity cs) const | - | ||||||||||||||||||
| 3687 | { | - | ||||||||||||||||||
| 3688 | return qt_string_count(unicode(), size(), str.unicode(), str.size(), cs); executed 4 times by 1 test: return qt_string_count(unicode(), size(), str.unicode(), str.size(), cs);Executed by:
| 4 | ||||||||||||||||||
| 3689 | } | - | ||||||||||||||||||
| 3690 | - | |||||||||||||||||||
| 3691 | - | |||||||||||||||||||
| 3692 | /*! \fn bool QString::contains(const QString &str, Qt::CaseSensitivity cs = Qt::CaseSensitive) const | - | ||||||||||||||||||
| 3693 | - | |||||||||||||||||||
| 3694 | Returns \c true if this string contains an occurrence of the string | - | ||||||||||||||||||
| 3695 | \a str; otherwise returns \c false. | - | ||||||||||||||||||
| 3696 | - | |||||||||||||||||||
| 3697 | If \a cs is Qt::CaseSensitive (default), the search is | - | ||||||||||||||||||
| 3698 | case sensitive; otherwise the search is case insensitive. | - | ||||||||||||||||||
| 3699 | - | |||||||||||||||||||
| 3700 | Example: | - | ||||||||||||||||||
| 3701 | \snippet qstring/main.cpp 17 | - | ||||||||||||||||||
| 3702 | - | |||||||||||||||||||
| 3703 | \sa indexOf(), count() | - | ||||||||||||||||||
| 3704 | */ | - | ||||||||||||||||||
| 3705 | - | |||||||||||||||||||
| 3706 | /*! \fn bool QString::contains(QLatin1String str, Qt::CaseSensitivity cs = Qt::CaseSensitive) const | - | ||||||||||||||||||
| 3707 | \since 5.3 | - | ||||||||||||||||||
| 3708 | - | |||||||||||||||||||
| 3709 | \overload contains() | - | ||||||||||||||||||
| 3710 | - | |||||||||||||||||||
| 3711 | Returns \c true if this string contains an occurrence of the latin-1 string | - | ||||||||||||||||||
| 3712 | \a str; otherwise returns \c false. | - | ||||||||||||||||||
| 3713 | */ | - | ||||||||||||||||||
| 3714 | - | |||||||||||||||||||
| 3715 | /*! \fn bool QString::contains(QChar ch, Qt::CaseSensitivity cs = Qt::CaseSensitive) const | - | ||||||||||||||||||
| 3716 | - | |||||||||||||||||||
| 3717 | \overload contains() | - | ||||||||||||||||||
| 3718 | - | |||||||||||||||||||
| 3719 | Returns \c true if this string contains an occurrence of the | - | ||||||||||||||||||
| 3720 | character \a ch; otherwise returns \c false. | - | ||||||||||||||||||
| 3721 | */ | - | ||||||||||||||||||
| 3722 | - | |||||||||||||||||||
| 3723 | /*! \fn bool QString::contains(const QStringRef &str, Qt::CaseSensitivity cs = Qt::CaseSensitive) const | - | ||||||||||||||||||
| 3724 | \since 4.8 | - | ||||||||||||||||||
| 3725 | - | |||||||||||||||||||
| 3726 | Returns \c true if this string contains an occurrence of the string | - | ||||||||||||||||||
| 3727 | reference \a str; otherwise returns \c false. | - | ||||||||||||||||||
| 3728 | - | |||||||||||||||||||
| 3729 | If \a cs is Qt::CaseSensitive (default), the search is | - | ||||||||||||||||||
| 3730 | case sensitive; otherwise the search is case insensitive. | - | ||||||||||||||||||
| 3731 | - | |||||||||||||||||||
| 3732 | \sa indexOf(), count() | - | ||||||||||||||||||
| 3733 | */ | - | ||||||||||||||||||
| 3734 | - | |||||||||||||||||||
| 3735 | /*! \fn bool QString::contains(const QRegExp &rx) const | - | ||||||||||||||||||
| 3736 | - | |||||||||||||||||||
| 3737 | \overload contains() | - | ||||||||||||||||||
| 3738 | - | |||||||||||||||||||
| 3739 | Returns \c true if the regular expression \a rx matches somewhere in | - | ||||||||||||||||||
| 3740 | this string; otherwise returns \c false. | - | ||||||||||||||||||
| 3741 | */ | - | ||||||||||||||||||
| 3742 | - | |||||||||||||||||||
| 3743 | /*! \fn bool QString::contains(QRegExp &rx) const | - | ||||||||||||||||||
| 3744 | \overload contains() | - | ||||||||||||||||||
| 3745 | \since 4.5 | - | ||||||||||||||||||
| 3746 | - | |||||||||||||||||||
| 3747 | Returns \c true if the regular expression \a rx matches somewhere in | - | ||||||||||||||||||
| 3748 | this string; otherwise returns \c false. | - | ||||||||||||||||||
| 3749 | - | |||||||||||||||||||
| 3750 | If there is a match, the \a rx regular expression will contain the | - | ||||||||||||||||||
| 3751 | matched captures (see QRegExp::matchedLength, QRegExp::cap). | - | ||||||||||||||||||
| 3752 | */ | - | ||||||||||||||||||
| 3753 | - | |||||||||||||||||||
| 3754 | #ifndef QT_NO_REGEXP | - | ||||||||||||||||||
| 3755 | /*! | - | ||||||||||||||||||
| 3756 | \overload indexOf() | - | ||||||||||||||||||
| 3757 | - | |||||||||||||||||||
| 3758 | Returns the index position of the first match of the regular | - | ||||||||||||||||||
| 3759 | expression \a rx in the string, searching forward from index | - | ||||||||||||||||||
| 3760 | position \a from. Returns -1 if \a rx didn't match anywhere. | - | ||||||||||||||||||
| 3761 | - | |||||||||||||||||||
| 3762 | Example: | - | ||||||||||||||||||
| 3763 | - | |||||||||||||||||||
| 3764 | \snippet qstring/main.cpp 25 | - | ||||||||||||||||||
| 3765 | */ | - | ||||||||||||||||||
| 3766 | int QString::indexOf(const QRegExp& rx, int from) const | - | ||||||||||||||||||
| 3767 | { | - | ||||||||||||||||||
| 3768 | QRegExp rx2(rx); | - | ||||||||||||||||||
| 3769 | return rx2.indexIn(*this, from); executed 20349 times by 11 tests: return rx2.indexIn(*this, from);Executed by:
| 20349 | ||||||||||||||||||
| 3770 | } | - | ||||||||||||||||||
| 3771 | - | |||||||||||||||||||
| 3772 | /*! | - | ||||||||||||||||||
| 3773 | \overload indexOf() | - | ||||||||||||||||||
| 3774 | \since 4.5 | - | ||||||||||||||||||
| 3775 | - | |||||||||||||||||||
| 3776 | Returns the index position of the first match of the regular | - | ||||||||||||||||||
| 3777 | expression \a rx in the string, searching forward from index | - | ||||||||||||||||||
| 3778 | position \a from. Returns -1 if \a rx didn't match anywhere. | - | ||||||||||||||||||
| 3779 | - | |||||||||||||||||||
| 3780 | If there is a match, the \a rx regular expression will contain the | - | ||||||||||||||||||
| 3781 | matched captures (see QRegExp::matchedLength, QRegExp::cap). | - | ||||||||||||||||||
| 3782 | - | |||||||||||||||||||
| 3783 | Example: | - | ||||||||||||||||||
| 3784 | - | |||||||||||||||||||
| 3785 | \snippet qstring/main.cpp 25 | - | ||||||||||||||||||
| 3786 | */ | - | ||||||||||||||||||
| 3787 | int QString::indexOf(QRegExp& rx, int from) const | - | ||||||||||||||||||
| 3788 | { | - | ||||||||||||||||||
| 3789 | return rx.indexIn(*this, from); executed 323 times by 5 tests: return rx.indexIn(*this, from);Executed by:
| 323 | ||||||||||||||||||
| 3790 | } | - | ||||||||||||||||||
| 3791 | - | |||||||||||||||||||
| 3792 | /*! | - | ||||||||||||||||||
| 3793 | \overload lastIndexOf() | - | ||||||||||||||||||
| 3794 | - | |||||||||||||||||||
| 3795 | Returns the index position of the last match of the regular | - | ||||||||||||||||||
| 3796 | expression \a rx in the string, searching backward from index | - | ||||||||||||||||||
| 3797 | position \a from. Returns -1 if \a rx didn't match anywhere. | - | ||||||||||||||||||
| 3798 | - | |||||||||||||||||||
| 3799 | Example: | - | ||||||||||||||||||
| 3800 | - | |||||||||||||||||||
| 3801 | \snippet qstring/main.cpp 30 | - | ||||||||||||||||||
| 3802 | */ | - | ||||||||||||||||||
| 3803 | int QString::lastIndexOf(const QRegExp& rx, int from) const | - | ||||||||||||||||||
| 3804 | { | - | ||||||||||||||||||
| 3805 | QRegExp rx2(rx); | - | ||||||||||||||||||
| 3806 | return rx2.lastIndexIn(*this, from); executed 36 times by 1 test: return rx2.lastIndexIn(*this, from);Executed by:
| 36 | ||||||||||||||||||
| 3807 | } | - | ||||||||||||||||||
| 3808 | - | |||||||||||||||||||
| 3809 | /*! | - | ||||||||||||||||||
| 3810 | \overload lastIndexOf() | - | ||||||||||||||||||
| 3811 | \since 4.5 | - | ||||||||||||||||||
| 3812 | - | |||||||||||||||||||
| 3813 | Returns the index position of the last match of the regular | - | ||||||||||||||||||
| 3814 | expression \a rx in the string, searching backward from index | - | ||||||||||||||||||
| 3815 | position \a from. Returns -1 if \a rx didn't match anywhere. | - | ||||||||||||||||||
| 3816 | - | |||||||||||||||||||
| 3817 | If there is a match, the \a rx regular expression will contain the | - | ||||||||||||||||||
| 3818 | matched captures (see QRegExp::matchedLength, QRegExp::cap). | - | ||||||||||||||||||
| 3819 | - | |||||||||||||||||||
| 3820 | Example: | - | ||||||||||||||||||
| 3821 | - | |||||||||||||||||||
| 3822 | \snippet qstring/main.cpp 30 | - | ||||||||||||||||||
| 3823 | */ | - | ||||||||||||||||||
| 3824 | int QString::lastIndexOf(QRegExp& rx, int from) const | - | ||||||||||||||||||
| 3825 | { | - | ||||||||||||||||||
| 3826 | return rx.lastIndexIn(*this, from); executed 36 times by 1 test: return rx.lastIndexIn(*this, from);Executed by:
| 36 | ||||||||||||||||||
| 3827 | } | - | ||||||||||||||||||
| 3828 | - | |||||||||||||||||||
| 3829 | /*! | - | ||||||||||||||||||
| 3830 | \overload count() | - | ||||||||||||||||||
| 3831 | - | |||||||||||||||||||
| 3832 | Returns the number of times the regular expression \a rx matches | - | ||||||||||||||||||
| 3833 | in the string. | - | ||||||||||||||||||
| 3834 | - | |||||||||||||||||||
| 3835 | This function counts overlapping matches, so in the example | - | ||||||||||||||||||
| 3836 | below, there are four instances of "ana" or "ama": | - | ||||||||||||||||||
| 3837 | - | |||||||||||||||||||
| 3838 | \snippet qstring/main.cpp 18 | - | ||||||||||||||||||
| 3839 | - | |||||||||||||||||||
| 3840 | */ | - | ||||||||||||||||||
| 3841 | int QString::count(const QRegExp& rx) const | - | ||||||||||||||||||
| 3842 | { | - | ||||||||||||||||||
| 3843 | QRegExp rx2(rx); | - | ||||||||||||||||||
| 3844 | int count = 0; | - | ||||||||||||||||||
| 3845 | int index = -1; | - | ||||||||||||||||||
| 3846 | int len = length(); | - | ||||||||||||||||||
| 3847 | while (index < len - 1) { // count overlapping matches
| 0-5 | ||||||||||||||||||
| 3848 | index = rx2.indexIn(*this, index + 1); | - | ||||||||||||||||||
| 3849 | if (index == -1)
| 2-3 | ||||||||||||||||||
| 3850 | break; executed 2 times by 1 test: break;Executed by:
| 2 | ||||||||||||||||||
| 3851 | count++; | - | ||||||||||||||||||
| 3852 | } executed 3 times by 1 test: end of blockExecuted by:
| 3 | ||||||||||||||||||
| 3853 | return count; executed 2 times by 1 test: return count;Executed by:
| 2 | ||||||||||||||||||
| 3854 | } | - | ||||||||||||||||||
| 3855 | #endif // QT_NO_REGEXP | - | ||||||||||||||||||
| 3856 | - | |||||||||||||||||||
| 3857 | #ifndef QT_NO_REGULAREXPRESSION | - | ||||||||||||||||||
| 3858 | #ifndef QT_BOOTSTRAPPED | - | ||||||||||||||||||
| 3859 | /*! | - | ||||||||||||||||||
| 3860 | \overload indexOf() | - | ||||||||||||||||||
| 3861 | \since 5.0 | - | ||||||||||||||||||
| 3862 | - | |||||||||||||||||||
| 3863 | Returns the index position of the first match of the regular | - | ||||||||||||||||||
| 3864 | expression \a re in the string, searching forward from index | - | ||||||||||||||||||
| 3865 | position \a from. Returns -1 if \a re didn't match anywhere. | - | ||||||||||||||||||
| 3866 | - | |||||||||||||||||||
| 3867 | Example: | - | ||||||||||||||||||
| 3868 | - | |||||||||||||||||||
| 3869 | \snippet qstring/main.cpp 93 | - | ||||||||||||||||||
| 3870 | */ | - | ||||||||||||||||||
| 3871 | int QString::indexOf(const QRegularExpression& re, int from) const | - | ||||||||||||||||||
| 3872 | { | - | ||||||||||||||||||
| 3873 | return indexOf(re, from, Q_NULLPTR); executed 65 times by 1 test: return indexOf(re, from, nullptr);Executed by:
| 65 | ||||||||||||||||||
| 3874 | } | - | ||||||||||||||||||
| 3875 | - | |||||||||||||||||||
| 3876 | /*! | - | ||||||||||||||||||
| 3877 | \overload | - | ||||||||||||||||||
| 3878 | \since 5.5 | - | ||||||||||||||||||
| 3879 | - | |||||||||||||||||||
| 3880 | Returns the index position of the first match of the regular | - | ||||||||||||||||||
| 3881 | expression \a re in the string, searching forward from index | - | ||||||||||||||||||
| 3882 | position \a from. Returns -1 if \a re didn't match anywhere. | - | ||||||||||||||||||
| 3883 | - | |||||||||||||||||||
| 3884 | If the match is successful and \a rmatch is not a null pointer, it also | - | ||||||||||||||||||
| 3885 | writes the results of the match into the QRegularExpressionMatch object | - | ||||||||||||||||||
| 3886 | pointed to by \a rmatch. | - | ||||||||||||||||||
| 3887 | - | |||||||||||||||||||
| 3888 | Example: | - | ||||||||||||||||||
| 3889 | - | |||||||||||||||||||
| 3890 | \snippet qstring/main.cpp 99 | - | ||||||||||||||||||
| 3891 | */ | - | ||||||||||||||||||
| 3892 | int QString::indexOf(const QRegularExpression &re, int from, QRegularExpressionMatch *rmatch) const | - | ||||||||||||||||||
| 3893 | { | - | ||||||||||||||||||
| 3894 | if (!re.isValid()) {
| 3-196 | ||||||||||||||||||
| 3895 | qWarning("QString::indexOf: invalid QRegularExpression object"); | - | ||||||||||||||||||
| 3896 | return -1; executed 3 times by 1 test: return -1;Executed by:
| 3 | ||||||||||||||||||
| 3897 | } | - | ||||||||||||||||||
| 3898 | - | |||||||||||||||||||
| 3899 | QRegularExpressionMatch match = re.match(*this, from); | - | ||||||||||||||||||
| 3900 | if (match.hasMatch()) {
| 87-109 | ||||||||||||||||||
| 3901 | const int ret = match.capturedStart(); | - | ||||||||||||||||||
| 3902 | if (rmatch)
| 39-70 | ||||||||||||||||||
| 3903 | *rmatch = qMove(match); executed 39 times by 2 tests: *rmatch = std::move(match);Executed by:
| 39 | ||||||||||||||||||
| 3904 | return ret; executed 109 times by 2 tests: return ret;Executed by:
| 109 | ||||||||||||||||||
| 3905 | } | - | ||||||||||||||||||
| 3906 | - | |||||||||||||||||||
| 3907 | return -1; executed 87 times by 1 test: return -1;Executed by:
| 87 | ||||||||||||||||||
| 3908 | } | - | ||||||||||||||||||
| 3909 | - | |||||||||||||||||||
| 3910 | /*! | - | ||||||||||||||||||
| 3911 | \overload lastIndexOf() | - | ||||||||||||||||||
| 3912 | \since 5.0 | - | ||||||||||||||||||
| 3913 | - | |||||||||||||||||||
| 3914 | Returns the index position of the last match of the regular | - | ||||||||||||||||||
| 3915 | expression \a re in the string, which starts before the index | - | ||||||||||||||||||
| 3916 | position \a from. Returns -1 if \a re didn't match anywhere. | - | ||||||||||||||||||
| 3917 | - | |||||||||||||||||||
| 3918 | Example: | - | ||||||||||||||||||
| 3919 | - | |||||||||||||||||||
| 3920 | \snippet qstring/main.cpp 94 | - | ||||||||||||||||||
| 3921 | */ | - | ||||||||||||||||||
| 3922 | int QString::lastIndexOf(const QRegularExpression &re, int from) const | - | ||||||||||||||||||
| 3923 | { | - | ||||||||||||||||||
| 3924 | return lastIndexOf(re, from, Q_NULLPTR); executed 19 times by 1 test: return lastIndexOf(re, from, nullptr);Executed by:
| 19 | ||||||||||||||||||
| 3925 | } | - | ||||||||||||||||||
| 3926 | - | |||||||||||||||||||
| 3927 | /*! | - | ||||||||||||||||||
| 3928 | \overload | - | ||||||||||||||||||
| 3929 | \since 5.5 | - | ||||||||||||||||||
| 3930 | - | |||||||||||||||||||
| 3931 | Returns the index position of the last match of the regular | - | ||||||||||||||||||
| 3932 | expression \a re in the string, which starts before the index | - | ||||||||||||||||||
| 3933 | position \a from. Returns -1 if \a re didn't match anywhere. | - | ||||||||||||||||||
| 3934 | - | |||||||||||||||||||
| 3935 | If the match is successful and \a rmatch is not a null pointer, it also | - | ||||||||||||||||||
| 3936 | writes the results of the match into the QRegularExpressionMatch object | - | ||||||||||||||||||
| 3937 | pointed to by \a rmatch. | - | ||||||||||||||||||
| 3938 | - | |||||||||||||||||||
| 3939 | Example: | - | ||||||||||||||||||
| 3940 | - | |||||||||||||||||||
| 3941 | \snippet qstring/main.cpp 100 | - | ||||||||||||||||||
| 3942 | */ | - | ||||||||||||||||||
| 3943 | int QString::lastIndexOf(const QRegularExpression &re, int from, QRegularExpressionMatch *rmatch) const | - | ||||||||||||||||||
| 3944 | { | - | ||||||||||||||||||
| 3945 | if (!re.isValid()) {
| 3-57 | ||||||||||||||||||
| 3946 | qWarning("QString::lastIndexOf: invalid QRegularExpression object"); | - | ||||||||||||||||||
| 3947 | return -1; executed 3 times by 1 test: return -1;Executed by:
| 3 | ||||||||||||||||||
| 3948 | } | - | ||||||||||||||||||
| 3949 | - | |||||||||||||||||||
| 3950 | int endpos = (from < 0) ? (size() + from + 1) : (from + 1);
| 18-39 | ||||||||||||||||||
| 3951 | QRegularExpressionMatchIterator iterator = re.globalMatch(*this); | - | ||||||||||||||||||
| 3952 | int lastIndex = -1; | - | ||||||||||||||||||
| 3953 | while (iterator.hasNext()) {
| 40-109 | ||||||||||||||||||
| 3954 | QRegularExpressionMatch match = iterator.next(); | - | ||||||||||||||||||
| 3955 | int start = match.capturedStart(); | - | ||||||||||||||||||
| 3956 | if (start < endpos) {
| 17-92 | ||||||||||||||||||
| 3957 | lastIndex = start; | - | ||||||||||||||||||
| 3958 | if (rmatch)
| 34-58 | ||||||||||||||||||
| 3959 | *rmatch = qMove(match); executed 34 times by 2 tests: *rmatch = std::move(match);Executed by:
| 34 | ||||||||||||||||||
| 3960 | } else { executed 92 times by 2 tests: end of blockExecuted by:
| 92 | ||||||||||||||||||
| 3961 | break; executed 17 times by 2 tests: break;Executed by:
| 17 | ||||||||||||||||||
| 3962 | } | - | ||||||||||||||||||
| 3963 | } | - | ||||||||||||||||||
| 3964 | - | |||||||||||||||||||
| 3965 | return lastIndex; executed 57 times by 2 tests: return lastIndex;Executed by:
| 57 | ||||||||||||||||||
| 3966 | } | - | ||||||||||||||||||
| 3967 | - | |||||||||||||||||||
| 3968 | /*! \overload contains() | - | ||||||||||||||||||
| 3969 | \since 5.0 | - | ||||||||||||||||||
| 3970 | - | |||||||||||||||||||
| 3971 | Returns \c true if the regular expression \a re matches somewhere in | - | ||||||||||||||||||
| 3972 | this string; otherwise returns \c false. | - | ||||||||||||||||||
| 3973 | */ | - | ||||||||||||||||||
| 3974 | bool QString::contains(const QRegularExpression &re) const | - | ||||||||||||||||||
| 3975 | { | - | ||||||||||||||||||
| 3976 | return contains(re, Q_NULLPTR); executed 6 times by 2 tests: return contains(re, nullptr);Executed by:
| 6 | ||||||||||||||||||
| 3977 | } | - | ||||||||||||||||||
| 3978 | - | |||||||||||||||||||
| 3979 | /*! | - | ||||||||||||||||||
| 3980 | \overload contains() | - | ||||||||||||||||||
| 3981 | \since 5.1 | - | ||||||||||||||||||
| 3982 | - | |||||||||||||||||||
| 3983 | Returns \c true if the regular expression \a re matches somewhere in this | - | ||||||||||||||||||
| 3984 | string; otherwise returns \c false. | - | ||||||||||||||||||
| 3985 | - | |||||||||||||||||||
| 3986 | If the match is successful and \a match is not a null pointer, it also | - | ||||||||||||||||||
| 3987 | writes the results of the match into the QRegularExpressionMatch object | - | ||||||||||||||||||
| 3988 | pointed to by \a match. | - | ||||||||||||||||||
| 3989 | - | |||||||||||||||||||
| 3990 | \sa QRegularExpression::match() | - | ||||||||||||||||||
| 3991 | */ | - | ||||||||||||||||||
| 3992 | - | |||||||||||||||||||
| 3993 | bool QString::contains(const QRegularExpression &re, QRegularExpressionMatch *match) const | - | ||||||||||||||||||
| 3994 | { | - | ||||||||||||||||||
| 3995 | if (!re.isValid()) {
| 1-12 | ||||||||||||||||||
| 3996 | qWarning("QString::contains: invalid QRegularExpression object"); | - | ||||||||||||||||||
| 3997 | return false; executed 1 time by 1 test: return false;Executed by:
| 1 | ||||||||||||||||||
| 3998 | } | - | ||||||||||||||||||
| 3999 | QRegularExpressionMatch m = re.match(*this); | - | ||||||||||||||||||
| 4000 | bool hasMatch = m.hasMatch(); | - | ||||||||||||||||||
| 4001 | if (hasMatch && match)
| 3-9 | ||||||||||||||||||
| 4002 | *match = qMove(m); executed 4 times by 1 test: *match = std::move(m);Executed by:
| 4 | ||||||||||||||||||
| 4003 | return hasMatch; executed 12 times by 2 tests: return hasMatch;Executed by:
| 12 | ||||||||||||||||||
| 4004 | } | - | ||||||||||||||||||
| 4005 | - | |||||||||||||||||||
| 4006 | /*! | - | ||||||||||||||||||
| 4007 | \overload count() | - | ||||||||||||||||||
| 4008 | \since 5.0 | - | ||||||||||||||||||
| 4009 | - | |||||||||||||||||||
| 4010 | Returns the number of times the regular expression \a re matches | - | ||||||||||||||||||
| 4011 | in the string. | - | ||||||||||||||||||
| 4012 | - | |||||||||||||||||||
| 4013 | This function counts overlapping matches, so in the example | - | ||||||||||||||||||
| 4014 | below, there are four instances of "ana" or "ama": | - | ||||||||||||||||||
| 4015 | - | |||||||||||||||||||
| 4016 | \snippet qstring/main.cpp 95 | - | ||||||||||||||||||
| 4017 | */ | - | ||||||||||||||||||
| 4018 | int QString::count(const QRegularExpression &re) const | - | ||||||||||||||||||
| 4019 | { | - | ||||||||||||||||||
| 4020 | if (!re.isValid()) {
| 1-122 | ||||||||||||||||||
| 4021 | qWarning("QString::count: invalid QRegularExpression object"); | - | ||||||||||||||||||
| 4022 | return 0; executed 1 time by 1 test: return 0;Executed by:
| 1 | ||||||||||||||||||
| 4023 | } | - | ||||||||||||||||||
| 4024 | int count = 0; | - | ||||||||||||||||||
| 4025 | int index = -1; | - | ||||||||||||||||||
| 4026 | int len = length(); | - | ||||||||||||||||||
| 4027 | while (index < len - 1) {
| 0-245 | ||||||||||||||||||
| 4028 | QRegularExpressionMatch match = re.match(*this, index + 1); | - | ||||||||||||||||||
| 4029 | if (!match.hasMatch())
| 122-123 | ||||||||||||||||||
| 4030 | break; executed 122 times by 2 tests: break;Executed by:
| 122 | ||||||||||||||||||
| 4031 | index = match.capturedStart(); | - | ||||||||||||||||||
| 4032 | count++; | - | ||||||||||||||||||
| 4033 | } executed 123 times by 2 tests: end of blockExecuted by:
| 123 | ||||||||||||||||||
| 4034 | return count; executed 122 times by 2 tests: return count;Executed by:
| 122 | ||||||||||||||||||
| 4035 | } | - | ||||||||||||||||||
| 4036 | #endif // QT_BOOTSTRAPPED | - | ||||||||||||||||||
| 4037 | #endif // QT_NO_REGULAREXPRESSION | - | ||||||||||||||||||
| 4038 | - | |||||||||||||||||||
| 4039 | /*! \fn int QString::count() const | - | ||||||||||||||||||
| 4040 | - | |||||||||||||||||||
| 4041 | \overload count() | - | ||||||||||||||||||
| 4042 | - | |||||||||||||||||||
| 4043 | Same as size(). | - | ||||||||||||||||||
| 4044 | */ | - | ||||||||||||||||||
| 4045 | - | |||||||||||||||||||
| 4046 | - | |||||||||||||||||||
| 4047 | /*! | - | ||||||||||||||||||
| 4048 | \enum QString::SectionFlag | - | ||||||||||||||||||
| 4049 | - | |||||||||||||||||||
| 4050 | This enum specifies flags that can be used to affect various | - | ||||||||||||||||||
| 4051 | aspects of the section() function's behavior with respect to | - | ||||||||||||||||||
| 4052 | separators and empty fields. | - | ||||||||||||||||||
| 4053 | - | |||||||||||||||||||
| 4054 | \value SectionDefault Empty fields are counted, leading and | - | ||||||||||||||||||
| 4055 | trailing separators are not included, and the separator is | - | ||||||||||||||||||
| 4056 | compared case sensitively. | - | ||||||||||||||||||
| 4057 | - | |||||||||||||||||||
| 4058 | \value SectionSkipEmpty Treat empty fields as if they don't exist, | - | ||||||||||||||||||
| 4059 | i.e. they are not considered as far as \e start and \e end are | - | ||||||||||||||||||
| 4060 | concerned. | - | ||||||||||||||||||
| 4061 | - | |||||||||||||||||||
| 4062 | \value SectionIncludeLeadingSep Include the leading separator (if | - | ||||||||||||||||||
| 4063 | any) in the result string. | - | ||||||||||||||||||
| 4064 | - | |||||||||||||||||||
| 4065 | \value SectionIncludeTrailingSep Include the trailing separator | - | ||||||||||||||||||
| 4066 | (if any) in the result string. | - | ||||||||||||||||||
| 4067 | - | |||||||||||||||||||
| 4068 | \value SectionCaseInsensitiveSeps Compare the separator | - | ||||||||||||||||||
| 4069 | case-insensitively. | - | ||||||||||||||||||
| 4070 | - | |||||||||||||||||||
| 4071 | \sa section() | - | ||||||||||||||||||
| 4072 | */ | - | ||||||||||||||||||
| 4073 | - | |||||||||||||||||||
| 4074 | /*! | - | ||||||||||||||||||
| 4075 | \fn QString QString::section(QChar sep, int start, int end = -1, SectionFlags flags) const | - | ||||||||||||||||||
| 4076 | - | |||||||||||||||||||
| 4077 | This function returns a section of the string. | - | ||||||||||||||||||
| 4078 | - | |||||||||||||||||||
| 4079 | This string is treated as a sequence of fields separated by the | - | ||||||||||||||||||
| 4080 | character, \a sep. The returned string consists of the fields from | - | ||||||||||||||||||
| 4081 | position \a start to position \a end inclusive. If \a end is not | - | ||||||||||||||||||
| 4082 | specified, all fields from position \a start to the end of the | - | ||||||||||||||||||
| 4083 | string are included. Fields are numbered 0, 1, 2, etc., counting | - | ||||||||||||||||||
| 4084 | from the left, and -1, -2, etc., counting from right to left. | - | ||||||||||||||||||
| 4085 | - | |||||||||||||||||||
| 4086 | The \a flags argument can be used to affect some aspects of the | - | ||||||||||||||||||
| 4087 | function's behavior, e.g. whether to be case sensitive, whether | - | ||||||||||||||||||
| 4088 | to skip empty fields and how to deal with leading and trailing | - | ||||||||||||||||||
| 4089 | separators; see \l{SectionFlags}. | - | ||||||||||||||||||
| 4090 | - | |||||||||||||||||||
| 4091 | \snippet qstring/main.cpp 52 | - | ||||||||||||||||||
| 4092 | - | |||||||||||||||||||
| 4093 | If \a start or \a end is negative, we count fields from the right | - | ||||||||||||||||||
| 4094 | of the string, the right-most field being -1, the one from | - | ||||||||||||||||||
| 4095 | right-most field being -2, and so on. | - | ||||||||||||||||||
| 4096 | - | |||||||||||||||||||
| 4097 | \snippet qstring/main.cpp 53 | - | ||||||||||||||||||
| 4098 | - | |||||||||||||||||||
| 4099 | \sa split() | - | ||||||||||||||||||
| 4100 | */ | - | ||||||||||||||||||
| 4101 | - | |||||||||||||||||||
| 4102 | /*! | - | ||||||||||||||||||
| 4103 | \overload section() | - | ||||||||||||||||||
| 4104 | - | |||||||||||||||||||
| 4105 | \snippet qstring/main.cpp 51 | - | ||||||||||||||||||
| 4106 | \snippet qstring/main.cpp 54 | - | ||||||||||||||||||
| 4107 | - | |||||||||||||||||||
| 4108 | \sa split() | - | ||||||||||||||||||
| 4109 | */ | - | ||||||||||||||||||
| 4110 | - | |||||||||||||||||||
| 4111 | QString QString::section(const QString &sep, int start, int end, SectionFlags flags) const | - | ||||||||||||||||||
| 4112 | { | - | ||||||||||||||||||
| 4113 | const QVector<QStringRef> sections = splitRef(sep, KeepEmptyParts, | - | ||||||||||||||||||
| 4114 | (flags & SectionCaseInsensitiveSeps) ? Qt::CaseInsensitive : Qt::CaseSensitive); | - | ||||||||||||||||||
| 4115 | const int sectionsSize = sections.size(); | - | ||||||||||||||||||
| 4116 | if (!(flags & SectionSkipEmpty)) {
| 230-1992 | ||||||||||||||||||
| 4117 | if (start < 0)
| 64-166 | ||||||||||||||||||
| 4118 | start += sectionsSize; executed 166 times by 8 tests: start += sectionsSize;Executed by:
| 166 | ||||||||||||||||||
| 4119 | if (end < 0)
| 59-171 | ||||||||||||||||||
| 4120 | end += sectionsSize; executed 171 times by 9 tests: end += sectionsSize;Executed by:
| 171 | ||||||||||||||||||
| 4121 | } else { executed 230 times by 11 tests: end of blockExecuted by:
| 230 | ||||||||||||||||||
| 4122 | int skip = 0; | - | ||||||||||||||||||
| 4123 | for (int k = 0; k < sectionsSize; ++k) {
| 1992-15024 | ||||||||||||||||||
| 4124 | if (sections.at(k).isEmpty())
| 2048-12976 | ||||||||||||||||||
| 4125 | skip++; executed 2048 times by 2 tests: skip++;Executed by:
| 2048 | ||||||||||||||||||
| 4126 | } executed 15024 times by 3 tests: end of blockExecuted by:
| 15024 | ||||||||||||||||||
| 4127 | if (start < 0)
| 4-1988 | ||||||||||||||||||
| 4128 | start += sectionsSize - skip; executed 4 times by 1 test: start += sectionsSize - skip;Executed by:
| 4 | ||||||||||||||||||
| 4129 | if (end < 0)
| 198-1794 | ||||||||||||||||||
| 4130 | end += sectionsSize - skip; executed 1794 times by 2 tests: end += sectionsSize - skip;Executed by:
| 1794 | ||||||||||||||||||
| 4131 | } executed 1992 times by 3 tests: end of blockExecuted by:
| 1992 | ||||||||||||||||||
| 4132 | if (start >= sectionsSize || end < 0 || start > end)
| 2-2220 | ||||||||||||||||||
| 4133 | return QString(); executed 6 times by 1 test: return QString();Executed by:
| 6 | ||||||||||||||||||
| 4134 | - | |||||||||||||||||||
| 4135 | QString ret; | - | ||||||||||||||||||
| 4136 | int first_i = start, last_i = end; | - | ||||||||||||||||||
| 4137 | for (int x = 0, i = 0; x <= end && i < sectionsSize; ++i) {
| 0-13295 | ||||||||||||||||||
| 4138 | const QStringRef §ion = sections.at(i); | - | ||||||||||||||||||
| 4139 | const bool empty = section.isEmpty(); | - | ||||||||||||||||||
| 4140 | if (x >= start) {
| 2307-10988 | ||||||||||||||||||
| 4141 | if(x == start)
| 45-2262 | ||||||||||||||||||
| 4142 | first_i = i; executed 2262 times by 13 tests: first_i = i;Executed by:
| 2262 | ||||||||||||||||||
| 4143 | if(x == end)
| 43-2264 | ||||||||||||||||||
| 4144 | last_i = i; executed 2264 times by 13 tests: last_i = i;Executed by:
| 2264 | ||||||||||||||||||
| 4145 | if (x > start && i > 0)
| 2-2262 | ||||||||||||||||||
| 4146 | ret += sep; executed 43 times by 2 tests: ret += sep;Executed by:
| 43 | ||||||||||||||||||
| 4147 | ret += section; | - | ||||||||||||||||||
| 4148 | } executed 2307 times by 13 tests: end of blockExecuted by:
| 2307 | ||||||||||||||||||
| 4149 | if (!empty || !(flags & SectionSkipEmpty))
| 24-13139 | ||||||||||||||||||
| 4150 | x++; executed 13163 times by 13 tests: x++;Executed by:
| 13163 | ||||||||||||||||||
| 4151 | } executed 13295 times by 13 tests: end of blockExecuted by:
| 13295 | ||||||||||||||||||
| 4152 | if ((flags & SectionIncludeLeadingSep) && first_i > 0)
| 10-16 | ||||||||||||||||||
| 4153 | ret.prepend(sep); executed 16 times by 1 test: ret.prepend(sep);Executed by:
| 16 | ||||||||||||||||||
| 4154 | if ((flags & SectionIncludeTrailingSep) && last_i < sectionsSize - 1)
| 4-16 | ||||||||||||||||||
| 4155 | ret += sep; executed 16 times by 1 test: ret += sep;Executed by:
| 16 | ||||||||||||||||||
| 4156 | return ret; executed 2216 times by 13 tests: return ret;Executed by:
| 2216 | ||||||||||||||||||
| 4157 | } | - | ||||||||||||||||||
| 4158 | - | |||||||||||||||||||
| 4159 | #if !(defined(QT_NO_REGEXP) && defined(QT_NO_REGULAREXPRESSION)) | - | ||||||||||||||||||
| 4160 | class qt_section_chunk { | - | ||||||||||||||||||
| 4161 | public: | - | ||||||||||||||||||
| 4162 | qt_section_chunk() {} | - | ||||||||||||||||||
| 4163 | qt_section_chunk(int l, QStringRef s) : length(l), string(qMove(s)) {} executed 638 times by 2 tests: end of blockExecuted by:
| 638 | ||||||||||||||||||
| 4164 | int length; | - | ||||||||||||||||||
| 4165 | QStringRef string; | - | ||||||||||||||||||
| 4166 | }; | - | ||||||||||||||||||
| 4167 | Q_DECLARE_TYPEINFO(qt_section_chunk, Q_MOVABLE_TYPE); | - | ||||||||||||||||||
| 4168 | - | |||||||||||||||||||
| 4169 | static QString extractSections(const QVector<qt_section_chunk> §ions, | - | ||||||||||||||||||
| 4170 | int start, | - | ||||||||||||||||||
| 4171 | int end, | - | ||||||||||||||||||
| 4172 | QString::SectionFlags flags) | - | ||||||||||||||||||
| 4173 | { | - | ||||||||||||||||||
| 4174 | const int sectionsSize = sections.size(); | - | ||||||||||||||||||
| 4175 | - | |||||||||||||||||||
| 4176 | if (!(flags & QString::SectionSkipEmpty)) {
| 18-72 | ||||||||||||||||||
| 4177 | if (start < 0)
| 9-63 | ||||||||||||||||||
| 4178 | start += sectionsSize; executed 9 times by 2 tests: start += sectionsSize;Executed by:
| 9 | ||||||||||||||||||
| 4179 | if (end < 0)
| 18-54 | ||||||||||||||||||
| 4180 | end += sectionsSize; executed 18 times by 2 tests: end += sectionsSize;Executed by:
| 18 | ||||||||||||||||||
| 4181 | } else { executed 72 times by 2 tests: end of blockExecuted by:
| 72 | ||||||||||||||||||
| 4182 | int skip = 0; | - | ||||||||||||||||||
| 4183 | for (int k = 0; k < sectionsSize; ++k) {
| 18-324 | ||||||||||||||||||
| 4184 | const qt_section_chunk §ion = sections.at(k); | - | ||||||||||||||||||
| 4185 | if (section.length == section.string.length())
| 68-256 | ||||||||||||||||||
| 4186 | skip++; executed 256 times by 1 test: skip++;Executed by:
| 256 | ||||||||||||||||||
| 4187 | } executed 324 times by 1 test: end of blockExecuted by:
| 324 | ||||||||||||||||||
| 4188 | if (start < 0)
| 4-14 | ||||||||||||||||||
| 4189 | start += sectionsSize - skip; executed 4 times by 1 test: start += sectionsSize - skip;Executed by:
| 4 | ||||||||||||||||||
| 4190 | if (end < 0)
| 2-16 | ||||||||||||||||||
| 4191 | end += sectionsSize - skip; executed 2 times by 1 test: end += sectionsSize - skip;Executed by:
| 2 | ||||||||||||||||||
| 4192 | } executed 18 times by 1 test: end of blockExecuted by:
| 18 | ||||||||||||||||||
| 4193 | if (start >= sectionsSize || end < 0 || start > end)
| 2-86 | ||||||||||||||||||
| 4194 | return QString(); executed 9 times by 2 tests: return QString();Executed by:
| 9 | ||||||||||||||||||
| 4195 | - | |||||||||||||||||||
| 4196 | QString ret; | - | ||||||||||||||||||
| 4197 | int x = 0; | - | ||||||||||||||||||
| 4198 | int first_i = start, last_i = end; | - | ||||||||||||||||||
| 4199 | for (int i = 0; x <= end && i < sectionsSize; ++i) {
| 0-365 | ||||||||||||||||||
| 4200 | const qt_section_chunk §ion = sections.at(i); | - | ||||||||||||||||||
| 4201 | const bool empty = (section.length == section.string.length()); | - | ||||||||||||||||||
| 4202 | if (x >= start) {
| 173-192 | ||||||||||||||||||
| 4203 | if (x == start)
| 65-127 | ||||||||||||||||||
| 4204 | first_i = i; executed 127 times by 2 tests: first_i = i;Executed by:
| 127 | ||||||||||||||||||
| 4205 | if (x == end)
| 63-129 | ||||||||||||||||||
| 4206 | last_i = i; executed 129 times by 2 tests: last_i = i;Executed by:
| 129 | ||||||||||||||||||
| 4207 | if (x != start)
| 65-127 | ||||||||||||||||||
| 4208 | ret += section.string; executed 65 times by 2 tests: ret += section.string;Executed by:
| 65 | ||||||||||||||||||
| 4209 | else | - | ||||||||||||||||||
| 4210 | ret += section.string.mid(section.length); executed 127 times by 2 tests: ret += section.string.mid(section.length);Executed by:
| 127 | ||||||||||||||||||
| 4211 | } | - | ||||||||||||||||||
| 4212 | if (!empty || !(flags & QString::SectionSkipEmpty))
| 50-183 | ||||||||||||||||||
| 4213 | x++; executed 233 times by 2 tests: x++;Executed by:
| 233 | ||||||||||||||||||
| 4214 | } executed 365 times by 2 tests: end of blockExecuted by:
| 365 | ||||||||||||||||||
| 4215 | - | |||||||||||||||||||
| 4216 | if ((flags & QString::SectionIncludeLeadingSep) && first_i >= 0) {
| 2-44 | ||||||||||||||||||
| 4217 | const qt_section_chunk §ion = sections.at(first_i); | - | ||||||||||||||||||
| 4218 | ret.prepend(section.string.left(section.length)); | - | ||||||||||||||||||
| 4219 | } executed 44 times by 1 test: end of blockExecuted by:
| 44 | ||||||||||||||||||
| 4220 | - | |||||||||||||||||||
| 4221 | if ((flags & QString::SectionIncludeTrailingSep) | - | ||||||||||||||||||
| 4222 | && last_i < sectionsSize - 1) {
| 6-28 | ||||||||||||||||||
| 4223 | const qt_section_chunk §ion = sections.at(last_i+1); | - | ||||||||||||||||||
| 4224 | ret += section.string.left(section.length); | - | ||||||||||||||||||
| 4225 | } executed 28 times by 1 test: end of blockExecuted by:
| 28 | ||||||||||||||||||
| 4226 | - | |||||||||||||||||||
| 4227 | return ret; executed 81 times by 2 tests: return ret;Executed by:
| 81 | ||||||||||||||||||
| 4228 | } | - | ||||||||||||||||||
| 4229 | #endif | - | ||||||||||||||||||
| 4230 | - | |||||||||||||||||||
| 4231 | #ifndef QT_NO_REGEXP | - | ||||||||||||||||||
| 4232 | /*! | - | ||||||||||||||||||
| 4233 | \overload section() | - | ||||||||||||||||||
| 4234 | - | |||||||||||||||||||
| 4235 | This string is treated as a sequence of fields separated by the | - | ||||||||||||||||||
| 4236 | regular expression, \a reg. | - | ||||||||||||||||||
| 4237 | - | |||||||||||||||||||
| 4238 | \snippet qstring/main.cpp 55 | - | ||||||||||||||||||
| 4239 | - | |||||||||||||||||||
| 4240 | \warning Using this QRegExp version is much more expensive than | - | ||||||||||||||||||
| 4241 | the overloaded string and character versions. | - | ||||||||||||||||||
| 4242 | - | |||||||||||||||||||
| 4243 | \sa split(), simplified() | - | ||||||||||||||||||
| 4244 | */ | - | ||||||||||||||||||
| 4245 | QString QString::section(const QRegExp ®, int start, int end, SectionFlags flags) const | - | ||||||||||||||||||
| 4246 | { | - | ||||||||||||||||||
| 4247 | const QChar *uc = unicode(); | - | ||||||||||||||||||
| 4248 | if(!uc)
| 0-48 | ||||||||||||||||||
| 4249 | return QString(); never executed: return QString(); | 0 | ||||||||||||||||||
| 4250 | - | |||||||||||||||||||
| 4251 | QRegExp sep(reg); | - | ||||||||||||||||||
| 4252 | sep.setCaseSensitivity((flags & SectionCaseInsensitiveSeps) ? Qt::CaseInsensitive | - | ||||||||||||||||||
| 4253 | : Qt::CaseSensitive); | - | ||||||||||||||||||
| 4254 | - | |||||||||||||||||||
| 4255 | QVector<qt_section_chunk> sections; | - | ||||||||||||||||||
| 4256 | int n = length(), m = 0, last_m = 0, last_len = 0; | - | ||||||||||||||||||
| 4257 | while ((m = sep.indexIn(*this, m)) != -1) {
| 48-277 | ||||||||||||||||||
| 4258 | sections.append(qt_section_chunk(last_len, QStringRef(this, last_m, m - last_m))); | - | ||||||||||||||||||
| 4259 | last_m = m; | - | ||||||||||||||||||
| 4260 | last_len = sep.matchedLength(); | - | ||||||||||||||||||
| 4261 | m += qMax(sep.matchedLength(), 1); | - | ||||||||||||||||||
| 4262 | } executed 277 times by 2 tests: end of blockExecuted by:
| 277 | ||||||||||||||||||
| 4263 | sections.append(qt_section_chunk(last_len, QStringRef(this, last_m, n - last_m))); | - | ||||||||||||||||||
| 4264 | - | |||||||||||||||||||
| 4265 | return extractSections(sections, start, end, flags); executed 48 times by 2 tests: return extractSections(sections, start, end, flags);Executed by:
| 48 | ||||||||||||||||||
| 4266 | } | - | ||||||||||||||||||
| 4267 | #endif | - | ||||||||||||||||||
| 4268 | - | |||||||||||||||||||
| 4269 | #ifndef QT_NO_REGULAREXPRESSION | - | ||||||||||||||||||
| 4270 | #ifndef QT_BOOTSTRAPPED | - | ||||||||||||||||||
| 4271 | /*! | - | ||||||||||||||||||
| 4272 | \overload section() | - | ||||||||||||||||||
| 4273 | \since 5.0 | - | ||||||||||||||||||
| 4274 | - | |||||||||||||||||||
| 4275 | This string is treated as a sequence of fields separated by the | - | ||||||||||||||||||
| 4276 | regular expression, \a re. | - | ||||||||||||||||||
| 4277 | - | |||||||||||||||||||
| 4278 | \snippet qstring/main.cpp 89 | - | ||||||||||||||||||
| 4279 | - | |||||||||||||||||||
| 4280 | \warning Using this QRegularExpression version is much more expensive than | - | ||||||||||||||||||
| 4281 | the overloaded string and character versions. | - | ||||||||||||||||||
| 4282 | - | |||||||||||||||||||
| 4283 | \sa split(), simplified() | - | ||||||||||||||||||
| 4284 | */ | - | ||||||||||||||||||
| 4285 | QString QString::section(const QRegularExpression &re, int start, int end, SectionFlags flags) const | - | ||||||||||||||||||
| 4286 | { | - | ||||||||||||||||||
| 4287 | if (!re.isValid()) {
| 0-42 | ||||||||||||||||||
| 4288 | qWarning("QString::section: invalid QRegularExpression object"); | - | ||||||||||||||||||
| 4289 | return QString(); never executed: return QString(); | 0 | ||||||||||||||||||
| 4290 | } | - | ||||||||||||||||||
| 4291 | - | |||||||||||||||||||
| 4292 | const QChar *uc = unicode(); | - | ||||||||||||||||||
| 4293 | if (!uc)
| 0-42 | ||||||||||||||||||
| 4294 | return QString(); never executed: return QString(); | 0 | ||||||||||||||||||
| 4295 | - | |||||||||||||||||||
| 4296 | QRegularExpression sep(re); | - | ||||||||||||||||||
| 4297 | if (flags & SectionCaseInsensitiveSeps)
| 1-41 | ||||||||||||||||||
| 4298 | sep.setPatternOptions(sep.patternOptions() | QRegularExpression::CaseInsensitiveOption); executed 1 time by 1 test: sep.setPatternOptions(sep.patternOptions() | QRegularExpression::CaseInsensitiveOption);Executed by:
| 1 | ||||||||||||||||||
| 4299 | - | |||||||||||||||||||
| 4300 | QVector<qt_section_chunk> sections; | - | ||||||||||||||||||
| 4301 | int n = length(), m = 0, last_m = 0, last_len = 0; | - | ||||||||||||||||||
| 4302 | QRegularExpressionMatchIterator iterator = sep.globalMatch(*this); | - | ||||||||||||||||||
| 4303 | while (iterator.hasNext()) {
| 42-271 | ||||||||||||||||||
| 4304 | QRegularExpressionMatch match = iterator.next(); | - | ||||||||||||||||||
| 4305 | m = match.capturedStart(); | - | ||||||||||||||||||
| 4306 | sections.append(qt_section_chunk(last_len, QStringRef(this, last_m, m - last_m))); | - | ||||||||||||||||||
| 4307 | last_m = m; | - | ||||||||||||||||||
| 4308 | last_len = match.capturedLength(); | - | ||||||||||||||||||
| 4309 | } executed 271 times by 1 test: end of blockExecuted by:
| 271 | ||||||||||||||||||
| 4310 | sections.append(qt_section_chunk(last_len, QStringRef(this, last_m, n - last_m))); | - | ||||||||||||||||||
| 4311 | - | |||||||||||||||||||
| 4312 | return extractSections(sections, start, end, flags); executed 42 times by 1 test: return extractSections(sections, start, end, flags);Executed by:
| 42 | ||||||||||||||||||
| 4313 | } | - | ||||||||||||||||||
| 4314 | #endif // QT_BOOTSTRAPPED | - | ||||||||||||||||||
| 4315 | #endif // QT_NO_REGULAREXPRESSION | - | ||||||||||||||||||
| 4316 | - | |||||||||||||||||||
| 4317 | /*! | - | ||||||||||||||||||
| 4318 | Returns a substring that contains the \a n leftmost characters | - | ||||||||||||||||||
| 4319 | of the string. | - | ||||||||||||||||||
| 4320 | - | |||||||||||||||||||
| 4321 | The entire string is returned if \a n is greater than or equal | - | ||||||||||||||||||
| 4322 | to size(), or less than zero. | - | ||||||||||||||||||
| 4323 | - | |||||||||||||||||||
| 4324 | \snippet qstring/main.cpp 31 | - | ||||||||||||||||||
| 4325 | - | |||||||||||||||||||
| 4326 | \sa right(), mid(), startsWith() | - | ||||||||||||||||||
| 4327 | */ | - | ||||||||||||||||||
| 4328 | QString QString::left(int n) const | - | ||||||||||||||||||
| 4329 | { | - | ||||||||||||||||||
| 4330 | if (uint(n) >= uint(d->size))
| 38684-82353 | ||||||||||||||||||
| 4331 | return *this; executed 38684 times by 85 tests: return *this;Executed by:
| 38684 | ||||||||||||||||||
| 4332 | return QString((const QChar*) d->data(), n); executed 82353 times by 198 tests: return QString((const QChar*) d->data(), n);Executed by:
| 82353 | ||||||||||||||||||
| 4333 | } | - | ||||||||||||||||||
| 4334 | - | |||||||||||||||||||
| 4335 | /*! | - | ||||||||||||||||||
| 4336 | Returns a substring that contains the \a n rightmost characters | - | ||||||||||||||||||
| 4337 | of the string. | - | ||||||||||||||||||
| 4338 | - | |||||||||||||||||||
| 4339 | The entire string is returned if \a n is greater than or equal | - | ||||||||||||||||||
| 4340 | to size(), or less than zero. | - | ||||||||||||||||||
| 4341 | - | |||||||||||||||||||
| 4342 | \snippet qstring/main.cpp 48 | - | ||||||||||||||||||
| 4343 | - | |||||||||||||||||||
| 4344 | \sa left(), mid(), endsWith() | - | ||||||||||||||||||
| 4345 | */ | - | ||||||||||||||||||
| 4346 | QString QString::right(int n) const | - | ||||||||||||||||||
| 4347 | { | - | ||||||||||||||||||
| 4348 | if (uint(n) >= uint(d->size))
| 62-4888 | ||||||||||||||||||
| 4349 | return *this; executed 62 times by 3 tests: return *this;Executed by:
| 62 | ||||||||||||||||||
| 4350 | return QString((const QChar*) d->data() + d->size - n, n); executed 4888 times by 32 tests: return QString((const QChar*) d->data() + d->size - n, n);Executed by:
| 4888 | ||||||||||||||||||
| 4351 | } | - | ||||||||||||||||||
| 4352 | - | |||||||||||||||||||
| 4353 | /*! | - | ||||||||||||||||||
| 4354 | Returns a string that contains \a n characters of this string, | - | ||||||||||||||||||
| 4355 | starting at the specified \a position index. | - | ||||||||||||||||||
| 4356 | - | |||||||||||||||||||
| 4357 | Returns a null string if the \a position index exceeds the | - | ||||||||||||||||||
| 4358 | length of the string. If there are less than \a n characters | - | ||||||||||||||||||
| 4359 | available in the string starting at the given \a position, or if | - | ||||||||||||||||||
| 4360 | \a n is -1 (default), the function returns all characters that | - | ||||||||||||||||||
| 4361 | are available from the specified \a position. | - | ||||||||||||||||||
| 4362 | - | |||||||||||||||||||
| 4363 | Example: | - | ||||||||||||||||||
| 4364 | - | |||||||||||||||||||
| 4365 | \snippet qstring/main.cpp 34 | - | ||||||||||||||||||
| 4366 | - | |||||||||||||||||||
| 4367 | \sa left(), right() | - | ||||||||||||||||||
| 4368 | */ | - | ||||||||||||||||||
| 4369 | - | |||||||||||||||||||
| 4370 | QString QString::mid(int position, int n) const | - | ||||||||||||||||||
| 4371 | { | - | ||||||||||||||||||
| 4372 | using namespace QtPrivate; | - | ||||||||||||||||||
| 4373 | switch (QContainerImplHelper::mid(d->size, &position, &n)) { | - | ||||||||||||||||||
| 4374 | case QContainerImplHelper::Null: executed 12345 times by 7 tests: case QContainerImplHelper::Null:Executed by:
| 12345 | ||||||||||||||||||
| 4375 | return QString(); executed 12345 times by 7 tests: return QString();Executed by:
| 12345 | ||||||||||||||||||
| 4376 | case QContainerImplHelper::Empty: executed 11669 times by 196 tests: case QContainerImplHelper::Empty:Executed by:
| 11669 | ||||||||||||||||||
| 4377 | { | - | ||||||||||||||||||
| 4378 | QStringDataPtr empty = { Data::allocate(0) }; | - | ||||||||||||||||||
| 4379 | return QString(empty); executed 11669 times by 196 tests: return QString(empty);Executed by:
| 11669 | ||||||||||||||||||
| 4380 | } | - | ||||||||||||||||||
| 4381 | case QContainerImplHelper::Full: executed 109317 times by 229 tests: case QContainerImplHelper::Full:Executed by:
| 109317 | ||||||||||||||||||
| 4382 | return *this; executed 109317 times by 229 tests: return *this;Executed by:
| 109317 | ||||||||||||||||||
| 4383 | case QContainerImplHelper::Subset: executed 910993 times by 339 tests: case QContainerImplHelper::Subset:Executed by:
| 910993 | ||||||||||||||||||
| 4384 | return QString((const QChar*)d->data() + position, n); executed 910993 times by 339 tests: return QString((const QChar*)d->data() + position, n);Executed by:
| 910993 | ||||||||||||||||||
| 4385 | } | - | ||||||||||||||||||
| 4386 | Q_UNREACHABLE(); | - | ||||||||||||||||||
| 4387 | return QString(); never executed: return QString(); | 0 | ||||||||||||||||||
| 4388 | } | - | ||||||||||||||||||
| 4389 | - | |||||||||||||||||||
| 4390 | /*! | - | ||||||||||||||||||
| 4391 | Returns \c true if the string starts with \a s; otherwise returns | - | ||||||||||||||||||
| 4392 | \c false. | - | ||||||||||||||||||
| 4393 | - | |||||||||||||||||||
| 4394 | If \a cs is Qt::CaseSensitive (default), the search is | - | ||||||||||||||||||
| 4395 | case sensitive; otherwise the search is case insensitive. | - | ||||||||||||||||||
| 4396 | - | |||||||||||||||||||
| 4397 | \snippet qstring/main.cpp 65 | - | ||||||||||||||||||
| 4398 | - | |||||||||||||||||||
| 4399 | \sa endsWith() | - | ||||||||||||||||||
| 4400 | */ | - | ||||||||||||||||||
| 4401 | bool QString::startsWith(const QString& s, Qt::CaseSensitivity cs) const | - | ||||||||||||||||||
| 4402 | { | - | ||||||||||||||||||
| 4403 | return qt_starts_with(isNull() ? 0 : unicode(), size(), executed 260839 times by 122 tests: return qt_starts_with(isNull() ? 0 : unicode(), size(), s.isNull() ? 0 : s.unicode(), s.size(), cs);Executed by:
| 260839 | ||||||||||||||||||
| 4404 | s.isNull() ? 0 : s.unicode(), s.size(), cs); executed 260839 times by 122 tests: return qt_starts_with(isNull() ? 0 : unicode(), size(), s.isNull() ? 0 : s.unicode(), s.size(), cs);Executed by:
| 260839 | ||||||||||||||||||
| 4405 | } | - | ||||||||||||||||||
| 4406 | - | |||||||||||||||||||
| 4407 | /*! | - | ||||||||||||||||||
| 4408 | \overload startsWith() | - | ||||||||||||||||||
| 4409 | */ | - | ||||||||||||||||||
| 4410 | bool QString::startsWith(QLatin1String s, Qt::CaseSensitivity cs) const | - | ||||||||||||||||||
| 4411 | { | - | ||||||||||||||||||
| 4412 | return qt_starts_with(isNull() ? 0 : unicode(), size(), s, cs); executed 271321 times by 235 tests: return qt_starts_with(isNull() ? 0 : unicode(), size(), s, cs);Executed by:
| 271321 | ||||||||||||||||||
| 4413 | } | - | ||||||||||||||||||
| 4414 | - | |||||||||||||||||||
| 4415 | /*! | - | ||||||||||||||||||
| 4416 | \overload startsWith() | - | ||||||||||||||||||
| 4417 | - | |||||||||||||||||||
| 4418 | Returns \c true if the string starts with \a c; otherwise returns | - | ||||||||||||||||||
| 4419 | \c false. | - | ||||||||||||||||||
| 4420 | */ | - | ||||||||||||||||||
| 4421 | bool QString::startsWith(QChar c, Qt::CaseSensitivity cs) const | - | ||||||||||||||||||
| 4422 | { | - | ||||||||||||||||||
| 4423 | return d->size executed 491395 times by 270 tests: return d->size && (cs == Qt::CaseSensitive ? d->data()[0] == c : foldCase(d->data()[0]) == foldCase(c.unicode()));Executed by:
| 4431-491395 | ||||||||||||||||||
| 4424 | && (cs == Qt::CaseSensitive executed 491395 times by 270 tests: return d->size && (cs == Qt::CaseSensitive ? d->data()[0] == c : foldCase(d->data()[0]) == foldCase(c.unicode()));Executed by:
| 7-491395 | ||||||||||||||||||
| 4425 | ? d->data()[0] == c executed 491395 times by 270 tests: return d->size && (cs == Qt::CaseSensitive ? d->data()[0] == c : foldCase(d->data()[0]) == foldCase(c.unicode()));Executed by:
| 204081-491395 | ||||||||||||||||||
| 4426 | : foldCase(d->data()[0]) == foldCase(c.unicode())); executed 491395 times by 270 tests: return d->size && (cs == Qt::CaseSensitive ? d->data()[0] == c : foldCase(d->data()[0]) == foldCase(c.unicode()));Executed by:
| 204081-491395 | ||||||||||||||||||
| 4427 | } | - | ||||||||||||||||||
| 4428 | - | |||||||||||||||||||
| 4429 | /*! | - | ||||||||||||||||||
| 4430 | \since 4.8 | - | ||||||||||||||||||
| 4431 | \overload | - | ||||||||||||||||||
| 4432 | Returns \c true if the string starts with the string reference \a s; | - | ||||||||||||||||||
| 4433 | otherwise returns \c false. | - | ||||||||||||||||||
| 4434 | - | |||||||||||||||||||
| 4435 | If \a cs is Qt::CaseSensitive (default), the search is case | - | ||||||||||||||||||
| 4436 | sensitive; otherwise the search is case insensitive. | - | ||||||||||||||||||
| 4437 | - | |||||||||||||||||||
| 4438 | \sa endsWith() | - | ||||||||||||||||||
| 4439 | */ | - | ||||||||||||||||||
| 4440 | bool QString::startsWith(const QStringRef &s, Qt::CaseSensitivity cs) const | - | ||||||||||||||||||
| 4441 | { | - | ||||||||||||||||||
| 4442 | return qt_starts_with(isNull() ? 0 : unicode(), size(), executed 4 times by 1 test: return qt_starts_with(isNull() ? 0 : unicode(), size(), s.isNull() ? 0 : s.unicode(), s.size(), cs);Executed by:
| 4 | ||||||||||||||||||
| 4443 | s.isNull() ? 0 : s.unicode(), s.size(), cs); executed 4 times by 1 test: return qt_starts_with(isNull() ? 0 : unicode(), size(), s.isNull() ? 0 : s.unicode(), s.size(), cs);Executed by:
| 4 | ||||||||||||||||||
| 4444 | } | - | ||||||||||||||||||
| 4445 | - | |||||||||||||||||||
| 4446 | /*! | - | ||||||||||||||||||
| 4447 | Returns \c true if the string ends with \a s; otherwise returns | - | ||||||||||||||||||
| 4448 | \c false. | - | ||||||||||||||||||
| 4449 | - | |||||||||||||||||||
| 4450 | If \a cs is Qt::CaseSensitive (default), the search is case | - | ||||||||||||||||||
| 4451 | sensitive; otherwise the search is case insensitive. | - | ||||||||||||||||||
| 4452 | - | |||||||||||||||||||
| 4453 | \snippet qstring/main.cpp 20 | - | ||||||||||||||||||
| 4454 | - | |||||||||||||||||||
| 4455 | \sa startsWith() | - | ||||||||||||||||||
| 4456 | */ | - | ||||||||||||||||||
| 4457 | bool QString::endsWith(const QString& s, Qt::CaseSensitivity cs) const | - | ||||||||||||||||||
| 4458 | { | - | ||||||||||||||||||
| 4459 | return qt_ends_with(isNull() ? 0 : unicode(), size(), executed 4627 times by 69 tests: return qt_ends_with(isNull() ? 0 : unicode(), size(), s.isNull() ? 0 : s.unicode(), s.size(), cs);Executed by:
| 4627 | ||||||||||||||||||
| 4460 | s.isNull() ? 0 : s.unicode(), s.size(), cs); executed 4627 times by 69 tests: return qt_ends_with(isNull() ? 0 : unicode(), size(), s.isNull() ? 0 : s.unicode(), s.size(), cs);Executed by:
| 4627 | ||||||||||||||||||
| 4461 | } | - | ||||||||||||||||||
| 4462 | - | |||||||||||||||||||
| 4463 | /*! | - | ||||||||||||||||||
| 4464 | \since 4.8 | - | ||||||||||||||||||
| 4465 | \overload endsWith() | - | ||||||||||||||||||
| 4466 | Returns \c true if the string ends with the string reference \a s; | - | ||||||||||||||||||
| 4467 | otherwise returns \c false. | - | ||||||||||||||||||
| 4468 | - | |||||||||||||||||||
| 4469 | If \a cs is Qt::CaseSensitive (default), the search is case | - | ||||||||||||||||||
| 4470 | sensitive; otherwise the search is case insensitive. | - | ||||||||||||||||||
| 4471 | - | |||||||||||||||||||
| 4472 | \sa startsWith() | - | ||||||||||||||||||
| 4473 | */ | - | ||||||||||||||||||
| 4474 | bool QString::endsWith(const QStringRef &s, Qt::CaseSensitivity cs) const | - | ||||||||||||||||||
| 4475 | { | - | ||||||||||||||||||
| 4476 | return qt_ends_with(isNull() ? 0 : unicode(), size(), executed 6 times by 1 test: return qt_ends_with(isNull() ? 0 : unicode(), size(), s.isNull() ? 0 : s.unicode(), s.size(), cs);Executed by:
| 6 | ||||||||||||||||||
| 4477 | s.isNull() ? 0 : s.unicode(), s.size(), cs); executed 6 times by 1 test: return qt_ends_with(isNull() ? 0 : unicode(), size(), s.isNull() ? 0 : s.unicode(), s.size(), cs);Executed by:
| 6 | ||||||||||||||||||
| 4478 | } | - | ||||||||||||||||||
| 4479 | - | |||||||||||||||||||
| 4480 | - | |||||||||||||||||||
| 4481 | /*! | - | ||||||||||||||||||
| 4482 | \overload endsWith() | - | ||||||||||||||||||
| 4483 | */ | - | ||||||||||||||||||
| 4484 | bool QString::endsWith(QLatin1String s, Qt::CaseSensitivity cs) const | - | ||||||||||||||||||
| 4485 | { | - | ||||||||||||||||||
| 4486 | return qt_ends_with(isNull() ? 0 : unicode(), size(), s, cs); executed 49832 times by 121 tests: return qt_ends_with(isNull() ? 0 : unicode(), size(), s, cs);Executed by:
| 49832 | ||||||||||||||||||
| 4487 | } | - | ||||||||||||||||||
| 4488 | - | |||||||||||||||||||
| 4489 | /*! | - | ||||||||||||||||||
| 4490 | Returns \c true if the string ends with \a c; otherwise returns | - | ||||||||||||||||||
| 4491 | \c false. | - | ||||||||||||||||||
| 4492 | - | |||||||||||||||||||
| 4493 | \overload endsWith() | - | ||||||||||||||||||
| 4494 | */ | - | ||||||||||||||||||
| 4495 | bool QString::endsWith(QChar c, Qt::CaseSensitivity cs) const | - | ||||||||||||||||||
| 4496 | { | - | ||||||||||||||||||
| 4497 | return d->size executed 278838 times by 335 tests: return d->size && (cs == Qt::CaseSensitive ? d->data()[d->size - 1] == c : foldCase(d->data()[d->size - 1]) == foldCase(c.unicode()));Executed by:
| 676-278838 | ||||||||||||||||||
| 4498 | && (cs == Qt::CaseSensitive executed 278838 times by 335 tests: return d->size && (cs == Qt::CaseSensitive ? d->data()[d->size - 1] == c : foldCase(d->data()[d->size - 1]) == foldCase(c.unicode()));Executed by:
| 7-278838 | ||||||||||||||||||
| 4499 | ? d->data()[d->size - 1] == c executed 278838 times by 335 tests: return d->size && (cs == Qt::CaseSensitive ? d->data()[d->size - 1] == c : foldCase(d->data()[d->size - 1]) == foldCase(c.unicode()));Executed by:
| 47682-278838 | ||||||||||||||||||
| 4500 | : foldCase(d->data()[d->size - 1]) == foldCase(c.unicode())); executed 278838 times by 335 tests: return d->size && (cs == Qt::CaseSensitive ? d->data()[d->size - 1] == c : foldCase(d->data()[d->size - 1]) == foldCase(c.unicode()));Executed by:
| 47682-278838 | ||||||||||||||||||
| 4501 | } | - | ||||||||||||||||||
| 4502 | - | |||||||||||||||||||
| 4503 | QByteArray QString::toLatin1_helper(const QString &string) | - | ||||||||||||||||||
| 4504 | { | - | ||||||||||||||||||
| 4505 | if (Q_UNLIKELY(string.isNull()))
| 6199-237874 | ||||||||||||||||||
| 4506 | return QByteArray(); executed 6199 times by 166 tests: return QByteArray();Executed by:
| 6199 | ||||||||||||||||||
| 4507 | - | |||||||||||||||||||
| 4508 | return toLatin1_helper(string.constData(), string.length()); executed 237874 times by 434 tests: return toLatin1_helper(string.constData(), string.length());Executed by:
| 237874 | ||||||||||||||||||
| 4509 | } | - | ||||||||||||||||||
| 4510 | - | |||||||||||||||||||
| 4511 | QByteArray QString::toLatin1_helper(const QChar *data, int length) | - | ||||||||||||||||||
| 4512 | { | - | ||||||||||||||||||
| 4513 | QByteArray ba(length, Qt::Uninitialized); | - | ||||||||||||||||||
| 4514 | - | |||||||||||||||||||
| 4515 | // since we own the only copy, we're going to const_cast the constData; | - | ||||||||||||||||||
| 4516 | // that avoids an unnecessary call to detach() and expansion code that will never get used | - | ||||||||||||||||||
| 4517 | qt_to_latin1(reinterpret_cast<uchar *>(const_cast<char *>(ba.constData())), | - | ||||||||||||||||||
| 4518 | reinterpret_cast<const ushort *>(data), length); | - | ||||||||||||||||||
| 4519 | return ba; executed 238133 times by 435 tests: return ba;Executed by:
| 238133 | ||||||||||||||||||
| 4520 | } | - | ||||||||||||||||||
| 4521 | - | |||||||||||||||||||
| 4522 | QByteArray QString::toLatin1_helper_inplace(QString &s) | - | ||||||||||||||||||
| 4523 | { | - | ||||||||||||||||||
| 4524 | if (!s.isDetached())
| 30170-51527 | ||||||||||||||||||
| 4525 | return s.toLatin1(); executed 30170 times by 159 tests: return s.toLatin1();Executed by:
| 30170 | ||||||||||||||||||
| 4526 | - | |||||||||||||||||||
| 4527 | // We can return our own buffer to the caller. | - | ||||||||||||||||||
| 4528 | // Conversion to Latin-1 always shrinks the buffer by half. | - | ||||||||||||||||||
| 4529 | const ushort *data = reinterpret_cast<const ushort *>(s.constData()); | - | ||||||||||||||||||
| 4530 | uint length = s.size(); | - | ||||||||||||||||||
| 4531 | - | |||||||||||||||||||
| 4532 | // Swap the d pointers. | - | ||||||||||||||||||
| 4533 | // Kids, avert your eyes. Don't try this at home. | - | ||||||||||||||||||
| 4534 | QArrayData *ba_d = s.d; | - | ||||||||||||||||||
| 4535 | - | |||||||||||||||||||
| 4536 | // multiply the allocated capacity by sizeof(ushort) | - | ||||||||||||||||||
| 4537 | ba_d->alloc *= sizeof(ushort); | - | ||||||||||||||||||
| 4538 | - | |||||||||||||||||||
| 4539 | // reset ourselves to QString() | - | ||||||||||||||||||
| 4540 | s.d = QString().d; | - | ||||||||||||||||||
| 4541 | - | |||||||||||||||||||
| 4542 | // do the in-place conversion | - | ||||||||||||||||||
| 4543 | uchar *dst = reinterpret_cast<uchar *>(ba_d->data()); | - | ||||||||||||||||||
| 4544 | qt_to_latin1(dst, data, length); | - | ||||||||||||||||||
| 4545 | dst[length] = '\0'; | - | ||||||||||||||||||
| 4546 | - | |||||||||||||||||||
| 4547 | QByteArrayDataPtr badptr = { ba_d }; | - | ||||||||||||||||||
| 4548 | return QByteArray(badptr); executed 51527 times by 135 tests: return QByteArray(badptr);Executed by:
| 51527 | ||||||||||||||||||
| 4549 | } | - | ||||||||||||||||||
| 4550 | - | |||||||||||||||||||
| 4551 | - | |||||||||||||||||||
| 4552 | /*! | - | ||||||||||||||||||
| 4553 | \fn QByteArray QString::toLatin1() const | - | ||||||||||||||||||
| 4554 | - | |||||||||||||||||||
| 4555 | Returns a Latin-1 representation of the string as a QByteArray. | - | ||||||||||||||||||
| 4556 | - | |||||||||||||||||||
| 4557 | The returned byte array is undefined if the string contains non-Latin1 | - | ||||||||||||||||||
| 4558 | characters. Those characters may be suppressed or replaced with a | - | ||||||||||||||||||
| 4559 | question mark. | - | ||||||||||||||||||
| 4560 | - | |||||||||||||||||||
| 4561 | \sa fromLatin1(), toUtf8(), toLocal8Bit(), QTextCodec | - | ||||||||||||||||||
| 4562 | */ | - | ||||||||||||||||||
| 4563 | - | |||||||||||||||||||
| 4564 | /*! | - | ||||||||||||||||||
| 4565 | \fn QByteArray QString::toAscii() const | - | ||||||||||||||||||
| 4566 | \deprecated | - | ||||||||||||||||||
| 4567 | Returns an 8-bit representation of the string as a QByteArray. | - | ||||||||||||||||||
| 4568 | - | |||||||||||||||||||
| 4569 | This function does the same as toLatin1(). | - | ||||||||||||||||||
| 4570 | - | |||||||||||||||||||
| 4571 | Note that, despite the name, this function does not necessarily return an US-ASCII | - | ||||||||||||||||||
| 4572 | (ANSI X3.4-1986) string and its result may not be US-ASCII compatible. | - | ||||||||||||||||||
| 4573 | - | |||||||||||||||||||
| 4574 | \sa fromAscii(), toLatin1(), toUtf8(), toLocal8Bit(), QTextCodec | - | ||||||||||||||||||
| 4575 | */ | - | ||||||||||||||||||
| 4576 | - | |||||||||||||||||||
| 4577 | /*! | - | ||||||||||||||||||
| 4578 | \fn QByteArray QString::toLocal8Bit() const | - | ||||||||||||||||||
| 4579 | - | |||||||||||||||||||
| 4580 | Returns the local 8-bit representation of the string as a | - | ||||||||||||||||||
| 4581 | QByteArray. The returned byte array is undefined if the string | - | ||||||||||||||||||
| 4582 | contains characters not supported by the local 8-bit encoding. | - | ||||||||||||||||||
| 4583 | - | |||||||||||||||||||
| 4584 | QTextCodec::codecForLocale() is used to perform the conversion from | - | ||||||||||||||||||
| 4585 | Unicode. If the locale encoding could not be determined, this function | - | ||||||||||||||||||
| 4586 | does the same as toLatin1(). | - | ||||||||||||||||||
| 4587 | - | |||||||||||||||||||
| 4588 | If this string contains any characters that cannot be encoded in the | - | ||||||||||||||||||
| 4589 | locale, the returned byte array is undefined. Those characters may be | - | ||||||||||||||||||
| 4590 | suppressed or replaced by another. | - | ||||||||||||||||||
| 4591 | - | |||||||||||||||||||
| 4592 | \sa fromLocal8Bit(), toLatin1(), toUtf8(), QTextCodec | - | ||||||||||||||||||
| 4593 | */ | - | ||||||||||||||||||
| 4594 | - | |||||||||||||||||||
| 4595 | QByteArray QString::toLocal8Bit_helper(const QChar *data, int size) | - | ||||||||||||||||||
| 4596 | { | - | ||||||||||||||||||
| 4597 | #ifndef QT_NO_TEXTCODEC | - | ||||||||||||||||||
| 4598 | QTextCodec *localeCodec = QTextCodec::codecForLocale(); | - | ||||||||||||||||||
| 4599 | if (localeCodec)
| 3-556603 | ||||||||||||||||||
| 4600 | return localeCodec->fromUnicode(data, size); executed 556603 times by 408 tests: return localeCodec->fromUnicode(data, size);Executed by:
| 556603 | ||||||||||||||||||
| 4601 | #endif // QT_NO_TEXTCODEC | - | ||||||||||||||||||
| 4602 | return toLatin1_helper(data, size); executed 3 times by 1 test: return toLatin1_helper(data, size);Executed by:
| 3 | ||||||||||||||||||
| 4603 | } | - | ||||||||||||||||||
| 4604 | - | |||||||||||||||||||
| 4605 | - | |||||||||||||||||||
| 4606 | /*! | - | ||||||||||||||||||
| 4607 | \fn QByteArray QString::toUtf8() const | - | ||||||||||||||||||
| 4608 | - | |||||||||||||||||||
| 4609 | Returns a UTF-8 representation of the string as a QByteArray. | - | ||||||||||||||||||
| 4610 | - | |||||||||||||||||||
| 4611 | UTF-8 is a Unicode codec and can represent all characters in a Unicode | - | ||||||||||||||||||
| 4612 | string like QString. | - | ||||||||||||||||||
| 4613 | - | |||||||||||||||||||
| 4614 | \sa fromUtf8(), toLatin1(), toLocal8Bit(), QTextCodec | - | ||||||||||||||||||
| 4615 | */ | - | ||||||||||||||||||
| 4616 | - | |||||||||||||||||||
| 4617 | QByteArray QString::toUtf8_helper(const QString &str) | - | ||||||||||||||||||
| 4618 | { | - | ||||||||||||||||||
| 4619 | if (str.isNull())
| 5786-109953 | ||||||||||||||||||
| 4620 | return QByteArray(); executed 5786 times by 155 tests: return QByteArray();Executed by:
| 5786 | ||||||||||||||||||
| 4621 | - | |||||||||||||||||||
| 4622 | return QUtf8::convertFromUnicode(str.constData(), str.length()); executed 109953 times by 247 tests: return QUtf8::convertFromUnicode(str.constData(), str.length());Executed by:
| 109953 | ||||||||||||||||||
| 4623 | } | - | ||||||||||||||||||
| 4624 | - | |||||||||||||||||||
| 4625 | /*! | - | ||||||||||||||||||
| 4626 | \since 4.2 | - | ||||||||||||||||||
| 4627 | - | |||||||||||||||||||
| 4628 | Returns a UCS-4/UTF-32 representation of the string as a QVector<uint>. | - | ||||||||||||||||||
| 4629 | - | |||||||||||||||||||
| 4630 | UCS-4 is a Unicode codec and therefore it is lossless. All characters from | - | ||||||||||||||||||
| 4631 | this string will be encoded in UCS-4. Any invalid sequence of code units in | - | ||||||||||||||||||
| 4632 | this string is replaced by the Unicode's replacement character | - | ||||||||||||||||||
| 4633 | (QChar::ReplacementCharacter, which corresponds to \c{U+FFFD}). | - | ||||||||||||||||||
| 4634 | - | |||||||||||||||||||
| 4635 | The returned vector is not NUL terminated. | - | ||||||||||||||||||
| 4636 | - | |||||||||||||||||||
| 4637 | \sa fromUtf8(), toUtf8(), toLatin1(), toLocal8Bit(), QTextCodec, fromUcs4(), toWCharArray() | - | ||||||||||||||||||
| 4638 | */ | - | ||||||||||||||||||
| 4639 | QVector<uint> QString::toUcs4() const | - | ||||||||||||||||||
| 4640 | { | - | ||||||||||||||||||
| 4641 | QVector<uint> v(length()); | - | ||||||||||||||||||
| 4642 | uint *a = v.data(); | - | ||||||||||||||||||
| 4643 | int len = toUcs4_helper(d->data(), length(), a); | - | ||||||||||||||||||
| 4644 | v.resize(len); | - | ||||||||||||||||||
| 4645 | return v; executed 10 times by 1 test: return v;Executed by:
| 10 | ||||||||||||||||||
| 4646 | } | - | ||||||||||||||||||
| 4647 | - | |||||||||||||||||||
| 4648 | QString::Data *QString::fromLatin1_helper(const char *str, int size) | - | ||||||||||||||||||
| 4649 | { | - | ||||||||||||||||||
| 4650 | Data *d; | - | ||||||||||||||||||
| 4651 | if (!str) {
| 103-1844871 | ||||||||||||||||||
| 4652 | d = Data::sharedNull(); | - | ||||||||||||||||||
| 4653 | } else if (size == 0 || (!*str && size < 0)) { executed 103 times by 7 tests: end of blockExecuted by:
| 0-1820269 | ||||||||||||||||||
| 4654 | d = Data::allocate(0); | - | ||||||||||||||||||
| 4655 | } else { executed 24602 times by 473 tests: end of blockExecuted by:
| 24602 | ||||||||||||||||||
| 4656 | if (size < 0)
| 0-1820269 | ||||||||||||||||||
| 4657 | size = qstrlen(str); never executed: size = qstrlen(str); | 0 | ||||||||||||||||||
| 4658 | d = Data::allocate(size + 1); | - | ||||||||||||||||||
| 4659 | Q_CHECK_PTR(d); never executed: qBadAlloc();
| 0-1820269 | ||||||||||||||||||
| 4660 | d->size = size; | - | ||||||||||||||||||
| 4661 | d->data()[size] = '\0'; | - | ||||||||||||||||||
| 4662 | ushort *dst = d->data(); | - | ||||||||||||||||||
| 4663 | - | |||||||||||||||||||
| 4664 | qt_from_latin1(dst, str, uint(size)); | - | ||||||||||||||||||
| 4665 | } executed 1820269 times by 720 tests: end of blockExecuted by:
| 1820269 | ||||||||||||||||||
| 4666 | return d; executed 1844974 times by 720 tests: return d;Executed by:
| 1844974 | ||||||||||||||||||
| 4667 | } | - | ||||||||||||||||||
| 4668 | - | |||||||||||||||||||
| 4669 | QString::Data *QString::fromAscii_helper(const char *str, int size) | - | ||||||||||||||||||
| 4670 | { | - | ||||||||||||||||||
| 4671 | QString s = fromUtf8(str, size); | - | ||||||||||||||||||
| 4672 | s.d->ref.ref(); | - | ||||||||||||||||||
| 4673 | return s.d; executed 4790842 times by 345 tests: return s.d;Executed by:
| 4790842 | ||||||||||||||||||
| 4674 | } | - | ||||||||||||||||||
| 4675 | - | |||||||||||||||||||
| 4676 | /*! \fn QString QString::fromLatin1(const char *str, int size) | - | ||||||||||||||||||
| 4677 | Returns a QString initialized with the first \a size characters | - | ||||||||||||||||||
| 4678 | of the Latin-1 string \a str. | - | ||||||||||||||||||
| 4679 | - | |||||||||||||||||||
| 4680 | If \a size is -1 (default), it is taken to be strlen(\a | - | ||||||||||||||||||
| 4681 | str). | - | ||||||||||||||||||
| 4682 | - | |||||||||||||||||||
| 4683 | \sa toLatin1(), fromUtf8(), fromLocal8Bit() | - | ||||||||||||||||||
| 4684 | */ | - | ||||||||||||||||||
| 4685 | - | |||||||||||||||||||
| 4686 | /*! | - | ||||||||||||||||||
| 4687 | \fn QString QString::fromLatin1(const QByteArray &str) | - | ||||||||||||||||||
| 4688 | \overload | - | ||||||||||||||||||
| 4689 | \since 5.0 | - | ||||||||||||||||||
| 4690 | - | |||||||||||||||||||
| 4691 | Returns a QString initialized with the Latin-1 string \a str. | - | ||||||||||||||||||
| 4692 | */ | - | ||||||||||||||||||
| 4693 | - | |||||||||||||||||||
| 4694 | /*! \fn QString QString::fromLocal8Bit(const char *str, int size) | - | ||||||||||||||||||
| 4695 | Returns a QString initialized with the first \a size characters | - | ||||||||||||||||||
| 4696 | of the 8-bit string \a str. | - | ||||||||||||||||||
| 4697 | - | |||||||||||||||||||
| 4698 | If \a size is -1 (default), it is taken to be strlen(\a | - | ||||||||||||||||||
| 4699 | str). | - | ||||||||||||||||||
| 4700 | - | |||||||||||||||||||
| 4701 | QTextCodec::codecForLocale() is used to perform the conversion. | - | ||||||||||||||||||
| 4702 | - | |||||||||||||||||||
| 4703 | \sa toLocal8Bit(), fromLatin1(), fromUtf8() | - | ||||||||||||||||||
| 4704 | */ | - | ||||||||||||||||||
| 4705 | - | |||||||||||||||||||
| 4706 | /*! | - | ||||||||||||||||||
| 4707 | \fn QString QString::fromLocal8Bit(const QByteArray &str) | - | ||||||||||||||||||
| 4708 | \overload | - | ||||||||||||||||||
| 4709 | \since 5.0 | - | ||||||||||||||||||
| 4710 | - | |||||||||||||||||||
| 4711 | Returns a QString initialized with the 8-bit string \a str. | - | ||||||||||||||||||
| 4712 | */ | - | ||||||||||||||||||
| 4713 | QString QString::fromLocal8Bit_helper(const char *str, int size) | - | ||||||||||||||||||
| 4714 | { | - | ||||||||||||||||||
| 4715 | if (!str)
| 1-285178 | ||||||||||||||||||
| 4716 | return QString(); executed 1 time by 1 test: return QString();Executed by:
| 1 | ||||||||||||||||||
| 4717 | if (size == 0 || (!*str && size < 0)) {
| 0-284284 | ||||||||||||||||||
| 4718 | QStringDataPtr empty = { Data::allocate(0) }; | - | ||||||||||||||||||
| 4719 | return QString(empty); executed 894 times by 12 tests: return QString(empty);Executed by:
| 894 | ||||||||||||||||||
| 4720 | } | - | ||||||||||||||||||
| 4721 | #if !defined(QT_NO_TEXTCODEC) | - | ||||||||||||||||||
| 4722 | if (size < 0)
| 0-284284 | ||||||||||||||||||
| 4723 | size = qstrlen(str); never executed: size = qstrlen(str); | 0 | ||||||||||||||||||
| 4724 | QTextCodec *codec = QTextCodec::codecForLocale(); | - | ||||||||||||||||||
| 4725 | if (codec)
| 2-284282 | ||||||||||||||||||
| 4726 | return codec->toUnicode(str, size); executed 284282 times by 340 tests: return codec->toUnicode(str, size);Executed by:
| 284282 | ||||||||||||||||||
| 4727 | #endif // !QT_NO_TEXTCODEC | - | ||||||||||||||||||
| 4728 | return fromLatin1(str, size); executed 2 times by 1 test: return fromLatin1(str, size);Executed by:
| 2 | ||||||||||||||||||
| 4729 | } | - | ||||||||||||||||||
| 4730 | - | |||||||||||||||||||
| 4731 | /*! \fn QString QString::fromAscii(const char *, int size); | - | ||||||||||||||||||
| 4732 | \deprecated | - | ||||||||||||||||||
| 4733 | - | |||||||||||||||||||
| 4734 | Returns a QString initialized with the first \a size characters | - | ||||||||||||||||||
| 4735 | from the string \a str. | - | ||||||||||||||||||
| 4736 | - | |||||||||||||||||||
| 4737 | If \a size is -1 (default), it is taken to be strlen(\a | - | ||||||||||||||||||
| 4738 | str). | - | ||||||||||||||||||
| 4739 | - | |||||||||||||||||||
| 4740 | This function does the same as fromLatin1(). | - | ||||||||||||||||||
| 4741 | - | |||||||||||||||||||
| 4742 | \sa toAscii(), fromLatin1(), fromUtf8(), fromLocal8Bit() | - | ||||||||||||||||||
| 4743 | */ | - | ||||||||||||||||||
| 4744 | - | |||||||||||||||||||
| 4745 | /*! | - | ||||||||||||||||||
| 4746 | \fn QString QString::fromAscii(const QByteArray &str) | - | ||||||||||||||||||
| 4747 | \deprecated | - | ||||||||||||||||||
| 4748 | \overload | - | ||||||||||||||||||
| 4749 | \since 5.0 | - | ||||||||||||||||||
| 4750 | - | |||||||||||||||||||
| 4751 | Returns a QString initialized with the string \a str. | - | ||||||||||||||||||
| 4752 | */ | - | ||||||||||||||||||
| 4753 | - | |||||||||||||||||||
| 4754 | /*! \fn QString QString::fromUtf8(const char *str, int size) | - | ||||||||||||||||||
| 4755 | Returns a QString initialized with the first \a size bytes | - | ||||||||||||||||||
| 4756 | of the UTF-8 string \a str. | - | ||||||||||||||||||
| 4757 | - | |||||||||||||||||||
| 4758 | If \a size is -1 (default), it is taken to be strlen(\a | - | ||||||||||||||||||
| 4759 | str). | - | ||||||||||||||||||
| 4760 | - | |||||||||||||||||||
| 4761 | UTF-8 is a Unicode codec and can represent all characters in a Unicode | - | ||||||||||||||||||
| 4762 | string like QString. However, invalid sequences are possible with UTF-8 | - | ||||||||||||||||||
| 4763 | and, if any such are found, they will be replaced with one or more | - | ||||||||||||||||||
| 4764 | "replacement characters", or suppressed. These include non-Unicode | - | ||||||||||||||||||
| 4765 | sequences, non-characters, overlong sequences or surrogate codepoints | - | ||||||||||||||||||
| 4766 | encoded into UTF-8. | - | ||||||||||||||||||
| 4767 | - | |||||||||||||||||||
| 4768 | This function can be used to process incoming data incrementally as long as | - | ||||||||||||||||||
| 4769 | all UTF-8 characters are terminated within the incoming data. Any | - | ||||||||||||||||||
| 4770 | unterminated characters at the end of the string will be replaced or | - | ||||||||||||||||||
| 4771 | suppressed. In order to do stateful decoding, please use \l QTextDecoder. | - | ||||||||||||||||||
| 4772 | - | |||||||||||||||||||
| 4773 | \sa toUtf8(), fromLatin1(), fromLocal8Bit() | - | ||||||||||||||||||
| 4774 | */ | - | ||||||||||||||||||
| 4775 | - | |||||||||||||||||||
| 4776 | /*! | - | ||||||||||||||||||
| 4777 | \fn QString QString::fromUtf8(const QByteArray &str) | - | ||||||||||||||||||
| 4778 | \overload | - | ||||||||||||||||||
| 4779 | \since 5.0 | - | ||||||||||||||||||
| 4780 | - | |||||||||||||||||||
| 4781 | Returns a QString initialized with the UTF-8 string \a str. | - | ||||||||||||||||||
| 4782 | */ | - | ||||||||||||||||||
| 4783 | QString QString::fromUtf8_helper(const char *str, int size) | - | ||||||||||||||||||
| 4784 | { | - | ||||||||||||||||||
| 4785 | if (!str)
| 7629-7808200 | ||||||||||||||||||
| 4786 | return QString(); executed 7629 times by 297 tests: return QString();Executed by:
| 7629 | ||||||||||||||||||
| 4787 | - | |||||||||||||||||||
| 4788 | Q_ASSERT(size != -1); | - | ||||||||||||||||||
| 4789 | return QUtf8::convertToUnicode(str, size); executed 7808200 times by 550 tests: return QUtf8::convertToUnicode(str, size);Executed by:
| 7808200 | ||||||||||||||||||
| 4790 | } | - | ||||||||||||||||||
| 4791 | - | |||||||||||||||||||
| 4792 | /*! | - | ||||||||||||||||||
| 4793 | Returns a QString initialized with the first \a size characters | - | ||||||||||||||||||
| 4794 | of the Unicode string \a unicode (ISO-10646-UTF-16 encoded). | - | ||||||||||||||||||
| 4795 | - | |||||||||||||||||||
| 4796 | If \a size is -1 (default), \a unicode must be terminated | - | ||||||||||||||||||
| 4797 | with a 0. | - | ||||||||||||||||||
| 4798 | - | |||||||||||||||||||
| 4799 | This function checks for a Byte Order Mark (BOM). If it is missing, | - | ||||||||||||||||||
| 4800 | host byte order is assumed. | - | ||||||||||||||||||
| 4801 | - | |||||||||||||||||||
| 4802 | This function is slow compared to the other Unicode conversions. | - | ||||||||||||||||||
| 4803 | Use QString(const QChar *, int) or QString(const QChar *) if possible. | - | ||||||||||||||||||
| 4804 | - | |||||||||||||||||||
| 4805 | QString makes a deep copy of the Unicode data. | - | ||||||||||||||||||
| 4806 | - | |||||||||||||||||||
| 4807 | \sa utf16(), setUtf16(), fromStdU16String() | - | ||||||||||||||||||
| 4808 | */ | - | ||||||||||||||||||
| 4809 | QString QString::fromUtf16(const ushort *unicode, int size) | - | ||||||||||||||||||
| 4810 | { | - | ||||||||||||||||||
| 4811 | if (!unicode)
| 0-233804 | ||||||||||||||||||
| 4812 | return QString(); never executed: return QString(); | 0 | ||||||||||||||||||
| 4813 | if (size < 0) {
| 132-233672 | ||||||||||||||||||
| 4814 | size = 0; | - | ||||||||||||||||||
| 4815 | while (unicode[size] != 0)
| 132-625 | ||||||||||||||||||
| 4816 | ++size; executed 625 times by 8 tests: ++size;Executed by:
| 625 | ||||||||||||||||||
| 4817 | } executed 132 times by 8 tests: end of blockExecuted by:
| 132 | ||||||||||||||||||
| 4818 | return QUtf16::convertToUnicode((const char *)unicode, size*2, 0); executed 233804 times by 18 tests: return QUtf16::convertToUnicode((const char *)unicode, size*2, 0);Executed by:
| 233804 | ||||||||||||||||||
| 4819 | } | - | ||||||||||||||||||
| 4820 | - | |||||||||||||||||||
| 4821 | /*! | - | ||||||||||||||||||
| 4822 | \fn QString QString::fromUtf16(const char16_t *str, int size) | - | ||||||||||||||||||
| 4823 | \since 5.3 | - | ||||||||||||||||||
| 4824 | - | |||||||||||||||||||
| 4825 | Returns a QString initialized with the first \a size characters | - | ||||||||||||||||||
| 4826 | of the Unicode string \a str (ISO-10646-UTF-16 encoded). | - | ||||||||||||||||||
| 4827 | - | |||||||||||||||||||
| 4828 | If \a size is -1 (default), \a str must be terminated | - | ||||||||||||||||||
| 4829 | with a 0. | - | ||||||||||||||||||
| 4830 | - | |||||||||||||||||||
| 4831 | This function checks for a Byte Order Mark (BOM). If it is missing, | - | ||||||||||||||||||
| 4832 | host byte order is assumed. | - | ||||||||||||||||||
| 4833 | - | |||||||||||||||||||
| 4834 | This function is slow compared to the other Unicode conversions. | - | ||||||||||||||||||
| 4835 | Use QString(const QChar *, int) or QString(const QChar *) if possible. | - | ||||||||||||||||||
| 4836 | - | |||||||||||||||||||
| 4837 | QString makes a deep copy of the Unicode data. | - | ||||||||||||||||||
| 4838 | - | |||||||||||||||||||
| 4839 | \sa utf16(), setUtf16(), fromStdU16String() | - | ||||||||||||||||||
| 4840 | */ | - | ||||||||||||||||||
| 4841 | - | |||||||||||||||||||
| 4842 | /*! | - | ||||||||||||||||||
| 4843 | \fn QString QString::fromUcs4(const char32_t *str, int size) | - | ||||||||||||||||||
| 4844 | \since 5.3 | - | ||||||||||||||||||
| 4845 | - | |||||||||||||||||||
| 4846 | Returns a QString initialized with the first \a size characters | - | ||||||||||||||||||
| 4847 | of the Unicode string \a str (ISO-10646-UCS-4 encoded). | - | ||||||||||||||||||
| 4848 | - | |||||||||||||||||||
| 4849 | If \a size is -1 (default), \a str must be terminated | - | ||||||||||||||||||
| 4850 | with a 0. | - | ||||||||||||||||||
| 4851 | - | |||||||||||||||||||
| 4852 | \sa toUcs4(), fromUtf16(), utf16(), setUtf16(), fromWCharArray(), fromStdU32String() | - | ||||||||||||||||||
| 4853 | */ | - | ||||||||||||||||||
| 4854 | - | |||||||||||||||||||
| 4855 | /*! | - | ||||||||||||||||||
| 4856 | \since 4.2 | - | ||||||||||||||||||
| 4857 | - | |||||||||||||||||||
| 4858 | Returns a QString initialized with the first \a size characters | - | ||||||||||||||||||
| 4859 | of the Unicode string \a unicode (ISO-10646-UCS-4 encoded). | - | ||||||||||||||||||
| 4860 | - | |||||||||||||||||||
| 4861 | If \a size is -1 (default), \a unicode must be terminated | - | ||||||||||||||||||
| 4862 | with a 0. | - | ||||||||||||||||||
| 4863 | - | |||||||||||||||||||
| 4864 | \sa toUcs4(), fromUtf16(), utf16(), setUtf16(), fromWCharArray(), fromStdU32String() | - | ||||||||||||||||||
| 4865 | */ | - | ||||||||||||||||||
| 4866 | QString QString::fromUcs4(const uint *unicode, int size) | - | ||||||||||||||||||
| 4867 | { | - | ||||||||||||||||||
| 4868 | if (!unicode)
| 3-410515 | ||||||||||||||||||
| 4869 | return QString(); executed 3 times by 1 test: return QString();Executed by:
| 3 | ||||||||||||||||||
| 4870 | if (size < 0) {
| 315-410200 | ||||||||||||||||||
| 4871 | size = 0; | - | ||||||||||||||||||
| 4872 | while (unicode[size] != 0)
| 315-1163 | ||||||||||||||||||
| 4873 | ++size; executed 1163 times by 3 tests: ++size;Executed by:
| 1163 | ||||||||||||||||||
| 4874 | } executed 315 times by 3 tests: end of blockExecuted by:
| 315 | ||||||||||||||||||
| 4875 | return QUtf32::convertToUnicode((const char *)unicode, size*4, 0); executed 410515 times by 8 tests: return QUtf32::convertToUnicode((const char *)unicode, size*4, 0);Executed by:
| 410515 | ||||||||||||||||||
| 4876 | } | - | ||||||||||||||||||
| 4877 | - | |||||||||||||||||||
| 4878 | /*! | - | ||||||||||||||||||
| 4879 | Resizes the string to \a size characters and copies \a unicode | - | ||||||||||||||||||
| 4880 | into the string. | - | ||||||||||||||||||
| 4881 | - | |||||||||||||||||||
| 4882 | If \a unicode is 0, nothing is copied, but the string is still | - | ||||||||||||||||||
| 4883 | resized to \a size. | - | ||||||||||||||||||
| 4884 | - | |||||||||||||||||||
| 4885 | \sa unicode(), setUtf16() | - | ||||||||||||||||||
| 4886 | */ | - | ||||||||||||||||||
| 4887 | QString& QString::setUnicode(const QChar *unicode, int size) | - | ||||||||||||||||||
| 4888 | { | - | ||||||||||||||||||
| 4889 | resize(size); | - | ||||||||||||||||||
| 4890 | if (unicode && size)
| 0-184392 | ||||||||||||||||||
| 4891 | memcpy(d->data(), unicode, size * sizeof(QChar)); executed 97526 times by 14 tests: memcpy(d->data(), unicode, size * sizeof(QChar));Executed by:
| 97526 | ||||||||||||||||||
| 4892 | return *this; executed 184392 times by 14 tests: return *this;Executed by:
| 184392 | ||||||||||||||||||
| 4893 | } | - | ||||||||||||||||||
| 4894 | - | |||||||||||||||||||
| 4895 | /*! | - | ||||||||||||||||||
| 4896 | \fn QString &QString::setUtf16(const ushort *unicode, int size) | - | ||||||||||||||||||
| 4897 | - | |||||||||||||||||||
| 4898 | Resizes the string to \a size characters and copies \a unicode | - | ||||||||||||||||||
| 4899 | into the string. | - | ||||||||||||||||||
| 4900 | - | |||||||||||||||||||
| 4901 | If \a unicode is 0, nothing is copied, but the string is still | - | ||||||||||||||||||
| 4902 | resized to \a size. | - | ||||||||||||||||||
| 4903 | - | |||||||||||||||||||
| 4904 | Note that unlike fromUtf16(), this function does not consider BOMs and | - | ||||||||||||||||||
| 4905 | possibly differing byte ordering. | - | ||||||||||||||||||
| 4906 | - | |||||||||||||||||||
| 4907 | \sa utf16(), setUnicode() | - | ||||||||||||||||||
| 4908 | */ | - | ||||||||||||||||||
| 4909 | - | |||||||||||||||||||
| 4910 | /*! | - | ||||||||||||||||||
| 4911 | \fn QString QString::simplified() const | - | ||||||||||||||||||
| 4912 | - | |||||||||||||||||||
| 4913 | Returns a string that has whitespace removed from the start | - | ||||||||||||||||||
| 4914 | and the end, and that has each sequence of internal whitespace | - | ||||||||||||||||||
| 4915 | replaced with a single space. | - | ||||||||||||||||||
| 4916 | - | |||||||||||||||||||
| 4917 | Whitespace means any character for which QChar::isSpace() returns | - | ||||||||||||||||||
| 4918 | \c true. This includes the ASCII characters '\\t', '\\n', '\\v', | - | ||||||||||||||||||
| 4919 | '\\f', '\\r', and ' '. | - | ||||||||||||||||||
| 4920 | - | |||||||||||||||||||
| 4921 | Example: | - | ||||||||||||||||||
| 4922 | - | |||||||||||||||||||
| 4923 | \snippet qstring/main.cpp 57 | - | ||||||||||||||||||
| 4924 | - | |||||||||||||||||||
| 4925 | \sa trimmed() | - | ||||||||||||||||||
| 4926 | */ | - | ||||||||||||||||||
| 4927 | QString QString::simplified_helper(const QString &str) | - | ||||||||||||||||||
| 4928 | { | - | ||||||||||||||||||
| 4929 | return QStringAlgorithms<const QString>::simplified_helper(str); executed 67827 times by 109 tests: return QStringAlgorithms<const QString>::simplified_helper(str);Executed by:
| 67827 | ||||||||||||||||||
| 4930 | } | - | ||||||||||||||||||
| 4931 | - | |||||||||||||||||||
| 4932 | QString QString::simplified_helper(QString &str) | - | ||||||||||||||||||
| 4933 | { | - | ||||||||||||||||||
| 4934 | return QStringAlgorithms<QString>::simplified_helper(str); executed 8900 times by 5 tests: return QStringAlgorithms<QString>::simplified_helper(str);Executed by:
| 8900 | ||||||||||||||||||
| 4935 | } | - | ||||||||||||||||||
| 4936 | - | |||||||||||||||||||
| 4937 | /*! | - | ||||||||||||||||||
| 4938 | \fn QString QString::trimmed() const | - | ||||||||||||||||||
| 4939 | - | |||||||||||||||||||
| 4940 | Returns a string that has whitespace removed from the start and | - | ||||||||||||||||||
| 4941 | the end. | - | ||||||||||||||||||
| 4942 | - | |||||||||||||||||||
| 4943 | Whitespace means any character for which QChar::isSpace() returns | - | ||||||||||||||||||
| 4944 | \c true. This includes the ASCII characters '\\t', '\\n', '\\v', | - | ||||||||||||||||||
| 4945 | '\\f', '\\r', and ' '. | - | ||||||||||||||||||
| 4946 | - | |||||||||||||||||||
| 4947 | Example: | - | ||||||||||||||||||
| 4948 | - | |||||||||||||||||||
| 4949 | \snippet qstring/main.cpp 82 | - | ||||||||||||||||||
| 4950 | - | |||||||||||||||||||
| 4951 | Unlike simplified(), trimmed() leaves internal whitespace alone. | - | ||||||||||||||||||
| 4952 | - | |||||||||||||||||||
| 4953 | \sa simplified() | - | ||||||||||||||||||
| 4954 | */ | - | ||||||||||||||||||
| 4955 | QString QString::trimmed_helper(const QString &str) | - | ||||||||||||||||||
| 4956 | { | - | ||||||||||||||||||
| 4957 | return QStringAlgorithms<const QString>::trimmed_helper(str); executed 45079 times by 191 tests: return QStringAlgorithms<const QString>::trimmed_helper(str);Executed by:
| 45079 | ||||||||||||||||||
| 4958 | } | - | ||||||||||||||||||
| 4959 | - | |||||||||||||||||||
| 4960 | QString QString::trimmed_helper(QString &str) | - | ||||||||||||||||||
| 4961 | { | - | ||||||||||||||||||
| 4962 | return QStringAlgorithms<QString>::trimmed_helper(str); executed 6520 times by 31 tests: return QStringAlgorithms<QString>::trimmed_helper(str);Executed by:
| 6520 | ||||||||||||||||||
| 4963 | } | - | ||||||||||||||||||
| 4964 | - | |||||||||||||||||||
| 4965 | /*! \fn const QChar QString::at(int position) const | - | ||||||||||||||||||
| 4966 | - | |||||||||||||||||||
| 4967 | Returns the character at the given index \a position in the | - | ||||||||||||||||||
| 4968 | string. | - | ||||||||||||||||||
| 4969 | - | |||||||||||||||||||
| 4970 | The \a position must be a valid index position in the string | - | ||||||||||||||||||
| 4971 | (i.e., 0 <= \a position < size()). | - | ||||||||||||||||||
| 4972 | - | |||||||||||||||||||
| 4973 | \sa operator[]() | - | ||||||||||||||||||
| 4974 | */ | - | ||||||||||||||||||
| 4975 | - | |||||||||||||||||||
| 4976 | /*! | - | ||||||||||||||||||
| 4977 | \fn QCharRef QString::operator[](int position) | - | ||||||||||||||||||
| 4978 | - | |||||||||||||||||||
| 4979 | Returns the character at the specified \a position in the string as a | - | ||||||||||||||||||
| 4980 | modifiable reference. | - | ||||||||||||||||||
| 4981 | - | |||||||||||||||||||
| 4982 | Example: | - | ||||||||||||||||||
| 4983 | - | |||||||||||||||||||
| 4984 | \snippet qstring/main.cpp 85 | - | ||||||||||||||||||
| 4985 | - | |||||||||||||||||||
| 4986 | The return value is of type QCharRef, a helper class for QString. | - | ||||||||||||||||||
| 4987 | When you get an object of type QCharRef, you can use it as if it | - | ||||||||||||||||||
| 4988 | were a QChar &. If you assign to it, the assignment will apply to | - | ||||||||||||||||||
| 4989 | the character in the QString from which you got the reference. | - | ||||||||||||||||||
| 4990 | - | |||||||||||||||||||
| 4991 | \sa at() | - | ||||||||||||||||||
| 4992 | */ | - | ||||||||||||||||||
| 4993 | - | |||||||||||||||||||
| 4994 | /*! | - | ||||||||||||||||||
| 4995 | \fn const QChar QString::operator[](int position) const | - | ||||||||||||||||||
| 4996 | - | |||||||||||||||||||
| 4997 | \overload operator[]() | - | ||||||||||||||||||
| 4998 | */ | - | ||||||||||||||||||
| 4999 | - | |||||||||||||||||||
| 5000 | /*! \fn QCharRef QString::operator[](uint position) | - | ||||||||||||||||||
| 5001 | - | |||||||||||||||||||
| 5002 | \overload operator[]() | - | ||||||||||||||||||
| 5003 | - | |||||||||||||||||||
| 5004 | Returns the character at the specified \a position in the string as a | - | ||||||||||||||||||
| 5005 | modifiable reference. | - | ||||||||||||||||||
| 5006 | */ | - | ||||||||||||||||||
| 5007 | - | |||||||||||||||||||
| 5008 | /*! \fn const QChar QString::operator[](uint position) const | - | ||||||||||||||||||
| 5009 | Equivalent to \c at(position). | - | ||||||||||||||||||
| 5010 | \overload operator[]() | - | ||||||||||||||||||
| 5011 | */ | - | ||||||||||||||||||
| 5012 | - | |||||||||||||||||||
| 5013 | /*! | - | ||||||||||||||||||
| 5014 | \fn void QString::truncate(int position) | - | ||||||||||||||||||
| 5015 | - | |||||||||||||||||||
| 5016 | Truncates the string at the given \a position index. | - | ||||||||||||||||||
| 5017 | - | |||||||||||||||||||
| 5018 | If the specified \a position index is beyond the end of the | - | ||||||||||||||||||
| 5019 | string, nothing happens. | - | ||||||||||||||||||
| 5020 | - | |||||||||||||||||||
| 5021 | Example: | - | ||||||||||||||||||
| 5022 | - | |||||||||||||||||||
| 5023 | \snippet qstring/main.cpp 83 | - | ||||||||||||||||||
| 5024 | - | |||||||||||||||||||
| 5025 | If \a position is negative, it is equivalent to passing zero. | - | ||||||||||||||||||
| 5026 | - | |||||||||||||||||||
| 5027 | \sa chop(), resize(), left(), QStringRef::truncate() | - | ||||||||||||||||||
| 5028 | */ | - | ||||||||||||||||||
| 5029 | - | |||||||||||||||||||
| 5030 | void QString::truncate(int pos) | - | ||||||||||||||||||
| 5031 | { | - | ||||||||||||||||||
| 5032 | if (pos < d->size)
| 7810261-42095002 | ||||||||||||||||||
| 5033 | resize(pos); executed 42095002 times by 367 tests: resize(pos);Executed by:
| 42095002 | ||||||||||||||||||
| 5034 | } executed 49905263 times by 574 tests: end of blockExecuted by:
| 49905263 | ||||||||||||||||||
| 5035 | - | |||||||||||||||||||
| 5036 | - | |||||||||||||||||||
| 5037 | /*! | - | ||||||||||||||||||
| 5038 | Removes \a n characters from the end of the string. | - | ||||||||||||||||||
| 5039 | - | |||||||||||||||||||
| 5040 | If \a n is greater than or equal to size(), the result is an | - | ||||||||||||||||||
| 5041 | empty string; if \a n is negative, it is equivalent to passing zero. | - | ||||||||||||||||||
| 5042 | - | |||||||||||||||||||
| 5043 | Example: | - | ||||||||||||||||||
| 5044 | \snippet qstring/main.cpp 15 | - | ||||||||||||||||||
| 5045 | - | |||||||||||||||||||
| 5046 | If you want to remove characters from the \e beginning of the | - | ||||||||||||||||||
| 5047 | string, use remove() instead. | - | ||||||||||||||||||
| 5048 | - | |||||||||||||||||||
| 5049 | \sa truncate(), resize(), remove() | - | ||||||||||||||||||
| 5050 | */ | - | ||||||||||||||||||
| 5051 | void QString::chop(int n) | - | ||||||||||||||||||
| 5052 | { | - | ||||||||||||||||||
| 5053 | if (n > 0)
| 140-68267 | ||||||||||||||||||
| 5054 | resize(d->size - n); executed 68267 times by 363 tests: resize(d->size - n);Executed by:
| 68267 | ||||||||||||||||||
| 5055 | } executed 68407 times by 363 tests: end of blockExecuted by:
| 68407 | ||||||||||||||||||
| 5056 | - | |||||||||||||||||||
| 5057 | /*! | - | ||||||||||||||||||
| 5058 | Sets every character in the string to character \a ch. If \a size | - | ||||||||||||||||||
| 5059 | is different from -1 (default), the string is resized to \a | - | ||||||||||||||||||
| 5060 | size beforehand. | - | ||||||||||||||||||
| 5061 | - | |||||||||||||||||||
| 5062 | Example: | - | ||||||||||||||||||
| 5063 | - | |||||||||||||||||||
| 5064 | \snippet qstring/main.cpp 21 | - | ||||||||||||||||||
| 5065 | - | |||||||||||||||||||
| 5066 | \sa resize() | - | ||||||||||||||||||
| 5067 | */ | - | ||||||||||||||||||
| 5068 | - | |||||||||||||||||||
| 5069 | QString& QString::fill(QChar ch, int size) | - | ||||||||||||||||||
| 5070 | { | - | ||||||||||||||||||
| 5071 | resize(size < 0 ? d->size : size); | - | ||||||||||||||||||
| 5072 | if (d->size) {
| 5425-11590 | ||||||||||||||||||
| 5073 | QChar *i = (QChar*)d->data() + d->size; | - | ||||||||||||||||||
| 5074 | QChar *b = (QChar*)d->data(); | - | ||||||||||||||||||
| 5075 | while (i != b)
| 11590-2697612 | ||||||||||||||||||
| 5076 | *--i = ch; executed 2697612 times by 11 tests: *--i = ch;Executed by:
| 2697612 | ||||||||||||||||||
| 5077 | } executed 11590 times by 11 tests: end of blockExecuted by:
| 11590 | ||||||||||||||||||
| 5078 | return *this; executed 17015 times by 13 tests: return *this;Executed by:
| 17015 | ||||||||||||||||||
| 5079 | } | - | ||||||||||||||||||
| 5080 | - | |||||||||||||||||||
| 5081 | /*! | - | ||||||||||||||||||
| 5082 | \fn int QString::length() const | - | ||||||||||||||||||
| 5083 | - | |||||||||||||||||||
| 5084 | Returns the number of characters in this string. Equivalent to | - | ||||||||||||||||||
| 5085 | size(). | - | ||||||||||||||||||
| 5086 | - | |||||||||||||||||||
| 5087 | \sa resize() | - | ||||||||||||||||||
| 5088 | */ | - | ||||||||||||||||||
| 5089 | - | |||||||||||||||||||
| 5090 | /*! | - | ||||||||||||||||||
| 5091 | \fn int QString::size() const | - | ||||||||||||||||||
| 5092 | - | |||||||||||||||||||
| 5093 | Returns the number of characters in this string. | - | ||||||||||||||||||
| 5094 | - | |||||||||||||||||||
| 5095 | The last character in the string is at position size() - 1. In | - | ||||||||||||||||||
| 5096 | addition, QString ensures that the character at position size() | - | ||||||||||||||||||
| 5097 | is always '\\0', so that you can use the return value of data() | - | ||||||||||||||||||
| 5098 | and constData() as arguments to functions that expect | - | ||||||||||||||||||
| 5099 | '\\0'-terminated strings. | - | ||||||||||||||||||
| 5100 | - | |||||||||||||||||||
| 5101 | Example: | - | ||||||||||||||||||
| 5102 | - | |||||||||||||||||||
| 5103 | \snippet qstring/main.cpp 58 | - | ||||||||||||||||||
| 5104 | - | |||||||||||||||||||
| 5105 | \sa isEmpty(), resize() | - | ||||||||||||||||||
| 5106 | */ | - | ||||||||||||||||||
| 5107 | - | |||||||||||||||||||
| 5108 | /*! \fn bool QString::isNull() const | - | ||||||||||||||||||
| 5109 | - | |||||||||||||||||||
| 5110 | Returns \c true if this string is null; otherwise returns \c false. | - | ||||||||||||||||||
| 5111 | - | |||||||||||||||||||
| 5112 | Example: | - | ||||||||||||||||||
| 5113 | - | |||||||||||||||||||
| 5114 | \snippet qstring/main.cpp 28 | - | ||||||||||||||||||
| 5115 | - | |||||||||||||||||||
| 5116 | Qt makes a distinction between null strings and empty strings for | - | ||||||||||||||||||
| 5117 | historical reasons. For most applications, what matters is | - | ||||||||||||||||||
| 5118 | whether or not a string contains any data, and this can be | - | ||||||||||||||||||
| 5119 | determined using the isEmpty() function. | - | ||||||||||||||||||
| 5120 | - | |||||||||||||||||||
| 5121 | \sa isEmpty() | - | ||||||||||||||||||
| 5122 | */ | - | ||||||||||||||||||
| 5123 | - | |||||||||||||||||||
| 5124 | /*! \fn bool QString::isEmpty() const | - | ||||||||||||||||||
| 5125 | - | |||||||||||||||||||
| 5126 | Returns \c true if the string has no characters; otherwise returns | - | ||||||||||||||||||
| 5127 | \c false. | - | ||||||||||||||||||
| 5128 | - | |||||||||||||||||||
| 5129 | Example: | - | ||||||||||||||||||
| 5130 | - | |||||||||||||||||||
| 5131 | \snippet qstring/main.cpp 27 | - | ||||||||||||||||||
| 5132 | - | |||||||||||||||||||
| 5133 | \sa size() | - | ||||||||||||||||||
| 5134 | */ | - | ||||||||||||||||||
| 5135 | - | |||||||||||||||||||
| 5136 | /*! \fn QString &QString::operator+=(const QString &other) | - | ||||||||||||||||||
| 5137 | - | |||||||||||||||||||
| 5138 | Appends the string \a other onto the end of this string and | - | ||||||||||||||||||
| 5139 | returns a reference to this string. | - | ||||||||||||||||||
| 5140 | - | |||||||||||||||||||
| 5141 | Example: | - | ||||||||||||||||||
| 5142 | - | |||||||||||||||||||
| 5143 | \snippet qstring/main.cpp 84 | - | ||||||||||||||||||
| 5144 | - | |||||||||||||||||||
| 5145 | This operation is typically very fast (\l{constant time}), | - | ||||||||||||||||||
| 5146 | because QString preallocates extra space at the end of the string | - | ||||||||||||||||||
| 5147 | data so it can grow without reallocating the entire string each | - | ||||||||||||||||||
| 5148 | time. | - | ||||||||||||||||||
| 5149 | - | |||||||||||||||||||
| 5150 | \sa append(), prepend() | - | ||||||||||||||||||
| 5151 | */ | - | ||||||||||||||||||
| 5152 | - | |||||||||||||||||||
| 5153 | /*! \fn QString &QString::operator+=(QLatin1String str) | - | ||||||||||||||||||
| 5154 | - | |||||||||||||||||||
| 5155 | \overload operator+=() | - | ||||||||||||||||||
| 5156 | - | |||||||||||||||||||
| 5157 | Appends the Latin-1 string \a str to this string. | - | ||||||||||||||||||
| 5158 | */ | - | ||||||||||||||||||
| 5159 | - | |||||||||||||||||||
| 5160 | /*! \fn QString &QString::operator+=(const QByteArray &ba) | - | ||||||||||||||||||
| 5161 | - | |||||||||||||||||||
| 5162 | \overload operator+=() | - | ||||||||||||||||||
| 5163 | - | |||||||||||||||||||
| 5164 | Appends the byte array \a ba to this string. The byte array is converted | - | ||||||||||||||||||
| 5165 | to Unicode using the fromUtf8() function. If any NUL characters ('\\0') | - | ||||||||||||||||||
| 5166 | are embedded in the \a ba byte array, they will be included in the | - | ||||||||||||||||||
| 5167 | transformation. | - | ||||||||||||||||||
| 5168 | - | |||||||||||||||||||
| 5169 | You can disable this function by defining \c | - | ||||||||||||||||||
| 5170 | QT_NO_CAST_FROM_ASCII when you compile your applications. This | - | ||||||||||||||||||
| 5171 | can be useful if you want to ensure that all user-visible strings | - | ||||||||||||||||||
| 5172 | go through QObject::tr(), for example. | - | ||||||||||||||||||
| 5173 | */ | - | ||||||||||||||||||
| 5174 | - | |||||||||||||||||||
| 5175 | /*! \fn QString &QString::operator+=(const char *str) | - | ||||||||||||||||||
| 5176 | - | |||||||||||||||||||
| 5177 | \overload operator+=() | - | ||||||||||||||||||
| 5178 | - | |||||||||||||||||||
| 5179 | Appends the string \a str to this string. The const char pointer | - | ||||||||||||||||||
| 5180 | is converted to Unicode using the fromUtf8() function. | - | ||||||||||||||||||
| 5181 | - | |||||||||||||||||||
| 5182 | You can disable this function by defining \c QT_NO_CAST_FROM_ASCII | - | ||||||||||||||||||
| 5183 | when you compile your applications. This can be useful if you want | - | ||||||||||||||||||
| 5184 | to ensure that all user-visible strings go through QObject::tr(), | - | ||||||||||||||||||
| 5185 | for example. | - | ||||||||||||||||||
| 5186 | */ | - | ||||||||||||||||||
| 5187 | - | |||||||||||||||||||
| 5188 | /*! \fn QString &QString::operator+=(const QStringRef &str) | - | ||||||||||||||||||
| 5189 | - | |||||||||||||||||||
| 5190 | \overload operator+=() | - | ||||||||||||||||||
| 5191 | - | |||||||||||||||||||
| 5192 | Appends the string section referenced by \a str to this string. | - | ||||||||||||||||||
| 5193 | */ | - | ||||||||||||||||||
| 5194 | - | |||||||||||||||||||
| 5195 | /*! \fn QString &QString::operator+=(char ch) | - | ||||||||||||||||||
| 5196 | - | |||||||||||||||||||
| 5197 | \overload operator+=() | - | ||||||||||||||||||
| 5198 | - | |||||||||||||||||||
| 5199 | Appends the character \a ch to this string. Note that the character is | - | ||||||||||||||||||
| 5200 | converted to Unicode using the fromLatin1() function, unlike other 8-bit | - | ||||||||||||||||||
| 5201 | functions that operate on UTF-8 data. | - | ||||||||||||||||||
| 5202 | - | |||||||||||||||||||
| 5203 | You can disable this function by defining \c QT_NO_CAST_FROM_ASCII | - | ||||||||||||||||||
| 5204 | when you compile your applications. This can be useful if you want | - | ||||||||||||||||||
| 5205 | to ensure that all user-visible strings go through QObject::tr(), | - | ||||||||||||||||||
| 5206 | for example. | - | ||||||||||||||||||
| 5207 | */ | - | ||||||||||||||||||
| 5208 | - | |||||||||||||||||||
| 5209 | /*! \fn QString &QString::operator+=(QChar ch) | - | ||||||||||||||||||
| 5210 | - | |||||||||||||||||||
| 5211 | \overload operator+=() | - | ||||||||||||||||||
| 5212 | - | |||||||||||||||||||
| 5213 | Appends the character \a ch to the string. | - | ||||||||||||||||||
| 5214 | */ | - | ||||||||||||||||||
| 5215 | - | |||||||||||||||||||
| 5216 | /*! \fn QString &QString::operator+=(QChar::SpecialCharacter c) | - | ||||||||||||||||||
| 5217 | - | |||||||||||||||||||
| 5218 | \overload operator+=() | - | ||||||||||||||||||
| 5219 | - | |||||||||||||||||||
| 5220 | \internal | - | ||||||||||||||||||
| 5221 | */ | - | ||||||||||||||||||
| 5222 | - | |||||||||||||||||||
| 5223 | /*! | - | ||||||||||||||||||
| 5224 | \fn bool operator==(const char *s1, const QString &s2) | - | ||||||||||||||||||
| 5225 | - | |||||||||||||||||||
| 5226 | \overload operator==() | - | ||||||||||||||||||
| 5227 | \relates QString | - | ||||||||||||||||||
| 5228 | - | |||||||||||||||||||
| 5229 | Returns \c true if \a s1 is equal to \a s2; otherwise returns \c false. | - | ||||||||||||||||||
| 5230 | Note that no string is equal to \a s1 being 0. | - | ||||||||||||||||||
| 5231 | - | |||||||||||||||||||
| 5232 | Equivalent to \c {s1 != 0 && compare(s1, s2) == 0}. | - | ||||||||||||||||||
| 5233 | - | |||||||||||||||||||
| 5234 | \sa QString::compare() | - | ||||||||||||||||||
| 5235 | */ | - | ||||||||||||||||||
| 5236 | - | |||||||||||||||||||
| 5237 | /*! | - | ||||||||||||||||||
| 5238 | \fn bool operator!=(const char *s1, const QString &s2) | - | ||||||||||||||||||
| 5239 | \relates QString | - | ||||||||||||||||||
| 5240 | - | |||||||||||||||||||
| 5241 | Returns \c true if \a s1 is not equal to \a s2; otherwise returns | - | ||||||||||||||||||
| 5242 | \c false. | - | ||||||||||||||||||
| 5243 | - | |||||||||||||||||||
| 5244 | For \a s1 != 0, this is equivalent to \c {compare(} \a s1, \a s2 | - | ||||||||||||||||||
| 5245 | \c {) != 0}. Note that no string is equal to \a s1 being 0. | - | ||||||||||||||||||
| 5246 | - | |||||||||||||||||||
| 5247 | \sa QString::compare() | - | ||||||||||||||||||
| 5248 | */ | - | ||||||||||||||||||
| 5249 | - | |||||||||||||||||||
| 5250 | /*! | - | ||||||||||||||||||
| 5251 | \fn bool operator<(const char *s1, const QString &s2) | - | ||||||||||||||||||
| 5252 | \relates QString | - | ||||||||||||||||||
| 5253 | - | |||||||||||||||||||
| 5254 | Returns \c true if \a s1 is lexically less than \a s2; otherwise | - | ||||||||||||||||||
| 5255 | returns \c false. For \a s1 != 0, this is equivalent to \c | - | ||||||||||||||||||
| 5256 | {compare(s1, s2) < 0}. | - | ||||||||||||||||||
| 5257 | - | |||||||||||||||||||
| 5258 | The comparison is based exclusively on the numeric Unicode values | - | ||||||||||||||||||
| 5259 | of the characters and is very fast, but is not what a human would | - | ||||||||||||||||||
| 5260 | expect. Consider sorting user-interface strings using the | - | ||||||||||||||||||
| 5261 | QString::localeAwareCompare() function. | - | ||||||||||||||||||
| 5262 | - | |||||||||||||||||||
| 5263 | \sa QString::compare() | - | ||||||||||||||||||
| 5264 | */ | - | ||||||||||||||||||
| 5265 | - | |||||||||||||||||||
| 5266 | /*! | - | ||||||||||||||||||
| 5267 | \fn bool operator<=(const char *s1, const QString &s2) | - | ||||||||||||||||||
| 5268 | \relates QString | - | ||||||||||||||||||
| 5269 | - | |||||||||||||||||||
| 5270 | Returns \c true if \a s1 is lexically less than or equal to \a s2; | - | ||||||||||||||||||
| 5271 | otherwise returns \c false. For \a s1 != 0, this is equivalent to \c | - | ||||||||||||||||||
| 5272 | {compare(s1, s2) <= 0}. | - | ||||||||||||||||||
| 5273 | - | |||||||||||||||||||
| 5274 | The comparison is based exclusively on the numeric Unicode values | - | ||||||||||||||||||
| 5275 | of the characters and is very fast, but is not what a human would | - | ||||||||||||||||||
| 5276 | expect. Consider sorting user-interface strings with | - | ||||||||||||||||||
| 5277 | QString::localeAwareCompare(). | - | ||||||||||||||||||
| 5278 | - | |||||||||||||||||||
| 5279 | \sa QString::compare() | - | ||||||||||||||||||
| 5280 | */ | - | ||||||||||||||||||
| 5281 | - | |||||||||||||||||||
| 5282 | /*! | - | ||||||||||||||||||
| 5283 | \fn bool operator>(const char *s1, const QString &s2) | - | ||||||||||||||||||
| 5284 | \relates QString | - | ||||||||||||||||||
| 5285 | - | |||||||||||||||||||
| 5286 | Returns \c true if \a s1 is lexically greater than \a s2; otherwise | - | ||||||||||||||||||
| 5287 | returns \c false. Equivalent to \c {compare(s1, s2) > 0}. | - | ||||||||||||||||||
| 5288 | - | |||||||||||||||||||
| 5289 | The comparison is based exclusively on the numeric Unicode values | - | ||||||||||||||||||
| 5290 | of the characters and is very fast, but is not what a human would | - | ||||||||||||||||||
| 5291 | expect. Consider sorting user-interface strings using the | - | ||||||||||||||||||
| 5292 | QString::localeAwareCompare() function. | - | ||||||||||||||||||
| 5293 | - | |||||||||||||||||||
| 5294 | \sa QString::compare() | - | ||||||||||||||||||
| 5295 | */ | - | ||||||||||||||||||
| 5296 | - | |||||||||||||||||||
| 5297 | /*! | - | ||||||||||||||||||
| 5298 | \fn bool operator>=(const char *s1, const QString &s2) | - | ||||||||||||||||||
| 5299 | \relates QString | - | ||||||||||||||||||
| 5300 | - | |||||||||||||||||||
| 5301 | Returns \c true if \a s1 is lexically greater than or equal to \a s2; | - | ||||||||||||||||||
| 5302 | otherwise returns \c false. For \a s1 != 0, this is equivalent to \c | - | ||||||||||||||||||
| 5303 | {compare(s1, s2) >= 0}. | - | ||||||||||||||||||
| 5304 | - | |||||||||||||||||||
| 5305 | The comparison is based exclusively on the numeric Unicode values | - | ||||||||||||||||||
| 5306 | of the characters and is very fast, but is not what a human would | - | ||||||||||||||||||
| 5307 | expect. Consider sorting user-interface strings using the | - | ||||||||||||||||||
| 5308 | QString::localeAwareCompare() function. | - | ||||||||||||||||||
| 5309 | */ | - | ||||||||||||||||||
| 5310 | - | |||||||||||||||||||
| 5311 | /*! | - | ||||||||||||||||||
| 5312 | \fn const QString operator+(const QString &s1, const QString &s2) | - | ||||||||||||||||||
| 5313 | \relates QString | - | ||||||||||||||||||
| 5314 | - | |||||||||||||||||||
| 5315 | Returns a string which is the result of concatenating \a s1 and \a | - | ||||||||||||||||||
| 5316 | s2. | - | ||||||||||||||||||
| 5317 | */ | - | ||||||||||||||||||
| 5318 | - | |||||||||||||||||||
| 5319 | /*! | - | ||||||||||||||||||
| 5320 | \fn const QString operator+(const QString &s1, const char *s2) | - | ||||||||||||||||||
| 5321 | \relates QString | - | ||||||||||||||||||
| 5322 | - | |||||||||||||||||||
| 5323 | Returns a string which is the result of concatenating \a s1 and \a | - | ||||||||||||||||||
| 5324 | s2 (\a s2 is converted to Unicode using the QString::fromUtf8() | - | ||||||||||||||||||
| 5325 | function). | - | ||||||||||||||||||
| 5326 | - | |||||||||||||||||||
| 5327 | \sa QString::fromUtf8() | - | ||||||||||||||||||
| 5328 | */ | - | ||||||||||||||||||
| 5329 | - | |||||||||||||||||||
| 5330 | /*! | - | ||||||||||||||||||
| 5331 | \fn const QString operator+(const char *s1, const QString &s2) | - | ||||||||||||||||||
| 5332 | \relates QString | - | ||||||||||||||||||
| 5333 | - | |||||||||||||||||||
| 5334 | Returns a string which is the result of concatenating \a s1 and \a | - | ||||||||||||||||||
| 5335 | s2 (\a s1 is converted to Unicode using the QString::fromUtf8() | - | ||||||||||||||||||
| 5336 | function). | - | ||||||||||||||||||
| 5337 | - | |||||||||||||||||||
| 5338 | \sa QString::fromUtf8() | - | ||||||||||||||||||
| 5339 | */ | - | ||||||||||||||||||
| 5340 | - | |||||||||||||||||||
| 5341 | /*! | - | ||||||||||||||||||
| 5342 | \fn const QString operator+(const QString &s, char ch) | - | ||||||||||||||||||
| 5343 | \relates QString | - | ||||||||||||||||||
| 5344 | - | |||||||||||||||||||
| 5345 | Returns a string which is the result of concatenating the string | - | ||||||||||||||||||
| 5346 | \a s and the character \a ch. | - | ||||||||||||||||||
| 5347 | */ | - | ||||||||||||||||||
| 5348 | - | |||||||||||||||||||
| 5349 | /*! | - | ||||||||||||||||||
| 5350 | \fn const QString operator+(char ch, const QString &s) | - | ||||||||||||||||||
| 5351 | \relates QString | - | ||||||||||||||||||
| 5352 | - | |||||||||||||||||||
| 5353 | Returns a string which is the result of concatenating the | - | ||||||||||||||||||
| 5354 | character \a ch and the string \a s. | - | ||||||||||||||||||
| 5355 | */ | - | ||||||||||||||||||
| 5356 | - | |||||||||||||||||||
| 5357 | /*! | - | ||||||||||||||||||
| 5358 | \fn int QString::compare(const QString &s1, const QString &s2, Qt::CaseSensitivity cs) | - | ||||||||||||||||||
| 5359 | \since 4.2 | - | ||||||||||||||||||
| 5360 | - | |||||||||||||||||||
| 5361 | Compares \a s1 with \a s2 and returns an integer less than, equal | - | ||||||||||||||||||
| 5362 | to, or greater than zero if \a s1 is less than, equal to, or | - | ||||||||||||||||||
| 5363 | greater than \a s2. | - | ||||||||||||||||||
| 5364 | - | |||||||||||||||||||
| 5365 | If \a cs is Qt::CaseSensitive, the comparison is case sensitive; | - | ||||||||||||||||||
| 5366 | otherwise the comparison is case insensitive. | - | ||||||||||||||||||
| 5367 | - | |||||||||||||||||||
| 5368 | Case sensitive comparison is based exclusively on the numeric | - | ||||||||||||||||||
| 5369 | Unicode values of the characters and is very fast, but is not what | - | ||||||||||||||||||
| 5370 | a human would expect. Consider sorting user-visible strings with | - | ||||||||||||||||||
| 5371 | localeAwareCompare(). | - | ||||||||||||||||||
| 5372 | - | |||||||||||||||||||
| 5373 | \snippet qstring/main.cpp 16 | - | ||||||||||||||||||
| 5374 | - | |||||||||||||||||||
| 5375 | \sa operator==(), operator<(), operator>() | - | ||||||||||||||||||
| 5376 | */ | - | ||||||||||||||||||
| 5377 | - | |||||||||||||||||||
| 5378 | /*! | - | ||||||||||||||||||
| 5379 | \fn int QString::compare(const QString &s1, QLatin1String s2, Qt::CaseSensitivity cs) | - | ||||||||||||||||||
| 5380 | \since 4.2 | - | ||||||||||||||||||
| 5381 | \overload compare() | - | ||||||||||||||||||
| 5382 | - | |||||||||||||||||||
| 5383 | Performs a comparison of \a s1 and \a s2, using the case | - | ||||||||||||||||||
| 5384 | sensitivity setting \a cs. | - | ||||||||||||||||||
| 5385 | */ | - | ||||||||||||||||||
| 5386 | - | |||||||||||||||||||
| 5387 | /*! | - | ||||||||||||||||||
| 5388 | \fn int QString::compare(QLatin1String s1, const QString &s2, Qt::CaseSensitivity cs = Qt::CaseSensitive) | - | ||||||||||||||||||
| 5389 | - | |||||||||||||||||||
| 5390 | \since 4.2 | - | ||||||||||||||||||
| 5391 | \overload compare() | - | ||||||||||||||||||
| 5392 | - | |||||||||||||||||||
| 5393 | Performs a comparison of \a s1 and \a s2, using the case | - | ||||||||||||||||||
| 5394 | sensitivity setting \a cs. | - | ||||||||||||||||||
| 5395 | */ | - | ||||||||||||||||||
| 5396 | - | |||||||||||||||||||
| 5397 | - | |||||||||||||||||||
| 5398 | /*! | - | ||||||||||||||||||
| 5399 | \overload compare() | - | ||||||||||||||||||
| 5400 | \since 4.2 | - | ||||||||||||||||||
| 5401 | - | |||||||||||||||||||
| 5402 | Lexically compares this string with the \a other string and | - | ||||||||||||||||||
| 5403 | returns an integer less than, equal to, or greater than zero if | - | ||||||||||||||||||
| 5404 | this string is less than, equal to, or greater than the other | - | ||||||||||||||||||
| 5405 | string. | - | ||||||||||||||||||
| 5406 | - | |||||||||||||||||||
| 5407 | Same as compare(*this, \a other, \a cs). | - | ||||||||||||||||||
| 5408 | */ | - | ||||||||||||||||||
| 5409 | int QString::compare(const QString &other, Qt::CaseSensitivity cs) const | - | ||||||||||||||||||
| 5410 | { | - | ||||||||||||||||||
| 5411 | if (cs == Qt::CaseSensitive)
| 235536-491957 | ||||||||||||||||||
| 5412 | return ucstrcmp(constData(), length(), other.constData(), other.length()); executed 235536 times by 214 tests: return ucstrcmp(constData(), length(), other.constData(), other.length());Executed by:
| 235536 | ||||||||||||||||||
| 5413 | return ucstricmp(d->data(), d->data() + d->size, other.d->data(), other.d->data() + other.d->size); executed 491957 times by 160 tests: return ucstricmp(d->data(), d->data() + d->size, other.d->data(), other.d->data() + other.d->size);Executed by:
| 491957 | ||||||||||||||||||
| 5414 | } | - | ||||||||||||||||||
| 5415 | - | |||||||||||||||||||
| 5416 | /*! | - | ||||||||||||||||||
| 5417 | \internal | - | ||||||||||||||||||
| 5418 | \since 4.5 | - | ||||||||||||||||||
| 5419 | */ | - | ||||||||||||||||||
| 5420 | int QString::compare_helper(const QChar *data1, int length1, const QChar *data2, int length2, | - | ||||||||||||||||||
| 5421 | Qt::CaseSensitivity cs) | - | ||||||||||||||||||
| 5422 | { | - | ||||||||||||||||||
| 5423 | if (cs == Qt::CaseSensitive)
| 162-373040 | ||||||||||||||||||
| 5424 | return ucstrcmp(data1, length1, data2, length2); executed 373040 times by 62 tests: return ucstrcmp(data1, length1, data2, length2);Executed by:
| 373040 | ||||||||||||||||||
| 5425 | const ushort *s1 = reinterpret_cast<const ushort *>(data1); | - | ||||||||||||||||||
| 5426 | const ushort *s2 = reinterpret_cast<const ushort *>(data2); | - | ||||||||||||||||||
| 5427 | return ucstricmp(s1, s1 + length1, s2, s2 + length2); executed 162 times by 3 tests: return ucstricmp(s1, s1 + length1, s2, s2 + length2);Executed by:
| 162 | ||||||||||||||||||
| 5428 | } | - | ||||||||||||||||||
| 5429 | - | |||||||||||||||||||
| 5430 | /*! | - | ||||||||||||||||||
| 5431 | \overload compare() | - | ||||||||||||||||||
| 5432 | \since 4.2 | - | ||||||||||||||||||
| 5433 | - | |||||||||||||||||||
| 5434 | Same as compare(*this, \a other, \a cs). | - | ||||||||||||||||||
| 5435 | */ | - | ||||||||||||||||||
| 5436 | int QString::compare(QLatin1String other, Qt::CaseSensitivity cs) const | - | ||||||||||||||||||
| 5437 | { | - | ||||||||||||||||||
| 5438 | return compare_helper(unicode(), length(), other, cs); executed 18451 times by 66 tests: return compare_helper(unicode(), length(), other, cs);Executed by:
| 18451 | ||||||||||||||||||
| 5439 | } | - | ||||||||||||||||||
| 5440 | - | |||||||||||||||||||
| 5441 | /*! | - | ||||||||||||||||||
| 5442 | \fn int QString::compare(const QStringRef &ref, Qt::CaseSensitivity cs = Qt::CaseSensitive) const | - | ||||||||||||||||||
| 5443 | \overload compare() | - | ||||||||||||||||||
| 5444 | - | |||||||||||||||||||
| 5445 | Compares the string reference, \a ref, with the string and returns | - | ||||||||||||||||||
| 5446 | an integer less than, equal to, or greater than zero if the string | - | ||||||||||||||||||
| 5447 | is less than, equal to, or greater than \a ref. | - | ||||||||||||||||||
| 5448 | */ | - | ||||||||||||||||||
| 5449 | - | |||||||||||||||||||
| 5450 | /*! | - | ||||||||||||||||||
| 5451 | \internal | - | ||||||||||||||||||
| 5452 | \since 5.0 | - | ||||||||||||||||||
| 5453 | */ | - | ||||||||||||||||||
| 5454 | int QString::compare_helper(const QChar *data1, int length1, const char *data2, int length2, | - | ||||||||||||||||||
| 5455 | Qt::CaseSensitivity cs) | - | ||||||||||||||||||
| 5456 | { | - | ||||||||||||||||||
| 5457 | // ### optimize me | - | ||||||||||||||||||
| 5458 | const QString s2 = QString::fromUtf8(data2, length2 == -1 ? (data2 ? int(strlen(data2)) : -1) : length2); | - | ||||||||||||||||||
| 5459 | return compare_helper(data1, length1, s2.constData(), s2.size(), cs); executed 372703 times by 61 tests: return compare_helper(data1, length1, s2.constData(), s2.size(), cs);Executed by:
| 372703 | ||||||||||||||||||
| 5460 | } | - | ||||||||||||||||||
| 5461 | - | |||||||||||||||||||
| 5462 | /*! | - | ||||||||||||||||||
| 5463 | \fn int QString::compare(const QString &s1, const QStringRef &s2, Qt::CaseSensitivity cs = Qt::CaseSensitive) | - | ||||||||||||||||||
| 5464 | \overload compare() | - | ||||||||||||||||||
| 5465 | */ | - | ||||||||||||||||||
| 5466 | - | |||||||||||||||||||
| 5467 | /*! | - | ||||||||||||||||||
| 5468 | \internal | - | ||||||||||||||||||
| 5469 | \since 4.5 | - | ||||||||||||||||||
| 5470 | */ | - | ||||||||||||||||||
| 5471 | int QString::compare_helper(const QChar *data1, int length1, QLatin1String s2, | - | ||||||||||||||||||
| 5472 | Qt::CaseSensitivity cs) | - | ||||||||||||||||||
| 5473 | { | - | ||||||||||||||||||
| 5474 | const ushort *uc = reinterpret_cast<const ushort *>(data1); | - | ||||||||||||||||||
| 5475 | const ushort *uce = uc + length1; | - | ||||||||||||||||||
| 5476 | const uchar *c = (const uchar *)s2.latin1(); | - | ||||||||||||||||||
| 5477 | - | |||||||||||||||||||
| 5478 | if (!c)
| 0-535041 | ||||||||||||||||||
| 5479 | return length1; never executed: return length1; | 0 | ||||||||||||||||||
| 5480 | - | |||||||||||||||||||
| 5481 | if (cs == Qt::CaseSensitive) {
| 16802-518239 | ||||||||||||||||||
| 5482 | return ucstrcmp(data1, length1, c, s2.size()); executed 518239 times by 443 tests: return ucstrcmp(data1, length1, c, s2.size());Executed by:
| 518239 | ||||||||||||||||||
| 5483 | } else { | - | ||||||||||||||||||
| 5484 | return ucstricmp(uc, uce, c, c + s2.size()); executed 16802 times by 48 tests: return ucstricmp(uc, uce, c, c + s2.size());Executed by:
| 16802 | ||||||||||||||||||
| 5485 | } | - | ||||||||||||||||||
| 5486 | } | - | ||||||||||||||||||
| 5487 | - | |||||||||||||||||||
| 5488 | /*! | - | ||||||||||||||||||
| 5489 | \fn int QString::localeAwareCompare(const QString & s1, const QString & s2) | - | ||||||||||||||||||
| 5490 | - | |||||||||||||||||||
| 5491 | Compares \a s1 with \a s2 and returns an integer less than, equal | - | ||||||||||||||||||
| 5492 | to, or greater than zero if \a s1 is less than, equal to, or | - | ||||||||||||||||||
| 5493 | greater than \a s2. | - | ||||||||||||||||||
| 5494 | - | |||||||||||||||||||
| 5495 | The comparison is performed in a locale- and also | - | ||||||||||||||||||
| 5496 | platform-dependent manner. Use this function to present sorted | - | ||||||||||||||||||
| 5497 | lists of strings to the user. | - | ||||||||||||||||||
| 5498 | - | |||||||||||||||||||
| 5499 | On \macos and iOS this function compares according the | - | ||||||||||||||||||
| 5500 | "Order for sorted lists" setting in the International preferences panel. | - | ||||||||||||||||||
| 5501 | - | |||||||||||||||||||
| 5502 | \sa compare(), QLocale | - | ||||||||||||||||||
| 5503 | */ | - | ||||||||||||||||||
| 5504 | - | |||||||||||||||||||
| 5505 | /*! | - | ||||||||||||||||||
| 5506 | \fn int QString::localeAwareCompare(const QStringRef &other) const | - | ||||||||||||||||||
| 5507 | \since 4.5 | - | ||||||||||||||||||
| 5508 | \overload localeAwareCompare() | - | ||||||||||||||||||
| 5509 | - | |||||||||||||||||||
| 5510 | Compares this string with the \a other string and returns an | - | ||||||||||||||||||
| 5511 | integer less than, equal to, or greater than zero if this string | - | ||||||||||||||||||
| 5512 | is less than, equal to, or greater than the \a other string. | - | ||||||||||||||||||
| 5513 | - | |||||||||||||||||||
| 5514 | The comparison is performed in a locale- and also | - | ||||||||||||||||||
| 5515 | platform-dependent manner. Use this function to present sorted | - | ||||||||||||||||||
| 5516 | lists of strings to the user. | - | ||||||||||||||||||
| 5517 | - | |||||||||||||||||||
| 5518 | Same as \c {localeAwareCompare(*this, other)}. | - | ||||||||||||||||||
| 5519 | */ | - | ||||||||||||||||||
| 5520 | - | |||||||||||||||||||
| 5521 | /*! | - | ||||||||||||||||||
| 5522 | \fn int QString::localeAwareCompare(const QString &s1, const QStringRef &s2) | - | ||||||||||||||||||
| 5523 | \since 4.5 | - | ||||||||||||||||||
| 5524 | \overload localeAwareCompare() | - | ||||||||||||||||||
| 5525 | - | |||||||||||||||||||
| 5526 | Compares \a s1 with \a s2 and returns an integer less than, equal | - | ||||||||||||||||||
| 5527 | to, or greater than zero if \a s1 is less than, equal to, or | - | ||||||||||||||||||
| 5528 | greater than \a s2. | - | ||||||||||||||||||
| 5529 | - | |||||||||||||||||||
| 5530 | The comparison is performed in a locale- and also | - | ||||||||||||||||||
| 5531 | platform-dependent manner. Use this function to present sorted | - | ||||||||||||||||||
| 5532 | lists of strings to the user. | - | ||||||||||||||||||
| 5533 | */ | - | ||||||||||||||||||
| 5534 | - | |||||||||||||||||||
| 5535 | - | |||||||||||||||||||
| 5536 | #if !defined(CSTR_LESS_THAN) | - | ||||||||||||||||||
| 5537 | #define CSTR_LESS_THAN 1 | - | ||||||||||||||||||
| 5538 | #define CSTR_EQUAL 2 | - | ||||||||||||||||||
| 5539 | #define CSTR_GREATER_THAN 3 | - | ||||||||||||||||||
| 5540 | #endif | - | ||||||||||||||||||
| 5541 | - | |||||||||||||||||||
| 5542 | /*! | - | ||||||||||||||||||
| 5543 | \overload localeAwareCompare() | - | ||||||||||||||||||
| 5544 | - | |||||||||||||||||||
| 5545 | Compares this string with the \a other string and returns an | - | ||||||||||||||||||
| 5546 | integer less than, equal to, or greater than zero if this string | - | ||||||||||||||||||
| 5547 | is less than, equal to, or greater than the \a other string. | - | ||||||||||||||||||
| 5548 | - | |||||||||||||||||||
| 5549 | The comparison is performed in a locale- and also | - | ||||||||||||||||||
| 5550 | platform-dependent manner. Use this function to present sorted | - | ||||||||||||||||||
| 5551 | lists of strings to the user. | - | ||||||||||||||||||
| 5552 | - | |||||||||||||||||||
| 5553 | Same as \c {localeAwareCompare(*this, other)}. | - | ||||||||||||||||||
| 5554 | */ | - | ||||||||||||||||||
| 5555 | int QString::localeAwareCompare(const QString &other) const | - | ||||||||||||||||||
| 5556 | { | - | ||||||||||||||||||
| 5557 | return localeAwareCompare_helper(constData(), length(), other.constData(), other.length()); executed 11402 times by 6 tests: return localeAwareCompare_helper(constData(), length(), other.constData(), other.length());Executed by:
| 11402 | ||||||||||||||||||
| 5558 | } | - | ||||||||||||||||||
| 5559 | - | |||||||||||||||||||
| 5560 | #if defined(QT_USE_ICU) && !defined(Q_OS_WIN32) && !defined(Q_OS_WINCE) && !defined (Q_OS_MAC) | - | ||||||||||||||||||
| 5561 | Q_GLOBAL_STATIC(QThreadStorage<QCollator>, defaultCollator) executed 6 times by 6 tests: end of blockExecuted by:
executed 6 times by 6 tests: guard.store(QtGlobalStatic::Destroyed);Executed by:
executed 22796 times by 6 tests: return &holder.value;Executed by:
| 0-22796 | ||||||||||||||||||
| 5562 | #endif | - | ||||||||||||||||||
| 5563 | - | |||||||||||||||||||
| 5564 | /*! | - | ||||||||||||||||||
| 5565 | \internal | - | ||||||||||||||||||
| 5566 | \since 4.5 | - | ||||||||||||||||||
| 5567 | */ | - | ||||||||||||||||||
| 5568 | int QString::localeAwareCompare_helper(const QChar *data1, int length1, | - | ||||||||||||||||||
| 5569 | const QChar *data2, int length2) | - | ||||||||||||||||||
| 5570 | { | - | ||||||||||||||||||
| 5571 | // do the right thing for null and empty | - | ||||||||||||||||||
| 5572 | if (length1 == 0 || length2 == 0)
| 0-11395 | ||||||||||||||||||
| 5573 | return ucstrcmp(data1, length1, data2, length2); executed 7 times by 1 test: return ucstrcmp(data1, length1, data2, length2);Executed by:
| 7 | ||||||||||||||||||
| 5574 | - | |||||||||||||||||||
| 5575 | #if defined(Q_OS_WIN32) || defined(Q_OS_WINCE) | - | ||||||||||||||||||
| 5576 | #ifndef Q_OS_WINRT | - | ||||||||||||||||||
| 5577 | int res = CompareString(GetUserDefaultLCID(), 0, (wchar_t*)data1, length1, (wchar_t*)data2, length2); | - | ||||||||||||||||||
| 5578 | #else | - | ||||||||||||||||||
| 5579 | int res = CompareStringEx(LOCALE_NAME_USER_DEFAULT, 0, (LPCWSTR)data1, length1, (LPCWSTR)data2, length2, NULL, NULL, 0); | - | ||||||||||||||||||
| 5580 | #endif | - | ||||||||||||||||||
| 5581 | - | |||||||||||||||||||
| 5582 | switch (res) { | - | ||||||||||||||||||
| 5583 | case CSTR_LESS_THAN: | - | ||||||||||||||||||
| 5584 | return -1; | - | ||||||||||||||||||
| 5585 | case CSTR_GREATER_THAN: | - | ||||||||||||||||||
| 5586 | return 1; | - | ||||||||||||||||||
| 5587 | default: | - | ||||||||||||||||||
| 5588 | return 0; | - | ||||||||||||||||||
| 5589 | } | - | ||||||||||||||||||
| 5590 | #elif defined (Q_OS_MAC) | - | ||||||||||||||||||
| 5591 | // Use CFStringCompare for comparing strings on Mac. This makes Qt order | - | ||||||||||||||||||
| 5592 | // strings the same way as native applications do, and also respects | - | ||||||||||||||||||
| 5593 | // the "Order for sorted lists" setting in the International preferences | - | ||||||||||||||||||
| 5594 | // panel. | - | ||||||||||||||||||
| 5595 | const CFStringRef thisString = | - | ||||||||||||||||||
| 5596 | CFStringCreateWithCharactersNoCopy(kCFAllocatorDefault, | - | ||||||||||||||||||
| 5597 | reinterpret_cast<const UniChar *>(data1), length1, kCFAllocatorNull); | - | ||||||||||||||||||
| 5598 | const CFStringRef otherString = | - | ||||||||||||||||||
| 5599 | CFStringCreateWithCharactersNoCopy(kCFAllocatorDefault, | - | ||||||||||||||||||
| 5600 | reinterpret_cast<const UniChar *>(data2), length2, kCFAllocatorNull); | - | ||||||||||||||||||
| 5601 | - | |||||||||||||||||||
| 5602 | const int result = CFStringCompare(thisString, otherString, kCFCompareLocalized); | - | ||||||||||||||||||
| 5603 | CFRelease(thisString); | - | ||||||||||||||||||
| 5604 | CFRelease(otherString); | - | ||||||||||||||||||
| 5605 | return result; | - | ||||||||||||||||||
| 5606 | #elif defined(QT_USE_ICU) | - | ||||||||||||||||||
| 5607 | if (!defaultCollator()->hasLocalData())
| 6-11389 | ||||||||||||||||||
| 5608 | defaultCollator()->setLocalData(QCollator()); executed 6 times by 6 tests: defaultCollator()->setLocalData(QCollator());Executed by:
| 6 | ||||||||||||||||||
| 5609 | return defaultCollator()->localData().compare(data1, length1, data2, length2); executed 11395 times by 6 tests: return defaultCollator()->localData().compare(data1, length1, data2, length2);Executed by:
| 11395 | ||||||||||||||||||
| 5610 | #elif defined(Q_OS_UNIX) | - | ||||||||||||||||||
| 5611 | // declared in <string.h> | - | ||||||||||||||||||
| 5612 | int delta = strcoll(toLocal8Bit_helper(data1, length1).constData(), toLocal8Bit_helper(data2, length2).constData()); | - | ||||||||||||||||||
| 5613 | if (delta == 0) | - | ||||||||||||||||||
| 5614 | delta = ucstrcmp(data1, length1, data2, length2); | - | ||||||||||||||||||
| 5615 | return delta; | - | ||||||||||||||||||
| 5616 | #else | - | ||||||||||||||||||
| 5617 | return ucstrcmp(data1, length1, data2, length2); | - | ||||||||||||||||||
| 5618 | #endif | - | ||||||||||||||||||
| 5619 | } | - | ||||||||||||||||||
| 5620 | - | |||||||||||||||||||
| 5621 | - | |||||||||||||||||||
| 5622 | /*! | - | ||||||||||||||||||
| 5623 | \fn const QChar *QString::unicode() const | - | ||||||||||||||||||
| 5624 | - | |||||||||||||||||||
| 5625 | Returns a '\\0'-terminated Unicode representation of the string. | - | ||||||||||||||||||
| 5626 | The result remains valid until the string is modified. | - | ||||||||||||||||||
| 5627 | - | |||||||||||||||||||
| 5628 | \sa utf16() | - | ||||||||||||||||||
| 5629 | */ | - | ||||||||||||||||||
| 5630 | - | |||||||||||||||||||
| 5631 | /*! | - | ||||||||||||||||||
| 5632 | \fn const ushort *QString::utf16() const | - | ||||||||||||||||||
| 5633 | - | |||||||||||||||||||
| 5634 | Returns the QString as a '\\0\'-terminated array of unsigned | - | ||||||||||||||||||
| 5635 | shorts. The result remains valid until the string is modified. | - | ||||||||||||||||||
| 5636 | - | |||||||||||||||||||
| 5637 | The returned string is in host byte order. | - | ||||||||||||||||||
| 5638 | - | |||||||||||||||||||
| 5639 | \sa unicode() | - | ||||||||||||||||||
| 5640 | */ | - | ||||||||||||||||||
| 5641 | - | |||||||||||||||||||
| 5642 | const ushort *QString::utf16() const | - | ||||||||||||||||||
| 5643 | { | - | ||||||||||||||||||
| 5644 | if (IS_RAW_DATA(d)) {
| 0-124123 | ||||||||||||||||||
| 5645 | // ensure '\0'-termination for ::fromRawData strings | - | ||||||||||||||||||
| 5646 | const_cast<QString*>(this)->reallocData(uint(d->size) + 1u); | - | ||||||||||||||||||
| 5647 | } never executed: end of block | 0 | ||||||||||||||||||
| 5648 | return d->data(); executed 124123 times by 30 tests: return d->data();Executed by:
| 124123 | ||||||||||||||||||
| 5649 | } | - | ||||||||||||||||||
| 5650 | - | |||||||||||||||||||
| 5651 | /*! | - | ||||||||||||||||||
| 5652 | Returns a string of size \a width that contains this string | - | ||||||||||||||||||
| 5653 | padded by the \a fill character. | - | ||||||||||||||||||
| 5654 | - | |||||||||||||||||||
| 5655 | If \a truncate is \c false and the size() of the string is more than | - | ||||||||||||||||||
| 5656 | \a width, then the returned string is a copy of the string. | - | ||||||||||||||||||
| 5657 | - | |||||||||||||||||||
| 5658 | \snippet qstring/main.cpp 32 | - | ||||||||||||||||||
| 5659 | - | |||||||||||||||||||
| 5660 | If \a truncate is \c true and the size() of the string is more than | - | ||||||||||||||||||
| 5661 | \a width, then any characters in a copy of the string after | - | ||||||||||||||||||
| 5662 | position \a width are removed, and the copy is returned. | - | ||||||||||||||||||
| 5663 | - | |||||||||||||||||||
| 5664 | \snippet qstring/main.cpp 33 | - | ||||||||||||||||||
| 5665 | - | |||||||||||||||||||
| 5666 | \sa rightJustified() | - | ||||||||||||||||||
| 5667 | */ | - | ||||||||||||||||||
| 5668 | - | |||||||||||||||||||
| 5669 | QString QString::leftJustified(int width, QChar fill, bool truncate) const | - | ||||||||||||||||||
| 5670 | { | - | ||||||||||||||||||
| 5671 | QString result; | - | ||||||||||||||||||
| 5672 | int len = length(); | - | ||||||||||||||||||
| 5673 | int padlen = width - len; | - | ||||||||||||||||||
| 5674 | if (padlen > 0) {
| 804-4209 | ||||||||||||||||||
| 5675 | result.resize(len+padlen); | - | ||||||||||||||||||
| 5676 | if (len)
| 1-803 | ||||||||||||||||||
| 5677 | memcpy(result.d->data(), d->data(), sizeof(QChar)*len); executed 803 times by 3 tests: memcpy(result.d->data(), d->data(), sizeof(QChar)*len);Executed by:
| 803 | ||||||||||||||||||
| 5678 | QChar *uc = (QChar*)result.d->data() + len; | - | ||||||||||||||||||
| 5679 | while (padlen--)
| 804-32181 | ||||||||||||||||||
| 5680 | * uc++ = fill; executed 32181 times by 3 tests: * uc++ = fill;Executed by:
| 32181 | ||||||||||||||||||
| 5681 | } else { executed 804 times by 3 tests: end of blockExecuted by:
| 804 | ||||||||||||||||||
| 5682 | if (truncate)
| 4-4205 | ||||||||||||||||||
| 5683 | result = left(width); executed 4 times by 1 test: result = left(width);Executed by:
| 4 | ||||||||||||||||||
| 5684 | else | - | ||||||||||||||||||
| 5685 | result = *this; executed 4205 times by 1 test: result = *this;Executed by:
| 4205 | ||||||||||||||||||
| 5686 | } | - | ||||||||||||||||||
| 5687 | return result; executed 5013 times by 3 tests: return result;Executed by:
| 5013 | ||||||||||||||||||
| 5688 | } | - | ||||||||||||||||||
| 5689 | - | |||||||||||||||||||
| 5690 | /*! | - | ||||||||||||||||||
| 5691 | Returns a string of size() \a width that contains the \a fill | - | ||||||||||||||||||
| 5692 | character followed by the string. For example: | - | ||||||||||||||||||
| 5693 | - | |||||||||||||||||||
| 5694 | \snippet qstring/main.cpp 49 | - | ||||||||||||||||||
| 5695 | - | |||||||||||||||||||
| 5696 | If \a truncate is \c false and the size() of the string is more than | - | ||||||||||||||||||
| 5697 | \a width, then the returned string is a copy of the string. | - | ||||||||||||||||||
| 5698 | - | |||||||||||||||||||
| 5699 | If \a truncate is true and the size() of the string is more than | - | ||||||||||||||||||
| 5700 | \a width, then the resulting string is truncated at position \a | - | ||||||||||||||||||
| 5701 | width. | - | ||||||||||||||||||
| 5702 | - | |||||||||||||||||||
| 5703 | \snippet qstring/main.cpp 50 | - | ||||||||||||||||||
| 5704 | - | |||||||||||||||||||
| 5705 | \sa leftJustified() | - | ||||||||||||||||||
| 5706 | */ | - | ||||||||||||||||||
| 5707 | - | |||||||||||||||||||
| 5708 | QString QString::rightJustified(int width, QChar fill, bool truncate) const | - | ||||||||||||||||||
| 5709 | { | - | ||||||||||||||||||
| 5710 | QString result; | - | ||||||||||||||||||
| 5711 | int len = length(); | - | ||||||||||||||||||
| 5712 | int padlen = width - len; | - | ||||||||||||||||||
| 5713 | if (padlen > 0) {
| 800-348892 | ||||||||||||||||||
| 5714 | result.resize(len+padlen); | - | ||||||||||||||||||
| 5715 | QChar *uc = (QChar*)result.d->data(); | - | ||||||||||||||||||
| 5716 | while (padlen--)
| 800-30752 | ||||||||||||||||||
| 5717 | * uc++ = fill; executed 30752 times by 4 tests: * uc++ = fill;Executed by:
| 30752 | ||||||||||||||||||
| 5718 | if (len)
| 1-799 | ||||||||||||||||||
| 5719 | memcpy(uc, d->data(), sizeof(QChar)*len); executed 799 times by 4 tests: memcpy(uc, d->data(), sizeof(QChar)*len);Executed by:
| 799 | ||||||||||||||||||
| 5720 | } else { executed 800 times by 4 tests: end of blockExecuted by:
| 800 | ||||||||||||||||||
| 5721 | if (truncate)
| 4-348888 | ||||||||||||||||||
| 5722 | result = left(width); executed 4 times by 1 test: result = left(width);Executed by:
| 4 | ||||||||||||||||||
| 5723 | else | - | ||||||||||||||||||
| 5724 | result = *this; executed 348888 times by 110 tests: result = *this;Executed by:
| 348888 | ||||||||||||||||||
| 5725 | } | - | ||||||||||||||||||
| 5726 | return result; executed 349692 times by 110 tests: return result;Executed by:
| 349692 | ||||||||||||||||||
| 5727 | } | - | ||||||||||||||||||
| 5728 | - | |||||||||||||||||||
| 5729 | /*! | - | ||||||||||||||||||
| 5730 | \fn QString QString::toLower() const | - | ||||||||||||||||||
| 5731 | - | |||||||||||||||||||
| 5732 | Returns a lowercase copy of the string. | - | ||||||||||||||||||
| 5733 | - | |||||||||||||||||||
| 5734 | \snippet qstring/main.cpp 75 | - | ||||||||||||||||||
| 5735 | - | |||||||||||||||||||
| 5736 | The case conversion will always happen in the 'C' locale. For locale dependent | - | ||||||||||||||||||
| 5737 | case folding use QLocale::toLower() | - | ||||||||||||||||||
| 5738 | - | |||||||||||||||||||
| 5739 | \sa toUpper(), QLocale::toLower() | - | ||||||||||||||||||
| 5740 | */ | - | ||||||||||||||||||
| 5741 | - | |||||||||||||||||||
| 5742 | namespace QUnicodeTables { | - | ||||||||||||||||||
| 5743 | /* | - | ||||||||||||||||||
| 5744 | \internal | - | ||||||||||||||||||
| 5745 | Converts the \a str string starting from the position pointed to by the \a | - | ||||||||||||||||||
| 5746 | it iterator, using the Unicode case traits \c Traits, and returns the | - | ||||||||||||||||||
| 5747 | result. The input string must not be empty (the convertCase function below | - | ||||||||||||||||||
| 5748 | guarantees that). | - | ||||||||||||||||||
| 5749 | - | |||||||||||||||||||
| 5750 | The string type \c{T} is also a template and is either \c{const QString} or | - | ||||||||||||||||||
| 5751 | \c{QString}. This function can do both copy-conversion and in-place | - | ||||||||||||||||||
| 5752 | conversion depending on the state of the \a str parameter: | - | ||||||||||||||||||
| 5753 | \list | - | ||||||||||||||||||
| 5754 | \li \c{T} is \c{const QString}: copy-convert | - | ||||||||||||||||||
| 5755 | \li \c{T} is \c{QString} and its refcount != 1: copy-convert | - | ||||||||||||||||||
| 5756 | \li \c{T} is \c{QString} and its refcount == 1: in-place convert | - | ||||||||||||||||||
| 5757 | \endlist | - | ||||||||||||||||||
| 5758 | - | |||||||||||||||||||
| 5759 | In copy-convert mode, the local variable \c{s} is detached from the input | - | ||||||||||||||||||
| 5760 | \a str. In the in-place convert mode, \a str is in moved-from state (which | - | ||||||||||||||||||
| 5761 | this function requires to be a valid, empty string) and \c{s} contains the | - | ||||||||||||||||||
| 5762 | only copy of the string, without reallocation (thus, \a it is still valid). | - | ||||||||||||||||||
| 5763 | - | |||||||||||||||||||
| 5764 | There's one pathological case left: when the in-place conversion needs to | - | ||||||||||||||||||
| 5765 | reallocate memory to grow the buffer. In that case, we need to adjust the \a | - | ||||||||||||||||||
| 5766 | it pointer. | - | ||||||||||||||||||
| 5767 | */ | - | ||||||||||||||||||
| 5768 | template <typename Traits, typename T> | - | ||||||||||||||||||
| 5769 | Q_NEVER_INLINE | - | ||||||||||||||||||
| 5770 | static QString detachAndConvertCase(T &str, QStringIterator it) | - | ||||||||||||||||||
| 5771 | { | - | ||||||||||||||||||
| 5772 | Q_ASSERT(!str.isEmpty()); | - | ||||||||||||||||||
| 5773 | QString s = qMove(str); // will copy if T is const QString | - | ||||||||||||||||||
| 5774 | QChar *pp = s.begin() + it.index(); // will detach if necessary | - | ||||||||||||||||||
| 5775 | - | |||||||||||||||||||
| 5776 | do { | - | ||||||||||||||||||
| 5777 | uint uc = it.nextUnchecked(); | - | ||||||||||||||||||
| 5778 | - | |||||||||||||||||||
| 5779 | const QUnicodeTables::Properties *prop = qGetProp(uc); | - | ||||||||||||||||||
| 5780 | signed short caseDiff = Traits::caseDiff(prop); | - | ||||||||||||||||||
| 5781 | - | |||||||||||||||||||
| 5782 | if (Q_UNLIKELY(Traits::caseSpecial(prop))) {
| 212-2302984 | ||||||||||||||||||
| 5783 | const ushort *specialCase = specialCaseMap + caseDiff; | - | ||||||||||||||||||
| 5784 | ushort length = *specialCase++; | - | ||||||||||||||||||
| 5785 | - | |||||||||||||||||||
| 5786 | if (Q_LIKELY(length == 1)) {
| 8-204 | ||||||||||||||||||
| 5787 | *pp++ = QChar(*specialCase); | - | ||||||||||||||||||
| 5788 | } else { executed 204 times by 1 test: end of blockExecuted by:
| 204 | ||||||||||||||||||
| 5789 | // slow path: the string is growing | - | ||||||||||||||||||
| 5790 | int inpos = it.index() - 1; | - | ||||||||||||||||||
| 5791 | int outpos = pp - s.constBegin(); | - | ||||||||||||||||||
| 5792 | - | |||||||||||||||||||
| 5793 | s.replace(outpos, 1, reinterpret_cast<const QChar *>(specialCase), length); | - | ||||||||||||||||||
| 5794 | pp = const_cast<QChar *>(s.constBegin()) + outpos + length; | - | ||||||||||||||||||
| 5795 | - | |||||||||||||||||||
| 5796 | // do we need to adjust the input iterator too? | - | ||||||||||||||||||
| 5797 | // if it is pointing to s's data, str is empty | - | ||||||||||||||||||
| 5798 | if (str.isEmpty())
| 2-6 | ||||||||||||||||||
| 5799 | it = QStringIterator(s.constBegin(), inpos + length, s.constEnd()); executed 6 times by 1 test: it = QStringIterator(s.constBegin(), inpos + length, s.constEnd());Executed by:
| 6 | ||||||||||||||||||
| 5800 | } executed 8 times by 1 test: end of blockExecuted by:
| 8 | ||||||||||||||||||
| 5801 | } else if (Q_UNLIKELY(QChar::requiresSurrogates(uc))) {
| 23-2302961 | ||||||||||||||||||
| 5802 | // so far, case convertion never changes planes (guaranteed by the qunicodetables generator) | - | ||||||||||||||||||
| 5803 | pp++; | - | ||||||||||||||||||
| 5804 | *pp++ = QChar::lowSurrogate(uc + caseDiff); | - | ||||||||||||||||||
| 5805 | } else { executed 23 times by 2 tests: end of blockExecuted by:
| 23 | ||||||||||||||||||
| 5806 | *pp++ = QChar(uc + caseDiff); | - | ||||||||||||||||||
| 5807 | } executed 2302961 times by 188 tests: end of blockExecuted by:
| 2302961 | ||||||||||||||||||
| 5808 | } while (it.hasNext());
| 266523-2036673 | ||||||||||||||||||
| 5809 | - | |||||||||||||||||||
| 5810 | return s; executed 266523 times by 188 tests: return s;Executed by:
| 266523 | ||||||||||||||||||
| 5811 | } | - | ||||||||||||||||||
| 5812 | - | |||||||||||||||||||
| 5813 | template <typename Traits, typename T> | - | ||||||||||||||||||
| 5814 | static QString convertCase(T &str) | - | ||||||||||||||||||
| 5815 | { | - | ||||||||||||||||||
| 5816 | const QChar *p = str.constBegin(); | - | ||||||||||||||||||
| 5817 | const QChar *e = p + str.size(); | - | ||||||||||||||||||
| 5818 | - | |||||||||||||||||||
| 5819 | // this avoids out of bounds check in the loop | - | ||||||||||||||||||
| 5820 | while (e != p && e[-1].isHighSurrogate())
| 2054-457969 | ||||||||||||||||||
| 5821 | --e; executed 2054 times by 1 test: --e;Executed by:
| 2054 | ||||||||||||||||||
| 5822 | - | |||||||||||||||||||
| 5823 | QStringIterator it(p, e); | - | ||||||||||||||||||
| 5824 | while (it.hasNext()) {
| 193330-755433 | ||||||||||||||||||
| 5825 | uint uc = it.nextUnchecked(); | - | ||||||||||||||||||
| 5826 | if (Traits::caseDiff(qGetProp(uc))) {
| 266523-488910 | ||||||||||||||||||
| 5827 | it.recedeUnchecked(); | - | ||||||||||||||||||
| 5828 | return detachAndConvertCase<Traits>(str, it); executed 266523 times by 188 tests: return detachAndConvertCase<Traits>(str, it);Executed by:
| 266523 | ||||||||||||||||||
| 5829 | } | - | ||||||||||||||||||
| 5830 | } executed 488910 times by 182 tests: end of blockExecuted by:
| 488910 | ||||||||||||||||||
| 5831 | return qMove(str); executed 193330 times by 179 tests: return std::move(str);Executed by:
| 193330 | ||||||||||||||||||
| 5832 | } | - | ||||||||||||||||||
| 5833 | } // namespace QUnicodeTables | - | ||||||||||||||||||
| 5834 | - | |||||||||||||||||||
| 5835 | QString QString::toLower_helper(const QString &str) | - | ||||||||||||||||||
| 5836 | { | - | ||||||||||||||||||
| 5837 | return QUnicodeTables::convertCase<QUnicodeTables::LowercaseTraits>(str); executed 222004 times by 197 tests: return QUnicodeTables::convertCase<QUnicodeTables::LowercaseTraits>(str);Executed by:
| 222004 | ||||||||||||||||||
| 5838 | } | - | ||||||||||||||||||
| 5839 | - | |||||||||||||||||||
| 5840 | QString QString::toLower_helper(QString &str) | - | ||||||||||||||||||
| 5841 | { | - | ||||||||||||||||||
| 5842 | return QUnicodeTables::convertCase<QUnicodeTables::LowercaseTraits>(str); executed 51524 times by 177 tests: return QUnicodeTables::convertCase<QUnicodeTables::LowercaseTraits>(str);Executed by:
| 51524 | ||||||||||||||||||
| 5843 | } | - | ||||||||||||||||||
| 5844 | - | |||||||||||||||||||
| 5845 | /*! | - | ||||||||||||||||||
| 5846 | \fn QString QString::toCaseFolded() const | - | ||||||||||||||||||
| 5847 | - | |||||||||||||||||||
| 5848 | Returns the case folded equivalent of the string. For most Unicode | - | ||||||||||||||||||
| 5849 | characters this is the same as toLower(). | - | ||||||||||||||||||
| 5850 | */ | - | ||||||||||||||||||
| 5851 | - | |||||||||||||||||||
| 5852 | QString QString::toCaseFolded_helper(const QString &str) | - | ||||||||||||||||||
| 5853 | { | - | ||||||||||||||||||
| 5854 | return QUnicodeTables::convertCase<QUnicodeTables::CasefoldTraits>(str); executed 175591 times by 125 tests: return QUnicodeTables::convertCase<QUnicodeTables::CasefoldTraits>(str);Executed by:
| 175591 | ||||||||||||||||||
| 5855 | } | - | ||||||||||||||||||
| 5856 | - | |||||||||||||||||||
| 5857 | QString QString::toCaseFolded_helper(QString &str) | - | ||||||||||||||||||
| 5858 | { | - | ||||||||||||||||||
| 5859 | return QUnicodeTables::convertCase<QUnicodeTables::CasefoldTraits>(str); executed 18 times by 1 test: return QUnicodeTables::convertCase<QUnicodeTables::CasefoldTraits>(str);Executed by:
| 18 | ||||||||||||||||||
| 5860 | } | - | ||||||||||||||||||
| 5861 | - | |||||||||||||||||||
| 5862 | /*! | - | ||||||||||||||||||
| 5863 | \fn QString QString::toUpper() const | - | ||||||||||||||||||
| 5864 | - | |||||||||||||||||||
| 5865 | Returns an uppercase copy of the string. | - | ||||||||||||||||||
| 5866 | - | |||||||||||||||||||
| 5867 | \snippet qstring/main.cpp 81 | - | ||||||||||||||||||
| 5868 | - | |||||||||||||||||||
| 5869 | The case conversion will always happen in the 'C' locale. For locale dependent | - | ||||||||||||||||||
| 5870 | case folding use QLocale::toUpper() | - | ||||||||||||||||||
| 5871 | - | |||||||||||||||||||
| 5872 | \sa toLower(), QLocale::toLower() | - | ||||||||||||||||||
| 5873 | */ | - | ||||||||||||||||||
| 5874 | - | |||||||||||||||||||
| 5875 | QString QString::toUpper_helper(const QString &str) | - | ||||||||||||||||||
| 5876 | { | - | ||||||||||||||||||
| 5877 | return QUnicodeTables::convertCase<QUnicodeTables::UppercaseTraits>(str); executed 6050 times by 15 tests: return QUnicodeTables::convertCase<QUnicodeTables::UppercaseTraits>(str);Executed by:
| 6050 | ||||||||||||||||||
| 5878 | } | - | ||||||||||||||||||
| 5879 | - | |||||||||||||||||||
| 5880 | QString QString::toUpper_helper(QString &str) | - | ||||||||||||||||||
| 5881 | { | - | ||||||||||||||||||
| 5882 | return QUnicodeTables::convertCase<QUnicodeTables::UppercaseTraits>(str); executed 4666 times by 23 tests: return QUnicodeTables::convertCase<QUnicodeTables::UppercaseTraits>(str);Executed by:
| 4666 | ||||||||||||||||||
| 5883 | } | - | ||||||||||||||||||
| 5884 | - | |||||||||||||||||||
| 5885 | /*! | - | ||||||||||||||||||
| 5886 | \obsolete | - | ||||||||||||||||||
| 5887 | - | |||||||||||||||||||
| 5888 | Use asprintf(), arg() or QTextStream instead. | - | ||||||||||||||||||
| 5889 | */ | - | ||||||||||||||||||
| 5890 | QString &QString::sprintf(const char *cformat, ...) | - | ||||||||||||||||||
| 5891 | { | - | ||||||||||||||||||
| 5892 | va_list ap; | - | ||||||||||||||||||
| 5893 | va_start(ap, cformat); | - | ||||||||||||||||||
| 5894 | *this = vasprintf(cformat, ap); | - | ||||||||||||||||||
| 5895 | va_end(ap); | - | ||||||||||||||||||
| 5896 | return *this; executed 10031 times by 3 tests: return *this;Executed by:
| 10031 | ||||||||||||||||||
| 5897 | } | - | ||||||||||||||||||
| 5898 | - | |||||||||||||||||||
| 5899 | // ### Qt 6: Consider whether this function shouldn't be removed See task 202871. | - | ||||||||||||||||||
| 5900 | /*! | - | ||||||||||||||||||
| 5901 | \since 5.5 | - | ||||||||||||||||||
| 5902 | - | |||||||||||||||||||
| 5903 | Safely builds a formatted string from the format string \a cformat | - | ||||||||||||||||||
| 5904 | and an arbitrary list of arguments. | - | ||||||||||||||||||
| 5905 | - | |||||||||||||||||||
| 5906 | The format string supports the conversion specifiers, length modifiers, | - | ||||||||||||||||||
| 5907 | and flags provided by printf() in the standard C++ library. The \a cformat | - | ||||||||||||||||||
| 5908 | string and \c{%s} arguments must be UTF-8 encoded. | - | ||||||||||||||||||
| 5909 | - | |||||||||||||||||||
| 5910 | \note The \c{%lc} escape sequence expects a unicode character of type | - | ||||||||||||||||||
| 5911 | \c char16_t, or \c ushort (as returned by QChar::unicode()). | - | ||||||||||||||||||
| 5912 | The \c{%ls} escape sequence expects a pointer to a zero-terminated array | - | ||||||||||||||||||
| 5913 | of unicode characters of type \c char16_t, or ushort (as returned by | - | ||||||||||||||||||
| 5914 | QString::utf16()). This is at odds with the printf() in the standard C++ | - | ||||||||||||||||||
| 5915 | library, which defines \c {%lc} to print a wchar_t and \c{%ls} to print | - | ||||||||||||||||||
| 5916 | a \c{wchar_t*}, and might also produce compiler warnings on platforms | - | ||||||||||||||||||
| 5917 | where the size of \c {wchar_t} is not 16 bits. | - | ||||||||||||||||||
| 5918 | - | |||||||||||||||||||
| 5919 | \warning We do not recommend using QString::asprintf() in new Qt | - | ||||||||||||||||||
| 5920 | code. Instead, consider using QTextStream or arg(), both of | - | ||||||||||||||||||
| 5921 | which support Unicode strings seamlessly and are type-safe. | - | ||||||||||||||||||
| 5922 | Here's an example that uses QTextStream: | - | ||||||||||||||||||
| 5923 | - | |||||||||||||||||||
| 5924 | \snippet qstring/main.cpp 64 | - | ||||||||||||||||||
| 5925 | - | |||||||||||||||||||
| 5926 | For \l {QObject::tr()}{translations}, especially if the strings | - | ||||||||||||||||||
| 5927 | contains more than one escape sequence, you should consider using | - | ||||||||||||||||||
| 5928 | the arg() function instead. This allows the order of the | - | ||||||||||||||||||
| 5929 | replacements to be controlled by the translator. | - | ||||||||||||||||||
| 5930 | - | |||||||||||||||||||
| 5931 | \sa arg() | - | ||||||||||||||||||
| 5932 | */ | - | ||||||||||||||||||
| 5933 | - | |||||||||||||||||||
| 5934 | QString QString::asprintf(const char *cformat, ...) | - | ||||||||||||||||||
| 5935 | { | - | ||||||||||||||||||
| 5936 | va_list ap; | - | ||||||||||||||||||
| 5937 | va_start(ap, cformat); | - | ||||||||||||||||||
| 5938 | const QString s = vasprintf(cformat, ap); | - | ||||||||||||||||||
| 5939 | va_end(ap); | - | ||||||||||||||||||
| 5940 | return s; executed 25889 times by 48 tests: return s;Executed by:
| 25889 | ||||||||||||||||||
| 5941 | } | - | ||||||||||||||||||
| 5942 | - | |||||||||||||||||||
| 5943 | /*! | - | ||||||||||||||||||
| 5944 | \obsolete | - | ||||||||||||||||||
| 5945 | - | |||||||||||||||||||
| 5946 | Use vasprintf(), arg() or QTextStream instead. | - | ||||||||||||||||||
| 5947 | */ | - | ||||||||||||||||||
| 5948 | QString &QString::vsprintf(const char *cformat, va_list ap) | - | ||||||||||||||||||
| 5949 | { | - | ||||||||||||||||||
| 5950 | return *this = vasprintf(cformat, ap); never executed: return *this = vasprintf(cformat, ap); | 0 | ||||||||||||||||||
| 5951 | } | - | ||||||||||||||||||
| 5952 | - | |||||||||||||||||||
| 5953 | /*! | - | ||||||||||||||||||
| 5954 | \fn QString::vasprintf(const char *cformat, va_list ap) | - | ||||||||||||||||||
| 5955 | \since 5.5 | - | ||||||||||||||||||
| 5956 | - | |||||||||||||||||||
| 5957 | Equivalent method to asprintf(), but takes a va_list \a ap | - | ||||||||||||||||||
| 5958 | instead a list of variable arguments. See the asprintf() | - | ||||||||||||||||||
| 5959 | documentation for an explanation of \a cformat. | - | ||||||||||||||||||
| 5960 | - | |||||||||||||||||||
| 5961 | This method does not call the va_end macro, the caller | - | ||||||||||||||||||
| 5962 | is responsible to call va_end on \a ap. | - | ||||||||||||||||||
| 5963 | - | |||||||||||||||||||
| 5964 | \sa asprintf() | - | ||||||||||||||||||
| 5965 | */ | - | ||||||||||||||||||
| 5966 | - | |||||||||||||||||||
| 5967 | QString QString::vasprintf(const char *cformat, va_list ap) | - | ||||||||||||||||||
| 5968 | { | - | ||||||||||||||||||
| 5969 | if (!cformat || !*cformat) {
| 0-247956 | ||||||||||||||||||
| 5970 | // Qt 1.x compat | - | ||||||||||||||||||
| 5971 | return fromLatin1(""); executed 1 time by 1 test: return fromLatin1("");Executed by:
| 1 | ||||||||||||||||||
| 5972 | } | - | ||||||||||||||||||
| 5973 | - | |||||||||||||||||||
| 5974 | // Parse cformat | - | ||||||||||||||||||
| 5975 | - | |||||||||||||||||||
| 5976 | QString result; | - | ||||||||||||||||||
| 5977 | const char *c = cformat; | - | ||||||||||||||||||
| 5978 | for (;;) { | - | ||||||||||||||||||
| 5979 | // Copy non-escape chars to result | - | ||||||||||||||||||
| 5980 | const char *cb = c; | - | ||||||||||||||||||
| 5981 | while (*c != '\0' && *c != '%')
| 209586-564273 | ||||||||||||||||||
| 5982 | c++; executed 209586 times by 160 tests: c++;Executed by:
| 209586 | ||||||||||||||||||
| 5983 | result.append(QString::fromUtf8(cb, (int)(c - cb))); | - | ||||||||||||||||||
| 5984 | - | |||||||||||||||||||
| 5985 | if (*c == '\0')
| 247956-354687 | ||||||||||||||||||
| 5986 | break; executed 247956 times by 160 tests: break;Executed by:
| 247956 | ||||||||||||||||||
| 5987 | - | |||||||||||||||||||
| 5988 | // Found '%' | - | ||||||||||||||||||
| 5989 | const char *escape_start = c; | - | ||||||||||||||||||
| 5990 | ++c; | - | ||||||||||||||||||
| 5991 | - | |||||||||||||||||||
| 5992 | if (*c == '\0') {
| 0-354687 | ||||||||||||||||||
| 5993 | result.append(QLatin1Char('%')); // a % at the end of the string - treat as non-escape text | - | ||||||||||||||||||
| 5994 | break; never executed: break; | 0 | ||||||||||||||||||
| 5995 | } | - | ||||||||||||||||||
| 5996 | if (*c == '%') {
| 14-354673 | ||||||||||||||||||
| 5997 | result.append(QLatin1Char('%')); // %% | - | ||||||||||||||||||
| 5998 | ++c; | - | ||||||||||||||||||
| 5999 | continue; executed 14 times by 2 tests: continue;Executed by:
| 14 | ||||||||||||||||||
| 6000 | } | - | ||||||||||||||||||
| 6001 | - | |||||||||||||||||||
| 6002 | // Parse flag characters | - | ||||||||||||||||||
| 6003 | uint flags = 0; | - | ||||||||||||||||||
| 6004 | bool no_more_flags = false; | - | ||||||||||||||||||
| 6005 | do { | - | ||||||||||||||||||
| 6006 | switch (*c) { | - | ||||||||||||||||||
| 6007 | case '#': flags |= QLocaleData::Alternate; break; executed 4992 times by 1 test: break;Executed by:
executed 4992 times by 1 test: case '#':Executed by:
| 4992 | ||||||||||||||||||
| 6008 | case '0': flags |= QLocaleData::ZeroPadded; break; executed 12776 times by 16 tests: break;Executed by:
executed 12776 times by 16 tests: case '0':Executed by:
| 12776 | ||||||||||||||||||
| 6009 | case '-': flags |= QLocaleData::LeftAdjusted; break; executed 4997 times by 1 test: break;Executed by:
executed 4997 times by 1 test: case '-':Executed by:
| 4997 | ||||||||||||||||||
| 6010 | case ' ': flags |= QLocaleData::BlankBeforePositive; break; executed 4992 times by 1 test: break;Executed by:
executed 4992 times by 1 test: case ' ':Executed by:
| 4992 | ||||||||||||||||||
| 6011 | case '+': flags |= QLocaleData::AlwaysShowSign; break; executed 4992 times by 1 test: break;Executed by:
executed 4992 times by 1 test: case '+':Executed by:
| 4992 | ||||||||||||||||||
| 6012 | case '\'': flags |= QLocaleData::ThousandsGroup; break; executed 9984 times by 1 test: break;Executed by:
executed 9984 times by 1 test: case '\'':Executed by:
| 9984 | ||||||||||||||||||
| 6013 | default: no_more_flags = true; break; executed 354673 times by 110 tests: break;Executed by:
executed 354673 times by 110 tests: default:Executed by:
| 354673 | ||||||||||||||||||
| 6014 | } | - | ||||||||||||||||||
| 6015 | - | |||||||||||||||||||
| 6016 | if (!no_more_flags)
| 42733-354673 | ||||||||||||||||||
| 6017 | ++c; executed 42733 times by 16 tests: ++c;Executed by:
| 42733 | ||||||||||||||||||
| 6018 | } while (!no_more_flags); executed 397406 times by 110 tests: end of blockExecuted by:
| 42733-397406 | ||||||||||||||||||
| 6019 | - | |||||||||||||||||||
| 6020 | if (*c == '\0') {
| 0-354673 | ||||||||||||||||||
| 6021 | result.append(QLatin1String(escape_start)); // incomplete escape, treat as non-escape text | - | ||||||||||||||||||
| 6022 | break; never executed: break; | 0 | ||||||||||||||||||
| 6023 | } | - | ||||||||||||||||||
| 6024 | - | |||||||||||||||||||
| 6025 | // Parse field width | - | ||||||||||||||||||
| 6026 | int width = -1; // -1 means unspecified | - | ||||||||||||||||||
| 6027 | if (qIsDigit(*c)) {
| 15288-339385 | ||||||||||||||||||
| 6028 | QString width_str; | - | ||||||||||||||||||
| 6029 | while (*c != '\0' && qIsDigit(*c))
| 0-35096 | ||||||||||||||||||
| 6030 | width_str.append(QLatin1Char(*c++)); executed 19808 times by 16 tests: width_str.append(QLatin1Char(*c++));Executed by:
| 19808 | ||||||||||||||||||
| 6031 | - | |||||||||||||||||||
| 6032 | // can't be negative - started with a digit | - | ||||||||||||||||||
| 6033 | // contains at least one digit | - | ||||||||||||||||||
| 6034 | width = width_str.toInt(); | - | ||||||||||||||||||
| 6035 | } executed 15288 times by 16 tests: end of blockExecuted by:
| 15288 | ||||||||||||||||||
| 6036 | else if (*c == '*') {
| 1-339384 | ||||||||||||||||||
| 6037 | width = va_arg(ap, int); | - | ||||||||||||||||||
| 6038 | if (width < 0)
| 0-1 | ||||||||||||||||||
| 6039 | width = -1; // treat all negative numbers as unspecified never executed: width = -1; | 0 | ||||||||||||||||||
| 6040 | ++c; | - | ||||||||||||||||||
| 6041 | } executed 1 time by 1 test: end of blockExecuted by:
| 1 | ||||||||||||||||||
| 6042 | - | |||||||||||||||||||
| 6043 | if (*c == '\0') {
| 0-354673 | ||||||||||||||||||
| 6044 | result.append(QLatin1String(escape_start)); // incomplete escape, treat as non-escape text | - | ||||||||||||||||||
| 6045 | break; never executed: break; | 0 | ||||||||||||||||||
| 6046 | } | - | ||||||||||||||||||
| 6047 | - | |||||||||||||||||||
| 6048 | // Parse precision | - | ||||||||||||||||||
| 6049 | int precision = -1; // -1 means unspecified | - | ||||||||||||||||||
| 6050 | if (*c == '.') {
| 9368-345305 | ||||||||||||||||||
| 6051 | ++c; | - | ||||||||||||||||||
| 6052 | if (qIsDigit(*c)) {
| 1-9367 | ||||||||||||||||||
| 6053 | QString precision_str; | - | ||||||||||||||||||
| 6054 | while (*c != '\0' && qIsDigit(*c))
| 0-21233 | ||||||||||||||||||
| 6055 | precision_str.append(QLatin1Char(*c++)); executed 11866 times by 8 tests: precision_str.append(QLatin1Char(*c++));Executed by:
| 11866 | ||||||||||||||||||
| 6056 | - | |||||||||||||||||||
| 6057 | // can't be negative - started with a digit | - | ||||||||||||||||||
| 6058 | // contains at least one digit | - | ||||||||||||||||||
| 6059 | precision = precision_str.toInt(); | - | ||||||||||||||||||
| 6060 | } executed 9367 times by 8 tests: end of blockExecuted by:
| 9367 | ||||||||||||||||||
| 6061 | else if (*c == '*') {
| 0-1 | ||||||||||||||||||
| 6062 | precision = va_arg(ap, int); | - | ||||||||||||||||||
| 6063 | if (precision < 0)
| 0-1 | ||||||||||||||||||
| 6064 | precision = -1; // treat all negative numbers as unspecified never executed: precision = -1; | 0 | ||||||||||||||||||
| 6065 | ++c; | - | ||||||||||||||||||
| 6066 | } executed 1 time by 1 test: end of blockExecuted by:
| 1 | ||||||||||||||||||
| 6067 | } executed 9368 times by 9 tests: end of blockExecuted by:
| 9368 | ||||||||||||||||||
| 6068 | - | |||||||||||||||||||
| 6069 | if (*c == '\0') {
| 0-354673 | ||||||||||||||||||
| 6070 | result.append(QLatin1String(escape_start)); // incomplete escape, treat as non-escape text | - | ||||||||||||||||||
| 6071 | break; never executed: break; | 0 | ||||||||||||||||||
| 6072 | } | - | ||||||||||||||||||
| 6073 | - | |||||||||||||||||||
| 6074 | // Parse the length modifier | - | ||||||||||||||||||
| 6075 | enum LengthMod { lm_none, lm_hh, lm_h, lm_l, lm_ll, lm_L, lm_j, lm_z, lm_t }; | - | ||||||||||||||||||
| 6076 | LengthMod length_mod = lm_none; | - | ||||||||||||||||||
| 6077 | switch (*c) { | - | ||||||||||||||||||
| 6078 | case 'h': never executed: case 'h': | 0 | ||||||||||||||||||
| 6079 | ++c; | - | ||||||||||||||||||
| 6080 | if (*c == 'h') {
| 0 | ||||||||||||||||||
| 6081 | length_mod = lm_hh; | - | ||||||||||||||||||
| 6082 | ++c; | - | ||||||||||||||||||
| 6083 | } never executed: end of block | 0 | ||||||||||||||||||
| 6084 | else | - | ||||||||||||||||||
| 6085 | length_mod = lm_h; never executed: length_mod = lm_h; | 0 | ||||||||||||||||||
| 6086 | break; never executed: break; | 0 | ||||||||||||||||||
| 6087 | - | |||||||||||||||||||
| 6088 | case 'l': executed 2026 times by 4 tests: case 'l':Executed by:
| 2026 | ||||||||||||||||||
| 6089 | ++c; | - | ||||||||||||||||||
| 6090 | if (*c == 'l') {
| 4-2022 | ||||||||||||||||||
| 6091 | length_mod = lm_ll; | - | ||||||||||||||||||
| 6092 | ++c; | - | ||||||||||||||||||
| 6093 | } executed 2022 times by 3 tests: end of blockExecuted by:
| 2022 | ||||||||||||||||||
| 6094 | else | - | ||||||||||||||||||
| 6095 | length_mod = lm_l; executed 4 times by 2 tests: length_mod = lm_l;Executed by:
| 4 | ||||||||||||||||||
| 6096 | break; executed 2026 times by 4 tests: break;Executed by:
| 2026 | ||||||||||||||||||
| 6097 | - | |||||||||||||||||||
| 6098 | case 'L': never executed: case 'L': | 0 | ||||||||||||||||||
| 6099 | ++c; | - | ||||||||||||||||||
| 6100 | length_mod = lm_L; | - | ||||||||||||||||||
| 6101 | break; never executed: break; | 0 | ||||||||||||||||||
| 6102 | - | |||||||||||||||||||
| 6103 | case 'j': never executed: case 'j': | 0 | ||||||||||||||||||
| 6104 | ++c; | - | ||||||||||||||||||
| 6105 | length_mod = lm_j; | - | ||||||||||||||||||
| 6106 | break; never executed: break; | 0 | ||||||||||||||||||
| 6107 | - | |||||||||||||||||||
| 6108 | case 'z': executed 3 times by 1 test: case 'z':Executed by:
| 3 | ||||||||||||||||||
| 6109 | case 'Z': never executed: case 'Z': | 0 | ||||||||||||||||||
| 6110 | ++c; | - | ||||||||||||||||||
| 6111 | length_mod = lm_z; | - | ||||||||||||||||||
| 6112 | break; executed 3 times by 1 test: break;Executed by:
| 3 | ||||||||||||||||||
| 6113 | - | |||||||||||||||||||
| 6114 | case 't': never executed: case 't': | 0 | ||||||||||||||||||
| 6115 | ++c; | - | ||||||||||||||||||
| 6116 | length_mod = lm_t; | - | ||||||||||||||||||
| 6117 | break; never executed: break; | 0 | ||||||||||||||||||
| 6118 | - | |||||||||||||||||||
| 6119 | default: break; executed 352644 times by 110 tests: break;Executed by:
executed 352644 times by 110 tests: default:Executed by:
| 352644 | ||||||||||||||||||
| 6120 | } | - | ||||||||||||||||||
| 6121 | - | |||||||||||||||||||
| 6122 | if (*c == '\0') {
| 0-354673 | ||||||||||||||||||
| 6123 | result.append(QLatin1String(escape_start)); // incomplete escape, treat as non-escape text | - | ||||||||||||||||||
| 6124 | break; never executed: break; | 0 | ||||||||||||||||||
| 6125 | } | - | ||||||||||||||||||
| 6126 | - | |||||||||||||||||||
| 6127 | // Parse the conversion specifier and do the conversion | - | ||||||||||||||||||
| 6128 | QString subst; | - | ||||||||||||||||||
| 6129 | switch (*c) { | - | ||||||||||||||||||
| 6130 | case 'd': executed 247852 times by 47 tests: case 'd':Executed by:
| 247852 | ||||||||||||||||||
| 6131 | case 'i': { executed 750 times by 7 tests: case 'i':Executed by:
| 750 | ||||||||||||||||||
| 6132 | qint64 i; | - | ||||||||||||||||||
| 6133 | switch (length_mod) { | - | ||||||||||||||||||
| 6134 | case lm_none: i = va_arg(ap, int); break; executed 248599 times by 51 tests: break;Executed by:
executed 248599 times by 51 tests: case lm_none:Executed by:
| 248599 | ||||||||||||||||||
| 6135 | case lm_hh: i = va_arg(ap, int); break; never executed: break;never executed: case lm_hh: | 0 | ||||||||||||||||||
| 6136 | case lm_h: i = va_arg(ap, int); break; never executed: break;never executed: case lm_h: | 0 | ||||||||||||||||||
| 6137 | case lm_l: i = va_arg(ap, long int); break; executed 2 times by 2 tests: break;Executed by:
executed 2 times by 2 tests: case lm_l:Executed by:
| 2 | ||||||||||||||||||
| 6138 | case lm_ll: i = va_arg(ap, qint64); break; executed 1 time by 1 test: break;Executed by:
executed 1 time by 1 test: case lm_ll:Executed by:
| 1 | ||||||||||||||||||
| 6139 | case lm_j: i = va_arg(ap, long int); break; never executed: break;never executed: case lm_j: | 0 | ||||||||||||||||||
| 6140 | case lm_z: i = va_arg(ap, size_t); break; never executed: break;never executed: case lm_z: | 0 | ||||||||||||||||||
| 6141 | case lm_t: i = va_arg(ap, int); break; never executed: break;never executed: case lm_t: | 0 | ||||||||||||||||||
| 6142 | default: i = 0; break; never executed: break;never executed: default: | 0 | ||||||||||||||||||
| 6143 | } | - | ||||||||||||||||||
| 6144 | subst = QLocaleData::c()->longLongToString(i, precision, 10, width, flags); | - | ||||||||||||||||||
| 6145 | ++c; | - | ||||||||||||||||||
| 6146 | break; executed 248602 times by 51 tests: break;Executed by:
| 248602 | ||||||||||||||||||
| 6147 | } | - | ||||||||||||||||||
| 6148 | case 'o': never executed: case 'o': | 0 | ||||||||||||||||||
| 6149 | case 'u': executed 6 times by 2 tests: case 'u':Executed by:
| 6 | ||||||||||||||||||
| 6150 | case 'x': executed 6044 times by 5 tests: case 'x':Executed by:
| 6044 | ||||||||||||||||||
| 6151 | case 'X': { never executed: case 'X': | 0 | ||||||||||||||||||
| 6152 | quint64 u; | - | ||||||||||||||||||
| 6153 | switch (length_mod) { | - | ||||||||||||||||||
| 6154 | case lm_none: u = va_arg(ap, uint); break; executed 4027 times by 6 tests: break;Executed by:
executed 4027 times by 6 tests: case lm_none:Executed by:
| 4027 | ||||||||||||||||||
| 6155 | case lm_hh: u = va_arg(ap, uint); break; never executed: break;never executed: case lm_hh: | 0 | ||||||||||||||||||
| 6156 | case lm_h: u = va_arg(ap, uint); break; never executed: break;never executed: case lm_h: | 0 | ||||||||||||||||||
| 6157 | case lm_l: u = va_arg(ap, ulong); break; never executed: break;never executed: case lm_l: | 0 | ||||||||||||||||||
| 6158 | case lm_ll: u = va_arg(ap, quint64); break; executed 2020 times by 1 test: break;Executed by:
executed 2020 times by 1 test: case lm_ll:Executed by:
| 2020 | ||||||||||||||||||
| 6159 | case lm_z: u = va_arg(ap, size_t); break; executed 3 times by 1 test: break;Executed by:
executed 3 times by 1 test: case lm_z:Executed by:
| 3 | ||||||||||||||||||
| 6160 | default: u = 0; break; never executed: break;never executed: default: | 0 | ||||||||||||||||||
| 6161 | } | - | ||||||||||||||||||
| 6162 | - | |||||||||||||||||||
| 6163 | if (qIsUpper(*c))
| 0-6050 | ||||||||||||||||||
| 6164 | flags |= QLocaleData::CapitalEorX; never executed: flags |= QLocaleData::CapitalEorX; | 0 | ||||||||||||||||||
| 6165 | - | |||||||||||||||||||
| 6166 | int base = 10; | - | ||||||||||||||||||
| 6167 | switch (qToLower(*c)) { | - | ||||||||||||||||||
| 6168 | case 'o': never executed: case 'o': | 0 | ||||||||||||||||||
| 6169 | base = 8; break; never executed: break; | 0 | ||||||||||||||||||
| 6170 | case 'u': executed 6 times by 2 tests: case 'u':Executed by:
| 6 | ||||||||||||||||||
| 6171 | base = 10; break; executed 6 times by 2 tests: break;Executed by:
| 6 | ||||||||||||||||||
| 6172 | case 'x': executed 6044 times by 5 tests: case 'x':Executed by:
| 6044 | ||||||||||||||||||
| 6173 | base = 16; break; executed 6044 times by 5 tests: break;Executed by:
| 6044 | ||||||||||||||||||
| 6174 | default: break; never executed: break;never executed: default: | 0 | ||||||||||||||||||
| 6175 | } | - | ||||||||||||||||||
| 6176 | subst = QLocaleData::c()->unsLongLongToString(u, precision, base, width, flags); | - | ||||||||||||||||||
| 6177 | ++c; | - | ||||||||||||||||||
| 6178 | break; executed 6050 times by 7 tests: break;Executed by:
| 6050 | ||||||||||||||||||
| 6179 | } | - | ||||||||||||||||||
| 6180 | case 'E': never executed: case 'E': | 0 | ||||||||||||||||||
| 6181 | case 'e': never executed: case 'e': | 0 | ||||||||||||||||||
| 6182 | case 'F': never executed: case 'F': | 0 | ||||||||||||||||||
| 6183 | case 'f': executed 55 times by 8 tests: case 'f':Executed by:
| 55 | ||||||||||||||||||
| 6184 | case 'G': executed 4992 times by 1 test: case 'G':Executed by:
| 4992 | ||||||||||||||||||
| 6185 | case 'g': executed 5001 times by 3 tests: case 'g':Executed by:
| 5001 | ||||||||||||||||||
| 6186 | case 'A': never executed: case 'A': | 0 | ||||||||||||||||||
| 6187 | case 'a': { never executed: case 'a': | 0 | ||||||||||||||||||
| 6188 | double d; | - | ||||||||||||||||||
| 6189 | if (length_mod == lm_L)
| 0-10048 | ||||||||||||||||||
| 6190 | d = va_arg(ap, long double); // not supported - converted to a double never executed: d = __builtin_va_arg(ap,long double); | 0 | ||||||||||||||||||
| 6191 | else | - | ||||||||||||||||||
| 6192 | d = va_arg(ap, double); executed 10048 times by 10 tests: d = __builtin_va_arg(ap,double);Executed by:
| 10048 | ||||||||||||||||||
| 6193 | - | |||||||||||||||||||
| 6194 | if (qIsUpper(*c))
| 4992-5056 | ||||||||||||||||||
| 6195 | flags |= QLocaleData::CapitalEorX; executed 4992 times by 1 test: flags |= QLocaleData::CapitalEorX;Executed by:
| 4992 | ||||||||||||||||||
| 6196 | - | |||||||||||||||||||
| 6197 | QLocaleData::DoubleForm form = QLocaleData::DFDecimal; | - | ||||||||||||||||||
| 6198 | switch (qToLower(*c)) { | - | ||||||||||||||||||
| 6199 | case 'e': form = QLocaleData::DFExponent; break; never executed: break;never executed: case 'e': | 0 | ||||||||||||||||||
| 6200 | case 'a': // not supported - decimal form used instead never executed: case 'a': | 0 | ||||||||||||||||||
| 6201 | case 'f': form = QLocaleData::DFDecimal; break; executed 55 times by 8 tests: break;Executed by:
executed 55 times by 8 tests: case 'f':Executed by:
| 55 | ||||||||||||||||||
| 6202 | case 'g': form = QLocaleData::DFSignificantDigits; break; executed 9993 times by 3 tests: break;Executed by:
executed 9993 times by 3 tests: case 'g':Executed by:
| 9993 | ||||||||||||||||||
| 6203 | default: break; never executed: break;never executed: default: | 0 | ||||||||||||||||||
| 6204 | } | - | ||||||||||||||||||
| 6205 | subst = QLocaleData::c()->doubleToString(d, precision, form, width, flags); | - | ||||||||||||||||||
| 6206 | ++c; | - | ||||||||||||||||||
| 6207 | break; executed 10048 times by 10 tests: break;Executed by:
| 10048 | ||||||||||||||||||
| 6208 | } | - | ||||||||||||||||||
| 6209 | case 'c': { executed 216 times by 4 tests: case 'c':Executed by:
| 216 | ||||||||||||||||||
| 6210 | if (length_mod == lm_l)
| 0-216 | ||||||||||||||||||
| 6211 | subst = QChar((ushort) va_arg(ap, int)); never executed: subst = QChar((ushort) __builtin_va_arg(ap,int)); | 0 | ||||||||||||||||||
| 6212 | else | - | ||||||||||||||||||
| 6213 | subst = QLatin1Char((uchar) va_arg(ap, int)); executed 216 times by 4 tests: subst = QLatin1Char((uchar) __builtin_va_arg(ap,int));Executed by:
| 216 | ||||||||||||||||||
| 6214 | ++c; | - | ||||||||||||||||||
| 6215 | break; executed 216 times by 4 tests: break;Executed by:
| 216 | ||||||||||||||||||
| 6216 | } | - | ||||||||||||||||||
| 6217 | case 's': { executed 87800 times by 50 tests: case 's':Executed by:
| 87800 | ||||||||||||||||||
| 6218 | if (length_mod == lm_l) {
| 0-87800 | ||||||||||||||||||
| 6219 | const ushort *buff = va_arg(ap, const ushort*); | - | ||||||||||||||||||
| 6220 | const ushort *ch = buff; | - | ||||||||||||||||||
| 6221 | while (*ch != 0)
| 0 | ||||||||||||||||||
| 6222 | ++ch; never executed: ++ch; | 0 | ||||||||||||||||||
| 6223 | subst.setUtf16(buff, ch - buff); | - | ||||||||||||||||||
| 6224 | } else never executed: end of block | 0 | ||||||||||||||||||
| 6225 | subst = QString::fromUtf8(va_arg(ap, const char*)); executed 87800 times by 50 tests: subst = QString::fromUtf8(__builtin_va_arg(ap,const char*));Executed by:
| 87800 | ||||||||||||||||||
| 6226 | if (precision != -1)
| 7-87793 | ||||||||||||||||||
| 6227 | subst.truncate(precision); executed 7 times by 1 test: subst.truncate(precision);Executed by:
| 7 | ||||||||||||||||||
| 6228 | ++c; | - | ||||||||||||||||||
| 6229 | break; executed 87800 times by 50 tests: break;Executed by:
| 87800 | ||||||||||||||||||
| 6230 | } | - | ||||||||||||||||||
| 6231 | case 'p': { executed 1955 times by 32 tests: case 'p':Executed by:
| 1955 | ||||||||||||||||||
| 6232 | void *arg = va_arg(ap, void*); | - | ||||||||||||||||||
| 6233 | const quint64 i = reinterpret_cast<quintptr>(arg); | - | ||||||||||||||||||
| 6234 | flags |= QLocaleData::Alternate; | - | ||||||||||||||||||
| 6235 | subst = QLocaleData::c()->unsLongLongToString(i, precision, 16, width, flags); | - | ||||||||||||||||||
| 6236 | ++c; | - | ||||||||||||||||||
| 6237 | break; executed 1955 times by 32 tests: break;Executed by:
| 1955 | ||||||||||||||||||
| 6238 | } | - | ||||||||||||||||||
| 6239 | case 'n': executed 2 times by 1 test: case 'n':Executed by:
| 2 | ||||||||||||||||||
| 6240 | switch (length_mod) { | - | ||||||||||||||||||
| 6241 | case lm_hh: { never executed: case lm_hh: | 0 | ||||||||||||||||||
| 6242 | signed char *n = va_arg(ap, signed char*); | - | ||||||||||||||||||
| 6243 | *n = result.length(); | - | ||||||||||||||||||
| 6244 | break; never executed: break; | 0 | ||||||||||||||||||
| 6245 | } | - | ||||||||||||||||||
| 6246 | case lm_h: { never executed: case lm_h: | 0 | ||||||||||||||||||
| 6247 | short int *n = va_arg(ap, short int*); | - | ||||||||||||||||||
| 6248 | *n = result.length(); | - | ||||||||||||||||||
| 6249 | break; never executed: break; | 0 | ||||||||||||||||||
| 6250 | } | - | ||||||||||||||||||
| 6251 | case lm_l: { never executed: case lm_l: | 0 | ||||||||||||||||||
| 6252 | long int *n = va_arg(ap, long int*); | - | ||||||||||||||||||
| 6253 | *n = result.length(); | - | ||||||||||||||||||
| 6254 | break; never executed: break; | 0 | ||||||||||||||||||
| 6255 | } | - | ||||||||||||||||||
| 6256 | case lm_ll: { executed 1 time by 1 test: case lm_ll:Executed by:
| 1 | ||||||||||||||||||
| 6257 | qint64 *n = va_arg(ap, qint64*); | - | ||||||||||||||||||
| 6258 | volatile uint tmp = result.length(); // egcs-2.91.66 gets internal | - | ||||||||||||||||||
| 6259 | *n = tmp; // compiler error without volatile | - | ||||||||||||||||||
| 6260 | break; executed 1 time by 1 test: break;Executed by:
| 1 | ||||||||||||||||||
| 6261 | } | - | ||||||||||||||||||
| 6262 | default: { executed 1 time by 1 test: default:Executed by:
| 1 | ||||||||||||||||||
| 6263 | int *n = va_arg(ap, int*); | - | ||||||||||||||||||
| 6264 | *n = result.length(); | - | ||||||||||||||||||
| 6265 | break; executed 1 time by 1 test: break;Executed by:
| 1 | ||||||||||||||||||
| 6266 | } | - | ||||||||||||||||||
| 6267 | } | - | ||||||||||||||||||
| 6268 | ++c; | - | ||||||||||||||||||
| 6269 | break; executed 2 times by 1 test: break;Executed by:
| 2 | ||||||||||||||||||
| 6270 | - | |||||||||||||||||||
| 6271 | default: // bad escape, treat as non-escape text never executed: default: | 0 | ||||||||||||||||||
| 6272 | for (const char *cc = escape_start; cc != c; ++cc)
| 0 | ||||||||||||||||||
| 6273 | result.append(QLatin1Char(*cc)); never executed: result.append(QLatin1Char(*cc)); | 0 | ||||||||||||||||||
| 6274 | continue; never executed: continue; | 0 | ||||||||||||||||||
| 6275 | } | - | ||||||||||||||||||
| 6276 | - | |||||||||||||||||||
| 6277 | if (flags & QLocaleData::LeftAdjusted)
| 4997-349676 | ||||||||||||||||||
| 6278 | result.append(subst.leftJustified(width)); executed 4997 times by 1 test: result.append(subst.leftJustified(width));Executed by:
| 4997 | ||||||||||||||||||
| 6279 | else | - | ||||||||||||||||||
| 6280 | result.append(subst.rightJustified(width)); executed 349676 times by 110 tests: result.append(subst.rightJustified(width));Executed by:
| 349676 | ||||||||||||||||||
| 6281 | } | - | ||||||||||||||||||
| 6282 | - | |||||||||||||||||||
| 6283 | return result; executed 247956 times by 160 tests: return result;Executed by:
| 247956 | ||||||||||||||||||
| 6284 | } | - | ||||||||||||||||||
| 6285 | - | |||||||||||||||||||
| 6286 | /*! | - | ||||||||||||||||||
| 6287 | Returns the string converted to a \c{long long} using base \a | - | ||||||||||||||||||
| 6288 | base, which is 10 by default and must be between 2 and 36, or 0. | - | ||||||||||||||||||
| 6289 | Returns 0 if the conversion fails. | - | ||||||||||||||||||
| 6290 | - | |||||||||||||||||||
| 6291 | If a conversion error occurs, *\a{ok} is set to \c false; otherwise | - | ||||||||||||||||||
| 6292 | *\a{ok} is set to \c true. | - | ||||||||||||||||||
| 6293 | - | |||||||||||||||||||
| 6294 | If \a base is 0, the C language convention is used: If the string | - | ||||||||||||||||||
| 6295 | begins with "0x", base 16 is used; if the string begins with "0", | - | ||||||||||||||||||
| 6296 | base 8 is used; otherwise, base 10 is used. | - | ||||||||||||||||||
| 6297 | - | |||||||||||||||||||
| 6298 | The string conversion will always happen in the 'C' locale. For locale | - | ||||||||||||||||||
| 6299 | dependent conversion use QLocale::toLongLong() | - | ||||||||||||||||||
| 6300 | - | |||||||||||||||||||
| 6301 | Example: | - | ||||||||||||||||||
| 6302 | - | |||||||||||||||||||
| 6303 | \snippet qstring/main.cpp 74 | - | ||||||||||||||||||
| 6304 | - | |||||||||||||||||||
| 6305 | \sa number(), toULongLong(), toInt(), QLocale::toLongLong() | - | ||||||||||||||||||
| 6306 | */ | - | ||||||||||||||||||
| 6307 | - | |||||||||||||||||||
| 6308 | qint64 QString::toLongLong(bool *ok, int base) const | - | ||||||||||||||||||
| 6309 | { | - | ||||||||||||||||||
| 6310 | return toIntegral_helper<qlonglong>(constData(), size(), ok, base); executed 59908 times by 42 tests: return toIntegral_helper<qlonglong>(constData(), size(), ok, base);Executed by:
| 59908 | ||||||||||||||||||
| 6311 | } | - | ||||||||||||||||||
| 6312 | - | |||||||||||||||||||
| 6313 | qlonglong QString::toIntegral_helper(const QChar *data, int len, bool *ok, int base) | - | ||||||||||||||||||
| 6314 | { | - | ||||||||||||||||||
| 6315 | #if defined(QT_CHECK_RANGE) | - | ||||||||||||||||||
| 6316 | if (base != 0 && (base < 2 || base > 36)) { | - | ||||||||||||||||||
| 6317 | qWarning("QString::toULongLong: Invalid base (%d)", base); | - | ||||||||||||||||||
| 6318 | base = 10; | - | ||||||||||||||||||
| 6319 | } | - | ||||||||||||||||||
| 6320 | #endif | - | ||||||||||||||||||
| 6321 | - | |||||||||||||||||||
| 6322 | return QLocaleData::c()->stringToLongLong(data, len, base, ok, QLocaleData::FailOnGroupSeparators); executed 180845 times by 79 tests: return QLocaleData::c()->stringToLongLong(data, len, base, ok, QLocaleData::FailOnGroupSeparators);Executed by:
| 180845 | ||||||||||||||||||
| 6323 | } | - | ||||||||||||||||||
| 6324 | - | |||||||||||||||||||
| 6325 | - | |||||||||||||||||||
| 6326 | /*! | - | ||||||||||||||||||
| 6327 | Returns the string converted to an \c{unsigned long long} using base \a | - | ||||||||||||||||||
| 6328 | base, which is 10 by default and must be between 2 and 36, or 0. | - | ||||||||||||||||||
| 6329 | Returns 0 if the conversion fails. | - | ||||||||||||||||||
| 6330 | - | |||||||||||||||||||
| 6331 | If a conversion error occurs, *\a{ok} is set to \c false; otherwise | - | ||||||||||||||||||
| 6332 | *\a{ok} is set to \c true. | - | ||||||||||||||||||
| 6333 | - | |||||||||||||||||||
| 6334 | If \a base is 0, the C language convention is used: If the string | - | ||||||||||||||||||
| 6335 | begins with "0x", base 16 is used; if the string begins with "0", | - | ||||||||||||||||||
| 6336 | base 8 is used; otherwise, base 10 is used. | - | ||||||||||||||||||
| 6337 | - | |||||||||||||||||||
| 6338 | The string conversion will always happen in the 'C' locale. For locale | - | ||||||||||||||||||
| 6339 | dependent conversion use QLocale::toULongLong() | - | ||||||||||||||||||
| 6340 | - | |||||||||||||||||||
| 6341 | Example: | - | ||||||||||||||||||
| 6342 | - | |||||||||||||||||||
| 6343 | \snippet qstring/main.cpp 79 | - | ||||||||||||||||||
| 6344 | - | |||||||||||||||||||
| 6345 | \sa number(), toLongLong(), QLocale::toULongLong() | - | ||||||||||||||||||
| 6346 | */ | - | ||||||||||||||||||
| 6347 | - | |||||||||||||||||||
| 6348 | quint64 QString::toULongLong(bool *ok, int base) const | - | ||||||||||||||||||
| 6349 | { | - | ||||||||||||||||||
| 6350 | return toIntegral_helper<qulonglong>(constData(), size(), ok, base); executed 88 times by 4 tests: return toIntegral_helper<qulonglong>(constData(), size(), ok, base);Executed by:
| 88 | ||||||||||||||||||
| 6351 | } | - | ||||||||||||||||||
| 6352 | - | |||||||||||||||||||
| 6353 | qulonglong QString::toIntegral_helper(const QChar *data, uint len, bool *ok, int base) | - | ||||||||||||||||||
| 6354 | { | - | ||||||||||||||||||
| 6355 | #if defined(QT_CHECK_RANGE) | - | ||||||||||||||||||
| 6356 | if (base != 0 && (base < 2 || base > 36)) { | - | ||||||||||||||||||
| 6357 | qWarning("QString::toULongLong: Invalid base (%d)", base); | - | ||||||||||||||||||
| 6358 | base = 10; | - | ||||||||||||||||||
| 6359 | } | - | ||||||||||||||||||
| 6360 | #endif | - | ||||||||||||||||||
| 6361 | - | |||||||||||||||||||
| 6362 | return QLocaleData::c()->stringToUnsLongLong(data, len, base, ok, QLocaleData::FailOnGroupSeparators); executed 3890 times by 20 tests: return QLocaleData::c()->stringToUnsLongLong(data, len, base, ok, QLocaleData::FailOnGroupSeparators);Executed by:
| 3890 | ||||||||||||||||||
| 6363 | } | - | ||||||||||||||||||
| 6364 | - | |||||||||||||||||||
| 6365 | /*! | - | ||||||||||||||||||
| 6366 | \fn long QString::toLong(bool *ok, int base) const | - | ||||||||||||||||||
| 6367 | - | |||||||||||||||||||
| 6368 | Returns the string converted to a \c long using base \a | - | ||||||||||||||||||
| 6369 | base, which is 10 by default and must be between 2 and 36, or 0. | - | ||||||||||||||||||
| 6370 | Returns 0 if the conversion fails. | - | ||||||||||||||||||
| 6371 | - | |||||||||||||||||||
| 6372 | If a conversion error occurs, *\a{ok} is set to \c false; otherwise | - | ||||||||||||||||||
| 6373 | *\a{ok} is set to \c true. | - | ||||||||||||||||||
| 6374 | - | |||||||||||||||||||
| 6375 | If \a base is 0, the C language convention is used: If the string | - | ||||||||||||||||||
| 6376 | begins with "0x", base 16 is used; if the string begins with "0", | - | ||||||||||||||||||
| 6377 | base 8 is used; otherwise, base 10 is used. | - | ||||||||||||||||||
| 6378 | - | |||||||||||||||||||
| 6379 | The string conversion will always happen in the 'C' locale. For locale | - | ||||||||||||||||||
| 6380 | dependent conversion use QLocale::toLongLong() | - | ||||||||||||||||||
| 6381 | - | |||||||||||||||||||
| 6382 | Example: | - | ||||||||||||||||||
| 6383 | - | |||||||||||||||||||
| 6384 | \snippet qstring/main.cpp 73 | - | ||||||||||||||||||
| 6385 | - | |||||||||||||||||||
| 6386 | \sa number(), toULong(), toInt(), QLocale::toInt() | - | ||||||||||||||||||
| 6387 | */ | - | ||||||||||||||||||
| 6388 | - | |||||||||||||||||||
| 6389 | long QString::toLong(bool *ok, int base) const | - | ||||||||||||||||||
| 6390 | { | - | ||||||||||||||||||
| 6391 | return toIntegral_helper<long>(constData(), size(), ok, base); executed 54 times by 1 test: return toIntegral_helper<long>(constData(), size(), ok, base);Executed by:
| 54 | ||||||||||||||||||
| 6392 | } | - | ||||||||||||||||||
| 6393 | - | |||||||||||||||||||
| 6394 | /*! | - | ||||||||||||||||||
| 6395 | \fn ulong QString::toULong(bool *ok, int base) const | - | ||||||||||||||||||
| 6396 | - | |||||||||||||||||||
| 6397 | Returns the string converted to an \c{unsigned long} using base \a | - | ||||||||||||||||||
| 6398 | base, which is 10 by default and must be between 2 and 36, or 0. | - | ||||||||||||||||||
| 6399 | Returns 0 if the conversion fails. | - | ||||||||||||||||||
| 6400 | - | |||||||||||||||||||
| 6401 | If a conversion error occurs, *\a{ok} is set to \c false; otherwise | - | ||||||||||||||||||
| 6402 | *\a{ok} is set to \c true. | - | ||||||||||||||||||
| 6403 | - | |||||||||||||||||||
| 6404 | If \a base is 0, the C language convention is used: If the string | - | ||||||||||||||||||
| 6405 | begins with "0x", base 16 is used; if the string begins with "0", | - | ||||||||||||||||||
| 6406 | base 8 is used; otherwise, base 10 is used. | - | ||||||||||||||||||
| 6407 | - | |||||||||||||||||||
| 6408 | The string conversion will always happen in the 'C' locale. For locale | - | ||||||||||||||||||
| 6409 | dependent conversion use QLocale::toULongLong() | - | ||||||||||||||||||
| 6410 | - | |||||||||||||||||||
| 6411 | Example: | - | ||||||||||||||||||
| 6412 | - | |||||||||||||||||||
| 6413 | \snippet qstring/main.cpp 78 | - | ||||||||||||||||||
| 6414 | - | |||||||||||||||||||
| 6415 | \sa number(), QLocale::toUInt() | - | ||||||||||||||||||
| 6416 | */ | - | ||||||||||||||||||
| 6417 | - | |||||||||||||||||||
| 6418 | ulong QString::toULong(bool *ok, int base) const | - | ||||||||||||||||||
| 6419 | { | - | ||||||||||||||||||
| 6420 | return toIntegral_helper<ulong>(constData(), size(), ok, base); executed 40 times by 1 test: return toIntegral_helper<ulong>(constData(), size(), ok, base);Executed by:
| 40 | ||||||||||||||||||
| 6421 | } | - | ||||||||||||||||||
| 6422 | - | |||||||||||||||||||
| 6423 | - | |||||||||||||||||||
| 6424 | /*! | - | ||||||||||||||||||
| 6425 | Returns the string converted to an \c int using base \a | - | ||||||||||||||||||
| 6426 | base, which is 10 by default and must be between 2 and 36, or 0. | - | ||||||||||||||||||
| 6427 | Returns 0 if the conversion fails. | - | ||||||||||||||||||
| 6428 | - | |||||||||||||||||||
| 6429 | If a conversion error occurs, *\a{ok} is set to \c false; otherwise | - | ||||||||||||||||||
| 6430 | *\a{ok} is set to \c true. | - | ||||||||||||||||||
| 6431 | - | |||||||||||||||||||
| 6432 | If \a base is 0, the C language convention is used: If the string | - | ||||||||||||||||||
| 6433 | begins with "0x", base 16 is used; if the string begins with "0", | - | ||||||||||||||||||
| 6434 | base 8 is used; otherwise, base 10 is used. | - | ||||||||||||||||||
| 6435 | - | |||||||||||||||||||
| 6436 | The string conversion will always happen in the 'C' locale. For locale | - | ||||||||||||||||||
| 6437 | dependent conversion use QLocale::toInt() | - | ||||||||||||||||||
| 6438 | - | |||||||||||||||||||
| 6439 | Example: | - | ||||||||||||||||||
| 6440 | - | |||||||||||||||||||
| 6441 | \snippet qstring/main.cpp 72 | - | ||||||||||||||||||
| 6442 | - | |||||||||||||||||||
| 6443 | \sa number(), toUInt(), toDouble(), QLocale::toInt() | - | ||||||||||||||||||
| 6444 | */ | - | ||||||||||||||||||
| 6445 | - | |||||||||||||||||||
| 6446 | int QString::toInt(bool *ok, int base) const | - | ||||||||||||||||||
| 6447 | { | - | ||||||||||||||||||
| 6448 | return toIntegral_helper<int>(constData(), size(), ok, base); executed 73138 times by 47 tests: return toIntegral_helper<int>(constData(), size(), ok, base);Executed by:
| 73138 | ||||||||||||||||||
| 6449 | } | - | ||||||||||||||||||
| 6450 | - | |||||||||||||||||||
| 6451 | /*! | - | ||||||||||||||||||
| 6452 | Returns the string converted to an \c{unsigned int} using base \a | - | ||||||||||||||||||
| 6453 | base, which is 10 by default and must be between 2 and 36, or 0. | - | ||||||||||||||||||
| 6454 | Returns 0 if the conversion fails. | - | ||||||||||||||||||
| 6455 | - | |||||||||||||||||||
| 6456 | If a conversion error occurs, *\a{ok} is set to \c false; otherwise | - | ||||||||||||||||||
| 6457 | *\a{ok} is set to \c true. | - | ||||||||||||||||||
| 6458 | - | |||||||||||||||||||
| 6459 | If \a base is 0, the C language convention is used: If the string | - | ||||||||||||||||||
| 6460 | begins with "0x", base 16 is used; if the string begins with "0", | - | ||||||||||||||||||
| 6461 | base 8 is used; otherwise, base 10 is used. | - | ||||||||||||||||||
| 6462 | - | |||||||||||||||||||
| 6463 | The string conversion will always happen in the 'C' locale. For locale | - | ||||||||||||||||||
| 6464 | dependent conversion use QLocale::toUInt() | - | ||||||||||||||||||
| 6465 | - | |||||||||||||||||||
| 6466 | Example: | - | ||||||||||||||||||
| 6467 | - | |||||||||||||||||||
| 6468 | \snippet qstring/main.cpp 77 | - | ||||||||||||||||||
| 6469 | - | |||||||||||||||||||
| 6470 | \sa number(), toInt(), QLocale::toUInt() | - | ||||||||||||||||||
| 6471 | */ | - | ||||||||||||||||||
| 6472 | - | |||||||||||||||||||
| 6473 | uint QString::toUInt(bool *ok, int base) const | - | ||||||||||||||||||
| 6474 | { | - | ||||||||||||||||||
| 6475 | return toIntegral_helper<uint>(constData(), size(), ok, base); executed 2060 times by 12 tests: return toIntegral_helper<uint>(constData(), size(), ok, base);Executed by:
| 2060 | ||||||||||||||||||
| 6476 | } | - | ||||||||||||||||||
| 6477 | - | |||||||||||||||||||
| 6478 | /*! | - | ||||||||||||||||||
| 6479 | Returns the string converted to a \c short using base \a | - | ||||||||||||||||||
| 6480 | base, which is 10 by default and must be between 2 and 36, or 0. | - | ||||||||||||||||||
| 6481 | Returns 0 if the conversion fails. | - | ||||||||||||||||||
| 6482 | - | |||||||||||||||||||
| 6483 | If a conversion error occurs, *\a{ok} is set to \c false; otherwise | - | ||||||||||||||||||
| 6484 | *\a{ok} is set to \c true. | - | ||||||||||||||||||
| 6485 | - | |||||||||||||||||||
| 6486 | If \a base is 0, the C language convention is used: If the string | - | ||||||||||||||||||
| 6487 | begins with "0x", base 16 is used; if the string begins with "0", | - | ||||||||||||||||||
| 6488 | base 8 is used; otherwise, base 10 is used. | - | ||||||||||||||||||
| 6489 | - | |||||||||||||||||||
| 6490 | The string conversion will always happen in the 'C' locale. For locale | - | ||||||||||||||||||
| 6491 | dependent conversion use QLocale::toShort() | - | ||||||||||||||||||
| 6492 | - | |||||||||||||||||||
| 6493 | Example: | - | ||||||||||||||||||
| 6494 | - | |||||||||||||||||||
| 6495 | \snippet qstring/main.cpp 76 | - | ||||||||||||||||||
| 6496 | - | |||||||||||||||||||
| 6497 | \sa number(), toUShort(), toInt(), QLocale::toShort() | - | ||||||||||||||||||
| 6498 | */ | - | ||||||||||||||||||
| 6499 | - | |||||||||||||||||||
| 6500 | short QString::toShort(bool *ok, int base) const | - | ||||||||||||||||||
| 6501 | { | - | ||||||||||||||||||
| 6502 | return toIntegral_helper<short>(constData(), size(), ok, base); executed 70 times by 1 test: return toIntegral_helper<short>(constData(), size(), ok, base);Executed by:
| 70 | ||||||||||||||||||
| 6503 | } | - | ||||||||||||||||||
| 6504 | - | |||||||||||||||||||
| 6505 | /*! | - | ||||||||||||||||||
| 6506 | Returns the string converted to an \c{unsigned short} using base \a | - | ||||||||||||||||||
| 6507 | base, which is 10 by default and must be between 2 and 36, or 0. | - | ||||||||||||||||||
| 6508 | Returns 0 if the conversion fails. | - | ||||||||||||||||||
| 6509 | - | |||||||||||||||||||
| 6510 | If a conversion error occurs, *\a{ok} is set to \c false; otherwise | - | ||||||||||||||||||
| 6511 | *\a{ok} is set to \c true. | - | ||||||||||||||||||
| 6512 | - | |||||||||||||||||||
| 6513 | If \a base is 0, the C language convention is used: If the string | - | ||||||||||||||||||
| 6514 | begins with "0x", base 16 is used; if the string begins with "0", | - | ||||||||||||||||||
| 6515 | base 8 is used; otherwise, base 10 is used. | - | ||||||||||||||||||
| 6516 | - | |||||||||||||||||||
| 6517 | The string conversion will always happen in the 'C' locale. For locale | - | ||||||||||||||||||
| 6518 | dependent conversion use QLocale::toUShort() | - | ||||||||||||||||||
| 6519 | - | |||||||||||||||||||
| 6520 | Example: | - | ||||||||||||||||||
| 6521 | - | |||||||||||||||||||
| 6522 | \snippet qstring/main.cpp 80 | - | ||||||||||||||||||
| 6523 | - | |||||||||||||||||||
| 6524 | \sa number(), toShort(), QLocale::toUShort() | - | ||||||||||||||||||
| 6525 | */ | - | ||||||||||||||||||
| 6526 | - | |||||||||||||||||||
| 6527 | ushort QString::toUShort(bool *ok, int base) const | - | ||||||||||||||||||
| 6528 | { | - | ||||||||||||||||||
| 6529 | return toIntegral_helper<ushort>(constData(), size(), ok, base); executed 93 times by 4 tests: return toIntegral_helper<ushort>(constData(), size(), ok, base);Executed by:
| 93 | ||||||||||||||||||
| 6530 | } | - | ||||||||||||||||||
| 6531 | - | |||||||||||||||||||
| 6532 | - | |||||||||||||||||||
| 6533 | /*! | - | ||||||||||||||||||
| 6534 | Returns the string converted to a \c double value. | - | ||||||||||||||||||
| 6535 | - | |||||||||||||||||||
| 6536 | Returns 0.0 if the conversion fails. | - | ||||||||||||||||||
| 6537 | - | |||||||||||||||||||
| 6538 | If a conversion error occurs, \c{*}\a{ok} is set to \c false; | - | ||||||||||||||||||
| 6539 | otherwise \c{*}\a{ok} is set to \c true. | - | ||||||||||||||||||
| 6540 | - | |||||||||||||||||||
| 6541 | \snippet qstring/main.cpp 66 | - | ||||||||||||||||||
| 6542 | - | |||||||||||||||||||
| 6543 | \warning The QString content may only contain valid numerical characters which includes the plus/minus sign, the characters g and e used in scientific notation, and the decimal point. Including the unit or additional characters leads to a conversion error. | - | ||||||||||||||||||
| 6544 | - | |||||||||||||||||||
| 6545 | \snippet qstring/main.cpp 67 | - | ||||||||||||||||||
| 6546 | - | |||||||||||||||||||
| 6547 | The string conversion will always happen in the 'C' locale. For locale | - | ||||||||||||||||||
| 6548 | dependent conversion use QLocale::toDouble() | - | ||||||||||||||||||
| 6549 | - | |||||||||||||||||||
| 6550 | \snippet qstring/main.cpp 68 | - | ||||||||||||||||||
| 6551 | - | |||||||||||||||||||
| 6552 | For historical reasons, this function does not handle | - | ||||||||||||||||||
| 6553 | thousands group separators. If you need to convert such numbers, | - | ||||||||||||||||||
| 6554 | use QLocale::toDouble(). | - | ||||||||||||||||||
| 6555 | - | |||||||||||||||||||
| 6556 | \snippet qstring/main.cpp 69 | - | ||||||||||||||||||
| 6557 | - | |||||||||||||||||||
| 6558 | \sa number(), QLocale::setDefault(), QLocale::toDouble(), trimmed() | - | ||||||||||||||||||
| 6559 | */ | - | ||||||||||||||||||
| 6560 | - | |||||||||||||||||||
| 6561 | double QString::toDouble(bool *ok) const | - | ||||||||||||||||||
| 6562 | { | - | ||||||||||||||||||
| 6563 | return QLocaleData::c()->stringToDouble(constData(), size(), ok, QLocaleData::FailOnGroupSeparators); executed 2728 times by 25 tests: return QLocaleData::c()->stringToDouble(constData(), size(), ok, QLocaleData::FailOnGroupSeparators);Executed by:
| 2728 | ||||||||||||||||||
| 6564 | } | - | ||||||||||||||||||
| 6565 | - | |||||||||||||||||||
| 6566 | /*! | - | ||||||||||||||||||
| 6567 | Returns the string converted to a \c float value. | - | ||||||||||||||||||
| 6568 | - | |||||||||||||||||||
| 6569 | If a conversion error occurs, *\a{ok} is set to \c false; otherwise | - | ||||||||||||||||||
| 6570 | *\a{ok} is set to \c true. Returns 0.0 if the conversion fails. | - | ||||||||||||||||||
| 6571 | - | |||||||||||||||||||
| 6572 | The string conversion will always happen in the 'C' locale. For locale | - | ||||||||||||||||||
| 6573 | dependent conversion use QLocale::toFloat() | - | ||||||||||||||||||
| 6574 | - | |||||||||||||||||||
| 6575 | Example: | - | ||||||||||||||||||
| 6576 | - | |||||||||||||||||||
| 6577 | \snippet qstring/main.cpp 71 | - | ||||||||||||||||||
| 6578 | - | |||||||||||||||||||
| 6579 | \sa number(), toDouble(), toInt(), QLocale::toFloat() | - | ||||||||||||||||||
| 6580 | */ | - | ||||||||||||||||||
| 6581 | - | |||||||||||||||||||
| 6582 | float QString::toFloat(bool *ok) const | - | ||||||||||||||||||
| 6583 | { | - | ||||||||||||||||||
| 6584 | return QLocaleData::convertDoubleToFloat(toDouble(ok), ok); executed 24 times by 3 tests: return QLocaleData::convertDoubleToFloat(toDouble(ok), ok);Executed by:
| 24 | ||||||||||||||||||
| 6585 | } | - | ||||||||||||||||||
| 6586 | - | |||||||||||||||||||
| 6587 | /*! \fn QString &QString::setNum(int n, int base) | - | ||||||||||||||||||
| 6588 | - | |||||||||||||||||||
| 6589 | Sets the string to the printed value of \a n in the specified \a | - | ||||||||||||||||||
| 6590 | base, and returns a reference to the string. | - | ||||||||||||||||||
| 6591 | - | |||||||||||||||||||
| 6592 | The base is 10 by default and must be between 2 and 36. For bases | - | ||||||||||||||||||
| 6593 | other than 10, \a n is treated as an unsigned integer. | - | ||||||||||||||||||
| 6594 | - | |||||||||||||||||||
| 6595 | \snippet qstring/main.cpp 56 | - | ||||||||||||||||||
| 6596 | - | |||||||||||||||||||
| 6597 | The formatting always uses QLocale::C, i.e., English/UnitedStates. | - | ||||||||||||||||||
| 6598 | To get a localized string representation of a number, use | - | ||||||||||||||||||
| 6599 | QLocale::toString() with the appropriate locale. | - | ||||||||||||||||||
| 6600 | */ | - | ||||||||||||||||||
| 6601 | - | |||||||||||||||||||
| 6602 | /*! \fn QString &QString::setNum(uint n, int base) | - | ||||||||||||||||||
| 6603 | - | |||||||||||||||||||
| 6604 | \overload | - | ||||||||||||||||||
| 6605 | */ | - | ||||||||||||||||||
| 6606 | - | |||||||||||||||||||
| 6607 | /*! \fn QString &QString::setNum(long n, int base) | - | ||||||||||||||||||
| 6608 | - | |||||||||||||||||||
| 6609 | \overload | - | ||||||||||||||||||
| 6610 | */ | - | ||||||||||||||||||
| 6611 | - | |||||||||||||||||||
| 6612 | /*! \fn QString &QString::setNum(ulong n, int base) | - | ||||||||||||||||||
| 6613 | - | |||||||||||||||||||
| 6614 | \overload | - | ||||||||||||||||||
| 6615 | */ | - | ||||||||||||||||||
| 6616 | - | |||||||||||||||||||
| 6617 | /*! | - | ||||||||||||||||||
| 6618 | \overload | - | ||||||||||||||||||
| 6619 | */ | - | ||||||||||||||||||
| 6620 | QString &QString::setNum(qlonglong n, int base) | - | ||||||||||||||||||
| 6621 | { | - | ||||||||||||||||||
| 6622 | return *this = number(n, base); executed 26915 times by 6 tests: return *this = number(n, base);Executed by:
| 26915 | ||||||||||||||||||
| 6623 | } | - | ||||||||||||||||||
| 6624 | - | |||||||||||||||||||
| 6625 | /*! | - | ||||||||||||||||||
| 6626 | \overload | - | ||||||||||||||||||
| 6627 | */ | - | ||||||||||||||||||
| 6628 | QString &QString::setNum(qulonglong n, int base) | - | ||||||||||||||||||
| 6629 | { | - | ||||||||||||||||||
| 6630 | return *this = number(n, base); executed 4 times by 1 test: return *this = number(n, base);Executed by:
| 4 | ||||||||||||||||||
| 6631 | } | - | ||||||||||||||||||
| 6632 | - | |||||||||||||||||||
| 6633 | /*! \fn QString &QString::setNum(short n, int base) | - | ||||||||||||||||||
| 6634 | - | |||||||||||||||||||
| 6635 | \overload | - | ||||||||||||||||||
| 6636 | */ | - | ||||||||||||||||||
| 6637 | - | |||||||||||||||||||
| 6638 | /*! \fn QString &QString::setNum(ushort n, int base) | - | ||||||||||||||||||
| 6639 | - | |||||||||||||||||||
| 6640 | \overload | - | ||||||||||||||||||
| 6641 | */ | - | ||||||||||||||||||
| 6642 | - | |||||||||||||||||||
| 6643 | /*! | - | ||||||||||||||||||
| 6644 | \fn QString &QString::setNum(double n, char format, int precision) | - | ||||||||||||||||||
| 6645 | \overload | - | ||||||||||||||||||
| 6646 | - | |||||||||||||||||||
| 6647 | Sets the string to the printed value of \a n, formatted according | - | ||||||||||||||||||
| 6648 | to the given \a format and \a precision, and returns a reference | - | ||||||||||||||||||
| 6649 | to the string. | - | ||||||||||||||||||
| 6650 | - | |||||||||||||||||||
| 6651 | The \a format can be 'e', 'E', 'f', 'g' or 'G' (see | - | ||||||||||||||||||
| 6652 | \l{Argument Formats} for an explanation of the formats). | - | ||||||||||||||||||
| 6653 | - | |||||||||||||||||||
| 6654 | The formatting always uses QLocale::C, i.e., English/UnitedStates. | - | ||||||||||||||||||
| 6655 | To get a localized string representation of a number, use | - | ||||||||||||||||||
| 6656 | QLocale::toString() with the appropriate locale. | - | ||||||||||||||||||
| 6657 | */ | - | ||||||||||||||||||
| 6658 | - | |||||||||||||||||||
| 6659 | QString &QString::setNum(double n, char f, int prec) | - | ||||||||||||||||||
| 6660 | { | - | ||||||||||||||||||
| 6661 | return *this = number(n, f, prec); executed 4 times by 2 tests: return *this = number(n, f, prec);Executed by:
| 4 | ||||||||||||||||||
| 6662 | } | - | ||||||||||||||||||
| 6663 | - | |||||||||||||||||||
| 6664 | /*! | - | ||||||||||||||||||
| 6665 | \fn QString &QString::setNum(float n, char format, int precision) | - | ||||||||||||||||||
| 6666 | \overload | - | ||||||||||||||||||
| 6667 | - | |||||||||||||||||||
| 6668 | Sets the string to the printed value of \a n, formatted according | - | ||||||||||||||||||
| 6669 | to the given \a format and \a precision, and returns a reference | - | ||||||||||||||||||
| 6670 | to the string. | - | ||||||||||||||||||
| 6671 | - | |||||||||||||||||||
| 6672 | The formatting always uses QLocale::C, i.e., English/UnitedStates. | - | ||||||||||||||||||
| 6673 | To get a localized string representation of a number, use | - | ||||||||||||||||||
| 6674 | QLocale::toString() with the appropriate locale. | - | ||||||||||||||||||
| 6675 | */ | - | ||||||||||||||||||
| 6676 | - | |||||||||||||||||||
| 6677 | - | |||||||||||||||||||
| 6678 | /*! | - | ||||||||||||||||||
| 6679 | \fn QString QString::number(long n, int base) | - | ||||||||||||||||||
| 6680 | - | |||||||||||||||||||
| 6681 | Returns a string equivalent of the number \a n according to the | - | ||||||||||||||||||
| 6682 | specified \a base. | - | ||||||||||||||||||
| 6683 | - | |||||||||||||||||||
| 6684 | The base is 10 by default and must be between 2 | - | ||||||||||||||||||
| 6685 | and 36. For bases other than 10, \a n is treated as an | - | ||||||||||||||||||
| 6686 | unsigned integer. | - | ||||||||||||||||||
| 6687 | - | |||||||||||||||||||
| 6688 | The formatting always uses QLocale::C, i.e., English/UnitedStates. | - | ||||||||||||||||||
| 6689 | To get a localized string representation of a number, use | - | ||||||||||||||||||
| 6690 | QLocale::toString() with the appropriate locale. | - | ||||||||||||||||||
| 6691 | - | |||||||||||||||||||
| 6692 | \snippet qstring/main.cpp 35 | - | ||||||||||||||||||
| 6693 | - | |||||||||||||||||||
| 6694 | \sa setNum() | - | ||||||||||||||||||
| 6695 | */ | - | ||||||||||||||||||
| 6696 | - | |||||||||||||||||||
| 6697 | QString QString::number(long n, int base) | - | ||||||||||||||||||
| 6698 | { | - | ||||||||||||||||||
| 6699 | return number(qlonglong(n), base); executed 18 times by 5 tests: return number(qlonglong(n), base);Executed by:
| 18 | ||||||||||||||||||
| 6700 | } | - | ||||||||||||||||||
| 6701 | - | |||||||||||||||||||
| 6702 | /*! | - | ||||||||||||||||||
| 6703 | \fn QString QString::number(ulong n, int base) | - | ||||||||||||||||||
| 6704 | - | |||||||||||||||||||
| 6705 | \overload | - | ||||||||||||||||||
| 6706 | */ | - | ||||||||||||||||||
| 6707 | QString QString::number(ulong n, int base) | - | ||||||||||||||||||
| 6708 | { | - | ||||||||||||||||||
| 6709 | return number(qulonglong(n), base); executed 32 times by 4 tests: return number(qulonglong(n), base);Executed by:
| 32 | ||||||||||||||||||
| 6710 | } | - | ||||||||||||||||||
| 6711 | - | |||||||||||||||||||
| 6712 | /*! | - | ||||||||||||||||||
| 6713 | \overload | - | ||||||||||||||||||
| 6714 | */ | - | ||||||||||||||||||
| 6715 | QString QString::number(int n, int base) | - | ||||||||||||||||||
| 6716 | { | - | ||||||||||||||||||
| 6717 | return number(qlonglong(n), base); executed 561031 times by 159 tests: return number(qlonglong(n), base);Executed by:
| 561031 | ||||||||||||||||||
| 6718 | } | - | ||||||||||||||||||
| 6719 | - | |||||||||||||||||||
| 6720 | /*! | - | ||||||||||||||||||
| 6721 | \overload | - | ||||||||||||||||||
| 6722 | */ | - | ||||||||||||||||||
| 6723 | QString QString::number(uint n, int base) | - | ||||||||||||||||||
| 6724 | { | - | ||||||||||||||||||
| 6725 | return number(qulonglong(n), base); executed 14397 times by 42 tests: return number(qulonglong(n), base);Executed by:
| 14397 | ||||||||||||||||||
| 6726 | } | - | ||||||||||||||||||
| 6727 | - | |||||||||||||||||||
| 6728 | /*! | - | ||||||||||||||||||
| 6729 | \overload | - | ||||||||||||||||||
| 6730 | */ | - | ||||||||||||||||||
| 6731 | QString QString::number(qlonglong n, int base) | - | ||||||||||||||||||
| 6732 | { | - | ||||||||||||||||||
| 6733 | #if defined(QT_CHECK_RANGE) | - | ||||||||||||||||||
| 6734 | if (base < 2 || base > 36) { | - | ||||||||||||||||||
| 6735 | qWarning("QString::setNum: Invalid base (%d)", base); | - | ||||||||||||||||||
| 6736 | base = 10; | - | ||||||||||||||||||
| 6737 | } | - | ||||||||||||||||||
| 6738 | #endif | - | ||||||||||||||||||
| 6739 | return QLocaleData::c()->longLongToString(n, -1, base); executed 627410 times by 175 tests: return QLocaleData::c()->longLongToString(n, -1, base);Executed by:
| 627410 | ||||||||||||||||||
| 6740 | } | - | ||||||||||||||||||
| 6741 | - | |||||||||||||||||||
| 6742 | /*! | - | ||||||||||||||||||
| 6743 | \overload | - | ||||||||||||||||||
| 6744 | */ | - | ||||||||||||||||||
| 6745 | QString QString::number(qulonglong n, int base) | - | ||||||||||||||||||
| 6746 | { | - | ||||||||||||||||||
| 6747 | #if defined(QT_CHECK_RANGE) | - | ||||||||||||||||||
| 6748 | if (base < 2 || base > 36) { | - | ||||||||||||||||||
| 6749 | qWarning("QString::setNum: Invalid base (%d)", base); | - | ||||||||||||||||||
| 6750 | base = 10; | - | ||||||||||||||||||
| 6751 | } | - | ||||||||||||||||||
| 6752 | #endif | - | ||||||||||||||||||
| 6753 | return QLocaleData::c()->unsLongLongToString(n, -1, base); executed 14870 times by 57 tests: return QLocaleData::c()->unsLongLongToString(n, -1, base);Executed by:
| 14870 | ||||||||||||||||||
| 6754 | } | - | ||||||||||||||||||
| 6755 | - | |||||||||||||||||||
| 6756 | - | |||||||||||||||||||
| 6757 | /*! | - | ||||||||||||||||||
| 6758 | \fn QString QString::number(double n, char format, int precision) | - | ||||||||||||||||||
| 6759 | - | |||||||||||||||||||
| 6760 | Returns a string equivalent of the number \a n, formatted | - | ||||||||||||||||||
| 6761 | according to the specified \a format and \a precision. See | - | ||||||||||||||||||
| 6762 | \l{Argument Formats} for details. | - | ||||||||||||||||||
| 6763 | - | |||||||||||||||||||
| 6764 | Unlike QLocale::toString(), this function does not honor the | - | ||||||||||||||||||
| 6765 | user's locale settings. | - | ||||||||||||||||||
| 6766 | - | |||||||||||||||||||
| 6767 | \sa setNum(), QLocale::toString() | - | ||||||||||||||||||
| 6768 | */ | - | ||||||||||||||||||
| 6769 | QString QString::number(double n, char f, int prec) | - | ||||||||||||||||||
| 6770 | { | - | ||||||||||||||||||
| 6771 | QLocaleData::DoubleForm form = QLocaleData::DFDecimal; | - | ||||||||||||||||||
| 6772 | uint flags = 0; | - | ||||||||||||||||||
| 6773 | - | |||||||||||||||||||
| 6774 | if (qIsUpper(f))
| 0-2702 | ||||||||||||||||||
| 6775 | flags = QLocaleData::CapitalEorX; never executed: flags = QLocaleData::CapitalEorX; | 0 | ||||||||||||||||||
| 6776 | f = qToLower(f); | - | ||||||||||||||||||
| 6777 | - | |||||||||||||||||||
| 6778 | switch (f) { | - | ||||||||||||||||||
| 6779 | case 'f': executed 987 times by 8 tests: case 'f':Executed by:
| 987 | ||||||||||||||||||
| 6780 | form = QLocaleData::DFDecimal; | - | ||||||||||||||||||
| 6781 | break; executed 987 times by 8 tests: break;Executed by:
| 987 | ||||||||||||||||||
| 6782 | case 'e': executed 12 times by 2 tests: case 'e':Executed by:
| 12 | ||||||||||||||||||
| 6783 | form = QLocaleData::DFExponent; | - | ||||||||||||||||||
| 6784 | break; executed 12 times by 2 tests: break;Executed by:
| 12 | ||||||||||||||||||
| 6785 | case 'g': executed 1703 times by 23 tests: case 'g':Executed by:
| 1703 | ||||||||||||||||||
| 6786 | form = QLocaleData::DFSignificantDigits; | - | ||||||||||||||||||
| 6787 | break; executed 1703 times by 23 tests: break;Executed by:
| 1703 | ||||||||||||||||||
| 6788 | default: never executed: default: | 0 | ||||||||||||||||||
| 6789 | #if defined(QT_CHECK_RANGE) | - | ||||||||||||||||||
| 6790 | qWarning("QString::setNum: Invalid format char '%c'", f); | - | ||||||||||||||||||
| 6791 | #endif | - | ||||||||||||||||||
| 6792 | break; never executed: break; | 0 | ||||||||||||||||||
| 6793 | } | - | ||||||||||||||||||
| 6794 | - | |||||||||||||||||||
| 6795 | return QLocaleData::c()->doubleToString(n, prec, form, -1, flags); executed 2702 times by 30 tests: return QLocaleData::c()->doubleToString(n, prec, form, -1, flags);Executed by:
| 2702 | ||||||||||||||||||
| 6796 | } | - | ||||||||||||||||||
| 6797 | - | |||||||||||||||||||
| 6798 | namespace { | - | ||||||||||||||||||
| 6799 | template<class ResultList, class StringSource> | - | ||||||||||||||||||
| 6800 | static ResultList splitString(const StringSource &source, const QChar *sep, | - | ||||||||||||||||||
| 6801 | QString::SplitBehavior behavior, Qt::CaseSensitivity cs, const int separatorSize) | - | ||||||||||||||||||
| 6802 | { | - | ||||||||||||||||||
| 6803 | ResultList list; | - | ||||||||||||||||||
| 6804 | int start = 0; | - | ||||||||||||||||||
| 6805 | int end; | - | ||||||||||||||||||
| 6806 | int extra = 0; | - | ||||||||||||||||||
| 6807 | while ((end = qFindString(source.constData(), source.size(), start + extra, sep, separatorSize, cs)) != -1) {
| 78545-348488 | ||||||||||||||||||
| 6808 | if (start != end || behavior == QString::KeepEmptyParts)
| 4428-321823 | ||||||||||||||||||
| 6809 | list.append(source.mid(start, end - start)); executed 326251 times by 239 tests: list.append(source.mid(start, end - start));Executed by:
| 326251 | ||||||||||||||||||
| 6810 | start = end + separatorSize; | - | ||||||||||||||||||
| 6811 | extra = (separatorSize == 0 ? 1 : 0);
| 48-348440 | ||||||||||||||||||
| 6812 | } executed 348488 times by 239 tests: end of blockExecuted by:
| 348488 | ||||||||||||||||||
| 6813 | if (start != source.size() || behavior == QString::KeepEmptyParts)
| 579-75068 | ||||||||||||||||||
| 6814 | list.append(source.mid(start, -1)); executed 77966 times by 274 tests: list.append(source.mid(start, -1));Executed by:
| 77966 | ||||||||||||||||||
| 6815 | return list; executed 78545 times by 275 tests: return list;Executed by:
| 78545 | ||||||||||||||||||
| 6816 | } | - | ||||||||||||||||||
| 6817 | - | |||||||||||||||||||
| 6818 | } // namespace | - | ||||||||||||||||||
| 6819 | - | |||||||||||||||||||
| 6820 | /*! | - | ||||||||||||||||||
| 6821 | Splits the string into substrings wherever \a sep occurs, and | - | ||||||||||||||||||
| 6822 | returns the list of those strings. If \a sep does not match | - | ||||||||||||||||||
| 6823 | anywhere in the string, split() returns a single-element list | - | ||||||||||||||||||
| 6824 | containing this string. | - | ||||||||||||||||||
| 6825 | - | |||||||||||||||||||
| 6826 | \a cs specifies whether \a sep should be matched case | - | ||||||||||||||||||
| 6827 | sensitively or case insensitively. | - | ||||||||||||||||||
| 6828 | - | |||||||||||||||||||
| 6829 | If \a behavior is QString::SkipEmptyParts, empty entries don't | - | ||||||||||||||||||
| 6830 | appear in the result. By default, empty entries are kept. | - | ||||||||||||||||||
| 6831 | - | |||||||||||||||||||
| 6832 | Example: | - | ||||||||||||||||||
| 6833 | - | |||||||||||||||||||
| 6834 | \snippet qstring/main.cpp 62 | - | ||||||||||||||||||
| 6835 | - | |||||||||||||||||||
| 6836 | \sa QStringList::join(), section() | - | ||||||||||||||||||
| 6837 | */ | - | ||||||||||||||||||
| 6838 | QStringList QString::split(const QString &sep, SplitBehavior behavior, Qt::CaseSensitivity cs) const | - | ||||||||||||||||||
| 6839 | { | - | ||||||||||||||||||
| 6840 | return splitString<QStringList>(*this, sep.constData(), behavior, cs, sep.size()); executed 1002 times by 29 tests: return splitString<QStringList>(*this, sep.constData(), behavior, cs, sep.size());Executed by:
| 1002 | ||||||||||||||||||
| 6841 | } | - | ||||||||||||||||||
| 6842 | - | |||||||||||||||||||
| 6843 | /*! | - | ||||||||||||||||||
| 6844 | Splits the string into substring references wherever \a sep occurs, and | - | ||||||||||||||||||
| 6845 | returns the list of those strings. If \a sep does not match | - | ||||||||||||||||||
| 6846 | anywhere in the string, splitRef() returns a single-element vector | - | ||||||||||||||||||
| 6847 | containing this string reference. | - | ||||||||||||||||||
| 6848 | - | |||||||||||||||||||
| 6849 | \a cs specifies whether \a sep should be matched case | - | ||||||||||||||||||
| 6850 | sensitively or case insensitively. | - | ||||||||||||||||||
| 6851 | - | |||||||||||||||||||
| 6852 | If \a behavior is QString::SkipEmptyParts, empty entries don't | - | ||||||||||||||||||
| 6853 | appear in the result. By default, empty entries are kept. | - | ||||||||||||||||||
| 6854 | - | |||||||||||||||||||
| 6855 | \note All references are valid as long this string is alive. Destroying this | - | ||||||||||||||||||
| 6856 | string will cause all references be dangling pointers. | - | ||||||||||||||||||
| 6857 | - | |||||||||||||||||||
| 6858 | \since 5.4 | - | ||||||||||||||||||
| 6859 | \sa QStringRef split() | - | ||||||||||||||||||
| 6860 | */ | - | ||||||||||||||||||
| 6861 | QVector<QStringRef> QString::splitRef(const QString &sep, SplitBehavior behavior, Qt::CaseSensitivity cs) const | - | ||||||||||||||||||
| 6862 | { | - | ||||||||||||||||||
| 6863 | return splitString<QVector<QStringRef> >(QStringRef(this), sep.constData(), behavior, cs, sep.size()); executed 2243 times by 13 tests: return splitString<QVector<QStringRef> >(QStringRef(this), sep.constData(), behavior, cs, sep.size());Executed by:
| 2243 | ||||||||||||||||||
| 6864 | } | - | ||||||||||||||||||
| 6865 | /*! | - | ||||||||||||||||||
| 6866 | \overload | - | ||||||||||||||||||
| 6867 | */ | - | ||||||||||||||||||
| 6868 | QStringList QString::split(QChar sep, SplitBehavior behavior, Qt::CaseSensitivity cs) const | - | ||||||||||||||||||
| 6869 | { | - | ||||||||||||||||||
| 6870 | return splitString<QStringList>(*this, &sep, behavior, cs, 1); executed 74194 times by 258 tests: return splitString<QStringList>(*this, &sep, behavior, cs, 1);Executed by:
| 74194 | ||||||||||||||||||
| 6871 | } | - | ||||||||||||||||||
| 6872 | - | |||||||||||||||||||
| 6873 | /*! | - | ||||||||||||||||||
| 6874 | \overload | - | ||||||||||||||||||
| 6875 | \since 5.4 | - | ||||||||||||||||||
| 6876 | */ | - | ||||||||||||||||||
| 6877 | QVector<QStringRef> QString::splitRef(QChar sep, SplitBehavior behavior, Qt::CaseSensitivity cs) const | - | ||||||||||||||||||
| 6878 | { | - | ||||||||||||||||||
| 6879 | return splitString<QVector<QStringRef> >(QStringRef(this), &sep, behavior, cs, 1); executed 973 times by 11 tests: return splitString<QVector<QStringRef> >(QStringRef(this), &sep, behavior, cs, 1);Executed by:
| 973 | ||||||||||||||||||
| 6880 | } | - | ||||||||||||||||||
| 6881 | - | |||||||||||||||||||
| 6882 | /*! | - | ||||||||||||||||||
| 6883 | Splits the string into substrings references wherever \a sep occurs, and | - | ||||||||||||||||||
| 6884 | returns the list of those strings. If \a sep does not match | - | ||||||||||||||||||
| 6885 | anywhere in the string, split() returns a single-element vector | - | ||||||||||||||||||
| 6886 | containing this string reference. | - | ||||||||||||||||||
| 6887 | - | |||||||||||||||||||
| 6888 | \a cs specifies whether \a sep should be matched case | - | ||||||||||||||||||
| 6889 | sensitively or case insensitively. | - | ||||||||||||||||||
| 6890 | - | |||||||||||||||||||
| 6891 | If \a behavior is QString::SkipEmptyParts, empty entries don't | - | ||||||||||||||||||
| 6892 | appear in the result. By default, empty entries are kept. | - | ||||||||||||||||||
| 6893 | - | |||||||||||||||||||
| 6894 | \note All references are valid as long this string is alive. Destroying this | - | ||||||||||||||||||
| 6895 | string will cause all references be dangling pointers. | - | ||||||||||||||||||
| 6896 | - | |||||||||||||||||||
| 6897 | \since 5.4 | - | ||||||||||||||||||
| 6898 | */ | - | ||||||||||||||||||
| 6899 | QVector<QStringRef> QStringRef::split(const QString &sep, QString::SplitBehavior behavior, Qt::CaseSensitivity cs) const | - | ||||||||||||||||||
| 6900 | { | - | ||||||||||||||||||
| 6901 | return splitString<QVector<QStringRef> >(*this, sep.constData(), behavior, cs, sep.size()); executed 30 times by 1 test: return splitString<QVector<QStringRef> >(*this, sep.constData(), behavior, cs, sep.size());Executed by:
| 30 | ||||||||||||||||||
| 6902 | } | - | ||||||||||||||||||
| 6903 | - | |||||||||||||||||||
| 6904 | /*! | - | ||||||||||||||||||
| 6905 | \overload | - | ||||||||||||||||||
| 6906 | \since 5.4 | - | ||||||||||||||||||
| 6907 | */ | - | ||||||||||||||||||
| 6908 | QVector<QStringRef> QStringRef::split(QChar sep, QString::SplitBehavior behavior, Qt::CaseSensitivity cs) const | - | ||||||||||||||||||
| 6909 | { | - | ||||||||||||||||||
| 6910 | return splitString<QVector<QStringRef> >(*this, &sep, behavior, cs, 1); executed 103 times by 5 tests: return splitString<QVector<QStringRef> >(*this, &sep, behavior, cs, 1);Executed by:
| 103 | ||||||||||||||||||
| 6911 | } | - | ||||||||||||||||||
| 6912 | - | |||||||||||||||||||
| 6913 | #ifndef QT_NO_REGEXP | - | ||||||||||||||||||
| 6914 | namespace { | - | ||||||||||||||||||
| 6915 | template<class ResultList, typename MidMethod> | - | ||||||||||||||||||
| 6916 | static ResultList splitString(const QString &source, MidMethod mid, const QRegExp &rx, QString::SplitBehavior behavior) | - | ||||||||||||||||||
| 6917 | { | - | ||||||||||||||||||
| 6918 | QRegExp rx2(rx); | - | ||||||||||||||||||
| 6919 | ResultList list; | - | ||||||||||||||||||
| 6920 | int start = 0; | - | ||||||||||||||||||
| 6921 | int extra = 0; | - | ||||||||||||||||||
| 6922 | int end; | - | ||||||||||||||||||
| 6923 | while ((end = rx2.indexIn(source, start + extra)) != -1) {
| 603-14356 | ||||||||||||||||||
| 6924 | int matchedLen = rx2.matchedLength(); | - | ||||||||||||||||||
| 6925 | if (start != end || behavior == QString::KeepEmptyParts)
| 22-13911 | ||||||||||||||||||
| 6926 | list.append((source.*mid)(start, end - start)); executed 14334 times by 7 tests: list.append((source.*mid)(start, end - start));Executed by:
| 14334 | ||||||||||||||||||
| 6927 | start = end + matchedLen; | - | ||||||||||||||||||
| 6928 | extra = (matchedLen == 0) ? 1 : 0;
| 62-14294 | ||||||||||||||||||
| 6929 | } executed 14356 times by 7 tests: end of blockExecuted by:
| 14356 | ||||||||||||||||||
| 6930 | if (start != source.size() || behavior == QString::KeepEmptyParts)
| 13-391 | ||||||||||||||||||
| 6931 | list.append((source.*mid)(start, -1)); executed 590 times by 9 tests: list.append((source.*mid)(start, -1));Executed by:
| 590 | ||||||||||||||||||
| 6932 | return list; executed 603 times by 10 tests: return list;Executed by:
| 603 | ||||||||||||||||||
| 6933 | } | - | ||||||||||||||||||
| 6934 | } // namespace | - | ||||||||||||||||||
| 6935 | - | |||||||||||||||||||
| 6936 | /*! | - | ||||||||||||||||||
| 6937 | \overload | - | ||||||||||||||||||
| 6938 | - | |||||||||||||||||||
| 6939 | Splits the string into substrings wherever the regular expression | - | ||||||||||||||||||
| 6940 | \a rx matches, and returns the list of those strings. If \a rx | - | ||||||||||||||||||
| 6941 | does not match anywhere in the string, split() returns a | - | ||||||||||||||||||
| 6942 | single-element list containing this string. | - | ||||||||||||||||||
| 6943 | - | |||||||||||||||||||
| 6944 | Here's an example where we extract the words in a sentence | - | ||||||||||||||||||
| 6945 | using one or more whitespace characters as the separator: | - | ||||||||||||||||||
| 6946 | - | |||||||||||||||||||
| 6947 | \snippet qstring/main.cpp 59 | - | ||||||||||||||||||
| 6948 | - | |||||||||||||||||||
| 6949 | Here's a similar example, but this time we use any sequence of | - | ||||||||||||||||||
| 6950 | non-word characters as the separator: | - | ||||||||||||||||||
| 6951 | - | |||||||||||||||||||
| 6952 | \snippet qstring/main.cpp 60 | - | ||||||||||||||||||
| 6953 | - | |||||||||||||||||||
| 6954 | Here's a third example where we use a zero-length assertion, | - | ||||||||||||||||||
| 6955 | \b{\\b} (word boundary), to split the string into an | - | ||||||||||||||||||
| 6956 | alternating sequence of non-word and word tokens: | - | ||||||||||||||||||
| 6957 | - | |||||||||||||||||||
| 6958 | \snippet qstring/main.cpp 61 | - | ||||||||||||||||||
| 6959 | - | |||||||||||||||||||
| 6960 | \sa QStringList::join(), section() | - | ||||||||||||||||||
| 6961 | */ | - | ||||||||||||||||||
| 6962 | QStringList QString::split(const QRegExp &rx, SplitBehavior behavior) const | - | ||||||||||||||||||
| 6963 | { | - | ||||||||||||||||||
| 6964 | return splitString<QStringList>(*this, &QString::mid, rx, behavior); executed 576 times by 10 tests: return splitString<QStringList>(*this, &QString::mid, rx, behavior);Executed by:
| 576 | ||||||||||||||||||
| 6965 | } | - | ||||||||||||||||||
| 6966 | - | |||||||||||||||||||
| 6967 | /*! | - | ||||||||||||||||||
| 6968 | \overload | - | ||||||||||||||||||
| 6969 | \since 5.4 | - | ||||||||||||||||||
| 6970 | - | |||||||||||||||||||
| 6971 | Splits the string into substring references wherever the regular expression | - | ||||||||||||||||||
| 6972 | \a rx matches, and returns the list of those strings. If \a rx | - | ||||||||||||||||||
| 6973 | does not match anywhere in the string, splitRef() returns a | - | ||||||||||||||||||
| 6974 | single-element vector containing this string reference. | - | ||||||||||||||||||
| 6975 | - | |||||||||||||||||||
| 6976 | \note All references are valid as long this string is alive. Destroying this | - | ||||||||||||||||||
| 6977 | string will cause all references be dangling pointers. | - | ||||||||||||||||||
| 6978 | - | |||||||||||||||||||
| 6979 | \sa QStringRef split() | - | ||||||||||||||||||
| 6980 | */ | - | ||||||||||||||||||
| 6981 | QVector<QStringRef> QString::splitRef(const QRegExp &rx, SplitBehavior behavior) const | - | ||||||||||||||||||
| 6982 | { | - | ||||||||||||||||||
| 6983 | return splitString<QVector<QStringRef> >(*this, &QString::midRef, rx, behavior); executed 27 times by 1 test: return splitString<QVector<QStringRef> >(*this, &QString::midRef, rx, behavior);Executed by:
| 27 | ||||||||||||||||||
| 6984 | } | - | ||||||||||||||||||
| 6985 | #endif | - | ||||||||||||||||||
| 6986 | - | |||||||||||||||||||
| 6987 | #ifndef QT_NO_REGULAREXPRESSION | - | ||||||||||||||||||
| 6988 | #ifndef QT_BOOTSTRAPPED | - | ||||||||||||||||||
| 6989 | namespace { | - | ||||||||||||||||||
| 6990 | template<class ResultList, typename MidMethod> | - | ||||||||||||||||||
| 6991 | static ResultList splitString(const QString &source, MidMethod mid, const QRegularExpression &re, | - | ||||||||||||||||||
| 6992 | QString::SplitBehavior behavior) | - | ||||||||||||||||||
| 6993 | { | - | ||||||||||||||||||
| 6994 | ResultList list; | - | ||||||||||||||||||
| 6995 | if (!re.isValid()) {
| 0-54 | ||||||||||||||||||
| 6996 | qWarning("QString::split: invalid QRegularExpression object"); | - | ||||||||||||||||||
| 6997 | return list; never executed: return list; | 0 | ||||||||||||||||||
| 6998 | } | - | ||||||||||||||||||
| 6999 | - | |||||||||||||||||||
| 7000 | int start = 0; | - | ||||||||||||||||||
| 7001 | int end = 0; | - | ||||||||||||||||||
| 7002 | QRegularExpressionMatchIterator iterator = re.globalMatch(source); | - | ||||||||||||||||||
| 7003 | while (iterator.hasNext()) {
| 54-210 | ||||||||||||||||||
| 7004 | QRegularExpressionMatch match = iterator.next(); | - | ||||||||||||||||||
| 7005 | end = match.capturedStart(); | - | ||||||||||||||||||
| 7006 | if (start != end || behavior == QString::KeepEmptyParts)
| 22-146 | ||||||||||||||||||
| 7007 | list.append((source.*mid)(start, end - start)); executed 188 times by 1 test: list.append((source.*mid)(start, end - start));Executed by:
| 188 | ||||||||||||||||||
| 7008 | start = match.capturedEnd(); | - | ||||||||||||||||||
| 7009 | } executed 210 times by 1 test: end of blockExecuted by:
| 210 | ||||||||||||||||||
| 7010 | - | |||||||||||||||||||
| 7011 | if (start != source.size() || behavior == QString::KeepEmptyParts)
| 12-34 | ||||||||||||||||||
| 7012 | list.append((source.*mid)(start, -1)); executed 42 times by 1 test: list.append((source.*mid)(start, -1));Executed by:
| 42 | ||||||||||||||||||
| 7013 | - | |||||||||||||||||||
| 7014 | return list; executed 54 times by 1 test: return list;Executed by:
| 54 | ||||||||||||||||||
| 7015 | } | - | ||||||||||||||||||
| 7016 | } // namespace | - | ||||||||||||||||||
| 7017 | - | |||||||||||||||||||
| 7018 | /*! | - | ||||||||||||||||||
| 7019 | \overload | - | ||||||||||||||||||
| 7020 | \since 5.0 | - | ||||||||||||||||||
| 7021 | - | |||||||||||||||||||
| 7022 | Splits the string into substrings wherever the regular expression | - | ||||||||||||||||||
| 7023 | \a re matches, and returns the list of those strings. If \a re | - | ||||||||||||||||||
| 7024 | does not match anywhere in the string, split() returns a | - | ||||||||||||||||||
| 7025 | single-element list containing this string. | - | ||||||||||||||||||
| 7026 | - | |||||||||||||||||||
| 7027 | Here's an example where we extract the words in a sentence | - | ||||||||||||||||||
| 7028 | using one or more whitespace characters as the separator: | - | ||||||||||||||||||
| 7029 | - | |||||||||||||||||||
| 7030 | \snippet qstring/main.cpp 90 | - | ||||||||||||||||||
| 7031 | - | |||||||||||||||||||
| 7032 | Here's a similar example, but this time we use any sequence of | - | ||||||||||||||||||
| 7033 | non-word characters as the separator: | - | ||||||||||||||||||
| 7034 | - | |||||||||||||||||||
| 7035 | \snippet qstring/main.cpp 91 | - | ||||||||||||||||||
| 7036 | - | |||||||||||||||||||
| 7037 | Here's a third example where we use a zero-length assertion, | - | ||||||||||||||||||
| 7038 | \b{\\b} (word boundary), to split the string into an | - | ||||||||||||||||||
| 7039 | alternating sequence of non-word and word tokens: | - | ||||||||||||||||||
| 7040 | - | |||||||||||||||||||
| 7041 | \snippet qstring/main.cpp 92 | - | ||||||||||||||||||
| 7042 | - | |||||||||||||||||||
| 7043 | \sa QStringList::join(), section() | - | ||||||||||||||||||
| 7044 | */ | - | ||||||||||||||||||
| 7045 | QStringList QString::split(const QRegularExpression &re, SplitBehavior behavior) const | - | ||||||||||||||||||
| 7046 | { | - | ||||||||||||||||||
| 7047 | return splitString<QStringList>(*this, &QString::mid, re, behavior); executed 27 times by 1 test: return splitString<QStringList>(*this, &QString::mid, re, behavior);Executed by:
| 27 | ||||||||||||||||||
| 7048 | } | - | ||||||||||||||||||
| 7049 | - | |||||||||||||||||||
| 7050 | /*! | - | ||||||||||||||||||
| 7051 | \overload | - | ||||||||||||||||||
| 7052 | \since 5.4 | - | ||||||||||||||||||
| 7053 | - | |||||||||||||||||||
| 7054 | Splits the string into substring references wherever the regular expression | - | ||||||||||||||||||
| 7055 | \a re matches, and returns the list of those strings. If \a re | - | ||||||||||||||||||
| 7056 | does not match anywhere in the string, splitRef() returns a | - | ||||||||||||||||||
| 7057 | single-element vector containing this string reference. | - | ||||||||||||||||||
| 7058 | - | |||||||||||||||||||
| 7059 | \note All references are valid as long this string is alive. Destroying this | - | ||||||||||||||||||
| 7060 | string will cause all references be dangling pointers. | - | ||||||||||||||||||
| 7061 | - | |||||||||||||||||||
| 7062 | \sa split() QStringRef | - | ||||||||||||||||||
| 7063 | */ | - | ||||||||||||||||||
| 7064 | QVector<QStringRef> QString::splitRef(const QRegularExpression &re, SplitBehavior behavior) const | - | ||||||||||||||||||
| 7065 | { | - | ||||||||||||||||||
| 7066 | return splitString<QVector<QStringRef> >(*this, &QString::midRef, re, behavior); executed 27 times by 1 test: return splitString<QVector<QStringRef> >(*this, &QString::midRef, re, behavior);Executed by:
| 27 | ||||||||||||||||||
| 7067 | } | - | ||||||||||||||||||
| 7068 | #endif // QT_BOOTSTRAPPED | - | ||||||||||||||||||
| 7069 | #endif // QT_NO_REGULAREXPRESSION | - | ||||||||||||||||||
| 7070 | - | |||||||||||||||||||
| 7071 | /*! | - | ||||||||||||||||||
| 7072 | \enum QString::NormalizationForm | - | ||||||||||||||||||
| 7073 | - | |||||||||||||||||||
| 7074 | This enum describes the various normalized forms of Unicode text. | - | ||||||||||||||||||
| 7075 | - | |||||||||||||||||||
| 7076 | \value NormalizationForm_D Canonical Decomposition | - | ||||||||||||||||||
| 7077 | \value NormalizationForm_C Canonical Decomposition followed by Canonical Composition | - | ||||||||||||||||||
| 7078 | \value NormalizationForm_KD Compatibility Decomposition | - | ||||||||||||||||||
| 7079 | \value NormalizationForm_KC Compatibility Decomposition followed by Canonical Composition | - | ||||||||||||||||||
| 7080 | - | |||||||||||||||||||
| 7081 | \sa normalized(), | - | ||||||||||||||||||
| 7082 | {http://www.unicode.org/reports/tr15/}{Unicode Standard Annex #15} | - | ||||||||||||||||||
| 7083 | */ | - | ||||||||||||||||||
| 7084 | - | |||||||||||||||||||
| 7085 | /*! | - | ||||||||||||||||||
| 7086 | \since 4.5 | - | ||||||||||||||||||
| 7087 | - | |||||||||||||||||||
| 7088 | Returns a copy of this string repeated the specified number of \a times. | - | ||||||||||||||||||
| 7089 | - | |||||||||||||||||||
| 7090 | If \a times is less than 1, an empty string is returned. | - | ||||||||||||||||||
| 7091 | - | |||||||||||||||||||
| 7092 | Example: | - | ||||||||||||||||||
| 7093 | - | |||||||||||||||||||
| 7094 | \code | - | ||||||||||||||||||
| 7095 | QString str("ab"); | - | ||||||||||||||||||
| 7096 | str.repeated(4); // returns "abababab" | - | ||||||||||||||||||
| 7097 | \endcode | - | ||||||||||||||||||
| 7098 | */ | - | ||||||||||||||||||
| 7099 | QString QString::repeated(int times) const | - | ||||||||||||||||||
| 7100 | { | - | ||||||||||||||||||
| 7101 | if (d->size == 0)
| 5-9 | ||||||||||||||||||
| 7102 | return *this; executed 5 times by 1 test: return *this;Executed by:
| 5 | ||||||||||||||||||
| 7103 | - | |||||||||||||||||||
| 7104 | if (times <= 1) {
| 4-5 | ||||||||||||||||||
| 7105 | if (times == 1)
| 1-3 | ||||||||||||||||||
| 7106 | return *this; executed 1 time by 1 test: return *this;Executed by:
| 1 | ||||||||||||||||||
| 7107 | return QString(); executed 3 times by 1 test: return QString();Executed by:
| 3 | ||||||||||||||||||
| 7108 | } | - | ||||||||||||||||||
| 7109 | - | |||||||||||||||||||
| 7110 | const int resultSize = times * d->size; | - | ||||||||||||||||||
| 7111 | - | |||||||||||||||||||
| 7112 | QString result; | - | ||||||||||||||||||
| 7113 | result.reserve(resultSize); | - | ||||||||||||||||||
| 7114 | if (result.d->alloc != uint(resultSize) + 1u)
| 0-5 | ||||||||||||||||||
| 7115 | return QString(); // not enough memory never executed: return QString(); | 0 | ||||||||||||||||||
| 7116 | - | |||||||||||||||||||
| 7117 | memcpy(result.d->data(), d->data(), d->size * sizeof(ushort)); | - | ||||||||||||||||||
| 7118 | - | |||||||||||||||||||
| 7119 | int sizeSoFar = d->size; | - | ||||||||||||||||||
| 7120 | ushort *end = result.d->data() + sizeSoFar; | - | ||||||||||||||||||
| 7121 | - | |||||||||||||||||||
| 7122 | const int halfResultSize = resultSize >> 1; | - | ||||||||||||||||||
| 7123 | while (sizeSoFar <= halfResultSize) {
| 5-16 | ||||||||||||||||||
| 7124 | memcpy(end, result.d->data(), sizeSoFar * sizeof(ushort)); | - | ||||||||||||||||||
| 7125 | end += sizeSoFar; | - | ||||||||||||||||||
| 7126 | sizeSoFar <<= 1; | - | ||||||||||||||||||
| 7127 | } executed 16 times by 2 tests: end of blockExecuted by:
| 16 | ||||||||||||||||||
| 7128 | memcpy(end, result.d->data(), (resultSize - sizeSoFar) * sizeof(ushort)); | - | ||||||||||||||||||
| 7129 | result.d->data()[resultSize] = '\0'; | - | ||||||||||||||||||
| 7130 | result.d->size = resultSize; | - | ||||||||||||||||||
| 7131 | return result; executed 5 times by 2 tests: return result;Executed by:
| 5 | ||||||||||||||||||
| 7132 | } | - | ||||||||||||||||||
| 7133 | - | |||||||||||||||||||
| 7134 | void qt_string_normalize(QString *data, QString::NormalizationForm mode, QChar::UnicodeVersion version, int from) | - | ||||||||||||||||||
| 7135 | { | - | ||||||||||||||||||
| 7136 | bool simple = true; | - | ||||||||||||||||||
| 7137 | const QChar *p = data->constData(); | - | ||||||||||||||||||
| 7138 | int len = data->length(); | - | ||||||||||||||||||
| 7139 | for (int i = from; i < len; ++i) {
| 11147-614491 | ||||||||||||||||||
| 7140 | if (p[i].unicode() >= 0x80) {
| 47962-566529 | ||||||||||||||||||
| 7141 | simple = false; | - | ||||||||||||||||||
| 7142 | if (i > from)
| 32720-533809 | ||||||||||||||||||
| 7143 | from = i - 1; executed 32720 times by 6 tests: from = i - 1;Executed by:
| 32720 | ||||||||||||||||||
| 7144 | break; executed 566529 times by 9 tests: break;Executed by:
| 566529 | ||||||||||||||||||
| 7145 | } | - | ||||||||||||||||||
| 7146 | } executed 47962 times by 6 tests: end of blockExecuted by:
| 47962 | ||||||||||||||||||
| 7147 | if (simple)
| 11147-566529 | ||||||||||||||||||
| 7148 | return; executed 11147 times by 3 tests: return;Executed by:
| 11147 | ||||||||||||||||||
| 7149 | - | |||||||||||||||||||
| 7150 | if (version == QChar::Unicode_Unassigned) {
| 825-565704 | ||||||||||||||||||
| 7151 | version = QChar::currentUnicodeVersion(); | - | ||||||||||||||||||
| 7152 | } else if (int(version) <= NormalizationCorrectionsVersionMax) { executed 565704 times by 4 tests: end of blockExecuted by:
| 0-565704 | ||||||||||||||||||
| 7153 | const QString &s = *data; | - | ||||||||||||||||||
| 7154 | QChar *d = 0; | - | ||||||||||||||||||
| 7155 | for (int i = 0; i < NumNormalizationCorrections; ++i) {
| 825-4950 | ||||||||||||||||||
| 7156 | const NormalizationCorrection &n = uc_normalization_corrections[i]; | - | ||||||||||||||||||
| 7157 | if (n.version > version) {
| 823-4127 | ||||||||||||||||||
| 7158 | int pos = from; | - | ||||||||||||||||||
| 7159 | if (QChar::requiresSurrogates(n.ucs4)) {
| 2-4125 | ||||||||||||||||||
| 7160 | ushort ucs4High = QChar::highSurrogate(n.ucs4); | - | ||||||||||||||||||
| 7161 | ushort ucs4Low = QChar::lowSurrogate(n.ucs4); | - | ||||||||||||||||||
| 7162 | ushort oldHigh = QChar::highSurrogate(n.old_mapping); | - | ||||||||||||||||||
| 7163 | ushort oldLow = QChar::lowSurrogate(n.old_mapping); | - | ||||||||||||||||||
| 7164 | while (pos < s.length() - 1) {
| 4125-9480 | ||||||||||||||||||
| 7165 | if (s.at(pos).unicode() == ucs4High && s.at(pos + 1).unicode() == ucs4Low) {
| 0-9478 | ||||||||||||||||||
| 7166 | if (!d)
| 0-2 | ||||||||||||||||||
| 7167 | d = data->data(); executed 2 times by 1 test: d = data->data();Executed by:
| 2 | ||||||||||||||||||
| 7168 | d[pos] = QChar(oldHigh); | - | ||||||||||||||||||
| 7169 | d[++pos] = QChar(oldLow); | - | ||||||||||||||||||
| 7170 | } executed 2 times by 1 test: end of blockExecuted by:
| 2 | ||||||||||||||||||
| 7171 | ++pos; | - | ||||||||||||||||||
| 7172 | } executed 9480 times by 6 tests: end of blockExecuted by:
| 9480 | ||||||||||||||||||
| 7173 | } else { executed 4125 times by 6 tests: end of blockExecuted by:
| 4125 | ||||||||||||||||||
| 7174 | while (pos < s.length()) {
| 2-3 | ||||||||||||||||||
| 7175 | if (s.at(pos).unicode() == n.ucs4) {
| 1-2 | ||||||||||||||||||
| 7176 | if (!d)
| 0-1 | ||||||||||||||||||
| 7177 | d = data->data(); executed 1 time by 1 test: d = data->data();Executed by:
| 1 | ||||||||||||||||||
| 7178 | d[pos] = QChar(n.old_mapping); | - | ||||||||||||||||||
| 7179 | } executed 1 time by 1 test: end of blockExecuted by:
| 1 | ||||||||||||||||||
| 7180 | ++pos; | - | ||||||||||||||||||
| 7181 | } executed 3 times by 1 test: end of blockExecuted by:
| 3 | ||||||||||||||||||
| 7182 | } executed 2 times by 1 test: end of blockExecuted by:
| 2 | ||||||||||||||||||
| 7183 | } | - | ||||||||||||||||||
| 7184 | } executed 4950 times by 6 tests: end of blockExecuted by:
| 4950 | ||||||||||||||||||
| 7185 | } executed 825 times by 6 tests: end of blockExecuted by:
| 825 | ||||||||||||||||||
| 7186 | - | |||||||||||||||||||
| 7187 | if (normalizationQuickCheckHelper(data, mode, from, &from))
| 166051-400478 | ||||||||||||||||||
| 7188 | return; executed 400478 times by 9 tests: return;Executed by:
| 400478 | ||||||||||||||||||
| 7189 | - | |||||||||||||||||||
| 7190 | decomposeHelper(data, mode < QString::NormalizationForm_KD, version, from); | - | ||||||||||||||||||
| 7191 | - | |||||||||||||||||||
| 7192 | canonicalOrderHelper(data, version, from); | - | ||||||||||||||||||
| 7193 | - | |||||||||||||||||||
| 7194 | if (mode == QString::NormalizationForm_D || mode == QString::NormalizationForm_KD)
| 40333-125718 | ||||||||||||||||||
| 7195 | return; executed 91668 times by 1 test: return;Executed by:
| 91668 | ||||||||||||||||||
| 7196 | - | |||||||||||||||||||
| 7197 | composeHelper(data, version, from); | - | ||||||||||||||||||
| 7198 | } executed 74383 times by 3 tests: end of blockExecuted by:
| 74383 | ||||||||||||||||||
| 7199 | - | |||||||||||||||||||
| 7200 | /*! | - | ||||||||||||||||||
| 7201 | Returns the string in the given Unicode normalization \a mode, | - | ||||||||||||||||||
| 7202 | according to the given \a version of the Unicode standard. | - | ||||||||||||||||||
| 7203 | */ | - | ||||||||||||||||||
| 7204 | QString QString::normalized(QString::NormalizationForm mode, QChar::UnicodeVersion version) const | - | ||||||||||||||||||
| 7205 | { | - | ||||||||||||||||||
| 7206 | QString copy = *this; | - | ||||||||||||||||||
| 7207 | qt_string_normalize(©, mode, version, 0); | - | ||||||||||||||||||
| 7208 | return copy; executed 576836 times by 4 tests: return copy;Executed by:
| 576836 | ||||||||||||||||||
| 7209 | } | - | ||||||||||||||||||
| 7210 | - | |||||||||||||||||||
| 7211 | - | |||||||||||||||||||
| 7212 | struct ArgEscapeData | - | ||||||||||||||||||
| 7213 | { | - | ||||||||||||||||||
| 7214 | int min_escape; // lowest escape sequence number | - | ||||||||||||||||||
| 7215 | int occurrences; // number of occurrences of the lowest escape sequence number | - | ||||||||||||||||||
| 7216 | int locale_occurrences; // number of occurrences of the lowest escape sequence number that | - | ||||||||||||||||||
| 7217 | // contain 'L' | - | ||||||||||||||||||
| 7218 | int escape_len; // total length of escape sequences which will be replaced | - | ||||||||||||||||||
| 7219 | }; | - | ||||||||||||||||||
| 7220 | - | |||||||||||||||||||
| 7221 | static ArgEscapeData findArgEscapes(const QString &s) | - | ||||||||||||||||||
| 7222 | { | - | ||||||||||||||||||
| 7223 | const QChar *uc_begin = s.unicode(); | - | ||||||||||||||||||
| 7224 | const QChar *uc_end = uc_begin + s.length(); | - | ||||||||||||||||||
| 7225 | - | |||||||||||||||||||
| 7226 | ArgEscapeData d; | - | ||||||||||||||||||
| 7227 | - | |||||||||||||||||||
| 7228 | d.min_escape = INT_MAX; | - | ||||||||||||||||||
| 7229 | d.occurrences = 0; | - | ||||||||||||||||||
| 7230 | d.escape_len = 0; | - | ||||||||||||||||||
| 7231 | d.locale_occurrences = 0; | - | ||||||||||||||||||
| 7232 | - | |||||||||||||||||||
| 7233 | const QChar *c = uc_begin; | - | ||||||||||||||||||
| 7234 | while (c != uc_end) {
| 10622012-22493547 | ||||||||||||||||||
| 7235 | while (c != uc_end && c->unicode() != '%')
| 309507-75218581 | ||||||||||||||||||
| 7236 | ++c; executed 53034541 times by 438 tests: ++c;Executed by:
| 53034541 | ||||||||||||||||||
| 7237 | - | |||||||||||||||||||
| 7238 | if (c == uc_end)
| 309507-22184040 | ||||||||||||||||||
| 7239 | break; executed 309507 times by 398 tests: break;Executed by:
| 309507 | ||||||||||||||||||
| 7240 | const QChar *escape_start = c; | - | ||||||||||||||||||
| 7241 | if (++c == uc_end)
| 14-22184026 | ||||||||||||||||||
| 7242 | break; executed 14 times by 2 tests: break;Executed by:
| 14 | ||||||||||||||||||
| 7243 | - | |||||||||||||||||||
| 7244 | bool locale_arg = false; | - | ||||||||||||||||||
| 7245 | if (c->unicode() == 'L') {
| 276-22183750 | ||||||||||||||||||
| 7246 | locale_arg = true; | - | ||||||||||||||||||
| 7247 | if (++c == uc_end)
| 16-260 | ||||||||||||||||||
| 7248 | break; executed 16 times by 1 test: break;Executed by:
| 16 | ||||||||||||||||||
| 7249 | } executed 260 times by 2 tests: end of blockExecuted by:
| 260 | ||||||||||||||||||
| 7250 | - | |||||||||||||||||||
| 7251 | int escape = c->digitValue(); | - | ||||||||||||||||||
| 7252 | if (escape == -1)
| 195-22183815 | ||||||||||||||||||
| 7253 | continue; executed 195 times by 1 test: continue;Executed by:
| 195 | ||||||||||||||||||
| 7254 | - | |||||||||||||||||||
| 7255 | ++c; | - | ||||||||||||||||||
| 7256 | - | |||||||||||||||||||
| 7257 | if (c != uc_end) {
| 10622010-11561805 | ||||||||||||||||||
| 7258 | int next_escape = c->digitValue(); | - | ||||||||||||||||||
| 7259 | if (next_escape != -1) {
| 94-11561711 | ||||||||||||||||||
| 7260 | escape = (10 * escape) + next_escape; | - | ||||||||||||||||||
| 7261 | ++c; | - | ||||||||||||||||||
| 7262 | } executed 94 times by 1 test: end of blockExecuted by:
| 94 | ||||||||||||||||||
| 7263 | } executed 11561805 times by 420 tests: end of blockExecuted by:
| 11561805 | ||||||||||||||||||
| 7264 | - | |||||||||||||||||||
| 7265 | if (escape > d.min_escape)
| 10932654-11251161 | ||||||||||||||||||
| 7266 | continue; executed 11251161 times by 367 tests: continue;Executed by:
| 11251161 | ||||||||||||||||||
| 7267 | - | |||||||||||||||||||
| 7268 | if (escape < d.min_escape) {
| 148-10932506 | ||||||||||||||||||
| 7269 | d.min_escape = escape; | - | ||||||||||||||||||
| 7270 | d.occurrences = 0; | - | ||||||||||||||||||
| 7271 | d.escape_len = 0; | - | ||||||||||||||||||
| 7272 | d.locale_occurrences = 0; | - | ||||||||||||||||||
| 7273 | } executed 10932506 times by 440 tests: end of blockExecuted by:
| 10932506 | ||||||||||||||||||
| 7274 | - | |||||||||||||||||||
| 7275 | ++d.occurrences; | - | ||||||||||||||||||
| 7276 | if (locale_arg)
| 225-10932429 | ||||||||||||||||||
| 7277 | ++d.locale_occurrences; executed 225 times by 2 tests: ++d.locale_occurrences;Executed by:
| 225 | ||||||||||||||||||
| 7278 | d.escape_len += c - escape_start; | - | ||||||||||||||||||
| 7279 | } executed 10932654 times by 440 tests: end of blockExecuted by:
| 10932654 | ||||||||||||||||||
| 7280 | return d; executed 10931549 times by 440 tests: return d;Executed by:
| 10931549 | ||||||||||||||||||
| 7281 | } | - | ||||||||||||||||||
| 7282 | - | |||||||||||||||||||
| 7283 | static QString replaceArgEscapes(const QString &s, const ArgEscapeData &d, int field_width, | - | ||||||||||||||||||
| 7284 | const QString &arg, const QString &larg, QChar fillChar = QLatin1Char(' ')) | - | ||||||||||||||||||
| 7285 | { | - | ||||||||||||||||||
| 7286 | const QChar *uc_begin = s.unicode(); | - | ||||||||||||||||||
| 7287 | const QChar *uc_end = uc_begin + s.length(); | - | ||||||||||||||||||
| 7288 | - | |||||||||||||||||||
| 7289 | int abs_field_width = qAbs(field_width); | - | ||||||||||||||||||
| 7290 | int result_len = s.length() | - | ||||||||||||||||||
| 7291 | - d.escape_len | - | ||||||||||||||||||
| 7292 | + (d.occurrences - d.locale_occurrences) | - | ||||||||||||||||||
| 7293 | *qMax(abs_field_width, arg.length()) | - | ||||||||||||||||||
| 7294 | + d.locale_occurrences | - | ||||||||||||||||||
| 7295 | *qMax(abs_field_width, larg.length()); | - | ||||||||||||||||||
| 7296 | - | |||||||||||||||||||
| 7297 | QString result(result_len, Qt::Uninitialized); | - | ||||||||||||||||||
| 7298 | QChar *result_buff = (QChar*) result.unicode(); | - | ||||||||||||||||||
| 7299 | - | |||||||||||||||||||
| 7300 | QChar *rc = result_buff; | - | ||||||||||||||||||
| 7301 | const QChar *c = uc_begin; | - | ||||||||||||||||||
| 7302 | int repl_cnt = 0; | - | ||||||||||||||||||
| 7303 | while (c != uc_end) {
| 10931543-10934379 | ||||||||||||||||||
| 7304 | /* We don't have to check if we run off the end of the string with c, | - | ||||||||||||||||||
| 7305 | because as long as d.occurrences > 0 we KNOW there are valid escape | - | ||||||||||||||||||
| 7306 | sequences. */ | - | ||||||||||||||||||
| 7307 | - | |||||||||||||||||||
| 7308 | const QChar *text_start = c; | - | ||||||||||||||||||
| 7309 | - | |||||||||||||||||||
| 7310 | while (c->unicode() != '%')
| 10934379-37290485 | ||||||||||||||||||
| 7311 | ++c; executed 37290485 times by 436 tests: ++c;Executed by:
| 37290485 | ||||||||||||||||||
| 7312 | - | |||||||||||||||||||
| 7313 | const QChar *escape_start = c++; | - | ||||||||||||||||||
| 7314 | - | |||||||||||||||||||
| 7315 | bool locale_arg = false; | - | ||||||||||||||||||
| 7316 | if (c->unicode() == 'L') {
| 225-10934154 | ||||||||||||||||||
| 7317 | locale_arg = true; | - | ||||||||||||||||||
| 7318 | ++c; | - | ||||||||||||||||||
| 7319 | } executed 225 times by 2 tests: end of blockExecuted by:
| 225 | ||||||||||||||||||
| 7320 | - | |||||||||||||||||||
| 7321 | int escape = c->digitValue(); | - | ||||||||||||||||||
| 7322 | if (escape != -1) {
| 63-10934316 | ||||||||||||||||||
| 7323 | if (c + 1 != uc_end && (c + 1)->digitValue() != -1) {
| 8-7281355 | ||||||||||||||||||
| 7324 | escape = (10 * escape) + (c + 1)->digitValue(); | - | ||||||||||||||||||
| 7325 | ++c; | - | ||||||||||||||||||
| 7326 | } executed 8 times by 1 test: end of blockExecuted by:
| 8 | ||||||||||||||||||
| 7327 | } executed 10934316 times by 440 tests: end of blockExecuted by:
| 10934316 | ||||||||||||||||||
| 7328 | - | |||||||||||||||||||
| 7329 | if (escape != d.min_escape) {
| 2690-10931689 | ||||||||||||||||||
| 7330 | memcpy(rc, text_start, (c - text_start)*sizeof(QChar)); | - | ||||||||||||||||||
| 7331 | rc += c - text_start; | - | ||||||||||||||||||
| 7332 | } executed 2690 times by 3 tests: end of blockExecuted by:
| 2690 | ||||||||||||||||||
| 7333 | else { | - | ||||||||||||||||||
| 7334 | ++c; | - | ||||||||||||||||||
| 7335 | - | |||||||||||||||||||
| 7336 | memcpy(rc, text_start, (escape_start - text_start)*sizeof(QChar)); | - | ||||||||||||||||||
| 7337 | rc += escape_start - text_start; | - | ||||||||||||||||||
| 7338 | - | |||||||||||||||||||
| 7339 | uint pad_chars; | - | ||||||||||||||||||
| 7340 | if (locale_arg)
| 224-10931465 | ||||||||||||||||||
| 7341 | pad_chars = qMax(abs_field_width, larg.length()) - larg.length(); executed 224 times by 2 tests: pad_chars = qMax(abs_field_width, larg.length()) - larg.length();Executed by:
| 224 | ||||||||||||||||||
| 7342 | else | - | ||||||||||||||||||
| 7343 | pad_chars = qMax(abs_field_width, arg.length()) - arg.length(); executed 10931465 times by 440 tests: pad_chars = qMax(abs_field_width, arg.length()) - arg.length();Executed by:
| 10931465 | ||||||||||||||||||
| 7344 | - | |||||||||||||||||||
| 7345 | if (field_width > 0) { // left padded
| 1102-10930587 | ||||||||||||||||||
| 7346 | for (uint i = 0; i < pad_chars; ++i)
| 1102-4915 | ||||||||||||||||||
| 7347 | (rc++)->unicode() = fillChar.unicode(); executed 4915 times by 3 tests: (rc++)->unicode() = fillChar.unicode();Executed by:
| 4915 | ||||||||||||||||||
| 7348 | } executed 1102 times by 8 tests: end of blockExecuted by:
| 1102 | ||||||||||||||||||
| 7349 | - | |||||||||||||||||||
| 7350 | if (locale_arg) {
| 224-10931465 | ||||||||||||||||||
| 7351 | memcpy(rc, larg.unicode(), larg.length()*sizeof(QChar)); | - | ||||||||||||||||||
| 7352 | rc += larg.length(); | - | ||||||||||||||||||
| 7353 | } executed 224 times by 2 tests: end of blockExecuted by:
| 224 | ||||||||||||||||||
| 7354 | else { | - | ||||||||||||||||||
| 7355 | memcpy(rc, arg.unicode(), arg.length()*sizeof(QChar)); | - | ||||||||||||||||||
| 7356 | rc += arg.length(); | - | ||||||||||||||||||
| 7357 | } executed 10931465 times by 440 tests: end of blockExecuted by:
| 10931465 | ||||||||||||||||||
| 7358 | - | |||||||||||||||||||
| 7359 | if (field_width < 0) { // right padded
| 5-10931684 | ||||||||||||||||||
| 7360 | for (uint i = 0; i < pad_chars; ++i)
| 5-12 | ||||||||||||||||||
| 7361 | (rc++)->unicode() = fillChar.unicode(); executed 12 times by 1 test: (rc++)->unicode() = fillChar.unicode();Executed by:
| 12 | ||||||||||||||||||
| 7362 | } executed 5 times by 1 test: end of blockExecuted by:
| 5 | ||||||||||||||||||
| 7363 | - | |||||||||||||||||||
| 7364 | if (++repl_cnt == d.occurrences) {
| 146-10931543 | ||||||||||||||||||
| 7365 | memcpy(rc, c, (uc_end - c)*sizeof(QChar)); | - | ||||||||||||||||||
| 7366 | rc += uc_end - c; | - | ||||||||||||||||||
| 7367 | Q_ASSERT(rc - result_buff == result_len); | - | ||||||||||||||||||
| 7368 | c = uc_end; | - | ||||||||||||||||||
| 7369 | } executed 10931543 times by 440 tests: end of blockExecuted by:
| 10931543 | ||||||||||||||||||
| 7370 | } executed 10931689 times by 440 tests: end of blockExecuted by:
| 10931689 | ||||||||||||||||||
| 7371 | } | - | ||||||||||||||||||
| 7372 | Q_ASSERT(rc == result_buff + result_len); | - | ||||||||||||||||||
| 7373 | - | |||||||||||||||||||
| 7374 | return result; executed 10931543 times by 440 tests: return result;Executed by:
| 10931543 | ||||||||||||||||||
| 7375 | } | - | ||||||||||||||||||
| 7376 | - | |||||||||||||||||||
| 7377 | /*! | - | ||||||||||||||||||
| 7378 | Returns a copy of this string with the lowest numbered place marker | - | ||||||||||||||||||
| 7379 | replaced by string \a a, i.e., \c %1, \c %2, ..., \c %99. | - | ||||||||||||||||||
| 7380 | - | |||||||||||||||||||
| 7381 | \a fieldWidth specifies the minimum amount of space that argument \a | - | ||||||||||||||||||
| 7382 | a shall occupy. If \a a requires less space than \a fieldWidth, it | - | ||||||||||||||||||
| 7383 | is padded to \a fieldWidth with character \a fillChar. A positive | - | ||||||||||||||||||
| 7384 | \a fieldWidth produces right-aligned text. A negative \a fieldWidth | - | ||||||||||||||||||
| 7385 | produces left-aligned text. | - | ||||||||||||||||||
| 7386 | - | |||||||||||||||||||
| 7387 | This example shows how we might create a \c status string for | - | ||||||||||||||||||
| 7388 | reporting progress while processing a list of files: | - | ||||||||||||||||||
| 7389 | - | |||||||||||||||||||
| 7390 | \snippet qstring/main.cpp 11 | - | ||||||||||||||||||
| 7391 | - | |||||||||||||||||||
| 7392 | First, \c arg(i) replaces \c %1. Then \c arg(total) replaces \c | - | ||||||||||||||||||
| 7393 | %2. Finally, \c arg(fileName) replaces \c %3. | - | ||||||||||||||||||
| 7394 | - | |||||||||||||||||||
| 7395 | One advantage of using arg() over asprintf() is that the order of the | - | ||||||||||||||||||
| 7396 | numbered place markers can change, if the application's strings are | - | ||||||||||||||||||
| 7397 | translated into other languages, but each arg() will still replace | - | ||||||||||||||||||
| 7398 | the lowest numbered unreplaced place marker, no matter where it | - | ||||||||||||||||||
| 7399 | appears. Also, if place marker \c %i appears more than once in the | - | ||||||||||||||||||
| 7400 | string, the arg() replaces all of them. | - | ||||||||||||||||||
| 7401 | - | |||||||||||||||||||
| 7402 | If there is no unreplaced place marker remaining, a warning message | - | ||||||||||||||||||
| 7403 | is output and the result is undefined. Place marker numbers must be | - | ||||||||||||||||||
| 7404 | in the range 1 to 99. | - | ||||||||||||||||||
| 7405 | */ | - | ||||||||||||||||||
| 7406 | QString QString::arg(const QString &a, int fieldWidth, QChar fillChar) const | - | ||||||||||||||||||
| 7407 | { | - | ||||||||||||||||||
| 7408 | ArgEscapeData d = findArgEscapes(*this); | - | ||||||||||||||||||
| 7409 | - | |||||||||||||||||||
| 7410 | if (d.occurrences == 0) {
| 0-138442 | ||||||||||||||||||
| 7411 | qWarning("QString::arg: Argument missing: %s, %s", toLocal8Bit().data(), | - | ||||||||||||||||||
| 7412 | a.toLocal8Bit().data()); | - | ||||||||||||||||||
| 7413 | return *this; never executed: return *this; | 0 | ||||||||||||||||||
| 7414 | } | - | ||||||||||||||||||
| 7415 | return replaceArgEscapes(*this, d, fieldWidth, a, a, fillChar); executed 138442 times by 408 tests: return replaceArgEscapes(*this, d, fieldWidth, a, a, fillChar);Executed by:
| 138442 | ||||||||||||||||||
| 7416 | } | - | ||||||||||||||||||
| 7417 | - | |||||||||||||||||||
| 7418 | /*! | - | ||||||||||||||||||
| 7419 | \fn QString QString::arg(const QString& a1, const QString& a2) const | - | ||||||||||||||||||
| 7420 | \overload arg() | - | ||||||||||||||||||
| 7421 | - | |||||||||||||||||||
| 7422 | This is the same as \c {str.arg(a1).arg(a2)}, except that the | - | ||||||||||||||||||
| 7423 | strings \a a1 and \a a2 are replaced in one pass. This can make a | - | ||||||||||||||||||
| 7424 | difference if \a a1 contains e.g. \c{%1}: | - | ||||||||||||||||||
| 7425 | - | |||||||||||||||||||
| 7426 | \snippet qstring/main.cpp 13 | - | ||||||||||||||||||
| 7427 | - | |||||||||||||||||||
| 7428 | A similar problem occurs when the numbered place markers are not | - | ||||||||||||||||||
| 7429 | white space separated: | - | ||||||||||||||||||
| 7430 | - | |||||||||||||||||||
| 7431 | \snippet qstring/main.cpp 12 | - | ||||||||||||||||||
| 7432 | \snippet qstring/main.cpp 97 | - | ||||||||||||||||||
| 7433 | - | |||||||||||||||||||
| 7434 | Let's look at the substitutions: | - | ||||||||||||||||||
| 7435 | \list | - | ||||||||||||||||||
| 7436 | \li First, \c Hello replaces \c {%1} so the string becomes \c {"Hello%3%2"}. | - | ||||||||||||||||||
| 7437 | \li Then, \c 20 replaces \c {%2} so the string becomes \c {"Hello%320"}. | - | ||||||||||||||||||
| 7438 | \li Since the maximum numbered place marker value is 99, \c 50 replaces \c {%32}. | - | ||||||||||||||||||
| 7439 | \endlist | - | ||||||||||||||||||
| 7440 | Thus the string finally becomes \c {"Hello500"}. | - | ||||||||||||||||||
| 7441 | - | |||||||||||||||||||
| 7442 | In such cases, the following yields the expected results: | - | ||||||||||||||||||
| 7443 | - | |||||||||||||||||||
| 7444 | \snippet qstring/main.cpp 12 | - | ||||||||||||||||||
| 7445 | \snippet qstring/main.cpp 98 | - | ||||||||||||||||||
| 7446 | */ | - | ||||||||||||||||||
| 7447 | - | |||||||||||||||||||
| 7448 | /*! | - | ||||||||||||||||||
| 7449 | \fn QString QString::arg(const QString& a1, const QString& a2, const QString& a3) const | - | ||||||||||||||||||
| 7450 | \overload arg() | - | ||||||||||||||||||
| 7451 | - | |||||||||||||||||||
| 7452 | This is the same as calling \c str.arg(a1).arg(a2).arg(a3), except | - | ||||||||||||||||||
| 7453 | that the strings \a a1, \a a2 and \a a3 are replaced in one pass. | - | ||||||||||||||||||
| 7454 | */ | - | ||||||||||||||||||
| 7455 | - | |||||||||||||||||||
| 7456 | /*! | - | ||||||||||||||||||
| 7457 | \fn QString QString::arg(const QString& a1, const QString& a2, const QString& a3, const QString& a4) const | - | ||||||||||||||||||
| 7458 | \overload arg() | - | ||||||||||||||||||
| 7459 | - | |||||||||||||||||||
| 7460 | This is the same as calling \c | - | ||||||||||||||||||
| 7461 | {str.arg(a1).arg(a2).arg(a3).arg(a4)}, except that the strings \a | - | ||||||||||||||||||
| 7462 | a1, \a a2, \a a3 and \a a4 are replaced in one pass. | - | ||||||||||||||||||
| 7463 | */ | - | ||||||||||||||||||
| 7464 | - | |||||||||||||||||||
| 7465 | /*! | - | ||||||||||||||||||
| 7466 | \fn QString QString::arg(const QString& a1, const QString& a2, const QString& a3, const QString& a4, const QString& a5) const | - | ||||||||||||||||||
| 7467 | \overload arg() | - | ||||||||||||||||||
| 7468 | - | |||||||||||||||||||
| 7469 | This is the same as calling \c | - | ||||||||||||||||||
| 7470 | {str.arg(a1).arg(a2).arg(a3).arg(a4).arg(a5)}, except that the strings | - | ||||||||||||||||||
| 7471 | \a a1, \a a2, \a a3, \a a4, and \a a5 are replaced in one pass. | - | ||||||||||||||||||
| 7472 | */ | - | ||||||||||||||||||
| 7473 | - | |||||||||||||||||||
| 7474 | /*! | - | ||||||||||||||||||
| 7475 | \fn QString QString::arg(const QString& a1, const QString& a2, const QString& a3, const QString& a4, const QString& a5, const QString& a6) const | - | ||||||||||||||||||
| 7476 | \overload arg() | - | ||||||||||||||||||
| 7477 | - | |||||||||||||||||||
| 7478 | This is the same as calling \c | - | ||||||||||||||||||
| 7479 | {str.arg(a1).arg(a2).arg(a3).arg(a4).arg(a5).arg(a6))}, except that | - | ||||||||||||||||||
| 7480 | the strings \a a1, \a a2, \a a3, \a a4, \a a5, and \a a6 are | - | ||||||||||||||||||
| 7481 | replaced in one pass. | - | ||||||||||||||||||
| 7482 | */ | - | ||||||||||||||||||
| 7483 | - | |||||||||||||||||||
| 7484 | /*! | - | ||||||||||||||||||
| 7485 | \fn QString QString::arg(const QString& a1, const QString& a2, const QString& a3, const QString& a4, const QString& a5, const QString& a6, const QString& a7) const | - | ||||||||||||||||||
| 7486 | \overload arg() | - | ||||||||||||||||||
| 7487 | - | |||||||||||||||||||
| 7488 | This is the same as calling \c | - | ||||||||||||||||||
| 7489 | {str.arg(a1).arg(a2).arg(a3).arg(a4).arg(a5).arg(a6).arg(a7)}, | - | ||||||||||||||||||
| 7490 | except that the strings \a a1, \a a2, \a a3, \a a4, \a a5, \a a6, | - | ||||||||||||||||||
| 7491 | and \a a7 are replaced in one pass. | - | ||||||||||||||||||
| 7492 | */ | - | ||||||||||||||||||
| 7493 | - | |||||||||||||||||||
| 7494 | /*! | - | ||||||||||||||||||
| 7495 | \fn QString QString::arg(const QString& a1, const QString& a2, const QString& a3, const QString& a4, const QString& a5, const QString& a6, const QString& a7, const QString& a8) const | - | ||||||||||||||||||
| 7496 | \overload arg() | - | ||||||||||||||||||
| 7497 | - | |||||||||||||||||||
| 7498 | This is the same as calling \c | - | ||||||||||||||||||
| 7499 | {str.arg(a1).arg(a2).arg(a3).arg(a4).arg(a5).arg(a6).arg(a7).arg(a8)}, | - | ||||||||||||||||||
| 7500 | except that the strings \a a1, \a a2, \a a3, \a a4, \a a5, \a a6, \a | - | ||||||||||||||||||
| 7501 | a7, and \a a8 are replaced in one pass. | - | ||||||||||||||||||
| 7502 | */ | - | ||||||||||||||||||
| 7503 | - | |||||||||||||||||||
| 7504 | /*! | - | ||||||||||||||||||
| 7505 | \fn QString QString::arg(const QString& a1, const QString& a2, const QString& a3, const QString& a4, const QString& a5, const QString& a6, const QString& a7, const QString& a8, const QString& a9) const | - | ||||||||||||||||||
| 7506 | \overload arg() | - | ||||||||||||||||||
| 7507 | - | |||||||||||||||||||
| 7508 | This is the same as calling \c | - | ||||||||||||||||||
| 7509 | {str.arg(a1).arg(a2).arg(a3).arg(a4).arg(a5).arg(a6).arg(a7).arg(a8).arg(a9)}, | - | ||||||||||||||||||
| 7510 | except that the strings \a a1, \a a2, \a a3, \a a4, \a a5, \a a6, \a | - | ||||||||||||||||||
| 7511 | a7, \a a8, and \a a9 are replaced in one pass. | - | ||||||||||||||||||
| 7512 | */ | - | ||||||||||||||||||
| 7513 | - | |||||||||||||||||||
| 7514 | /*! \fn QString QString::arg(int a, int fieldWidth, int base, QChar fillChar) const | - | ||||||||||||||||||
| 7515 | \overload arg() | - | ||||||||||||||||||
| 7516 | - | |||||||||||||||||||
| 7517 | The \a a argument is expressed in base \a base, which is 10 by | - | ||||||||||||||||||
| 7518 | default and must be between 2 and 36. For bases other than 10, \a a | - | ||||||||||||||||||
| 7519 | is treated as an unsigned integer. | - | ||||||||||||||||||
| 7520 | - | |||||||||||||||||||
| 7521 | \a fieldWidth specifies the minimum amount of space that \a a is | - | ||||||||||||||||||
| 7522 | padded to and filled with the character \a fillChar. A positive | - | ||||||||||||||||||
| 7523 | value produces right-aligned text; a negative value produces | - | ||||||||||||||||||
| 7524 | left-aligned text. | - | ||||||||||||||||||
| 7525 | - | |||||||||||||||||||
| 7526 | The '%' can be followed by an 'L', in which case the sequence is | - | ||||||||||||||||||
| 7527 | replaced with a localized representation of \a a. The conversion | - | ||||||||||||||||||
| 7528 | uses the default locale, set by QLocale::setDefault(). If no default | - | ||||||||||||||||||
| 7529 | locale was specified, the "C" locale is used. The 'L' flag is | - | ||||||||||||||||||
| 7530 | ignored if \a base is not 10. | - | ||||||||||||||||||
| 7531 | - | |||||||||||||||||||
| 7532 | \snippet qstring/main.cpp 12 | - | ||||||||||||||||||
| 7533 | \snippet qstring/main.cpp 14 | - | ||||||||||||||||||
| 7534 | - | |||||||||||||||||||
| 7535 | If \a fillChar is '0' (the number 0, ASCII 48), the locale's zero is | - | ||||||||||||||||||
| 7536 | used. For negative numbers, zero padding might appear before the | - | ||||||||||||||||||
| 7537 | minus sign. | - | ||||||||||||||||||
| 7538 | */ | - | ||||||||||||||||||
| 7539 | - | |||||||||||||||||||
| 7540 | /*! \fn QString QString::arg(uint a, int fieldWidth, int base, QChar fillChar) const | - | ||||||||||||||||||
| 7541 | \overload arg() | - | ||||||||||||||||||
| 7542 | - | |||||||||||||||||||
| 7543 | The \a base argument specifies the base to use when converting the | - | ||||||||||||||||||
| 7544 | integer \a a into a string. The base must be between 2 and 36. | - | ||||||||||||||||||
| 7545 | - | |||||||||||||||||||
| 7546 | If \a fillChar is '0' (the number 0, ASCII 48), the locale's zero is | - | ||||||||||||||||||
| 7547 | used. For negative numbers, zero padding might appear before the | - | ||||||||||||||||||
| 7548 | minus sign. | - | ||||||||||||||||||
| 7549 | */ | - | ||||||||||||||||||
| 7550 | - | |||||||||||||||||||
| 7551 | /*! \fn QString QString::arg(long a, int fieldWidth, int base, QChar fillChar) const | - | ||||||||||||||||||
| 7552 | \overload arg() | - | ||||||||||||||||||
| 7553 | - | |||||||||||||||||||
| 7554 | \a fieldWidth specifies the minimum amount of space that \a a is | - | ||||||||||||||||||
| 7555 | padded to and filled with the character \a fillChar. A positive | - | ||||||||||||||||||
| 7556 | value produces right-aligned text; a negative value produces | - | ||||||||||||||||||
| 7557 | left-aligned text. | - | ||||||||||||||||||
| 7558 | - | |||||||||||||||||||
| 7559 | The \a a argument is expressed in the given \a base, which is 10 by | - | ||||||||||||||||||
| 7560 | default and must be between 2 and 36. | - | ||||||||||||||||||
| 7561 | - | |||||||||||||||||||
| 7562 | The '%' can be followed by an 'L', in which case the sequence is | - | ||||||||||||||||||
| 7563 | replaced with a localized representation of \a a. The conversion | - | ||||||||||||||||||
| 7564 | uses the default locale. The default locale is determined from the | - | ||||||||||||||||||
| 7565 | system's locale settings at application startup. It can be changed | - | ||||||||||||||||||
| 7566 | using QLocale::setDefault(). The 'L' flag is ignored if \a base is | - | ||||||||||||||||||
| 7567 | not 10. | - | ||||||||||||||||||
| 7568 | - | |||||||||||||||||||
| 7569 | \snippet qstring/main.cpp 12 | - | ||||||||||||||||||
| 7570 | \snippet qstring/main.cpp 14 | - | ||||||||||||||||||
| 7571 | - | |||||||||||||||||||
| 7572 | If \a fillChar is '0' (the number 0, ASCII 48), the locale's zero is | - | ||||||||||||||||||
| 7573 | used. For negative numbers, zero padding might appear before the | - | ||||||||||||||||||
| 7574 | minus sign. | - | ||||||||||||||||||
| 7575 | */ | - | ||||||||||||||||||
| 7576 | - | |||||||||||||||||||
| 7577 | /*! \fn QString QString::arg(ulong a, int fieldWidth, int base, QChar fillChar) const | - | ||||||||||||||||||
| 7578 | \overload arg() | - | ||||||||||||||||||
| 7579 | - | |||||||||||||||||||
| 7580 | \a fieldWidth specifies the minimum amount of space that \a a is | - | ||||||||||||||||||
| 7581 | padded to and filled with the character \a fillChar. A positive | - | ||||||||||||||||||
| 7582 | value produces right-aligned text; a negative value produces | - | ||||||||||||||||||
| 7583 | left-aligned text. | - | ||||||||||||||||||
| 7584 | - | |||||||||||||||||||
| 7585 | The \a base argument specifies the base to use when converting the | - | ||||||||||||||||||
| 7586 | integer \a a to a string. The base must be between 2 and 36, with 8 | - | ||||||||||||||||||
| 7587 | giving octal, 10 decimal, and 16 hexadecimal numbers. | - | ||||||||||||||||||
| 7588 | - | |||||||||||||||||||
| 7589 | If \a fillChar is '0' (the number 0, ASCII 48), the locale's zero is | - | ||||||||||||||||||
| 7590 | used. For negative numbers, zero padding might appear before the | - | ||||||||||||||||||
| 7591 | minus sign. | - | ||||||||||||||||||
| 7592 | */ | - | ||||||||||||||||||
| 7593 | - | |||||||||||||||||||
| 7594 | /*! | - | ||||||||||||||||||
| 7595 | \overload arg() | - | ||||||||||||||||||
| 7596 | - | |||||||||||||||||||
| 7597 | \a fieldWidth specifies the minimum amount of space that \a a is | - | ||||||||||||||||||
| 7598 | padded to and filled with the character \a fillChar. A positive | - | ||||||||||||||||||
| 7599 | value produces right-aligned text; a negative value produces | - | ||||||||||||||||||
| 7600 | left-aligned text. | - | ||||||||||||||||||
| 7601 | - | |||||||||||||||||||
| 7602 | The \a base argument specifies the base to use when converting the | - | ||||||||||||||||||
| 7603 | integer \a a into a string. The base must be between 2 and 36, with | - | ||||||||||||||||||
| 7604 | 8 giving octal, 10 decimal, and 16 hexadecimal numbers. | - | ||||||||||||||||||
| 7605 | - | |||||||||||||||||||
| 7606 | If \a fillChar is '0' (the number 0, ASCII 48), the locale's zero is | - | ||||||||||||||||||
| 7607 | used. For negative numbers, zero padding might appear before the | - | ||||||||||||||||||
| 7608 | minus sign. | - | ||||||||||||||||||
| 7609 | */ | - | ||||||||||||||||||
| 7610 | QString QString::arg(qlonglong a, int fieldWidth, int base, QChar fillChar) const | - | ||||||||||||||||||
| 7611 | { | - | ||||||||||||||||||
| 7612 | ArgEscapeData d = findArgEscapes(*this); | - | ||||||||||||||||||
| 7613 | - | |||||||||||||||||||
| 7614 | if (d.occurrences == 0) {
| 6-10690556 | ||||||||||||||||||
| 7615 | qWarning() << "QString::arg: Argument missing:" << *this << ',' << a; | - | ||||||||||||||||||
| 7616 | return *this; executed 6 times by 1 test: return *this;Executed by:
| 6 | ||||||||||||||||||
| 7617 | } | - | ||||||||||||||||||
| 7618 | - | |||||||||||||||||||
| 7619 | unsigned flags = QLocaleData::NoFlags; | - | ||||||||||||||||||
| 7620 | if (fillChar == QLatin1Char('0'))
| 41-10690515 | ||||||||||||||||||
| 7621 | flags = QLocaleData::ZeroPadded; executed 41 times by 5 tests: flags = QLocaleData::ZeroPadded;Executed by:
| 41 | ||||||||||||||||||
| 7622 | - | |||||||||||||||||||
| 7623 | QString arg; | - | ||||||||||||||||||
| 7624 | if (d.occurrences > d.locale_occurrences)
| 211-10690345 | ||||||||||||||||||
| 7625 | arg = QLocaleData::c()->longLongToString(a, -1, base, fieldWidth, flags); executed 10690345 times by 385 tests: arg = QLocaleData::c()->longLongToString(a, -1, base, fieldWidth, flags);Executed by:
| 10690345 | ||||||||||||||||||
| 7626 | - | |||||||||||||||||||
| 7627 | QString locale_arg; | - | ||||||||||||||||||
| 7628 | if (d.locale_occurrences > 0) {
| 211-10690345 | ||||||||||||||||||
| 7629 | QLocale locale; | - | ||||||||||||||||||
| 7630 | if (!(locale.numberOptions() & QLocale::OmitGroupSeparator))
| 2-209 | ||||||||||||||||||
| 7631 | flags |= QLocaleData::ThousandsGroup; executed 209 times by 2 tests: flags |= QLocaleData::ThousandsGroup;Executed by:
| 209 | ||||||||||||||||||
| 7632 | locale_arg = locale.d->m_data->longLongToString(a, -1, base, fieldWidth, flags); | - | ||||||||||||||||||
| 7633 | } executed 211 times by 2 tests: end of blockExecuted by:
| 211 | ||||||||||||||||||
| 7634 | - | |||||||||||||||||||
| 7635 | return replaceArgEscapes(*this, d, fieldWidth, arg, locale_arg, fillChar); executed 10690556 times by 385 tests: return replaceArgEscapes(*this, d, fieldWidth, arg, locale_arg, fillChar);Executed by:
| 10690556 | ||||||||||||||||||
| 7636 | } | - | ||||||||||||||||||
| 7637 | - | |||||||||||||||||||
| 7638 | /*! | - | ||||||||||||||||||
| 7639 | \overload arg() | - | ||||||||||||||||||
| 7640 | - | |||||||||||||||||||
| 7641 | \a fieldWidth specifies the minimum amount of space that \a a is | - | ||||||||||||||||||
| 7642 | padded to and filled with the character \a fillChar. A positive | - | ||||||||||||||||||
| 7643 | value produces right-aligned text; a negative value produces | - | ||||||||||||||||||
| 7644 | left-aligned text. | - | ||||||||||||||||||
| 7645 | - | |||||||||||||||||||
| 7646 | The \a base argument specifies the base to use when converting the | - | ||||||||||||||||||
| 7647 | integer \a a into a string. \a base must be between 2 and 36, with 8 | - | ||||||||||||||||||
| 7648 | giving octal, 10 decimal, and 16 hexadecimal numbers. | - | ||||||||||||||||||
| 7649 | - | |||||||||||||||||||
| 7650 | If \a fillChar is '0' (the number 0, ASCII 48), the locale's zero is | - | ||||||||||||||||||
| 7651 | used. For negative numbers, zero padding might appear before the | - | ||||||||||||||||||
| 7652 | minus sign. | - | ||||||||||||||||||
| 7653 | */ | - | ||||||||||||||||||
| 7654 | QString QString::arg(qulonglong a, int fieldWidth, int base, QChar fillChar) const | - | ||||||||||||||||||
| 7655 | { | - | ||||||||||||||||||
| 7656 | ArgEscapeData d = findArgEscapes(*this); | - | ||||||||||||||||||
| 7657 | - | |||||||||||||||||||
| 7658 | if (d.occurrences == 0) {
| 0-6442 | ||||||||||||||||||
| 7659 | qWarning() << "QString::arg: Argument missing:" << *this << ',' << a; | - | ||||||||||||||||||
| 7660 | return *this; never executed: return *this; | 0 | ||||||||||||||||||
| 7661 | } | - | ||||||||||||||||||
| 7662 | - | |||||||||||||||||||
| 7663 | unsigned flags = QLocaleData::NoFlags; | - | ||||||||||||||||||
| 7664 | if (fillChar == QLatin1Char('0'))
| 442-6000 | ||||||||||||||||||
| 7665 | flags = QLocaleData::ZeroPadded; executed 442 times by 1 test: flags = QLocaleData::ZeroPadded;Executed by:
| 442 | ||||||||||||||||||
| 7666 | - | |||||||||||||||||||
| 7667 | QString arg; | - | ||||||||||||||||||
| 7668 | if (d.occurrences > d.locale_occurrences)
| 0-6442 | ||||||||||||||||||
| 7669 | arg = QLocaleData::c()->unsLongLongToString(a, -1, base, fieldWidth, flags); executed 6442 times by 14 tests: arg = QLocaleData::c()->unsLongLongToString(a, -1, base, fieldWidth, flags);Executed by:
| 6442 | ||||||||||||||||||
| 7670 | - | |||||||||||||||||||
| 7671 | QString locale_arg; | - | ||||||||||||||||||
| 7672 | if (d.locale_occurrences > 0) {
| 0-6442 | ||||||||||||||||||
| 7673 | QLocale locale; | - | ||||||||||||||||||
| 7674 | if (!(locale.numberOptions() & QLocale::OmitGroupSeparator))
| 0 | ||||||||||||||||||
| 7675 | flags |= QLocaleData::ThousandsGroup; never executed: flags |= QLocaleData::ThousandsGroup; | 0 | ||||||||||||||||||
| 7676 | locale_arg = locale.d->m_data->unsLongLongToString(a, -1, base, fieldWidth, flags); | - | ||||||||||||||||||
| 7677 | } never executed: end of block | 0 | ||||||||||||||||||
| 7678 | - | |||||||||||||||||||
| 7679 | return replaceArgEscapes(*this, d, fieldWidth, arg, locale_arg, fillChar); executed 6442 times by 14 tests: return replaceArgEscapes(*this, d, fieldWidth, arg, locale_arg, fillChar);Executed by:
| 6442 | ||||||||||||||||||
| 7680 | } | - | ||||||||||||||||||
| 7681 | - | |||||||||||||||||||
| 7682 | /*! | - | ||||||||||||||||||
| 7683 | \overload arg() | - | ||||||||||||||||||
| 7684 | - | |||||||||||||||||||
| 7685 | \fn QString QString::arg(short a, int fieldWidth, int base, QChar fillChar) const | - | ||||||||||||||||||
| 7686 | - | |||||||||||||||||||
| 7687 | \a fieldWidth specifies the minimum amount of space that \a a is | - | ||||||||||||||||||
| 7688 | padded to and filled with the character \a fillChar. A positive | - | ||||||||||||||||||
| 7689 | value produces right-aligned text; a negative value produces | - | ||||||||||||||||||
| 7690 | left-aligned text. | - | ||||||||||||||||||
| 7691 | - | |||||||||||||||||||
| 7692 | The \a base argument specifies the base to use when converting the | - | ||||||||||||||||||
| 7693 | integer \a a into a string. The base must be between 2 and 36, with | - | ||||||||||||||||||
| 7694 | 8 giving octal, 10 decimal, and 16 hexadecimal numbers. | - | ||||||||||||||||||
| 7695 | - | |||||||||||||||||||
| 7696 | If \a fillChar is '0' (the number 0, ASCII 48), the locale's zero is | - | ||||||||||||||||||
| 7697 | used. For negative numbers, zero padding might appear before the | - | ||||||||||||||||||
| 7698 | minus sign. | - | ||||||||||||||||||
| 7699 | */ | - | ||||||||||||||||||
| 7700 | - | |||||||||||||||||||
| 7701 | /*! | - | ||||||||||||||||||
| 7702 | \fn QString QString::arg(ushort a, int fieldWidth, int base, QChar fillChar) const | - | ||||||||||||||||||
| 7703 | \overload arg() | - | ||||||||||||||||||
| 7704 | - | |||||||||||||||||||
| 7705 | \a fieldWidth specifies the minimum amount of space that \a a is | - | ||||||||||||||||||
| 7706 | padded to and filled with the character \a fillChar. A positive | - | ||||||||||||||||||
| 7707 | value produces right-aligned text; a negative value produces | - | ||||||||||||||||||
| 7708 | left-aligned text. | - | ||||||||||||||||||
| 7709 | - | |||||||||||||||||||
| 7710 | The \a base argument specifies the base to use when converting the | - | ||||||||||||||||||
| 7711 | integer \a a into a string. The base must be between 2 and 36, with | - | ||||||||||||||||||
| 7712 | 8 giving octal, 10 decimal, and 16 hexadecimal numbers. | - | ||||||||||||||||||
| 7713 | - | |||||||||||||||||||
| 7714 | If \a fillChar is '0' (the number 0, ASCII 48), the locale's zero is | - | ||||||||||||||||||
| 7715 | used. For negative numbers, zero padding might appear before the | - | ||||||||||||||||||
| 7716 | minus sign. | - | ||||||||||||||||||
| 7717 | */ | - | ||||||||||||||||||
| 7718 | - | |||||||||||||||||||
| 7719 | /*! | - | ||||||||||||||||||
| 7720 | \overload arg() | - | ||||||||||||||||||
| 7721 | */ | - | ||||||||||||||||||
| 7722 | QString QString::arg(QChar a, int fieldWidth, QChar fillChar) const | - | ||||||||||||||||||
| 7723 | { | - | ||||||||||||||||||
| 7724 | QString c; | - | ||||||||||||||||||
| 7725 | c += a; | - | ||||||||||||||||||
| 7726 | return arg(c, fieldWidth, fillChar); executed 419 times by 14 tests: return arg(c, fieldWidth, fillChar);Executed by:
| 419 | ||||||||||||||||||
| 7727 | } | - | ||||||||||||||||||
| 7728 | - | |||||||||||||||||||
| 7729 | /*! | - | ||||||||||||||||||
| 7730 | \overload arg() | - | ||||||||||||||||||
| 7731 | - | |||||||||||||||||||
| 7732 | The \a a argument is interpreted as a Latin-1 character. | - | ||||||||||||||||||
| 7733 | */ | - | ||||||||||||||||||
| 7734 | QString QString::arg(char a, int fieldWidth, QChar fillChar) const | - | ||||||||||||||||||
| 7735 | { | - | ||||||||||||||||||
| 7736 | QString c; | - | ||||||||||||||||||
| 7737 | c += QLatin1Char(a); | - | ||||||||||||||||||
| 7738 | return arg(c, fieldWidth, fillChar); executed 4 times by 2 tests: return arg(c, fieldWidth, fillChar);Executed by:
| 4 | ||||||||||||||||||
| 7739 | } | - | ||||||||||||||||||
| 7740 | - | |||||||||||||||||||
| 7741 | /*! | - | ||||||||||||||||||
| 7742 | \fn QString QString::arg(double a, int fieldWidth, char format, int precision, QChar fillChar) const | - | ||||||||||||||||||
| 7743 | \overload arg() | - | ||||||||||||||||||
| 7744 | - | |||||||||||||||||||
| 7745 | Argument \a a is formatted according to the specified \a format and | - | ||||||||||||||||||
| 7746 | \a precision. See \l{Argument Formats} for details. | - | ||||||||||||||||||
| 7747 | - | |||||||||||||||||||
| 7748 | \a fieldWidth specifies the minimum amount of space that \a a is | - | ||||||||||||||||||
| 7749 | padded to and filled with the character \a fillChar. A positive | - | ||||||||||||||||||
| 7750 | value produces right-aligned text; a negative value produces | - | ||||||||||||||||||
| 7751 | left-aligned text. | - | ||||||||||||||||||
| 7752 | - | |||||||||||||||||||
| 7753 | \snippet code/src_corelib_tools_qstring.cpp 2 | - | ||||||||||||||||||
| 7754 | - | |||||||||||||||||||
| 7755 | The '%' can be followed by an 'L', in which case the sequence is | - | ||||||||||||||||||
| 7756 | replaced with a localized representation of \a a. The conversion | - | ||||||||||||||||||
| 7757 | uses the default locale, set by QLocale::setDefault(). If no | - | ||||||||||||||||||
| 7758 | default locale was specified, the "C" locale is used. | - | ||||||||||||||||||
| 7759 | - | |||||||||||||||||||
| 7760 | If \a fillChar is '0' (the number 0, ASCII 48), this function will | - | ||||||||||||||||||
| 7761 | use the locale's zero to pad. For negative numbers, the zero padding | - | ||||||||||||||||||
| 7762 | will probably appear before the minus sign. | - | ||||||||||||||||||
| 7763 | - | |||||||||||||||||||
| 7764 | \sa QLocale::toString() | - | ||||||||||||||||||
| 7765 | */ | - | ||||||||||||||||||
| 7766 | QString QString::arg(double a, int fieldWidth, char fmt, int prec, QChar fillChar) const | - | ||||||||||||||||||
| 7767 | { | - | ||||||||||||||||||
| 7768 | ArgEscapeData d = findArgEscapes(*this); | - | ||||||||||||||||||
| 7769 | - | |||||||||||||||||||
| 7770 | if (d.occurrences == 0) {
| 0-96103 | ||||||||||||||||||
| 7771 | qWarning("QString::arg: Argument missing: %s, %g", toLocal8Bit().data(), a); | - | ||||||||||||||||||
| 7772 | return *this; never executed: return *this; | 0 | ||||||||||||||||||
| 7773 | } | - | ||||||||||||||||||
| 7774 | - | |||||||||||||||||||
| 7775 | unsigned flags = QLocaleData::NoFlags; | - | ||||||||||||||||||
| 7776 | if (fillChar == QLatin1Char('0'))
| 5-96098 | ||||||||||||||||||
| 7777 | flags = QLocaleData::ZeroPadded; executed 5 times by 1 test: flags = QLocaleData::ZeroPadded;Executed by:
| 5 | ||||||||||||||||||
| 7778 | - | |||||||||||||||||||
| 7779 | if (qIsUpper(fmt))
| 0-96103 | ||||||||||||||||||
| 7780 | flags |= QLocaleData::CapitalEorX; never executed: flags |= QLocaleData::CapitalEorX; | 0 | ||||||||||||||||||
| 7781 | fmt = qToLower(fmt); | - | ||||||||||||||||||
| 7782 | - | |||||||||||||||||||
| 7783 | QLocaleData::DoubleForm form = QLocaleData::DFDecimal; | - | ||||||||||||||||||
| 7784 | switch (fmt) { | - | ||||||||||||||||||
| 7785 | case 'f': never executed: case 'f': | 0 | ||||||||||||||||||
| 7786 | form = QLocaleData::DFDecimal; | - | ||||||||||||||||||
| 7787 | break; never executed: break; | 0 | ||||||||||||||||||
| 7788 | case 'e': never executed: case 'e': | 0 | ||||||||||||||||||
| 7789 | form = QLocaleData::DFExponent; | - | ||||||||||||||||||
| 7790 | break; never executed: break; | 0 | ||||||||||||||||||
| 7791 | case 'g': executed 96103 times by 10 tests: case 'g':Executed by:
| 96103 | ||||||||||||||||||
| 7792 | form = QLocaleData::DFSignificantDigits; | - | ||||||||||||||||||
| 7793 | break; executed 96103 times by 10 tests: break;Executed by:
| 96103 | ||||||||||||||||||
| 7794 | default: never executed: default: | 0 | ||||||||||||||||||
| 7795 | #if defined(QT_CHECK_RANGE) | - | ||||||||||||||||||
| 7796 | qWarning("QString::arg: Invalid format char '%c'", fmt); | - | ||||||||||||||||||
| 7797 | #endif | - | ||||||||||||||||||
| 7798 | break; never executed: break; | 0 | ||||||||||||||||||
| 7799 | } | - | ||||||||||||||||||
| 7800 | - | |||||||||||||||||||
| 7801 | QString arg; | - | ||||||||||||||||||
| 7802 | if (d.occurrences > d.locale_occurrences)
| 9-96094 | ||||||||||||||||||
| 7803 | arg = QLocaleData::c()->doubleToString(a, prec, form, fieldWidth, flags); executed 96094 times by 10 tests: arg = QLocaleData::c()->doubleToString(a, prec, form, fieldWidth, flags);Executed by:
| 96094 | ||||||||||||||||||
| 7804 | - | |||||||||||||||||||
| 7805 | QString locale_arg; | - | ||||||||||||||||||
| 7806 | if (d.locale_occurrences > 0) {
| 9-96094 | ||||||||||||||||||
| 7807 | QLocale locale; | - | ||||||||||||||||||
| 7808 | - | |||||||||||||||||||
| 7809 | if (!(locale.numberOptions() & QLocale::OmitGroupSeparator))
| 2-7 | ||||||||||||||||||
| 7810 | flags |= QLocaleData::ThousandsGroup; executed 7 times by 1 test: flags |= QLocaleData::ThousandsGroup;Executed by:
| 7 | ||||||||||||||||||
| 7811 | locale_arg = locale.d->m_data->doubleToString(a, prec, form, fieldWidth, flags); | - | ||||||||||||||||||
| 7812 | } executed 9 times by 1 test: end of blockExecuted by:
| 9 | ||||||||||||||||||
| 7813 | - | |||||||||||||||||||
| 7814 | return replaceArgEscapes(*this, d, fieldWidth, arg, locale_arg, fillChar); executed 96103 times by 10 tests: return replaceArgEscapes(*this, d, fieldWidth, arg, locale_arg, fillChar);Executed by:
| 96103 | ||||||||||||||||||
| 7815 | } | - | ||||||||||||||||||
| 7816 | - | |||||||||||||||||||
| 7817 | static int getEscape(const QChar *uc, int *pos, int len, int maxNumber = 999) | - | ||||||||||||||||||
| 7818 | { | - | ||||||||||||||||||
| 7819 | int i = *pos; | - | ||||||||||||||||||
| 7820 | ++i; | - | ||||||||||||||||||
| 7821 | if (i < len && uc[i] == QLatin1Char('L'))
| 0-675339 | ||||||||||||||||||
| 7822 | ++i; never executed: ++i; | 0 | ||||||||||||||||||
| 7823 | if (i < len) {
| 0-675339 | ||||||||||||||||||
| 7824 | int escape = uc[i].unicode() - '0'; | - | ||||||||||||||||||
| 7825 | if (uint(escape) >= 10U)
| 4-675335 | ||||||||||||||||||
| 7826 | return -1; executed 4 times by 1 test: return -1;Executed by:
| 4 | ||||||||||||||||||
| 7827 | ++i; | - | ||||||||||||||||||
| 7828 | while (i < len) {
| 4907-670450 | ||||||||||||||||||
| 7829 | int digit = uc[i].unicode() - '0'; | - | ||||||||||||||||||
| 7830 | if (uint(digit) >= 10U)
| 22-670428 | ||||||||||||||||||
| 7831 | break; executed 670428 times by 332 tests: break;Executed by:
| 670428 | ||||||||||||||||||
| 7832 | escape = (escape * 10) + digit; | - | ||||||||||||||||||
| 7833 | ++i; | - | ||||||||||||||||||
| 7834 | } executed 22 times by 1 test: end of blockExecuted by:
| 22 | ||||||||||||||||||
| 7835 | if (escape <= maxNumber) {
| 2-675333 | ||||||||||||||||||
| 7836 | *pos = i; | - | ||||||||||||||||||
| 7837 | return escape; executed 675333 times by 332 tests: return escape;Executed by:
| 675333 | ||||||||||||||||||
| 7838 | } | - | ||||||||||||||||||
| 7839 | } executed 2 times by 1 test: end of blockExecuted by:
| 2 | ||||||||||||||||||
| 7840 | return -1; executed 2 times by 1 test: return -1;Executed by:
| 2 | ||||||||||||||||||
| 7841 | } | - | ||||||||||||||||||
| 7842 | - | |||||||||||||||||||
| 7843 | /* | - | ||||||||||||||||||
| 7844 | Algorithm for multiArg: | - | ||||||||||||||||||
| 7845 | - | |||||||||||||||||||
| 7846 | 1. Parse the string as a sequence of verbatim text and placeholders (%L?\d{,3}). | - | ||||||||||||||||||
| 7847 | The L is parsed and accepted for compatibility with non-multi-arg, but since | - | ||||||||||||||||||
| 7848 | multiArg only accepts strings as replacements, the localization request can | - | ||||||||||||||||||
| 7849 | be safely ignored. | - | ||||||||||||||||||
| 7850 | 2. The result of step (1) is a list of (string-ref,int)-tuples. The string-ref | - | ||||||||||||||||||
| 7851 | either points at text to be copied verbatim (in which case the int is -1), | - | ||||||||||||||||||
| 7852 | or, initially, at the textual representation of the placeholder. In that case, | - | ||||||||||||||||||
| 7853 | the int contains the numerical number as parsed from the placeholder. | - | ||||||||||||||||||
| 7854 | 3. Next, collect all the non-negative ints found, sort them in ascending order and | - | ||||||||||||||||||
| 7855 | remove duplicates. | - | ||||||||||||||||||
| 7856 | 3a. If the result has more entires than multiArg() was given replacement strings, | - | ||||||||||||||||||
| 7857 | we have found placeholders we can't satisfy with replacement strings. That is | - | ||||||||||||||||||
| 7858 | fine (there could be another .arg() call coming after this one), so just | - | ||||||||||||||||||
| 7859 | truncate the result to the number of actual multiArg() replacement strings. | - | ||||||||||||||||||
| 7860 | 3b. If the result has less entries than multiArg() was given replacement strings, | - | ||||||||||||||||||
| 7861 | the string is missing placeholders. This is an error that the user should be | - | ||||||||||||||||||
| 7862 | warned about. | - | ||||||||||||||||||
| 7863 | 4. The result of step (3) is a mapping from the index of any replacement string to | - | ||||||||||||||||||
| 7864 | placeholder number. This is the wrong way around, but since placeholder | - | ||||||||||||||||||
| 7865 | numbers could get as large as 999, while we typically don't have more than 9 | - | ||||||||||||||||||
| 7866 | replacement strings, we trade 4K of sparsely-used memory for doing a reverse lookup | - | ||||||||||||||||||
| 7867 | each time we need to map a placeholder number to a replacement string index | - | ||||||||||||||||||
| 7868 | (that's a linear search; but still *much* faster than using an associative container). | - | ||||||||||||||||||
| 7869 | 5. Next, for each of the tuples found in step (1), do the following: | - | ||||||||||||||||||
| 7870 | 5a. If the int is negative, do nothing. | - | ||||||||||||||||||
| 7871 | 5b. Otherwise, if the int is found in the result of step (3) at index I, replace | - | ||||||||||||||||||
| 7872 | the string-ref with a string-ref for the (complete) I'th replacement string. | - | ||||||||||||||||||
| 7873 | 5c. Otherwise, do nothing. | - | ||||||||||||||||||
| 7874 | 6. Concatenate all string refs into a single result string. | - | ||||||||||||||||||
| 7875 | */ | - | ||||||||||||||||||
| 7876 | - | |||||||||||||||||||
| 7877 | namespace { | - | ||||||||||||||||||
| 7878 | struct Part | - | ||||||||||||||||||
| 7879 | { | - | ||||||||||||||||||
| 7880 | Part() : stringRef(), number(0) {} never executed: end of block | 0 | ||||||||||||||||||
| 7881 | Part(const QString &s, int pos, int len, int num = -1) Q_DECL_NOTHROW | - | ||||||||||||||||||
| 7882 | : stringRef(&s, pos, len), number(num) {} executed 1511589 times by 332 tests: end of blockExecuted by:
| 1511589 | ||||||||||||||||||
| 7883 | - | |||||||||||||||||||
| 7884 | QStringRef stringRef; | - | ||||||||||||||||||
| 7885 | int number; | - | ||||||||||||||||||
| 7886 | }; | - | ||||||||||||||||||
| 7887 | } // unnamed namespace | - | ||||||||||||||||||
| 7888 | - | |||||||||||||||||||
| 7889 | template <> | - | ||||||||||||||||||
| 7890 | class QTypeInfo<Part> : public QTypeInfoMerger<Part, QStringRef, int> {}; // Q_DECLARE_METATYPE | - | ||||||||||||||||||
| 7891 | - | |||||||||||||||||||
| 7892 | - | |||||||||||||||||||
| 7893 | namespace { | - | ||||||||||||||||||
| 7894 | - | |||||||||||||||||||
| 7895 | enum { ExpectedParts = 32 }; | - | ||||||||||||||||||
| 7896 | - | |||||||||||||||||||
| 7897 | typedef QVarLengthArray<Part, ExpectedParts> ParseResult; | - | ||||||||||||||||||
| 7898 | typedef QVarLengthArray<int, ExpectedParts/2> ArgIndexToPlaceholderMap; | - | ||||||||||||||||||
| 7899 | - | |||||||||||||||||||
| 7900 | static ParseResult parseMultiArgFormatString(const QString &s) | - | ||||||||||||||||||
| 7901 | { | - | ||||||||||||||||||
| 7902 | ParseResult result; | - | ||||||||||||||||||
| 7903 | - | |||||||||||||||||||
| 7904 | const QChar *uc = s.constData(); | - | ||||||||||||||||||
| 7905 | const int len = s.size(); | - | ||||||||||||||||||
| 7906 | const int end = len - 1; | - | ||||||||||||||||||
| 7907 | int i = 0; | - | ||||||||||||||||||
| 7908 | int last = 0; | - | ||||||||||||||||||
| 7909 | - | |||||||||||||||||||
| 7910 | while (i < end) {
| 176270-6557102 | ||||||||||||||||||
| 7911 | if (uc[i] == QLatin1Char('%')) {
| 675339-5881763 | ||||||||||||||||||
| 7912 | int percent = i; | - | ||||||||||||||||||
| 7913 | int number = getEscape(uc, &i, len); | - | ||||||||||||||||||
| 7914 | if (number != -1) {
| 6-675333 | ||||||||||||||||||
| 7915 | if (last != percent)
| 10441-664892 | ||||||||||||||||||
| 7916 | result.push_back(Part(s, last, percent - last)); // literal text (incl. failed placeholders) executed 664892 times by 332 tests: result.push_back(Part(s, last, percent - last));Executed by:
| 664892 | ||||||||||||||||||
| 7917 | result.push_back(Part(s, percent, i - percent, number)); // parsed placeholder | - | ||||||||||||||||||
| 7918 | last = i; | - | ||||||||||||||||||
| 7919 | continue; executed 675333 times by 332 tests: continue;Executed by:
| 675333 | ||||||||||||||||||
| 7920 | } | - | ||||||||||||||||||
| 7921 | } executed 6 times by 1 test: end of blockExecuted by:
| 6 | ||||||||||||||||||
| 7922 | ++i; | - | ||||||||||||||||||
| 7923 | } executed 5881769 times by 332 tests: end of blockExecuted by:
| 5881769 | ||||||||||||||||||
| 7924 | - | |||||||||||||||||||
| 7925 | if (last < len)
| 4906-171364 | ||||||||||||||||||
| 7926 | result.push_back(Part(s, last, len - last)); // trailing literal text executed 171364 times by 313 tests: result.push_back(Part(s, last, len - last));Executed by:
| 171364 | ||||||||||||||||||
| 7927 | - | |||||||||||||||||||
| 7928 | return result; executed 176270 times by 332 tests: return result;Executed by:
| 176270 | ||||||||||||||||||
| 7929 | } | - | ||||||||||||||||||
| 7930 | - | |||||||||||||||||||
| 7931 | static ArgIndexToPlaceholderMap makeArgIndexToPlaceholderMap(const ParseResult &parts) | - | ||||||||||||||||||
| 7932 | { | - | ||||||||||||||||||
| 7933 | ArgIndexToPlaceholderMap result; | - | ||||||||||||||||||
| 7934 | - | |||||||||||||||||||
| 7935 | for (ParseResult::const_iterator it = parts.begin(), end = parts.end(); it != end; ++it) {
| 176270-1511589 | ||||||||||||||||||
| 7936 | if (it->number >= 0)
| 675333-836256 | ||||||||||||||||||
| 7937 | result.push_back(it->number); executed 675333 times by 332 tests: result.push_back(it->number);Executed by:
| 675333 | ||||||||||||||||||
| 7938 | } executed 1511589 times by 332 tests: end of blockExecuted by:
| 1511589 | ||||||||||||||||||
| 7939 | - | |||||||||||||||||||
| 7940 | std::sort(result.begin(), result.end()); | - | ||||||||||||||||||
| 7941 | result.erase(std::unique(result.begin(), result.end()), | - | ||||||||||||||||||
| 7942 | result.end()); | - | ||||||||||||||||||
| 7943 | - | |||||||||||||||||||
| 7944 | return result; executed 176270 times by 332 tests: return result;Executed by:
| 176270 | ||||||||||||||||||
| 7945 | } | - | ||||||||||||||||||
| 7946 | - | |||||||||||||||||||
| 7947 | static int resolveStringRefsAndReturnTotalSize(ParseResult &parts, const ArgIndexToPlaceholderMap &argIndexToPlaceholderMap, const QString *args[]) | - | ||||||||||||||||||
| 7948 | { | - | ||||||||||||||||||
| 7949 | int totalSize = 0; | - | ||||||||||||||||||
| 7950 | for (ParseResult::iterator pit = parts.begin(), end = parts.end(); pit != end; ++pit) {
| 176270-1511589 | ||||||||||||||||||
| 7951 | if (pit->number != -1) {
| 675333-836256 | ||||||||||||||||||
| 7952 | const ArgIndexToPlaceholderMap::const_iterator ait | - | ||||||||||||||||||
| 7953 | = std::find(argIndexToPlaceholderMap.begin(), argIndexToPlaceholderMap.end(), pit->number); | - | ||||||||||||||||||
| 7954 | if (ait != argIndexToPlaceholderMap.end())
| 29-675304 | ||||||||||||||||||
| 7955 | pit->stringRef = QStringRef(args[ait - argIndexToPlaceholderMap.begin()]); executed 675304 times by 332 tests: pit->stringRef = QStringRef(args[ait - argIndexToPlaceholderMap.begin()]);Executed by:
| 675304 | ||||||||||||||||||
| 7956 | } executed 675333 times by 332 tests: end of blockExecuted by:
| 675333 | ||||||||||||||||||
| 7957 | totalSize += pit->stringRef.size(); | - | ||||||||||||||||||
| 7958 | } executed 1511589 times by 332 tests: end of blockExecuted by:
| 1511589 | ||||||||||||||||||
| 7959 | return totalSize; executed 176270 times by 332 tests: return totalSize;Executed by:
| 176270 | ||||||||||||||||||
| 7960 | } | - | ||||||||||||||||||
| 7961 | - | |||||||||||||||||||
| 7962 | } // unnamed namespace | - | ||||||||||||||||||
| 7963 | - | |||||||||||||||||||
| 7964 | QString QString::multiArg(int numArgs, const QString **args) const | - | ||||||||||||||||||
| 7965 | { | - | ||||||||||||||||||
| 7966 | // Step 1-2 above | - | ||||||||||||||||||
| 7967 | ParseResult parts = parseMultiArgFormatString(*this); | - | ||||||||||||||||||
| 7968 | - | |||||||||||||||||||
| 7969 | // 3-4 | - | ||||||||||||||||||
| 7970 | ArgIndexToPlaceholderMap argIndexToPlaceholderMap = makeArgIndexToPlaceholderMap(parts); | - | ||||||||||||||||||
| 7971 | - | |||||||||||||||||||
| 7972 | if (argIndexToPlaceholderMap.size() > numArgs) // 3a
| 27-176243 | ||||||||||||||||||
| 7973 | argIndexToPlaceholderMap.resize(numArgs); executed 27 times by 2 tests: argIndexToPlaceholderMap.resize(numArgs);Executed by:
| 27 | ||||||||||||||||||
| 7974 | else if (argIndexToPlaceholderMap.size() < numArgs) // 3b
| 0-176243 | ||||||||||||||||||
| 7975 | qWarning("QString::arg: %d argument(s) missing in %s", never executed: QMessageLogger(__FILE__, 7975, __PRETTY_FUNCTION__).warning("QString::arg: %d argument(s) missing in %s", numArgs - argIndexToPlaceholderMap.size(), toLocal8Bit().data()); | 0 | ||||||||||||||||||
| 7976 | numArgs - argIndexToPlaceholderMap.size(), toLocal8Bit().data()); never executed: QMessageLogger(__FILE__, 7975, __PRETTY_FUNCTION__).warning("QString::arg: %d argument(s) missing in %s", numArgs - argIndexToPlaceholderMap.size(), toLocal8Bit().data()); | 0 | ||||||||||||||||||
| 7977 | - | |||||||||||||||||||
| 7978 | // 5 | - | ||||||||||||||||||
| 7979 | const int totalSize = resolveStringRefsAndReturnTotalSize(parts, argIndexToPlaceholderMap, args); | - | ||||||||||||||||||
| 7980 | - | |||||||||||||||||||
| 7981 | // 6: | - | ||||||||||||||||||
| 7982 | QString result(totalSize, Qt::Uninitialized); | - | ||||||||||||||||||
| 7983 | QChar *out = result.data(); | - | ||||||||||||||||||
| 7984 | - | |||||||||||||||||||
| 7985 | for (ParseResult::const_iterator it = parts.begin(), end = parts.end(); it != end; ++it) {
| 176270-1511589 | ||||||||||||||||||
| 7986 | if (const int sz = it->stringRef.size()) {
| 2974-1508615 | ||||||||||||||||||
| 7987 | memcpy(out, it->stringRef.constData(), sz * sizeof(QChar)); | - | ||||||||||||||||||
| 7988 | out += sz; | - | ||||||||||||||||||
| 7989 | } executed 1508615 times by 332 tests: end of blockExecuted by:
| 1508615 | ||||||||||||||||||
| 7990 | } executed 1511589 times by 332 tests: end of blockExecuted by:
| 1511589 | ||||||||||||||||||
| 7991 | - | |||||||||||||||||||
| 7992 | return result; executed 176270 times by 332 tests: return result;Executed by:
| 176270 | ||||||||||||||||||
| 7993 | } | - | ||||||||||||||||||
| 7994 | - | |||||||||||||||||||
| 7995 | - | |||||||||||||||||||
| 7996 | /*! \fn QString QString::fromCFString(CFStringRef string) | - | ||||||||||||||||||
| 7997 | \since 5.2 | - | ||||||||||||||||||
| 7998 | - | |||||||||||||||||||
| 7999 | Constructs a new QString containing a copy of the \a string CFString. | - | ||||||||||||||||||
| 8000 | - | |||||||||||||||||||
| 8001 | \note this function is only available on \macos and iOS. | - | ||||||||||||||||||
| 8002 | */ | - | ||||||||||||||||||
| 8003 | - | |||||||||||||||||||
| 8004 | /*! \fn CFStringRef QString::toCFString() const | - | ||||||||||||||||||
| 8005 | \since 5.2 | - | ||||||||||||||||||
| 8006 | - | |||||||||||||||||||
| 8007 | Creates a CFString from a QString. The caller owns the CFString and is | - | ||||||||||||||||||
| 8008 | responsible for releasing it. | - | ||||||||||||||||||
| 8009 | - | |||||||||||||||||||
| 8010 | \note this function is only available on \macos and iOS. | - | ||||||||||||||||||
| 8011 | */ | - | ||||||||||||||||||
| 8012 | - | |||||||||||||||||||
| 8013 | /*! \fn QString QString::fromNSString(const NSString *string) | - | ||||||||||||||||||
| 8014 | \since 5.2 | - | ||||||||||||||||||
| 8015 | - | |||||||||||||||||||
| 8016 | Constructs a new QString containing a copy of the \a string NSString. | - | ||||||||||||||||||
| 8017 | - | |||||||||||||||||||
| 8018 | \note this function is only available on \macos and iOS. | - | ||||||||||||||||||
| 8019 | */ | - | ||||||||||||||||||
| 8020 | - | |||||||||||||||||||
| 8021 | /*! \fn NSString QString::toNSString() const | - | ||||||||||||||||||
| 8022 | \since 5.2 | - | ||||||||||||||||||
| 8023 | - | |||||||||||||||||||
| 8024 | Creates a NSString from a QString. The NSString is autoreleased. | - | ||||||||||||||||||
| 8025 | - | |||||||||||||||||||
| 8026 | \note this function is only available on \macos and iOS. | - | ||||||||||||||||||
| 8027 | */ | - | ||||||||||||||||||
| 8028 | - | |||||||||||||||||||
| 8029 | /*! \fn bool QString::isSimpleText() const | - | ||||||||||||||||||
| 8030 | - | |||||||||||||||||||
| 8031 | \internal | - | ||||||||||||||||||
| 8032 | */ | - | ||||||||||||||||||
| 8033 | bool QString::isSimpleText() const | - | ||||||||||||||||||
| 8034 | { | - | ||||||||||||||||||
| 8035 | const ushort *p = d->data(); | - | ||||||||||||||||||
| 8036 | const ushort * const end = p + d->size; | - | ||||||||||||||||||
| 8037 | while (p < end) {
| 0 | ||||||||||||||||||
| 8038 | ushort uc = *p; | - | ||||||||||||||||||
| 8039 | // sort out regions of complex text formatting | - | ||||||||||||||||||
| 8040 | if (uc > 0x058f && (uc < 0x1100 || uc > 0xfb0f)) {
| 0 | ||||||||||||||||||
| 8041 | return false; never executed: return false; | 0 | ||||||||||||||||||
| 8042 | } | - | ||||||||||||||||||
| 8043 | p++; | - | ||||||||||||||||||
| 8044 | } never executed: end of block | 0 | ||||||||||||||||||
| 8045 | - | |||||||||||||||||||
| 8046 | return true; never executed: return true; | 0 | ||||||||||||||||||
| 8047 | } | - | ||||||||||||||||||
| 8048 | - | |||||||||||||||||||
| 8049 | /*! \fn bool QString::isRightToLeft() const | - | ||||||||||||||||||
| 8050 | - | |||||||||||||||||||
| 8051 | Returns \c true if the string is read right to left. | - | ||||||||||||||||||
| 8052 | */ | - | ||||||||||||||||||
| 8053 | bool QString::isRightToLeft() const | - | ||||||||||||||||||
| 8054 | { | - | ||||||||||||||||||
| 8055 | const ushort *p = d->data(); | - | ||||||||||||||||||
| 8056 | const ushort * const end = p + d->size; | - | ||||||||||||||||||
| 8057 | while (p < end) {
| 99380-762475 | ||||||||||||||||||
| 8058 | uint ucs4 = *p; | - | ||||||||||||||||||
| 8059 | if (QChar::isHighSurrogate(ucs4) && p < end - 1) {
| 0-762465 | ||||||||||||||||||
| 8060 | ushort low = p[1]; | - | ||||||||||||||||||
| 8061 | if (QChar::isLowSurrogate(low)) {
| 0-10 | ||||||||||||||||||
| 8062 | ucs4 = QChar::surrogateToUcs4(ucs4, low); | - | ||||||||||||||||||
| 8063 | ++p; | - | ||||||||||||||||||
| 8064 | } executed 10 times by 2 tests: end of blockExecuted by:
| 10 | ||||||||||||||||||
| 8065 | } executed 10 times by 2 tests: end of blockExecuted by:
| 10 | ||||||||||||||||||
| 8066 | switch (QChar::direction(ucs4)) | - | ||||||||||||||||||
| 8067 | { | - | ||||||||||||||||||
| 8068 | case QChar::DirL: executed 66885 times by 93 tests: case QChar::DirL:Executed by:
| 66885 | ||||||||||||||||||
| 8069 | return false; executed 66885 times by 93 tests: return false;Executed by:
| 66885 | ||||||||||||||||||
| 8070 | case QChar::DirR: executed 428 times by 5 tests: case QChar::DirR:Executed by:
| 428 | ||||||||||||||||||
| 8071 | case QChar::DirAL: executed 21 times by 5 tests: case QChar::DirAL:Executed by:
| 21 | ||||||||||||||||||
| 8072 | return true; executed 449 times by 9 tests: return true;Executed by:
| 449 | ||||||||||||||||||
| 8073 | default: executed 695141 times by 59 tests: default:Executed by:
| 695141 | ||||||||||||||||||
| 8074 | break; executed 695141 times by 59 tests: break;Executed by:
| 695141 | ||||||||||||||||||
| 8075 | } | - | ||||||||||||||||||
| 8076 | ++p; | - | ||||||||||||||||||
| 8077 | } executed 695141 times by 59 tests: end of blockExecuted by:
| 695141 | ||||||||||||||||||
| 8078 | return false; executed 99380 times by 50 tests: return false;Executed by:
| 99380 | ||||||||||||||||||
| 8079 | } | - | ||||||||||||||||||
| 8080 | - | |||||||||||||||||||
| 8081 | /*! \fn QChar *QString::data() | - | ||||||||||||||||||
| 8082 | - | |||||||||||||||||||
| 8083 | Returns a pointer to the data stored in the QString. The pointer | - | ||||||||||||||||||
| 8084 | can be used to access and modify the characters that compose the | - | ||||||||||||||||||
| 8085 | string. For convenience, the data is '\\0'-terminated. | - | ||||||||||||||||||
| 8086 | - | |||||||||||||||||||
| 8087 | Example: | - | ||||||||||||||||||
| 8088 | - | |||||||||||||||||||
| 8089 | \snippet qstring/main.cpp 19 | - | ||||||||||||||||||
| 8090 | - | |||||||||||||||||||
| 8091 | Note that the pointer remains valid only as long as the string is | - | ||||||||||||||||||
| 8092 | not modified by other means. For read-only access, constData() is | - | ||||||||||||||||||
| 8093 | faster because it never causes a \l{deep copy} to occur. | - | ||||||||||||||||||
| 8094 | - | |||||||||||||||||||
| 8095 | \sa constData(), operator[]() | - | ||||||||||||||||||
| 8096 | */ | - | ||||||||||||||||||
| 8097 | - | |||||||||||||||||||
| 8098 | /*! \fn const QChar *QString::data() const | - | ||||||||||||||||||
| 8099 | - | |||||||||||||||||||
| 8100 | \overload | - | ||||||||||||||||||
| 8101 | */ | - | ||||||||||||||||||
| 8102 | - | |||||||||||||||||||
| 8103 | /*! \fn const QChar *QString::constData() const | - | ||||||||||||||||||
| 8104 | - | |||||||||||||||||||
| 8105 | Returns a pointer to the data stored in the QString. The pointer | - | ||||||||||||||||||
| 8106 | can be used to access the characters that compose the string. For | - | ||||||||||||||||||
| 8107 | convenience, the data is '\\0'-terminated. | - | ||||||||||||||||||
| 8108 | - | |||||||||||||||||||
| 8109 | Note that the pointer remains valid only as long as the string is | - | ||||||||||||||||||
| 8110 | not modified. | - | ||||||||||||||||||
| 8111 | - | |||||||||||||||||||
| 8112 | \sa data(), operator[]() | - | ||||||||||||||||||
| 8113 | */ | - | ||||||||||||||||||
| 8114 | - | |||||||||||||||||||
| 8115 | /*! \fn void QString::push_front(const QString &other) | - | ||||||||||||||||||
| 8116 | - | |||||||||||||||||||
| 8117 | This function is provided for STL compatibility, prepending the | - | ||||||||||||||||||
| 8118 | given \a other string to the beginning of this string. It is | - | ||||||||||||||||||
| 8119 | equivalent to \c prepend(other). | - | ||||||||||||||||||
| 8120 | - | |||||||||||||||||||
| 8121 | \sa prepend() | - | ||||||||||||||||||
| 8122 | */ | - | ||||||||||||||||||
| 8123 | - | |||||||||||||||||||
| 8124 | /*! \fn void QString::push_front(QChar ch) | - | ||||||||||||||||||
| 8125 | - | |||||||||||||||||||
| 8126 | \overload | - | ||||||||||||||||||
| 8127 | - | |||||||||||||||||||
| 8128 | Prepends the given \a ch character to the beginning of this string. | - | ||||||||||||||||||
| 8129 | */ | - | ||||||||||||||||||
| 8130 | - | |||||||||||||||||||
| 8131 | /*! \fn void QString::push_back(const QString &other) | - | ||||||||||||||||||
| 8132 | - | |||||||||||||||||||
| 8133 | This function is provided for STL compatibility, appending the | - | ||||||||||||||||||
| 8134 | given \a other string onto the end of this string. It is | - | ||||||||||||||||||
| 8135 | equivalent to \c append(other). | - | ||||||||||||||||||
| 8136 | - | |||||||||||||||||||
| 8137 | \sa append() | - | ||||||||||||||||||
| 8138 | */ | - | ||||||||||||||||||
| 8139 | - | |||||||||||||||||||
| 8140 | /*! \fn void QString::push_back(QChar ch) | - | ||||||||||||||||||
| 8141 | - | |||||||||||||||||||
| 8142 | \overload | - | ||||||||||||||||||
| 8143 | - | |||||||||||||||||||
| 8144 | Appends the given \a ch character onto the end of this string. | - | ||||||||||||||||||
| 8145 | */ | - | ||||||||||||||||||
| 8146 | - | |||||||||||||||||||
| 8147 | /*! | - | ||||||||||||||||||
| 8148 | \fn std::string QString::toStdString() const | - | ||||||||||||||||||
| 8149 | - | |||||||||||||||||||
| 8150 | Returns a std::string object with the data contained in this | - | ||||||||||||||||||
| 8151 | QString. The Unicode data is converted into 8-bit characters using | - | ||||||||||||||||||
| 8152 | the toUtf8() function. | - | ||||||||||||||||||
| 8153 | - | |||||||||||||||||||
| 8154 | This method is mostly useful to pass a QString to a function | - | ||||||||||||||||||
| 8155 | that accepts a std::string object. | - | ||||||||||||||||||
| 8156 | - | |||||||||||||||||||
| 8157 | \sa toLatin1(), toUtf8(), toLocal8Bit(), QByteArray::toStdString() | - | ||||||||||||||||||
| 8158 | */ | - | ||||||||||||||||||
| 8159 | - | |||||||||||||||||||
| 8160 | /*! | - | ||||||||||||||||||
| 8161 | Constructs a QString that uses the first \a size Unicode characters | - | ||||||||||||||||||
| 8162 | in the array \a unicode. The data in \a unicode is \e not | - | ||||||||||||||||||
| 8163 | copied. The caller must be able to guarantee that \a unicode will | - | ||||||||||||||||||
| 8164 | not be deleted or modified as long as the QString (or an | - | ||||||||||||||||||
| 8165 | unmodified copy of it) exists. | - | ||||||||||||||||||
| 8166 | - | |||||||||||||||||||
| 8167 | Any attempts to modify the QString or copies of it will cause it | - | ||||||||||||||||||
| 8168 | to create a deep copy of the data, ensuring that the raw data | - | ||||||||||||||||||
| 8169 | isn't modified. | - | ||||||||||||||||||
| 8170 | - | |||||||||||||||||||
| 8171 | Here's an example of how we can use a QRegExp on raw data in | - | ||||||||||||||||||
| 8172 | memory without requiring to copy the data into a QString: | - | ||||||||||||||||||
| 8173 | - | |||||||||||||||||||
| 8174 | \snippet qstring/main.cpp 22 | - | ||||||||||||||||||
| 8175 | \snippet qstring/main.cpp 23 | - | ||||||||||||||||||
| 8176 | - | |||||||||||||||||||
| 8177 | \warning A string created with fromRawData() is \e not | - | ||||||||||||||||||
| 8178 | '\\0'-terminated, unless the raw data contains a '\\0' character | - | ||||||||||||||||||
| 8179 | at position \a size. This means unicode() will \e not return a | - | ||||||||||||||||||
| 8180 | '\\0'-terminated string (although utf16() does, at the cost of | - | ||||||||||||||||||
| 8181 | copying the raw data). | - | ||||||||||||||||||
| 8182 | - | |||||||||||||||||||
| 8183 | \sa fromUtf16(), setRawData() | - | ||||||||||||||||||
| 8184 | */ | - | ||||||||||||||||||
| 8185 | QString QString::fromRawData(const QChar *unicode, int size) | - | ||||||||||||||||||
| 8186 | { | - | ||||||||||||||||||
| 8187 | Data *x; | - | ||||||||||||||||||
| 8188 | if (!unicode) {
| 2-79154 | ||||||||||||||||||
| 8189 | x = Data::sharedNull(); | - | ||||||||||||||||||
| 8190 | } else if (!size) { executed 2 times by 1 test: end of blockExecuted by:
| 2-79136 | ||||||||||||||||||
| 8191 | x = Data::allocate(0); | - | ||||||||||||||||||
| 8192 | } else { executed 18 times by 4 tests: end of blockExecuted by:
| 18 | ||||||||||||||||||
| 8193 | x = Data::fromRawData(reinterpret_cast<const ushort *>(unicode), size); | - | ||||||||||||||||||
| 8194 | Q_CHECK_PTR(x); never executed: qBadAlloc();
| 0-79136 | ||||||||||||||||||
| 8195 | } executed 79136 times by 91 tests: end of blockExecuted by:
| 79136 | ||||||||||||||||||
| 8196 | QStringDataPtr dataPtr = { x }; | - | ||||||||||||||||||
| 8197 | return QString(dataPtr); executed 79156 times by 91 tests: return QString(dataPtr);Executed by:
| 79156 | ||||||||||||||||||
| 8198 | } | - | ||||||||||||||||||
| 8199 | - | |||||||||||||||||||
| 8200 | /*! | - | ||||||||||||||||||
| 8201 | \since 4.7 | - | ||||||||||||||||||
| 8202 | - | |||||||||||||||||||
| 8203 | Resets the QString to use the first \a size Unicode characters | - | ||||||||||||||||||
| 8204 | in the array \a unicode. The data in \a unicode is \e not | - | ||||||||||||||||||
| 8205 | copied. The caller must be able to guarantee that \a unicode will | - | ||||||||||||||||||
| 8206 | not be deleted or modified as long as the QString (or an | - | ||||||||||||||||||
| 8207 | unmodified copy of it) exists. | - | ||||||||||||||||||
| 8208 | - | |||||||||||||||||||
| 8209 | This function can be used instead of fromRawData() to re-use | - | ||||||||||||||||||
| 8210 | existings QString objects to save memory re-allocations. | - | ||||||||||||||||||
| 8211 | - | |||||||||||||||||||
| 8212 | \sa fromRawData() | - | ||||||||||||||||||
| 8213 | */ | - | ||||||||||||||||||
| 8214 | QString &QString::setRawData(const QChar *unicode, int size) | - | ||||||||||||||||||
| 8215 | { | - | ||||||||||||||||||
| 8216 | if (d->ref.isShared() || d->alloc) {
| 1-761 | ||||||||||||||||||
| 8217 | *this = fromRawData(unicode, size); | - | ||||||||||||||||||
| 8218 | } else { executed 762 times by 2 tests: end of blockExecuted by:
| 762 | ||||||||||||||||||
| 8219 | if (unicode) {
| 0-607 | ||||||||||||||||||
| 8220 | d->size = size; | - | ||||||||||||||||||
| 8221 | d->offset = reinterpret_cast<const char *>(unicode) - reinterpret_cast<char *>(d); | - | ||||||||||||||||||
| 8222 | } else { executed 607 times by 2 tests: end of blockExecuted by:
| 607 | ||||||||||||||||||
| 8223 | d->offset = sizeof(QStringData); | - | ||||||||||||||||||
| 8224 | d->size = 0; | - | ||||||||||||||||||
| 8225 | } never executed: end of block | 0 | ||||||||||||||||||
| 8226 | } | - | ||||||||||||||||||
| 8227 | return *this; executed 1369 times by 2 tests: return *this;Executed by:
| 1369 | ||||||||||||||||||
| 8228 | } | - | ||||||||||||||||||
| 8229 | - | |||||||||||||||||||
| 8230 | /*! \fn QString QString::fromStdU16String(const std::u16string &str) | - | ||||||||||||||||||
| 8231 | \since 5.5 | - | ||||||||||||||||||
| 8232 | - | |||||||||||||||||||
| 8233 | Returns a copy of the \a str string. The given string is assumed | - | ||||||||||||||||||
| 8234 | to be encoded in UTF-16. | - | ||||||||||||||||||
| 8235 | - | |||||||||||||||||||
| 8236 | \sa fromUtf16(), fromStdWString(), fromStdU32String() | - | ||||||||||||||||||
| 8237 | */ | - | ||||||||||||||||||
| 8238 | - | |||||||||||||||||||
| 8239 | /*! | - | ||||||||||||||||||
| 8240 | \fn std::u16string QString::toStdU16String() const | - | ||||||||||||||||||
| 8241 | \since 5.5 | - | ||||||||||||||||||
| 8242 | - | |||||||||||||||||||
| 8243 | Returns a std::u16string object with the data contained in this | - | ||||||||||||||||||
| 8244 | QString. The Unicode data is the same as returned by the utf16() | - | ||||||||||||||||||
| 8245 | method. | - | ||||||||||||||||||
| 8246 | - | |||||||||||||||||||
| 8247 | \sa utf16(), toStdWString(), toStdU32String() | - | ||||||||||||||||||
| 8248 | */ | - | ||||||||||||||||||
| 8249 | - | |||||||||||||||||||
| 8250 | /*! \fn QString QString::fromStdU32String(const std::u32string &str) | - | ||||||||||||||||||
| 8251 | \since 5.5 | - | ||||||||||||||||||
| 8252 | - | |||||||||||||||||||
| 8253 | Returns a copy of the \a str string. The given string is assumed | - | ||||||||||||||||||
| 8254 | to be encoded in UCS-4. | - | ||||||||||||||||||
| 8255 | - | |||||||||||||||||||
| 8256 | \sa fromUcs4(), fromStdWString(), fromStdU16String() | - | ||||||||||||||||||
| 8257 | */ | - | ||||||||||||||||||
| 8258 | - | |||||||||||||||||||
| 8259 | /*! | - | ||||||||||||||||||
| 8260 | \fn std::u32string QString::toStdU32String() const | - | ||||||||||||||||||
| 8261 | \since 5.5 | - | ||||||||||||||||||
| 8262 | - | |||||||||||||||||||
| 8263 | Returns a std::u32string object with the data contained in this | - | ||||||||||||||||||
| 8264 | QString. The Unicode data is the same as returned by the toUcs4() | - | ||||||||||||||||||
| 8265 | method. | - | ||||||||||||||||||
| 8266 | - | |||||||||||||||||||
| 8267 | \sa toUcs4(), toStdWString(), toStdU16String() | - | ||||||||||||||||||
| 8268 | */ | - | ||||||||||||||||||
| 8269 | - | |||||||||||||||||||
| 8270 | /*! \class QLatin1String | - | ||||||||||||||||||
| 8271 | \inmodule QtCore | - | ||||||||||||||||||
| 8272 | \brief The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal. | - | ||||||||||||||||||
| 8273 | - | |||||||||||||||||||
| 8274 | \ingroup string-processing | - | ||||||||||||||||||
| 8275 | \reentrant | - | ||||||||||||||||||
| 8276 | - | |||||||||||||||||||
| 8277 | Many of QString's member functions are overloaded to accept | - | ||||||||||||||||||
| 8278 | \c{const char *} instead of QString. This includes the copy | - | ||||||||||||||||||
| 8279 | constructor, the assignment operator, the comparison operators, | - | ||||||||||||||||||
| 8280 | and various other functions such as \l{QString::insert()}{insert()}, \l{QString::replace()}{replace()}, | - | ||||||||||||||||||
| 8281 | and \l{QString::indexOf()}{indexOf()}. These functions | - | ||||||||||||||||||
| 8282 | are usually optimized to avoid constructing a QString object for | - | ||||||||||||||||||
| 8283 | the \c{const char *} data. For example, assuming \c str is a | - | ||||||||||||||||||
| 8284 | QString, | - | ||||||||||||||||||
| 8285 | - | |||||||||||||||||||
| 8286 | \snippet code/src_corelib_tools_qstring.cpp 3 | - | ||||||||||||||||||
| 8287 | - | |||||||||||||||||||
| 8288 | is much faster than | - | ||||||||||||||||||
| 8289 | - | |||||||||||||||||||
| 8290 | \snippet code/src_corelib_tools_qstring.cpp 4 | - | ||||||||||||||||||
| 8291 | - | |||||||||||||||||||
| 8292 | because it doesn't construct four temporary QString objects and | - | ||||||||||||||||||
| 8293 | make a deep copy of the character data. | - | ||||||||||||||||||
| 8294 | - | |||||||||||||||||||
| 8295 | Applications that define \c QT_NO_CAST_FROM_ASCII (as explained | - | ||||||||||||||||||
| 8296 | in the QString documentation) don't have access to QString's | - | ||||||||||||||||||
| 8297 | \c{const char *} API. To provide an efficient way of specifying | - | ||||||||||||||||||
| 8298 | constant Latin-1 strings, Qt provides the QLatin1String, which is | - | ||||||||||||||||||
| 8299 | just a very thin wrapper around a \c{const char *}. Using | - | ||||||||||||||||||
| 8300 | QLatin1String, the example code above becomes | - | ||||||||||||||||||
| 8301 | - | |||||||||||||||||||
| 8302 | \snippet code/src_corelib_tools_qstring.cpp 5 | - | ||||||||||||||||||
| 8303 | - | |||||||||||||||||||
| 8304 | This is a bit longer to type, but it provides exactly the same | - | ||||||||||||||||||
| 8305 | benefits as the first version of the code, and is faster than | - | ||||||||||||||||||
| 8306 | converting the Latin-1 strings using QString::fromLatin1(). | - | ||||||||||||||||||
| 8307 | - | |||||||||||||||||||
| 8308 | Thanks to the QString(QLatin1String) constructor, | - | ||||||||||||||||||
| 8309 | QLatin1String can be used everywhere a QString is expected. For | - | ||||||||||||||||||
| 8310 | example: | - | ||||||||||||||||||
| 8311 | - | |||||||||||||||||||
| 8312 | \snippet code/src_corelib_tools_qstring.cpp 6 | - | ||||||||||||||||||
| 8313 | - | |||||||||||||||||||
| 8314 | \note If the function you're calling with a QLatin1String | - | ||||||||||||||||||
| 8315 | argument isn't actually overloaded to take QLatin1String, the | - | ||||||||||||||||||
| 8316 | implicit conversion to QString will trigger a memory allocation, | - | ||||||||||||||||||
| 8317 | which is usually what you want to avoid by using QLatin1String | - | ||||||||||||||||||
| 8318 | in the first place. In those cases, using QStringLiteral may be | - | ||||||||||||||||||
| 8319 | the better option. | - | ||||||||||||||||||
| 8320 | - | |||||||||||||||||||
| 8321 | \sa QString, QLatin1Char, {QStringLiteral()}{QStringLiteral} | - | ||||||||||||||||||
| 8322 | */ | - | ||||||||||||||||||
| 8323 | - | |||||||||||||||||||
| 8324 | /*! \fn QLatin1String::QLatin1String() | - | ||||||||||||||||||
| 8325 | \since 5.6 | - | ||||||||||||||||||
| 8326 | - | |||||||||||||||||||
| 8327 | Constructs a QLatin1String object that stores a nullptr. | - | ||||||||||||||||||
| 8328 | */ | - | ||||||||||||||||||
| 8329 | - | |||||||||||||||||||
| 8330 | /*! \fn QLatin1String::QLatin1String(const char *str) | - | ||||||||||||||||||
| 8331 | - | |||||||||||||||||||
| 8332 | Constructs a QLatin1String object that stores \a str. | - | ||||||||||||||||||
| 8333 | - | |||||||||||||||||||
| 8334 | The string data is \e not copied. The caller must be able to | - | ||||||||||||||||||
| 8335 | guarantee that \a str will not be deleted or modified as long as | - | ||||||||||||||||||
| 8336 | the QLatin1String object exists. | - | ||||||||||||||||||
| 8337 | - | |||||||||||||||||||
| 8338 | \sa latin1() | - | ||||||||||||||||||
| 8339 | */ | - | ||||||||||||||||||
| 8340 | - | |||||||||||||||||||
| 8341 | /*! \fn QLatin1String::QLatin1String(const char *str, int size) | - | ||||||||||||||||||
| 8342 | - | |||||||||||||||||||
| 8343 | Constructs a QLatin1String object that stores \a str with \a size. | - | ||||||||||||||||||
| 8344 | - | |||||||||||||||||||
| 8345 | The string data is \e not copied. The caller must be able to | - | ||||||||||||||||||
| 8346 | guarantee that \a str will not be deleted or modified as long as | - | ||||||||||||||||||
| 8347 | the QLatin1String object exists. | - | ||||||||||||||||||
| 8348 | - | |||||||||||||||||||
| 8349 | \sa latin1() | - | ||||||||||||||||||
| 8350 | */ | - | ||||||||||||||||||
| 8351 | - | |||||||||||||||||||
| 8352 | /*! \fn QLatin1String::QLatin1String(const QByteArray &str) | - | ||||||||||||||||||
| 8353 | - | |||||||||||||||||||
| 8354 | Constructs a QLatin1String object that stores \a str. | - | ||||||||||||||||||
| 8355 | - | |||||||||||||||||||
| 8356 | The string data is \e not copied. The caller must be able to | - | ||||||||||||||||||
| 8357 | guarantee that \a str will not be deleted or modified as long as | - | ||||||||||||||||||
| 8358 | the QLatin1String object exists. | - | ||||||||||||||||||
| 8359 | - | |||||||||||||||||||
| 8360 | \sa latin1() | - | ||||||||||||||||||
| 8361 | */ | - | ||||||||||||||||||
| 8362 | - | |||||||||||||||||||
| 8363 | /*! \fn const char *QLatin1String::latin1() const | - | ||||||||||||||||||
| 8364 | - | |||||||||||||||||||
| 8365 | Returns the Latin-1 string stored in this object. | - | ||||||||||||||||||
| 8366 | */ | - | ||||||||||||||||||
| 8367 | - | |||||||||||||||||||
| 8368 | /*! \fn const char *QLatin1String::data() const | - | ||||||||||||||||||
| 8369 | - | |||||||||||||||||||
| 8370 | Returns the Latin-1 string stored in this object. | - | ||||||||||||||||||
| 8371 | */ | - | ||||||||||||||||||
| 8372 | - | |||||||||||||||||||
| 8373 | /*! \fn int QLatin1String::size() const | - | ||||||||||||||||||
| 8374 | - | |||||||||||||||||||
| 8375 | Returns the size of the Latin-1 string stored in this object. | - | ||||||||||||||||||
| 8376 | */ | - | ||||||||||||||||||
| 8377 | - | |||||||||||||||||||
| 8378 | /*! \fn bool QLatin1String::operator==(const QString &other) const | - | ||||||||||||||||||
| 8379 | - | |||||||||||||||||||
| 8380 | Returns \c true if this string is equal to string \a other; | - | ||||||||||||||||||
| 8381 | otherwise returns \c false. | - | ||||||||||||||||||
| 8382 | - | |||||||||||||||||||
| 8383 | The comparison is based exclusively on the numeric Unicode values | - | ||||||||||||||||||
| 8384 | of the characters and is very fast, but is not what a human would | - | ||||||||||||||||||
| 8385 | expect. Consider sorting user-interface strings with | - | ||||||||||||||||||
| 8386 | QString::localeAwareCompare(). | - | ||||||||||||||||||
| 8387 | */ | - | ||||||||||||||||||
| 8388 | - | |||||||||||||||||||
| 8389 | /*! | - | ||||||||||||||||||
| 8390 | \fn bool QLatin1String::operator==(const char *other) const | - | ||||||||||||||||||
| 8391 | \since 4.3 | - | ||||||||||||||||||
| 8392 | \overload | - | ||||||||||||||||||
| 8393 | - | |||||||||||||||||||
| 8394 | The \a other const char pointer is converted to a QString using | - | ||||||||||||||||||
| 8395 | the QString::fromUtf8() function. | - | ||||||||||||||||||
| 8396 | - | |||||||||||||||||||
| 8397 | You can disable this operator by defining \c | - | ||||||||||||||||||
| 8398 | QT_NO_CAST_FROM_ASCII when you compile your applications. This | - | ||||||||||||||||||
| 8399 | can be useful if you want to ensure that all user-visible strings | - | ||||||||||||||||||
| 8400 | go through QObject::tr(), for example. | - | ||||||||||||||||||
| 8401 | */ | - | ||||||||||||||||||
| 8402 | - | |||||||||||||||||||
| 8403 | /*! | - | ||||||||||||||||||
| 8404 | \fn bool QLatin1String::operator==(const QByteArray &other) const | - | ||||||||||||||||||
| 8405 | \since 5.0 | - | ||||||||||||||||||
| 8406 | \overload | - | ||||||||||||||||||
| 8407 | - | |||||||||||||||||||
| 8408 | The \a other byte array is converted to a QString using | - | ||||||||||||||||||
| 8409 | the QString::fromUtf8() function. | - | ||||||||||||||||||
| 8410 | - | |||||||||||||||||||
| 8411 | You can disable this operator by defining \c | - | ||||||||||||||||||
| 8412 | QT_NO_CAST_FROM_ASCII when you compile your applications. This | - | ||||||||||||||||||
| 8413 | can be useful if you want to ensure that all user-visible strings | - | ||||||||||||||||||
| 8414 | go through QObject::tr(), for example. | - | ||||||||||||||||||
| 8415 | */ | - | ||||||||||||||||||
| 8416 | - | |||||||||||||||||||
| 8417 | /*! \fn bool QLatin1String::operator!=(const QString &other) const | - | ||||||||||||||||||
| 8418 | - | |||||||||||||||||||
| 8419 | Returns \c true if this string is not equal to string \a other; | - | ||||||||||||||||||
| 8420 | otherwise returns \c false. | - | ||||||||||||||||||
| 8421 | - | |||||||||||||||||||
| 8422 | The comparison is based exclusively on the numeric Unicode values | - | ||||||||||||||||||
| 8423 | of the characters and is very fast, but is not what a human would | - | ||||||||||||||||||
| 8424 | expect. Consider sorting user-interface strings with | - | ||||||||||||||||||
| 8425 | QString::localeAwareCompare(). | - | ||||||||||||||||||
| 8426 | */ | - | ||||||||||||||||||
| 8427 | - | |||||||||||||||||||
| 8428 | /*! | - | ||||||||||||||||||
| 8429 | \fn bool QLatin1String::operator!=(const char *other) const | - | ||||||||||||||||||
| 8430 | \since 4.3 | - | ||||||||||||||||||
| 8431 | \overload operator!=() | - | ||||||||||||||||||
| 8432 | - | |||||||||||||||||||
| 8433 | The \a other const char pointer is converted to a QString using | - | ||||||||||||||||||
| 8434 | the QString::fromUtf8() function. | - | ||||||||||||||||||
| 8435 | - | |||||||||||||||||||
| 8436 | You can disable this operator by defining \c | - | ||||||||||||||||||
| 8437 | QT_NO_CAST_FROM_ASCII when you compile your applications. This | - | ||||||||||||||||||
| 8438 | can be useful if you want to ensure that all user-visible strings | - | ||||||||||||||||||
| 8439 | go through QObject::tr(), for example. | - | ||||||||||||||||||
| 8440 | */ | - | ||||||||||||||||||
| 8441 | - | |||||||||||||||||||
| 8442 | /*! | - | ||||||||||||||||||
| 8443 | \fn bool QLatin1String::operator!=(const QByteArray &other) const | - | ||||||||||||||||||
| 8444 | \since 5.0 | - | ||||||||||||||||||
| 8445 | \overload operator!=() | - | ||||||||||||||||||
| 8446 | - | |||||||||||||||||||
| 8447 | The \a other byte array is converted to a QString using | - | ||||||||||||||||||
| 8448 | the QString::fromUtf8() function. | - | ||||||||||||||||||
| 8449 | - | |||||||||||||||||||
| 8450 | You can disable this operator by defining \c | - | ||||||||||||||||||
| 8451 | QT_NO_CAST_FROM_ASCII when you compile your applications. This | - | ||||||||||||||||||
| 8452 | can be useful if you want to ensure that all user-visible strings | - | ||||||||||||||||||
| 8453 | go through QObject::tr(), for example. | - | ||||||||||||||||||
| 8454 | */ | - | ||||||||||||||||||
| 8455 | - | |||||||||||||||||||
| 8456 | /*! | - | ||||||||||||||||||
| 8457 | \fn bool QLatin1String::operator>(const QString &other) const | - | ||||||||||||||||||
| 8458 | - | |||||||||||||||||||
| 8459 | Returns \c true if this string is lexically greater than string \a | - | ||||||||||||||||||
| 8460 | other; otherwise returns \c false. | - | ||||||||||||||||||
| 8461 | - | |||||||||||||||||||
| 8462 | The comparison is based exclusively on the numeric Unicode values | - | ||||||||||||||||||
| 8463 | of the characters and is very fast, but is not what a human would | - | ||||||||||||||||||
| 8464 | expect. Consider sorting user-interface strings with | - | ||||||||||||||||||
| 8465 | QString::localeAwareCompare(). | - | ||||||||||||||||||
| 8466 | */ | - | ||||||||||||||||||
| 8467 | - | |||||||||||||||||||
| 8468 | /*! | - | ||||||||||||||||||
| 8469 | \fn bool QLatin1String::operator>(const char *other) const | - | ||||||||||||||||||
| 8470 | \since 4.3 | - | ||||||||||||||||||
| 8471 | \overload | - | ||||||||||||||||||
| 8472 | - | |||||||||||||||||||
| 8473 | The \a other const char pointer is converted to a QString using | - | ||||||||||||||||||
| 8474 | the QString::fromUtf8() function. | - | ||||||||||||||||||
| 8475 | - | |||||||||||||||||||
| 8476 | You can disable this operator by defining \c QT_NO_CAST_FROM_ASCII | - | ||||||||||||||||||
| 8477 | when you compile your applications. This can be useful if you want | - | ||||||||||||||||||
| 8478 | to ensure that all user-visible strings go through QObject::tr(), | - | ||||||||||||||||||
| 8479 | for example. | - | ||||||||||||||||||
| 8480 | */ | - | ||||||||||||||||||
| 8481 | - | |||||||||||||||||||
| 8482 | /*! | - | ||||||||||||||||||
| 8483 | \fn bool QLatin1String::operator>(const QByteArray &other) const | - | ||||||||||||||||||
| 8484 | \since 5.0 | - | ||||||||||||||||||
| 8485 | \overload | - | ||||||||||||||||||
| 8486 | - | |||||||||||||||||||
| 8487 | The \a other const char pointer is converted to a QString using | - | ||||||||||||||||||
| 8488 | the QString::fromUtf8() function. | - | ||||||||||||||||||
| 8489 | - | |||||||||||||||||||
| 8490 | You can disable this operator by defining \c QT_NO_CAST_FROM_ASCII | - | ||||||||||||||||||
| 8491 | when you compile your applications. This can be useful if you want | - | ||||||||||||||||||
| 8492 | to ensure that all user-visible strings go through QObject::tr(), | - | ||||||||||||||||||
| 8493 | for example. | - | ||||||||||||||||||
| 8494 | */ | - | ||||||||||||||||||
| 8495 | - | |||||||||||||||||||
| 8496 | /*! | - | ||||||||||||||||||
| 8497 | \fn bool QLatin1String::operator<(const QString &other) const | - | ||||||||||||||||||
| 8498 | - | |||||||||||||||||||
| 8499 | Returns \c true if this string is lexically less than the \a other | - | ||||||||||||||||||
| 8500 | string; otherwise returns \c false. | - | ||||||||||||||||||
| 8501 | - | |||||||||||||||||||
| 8502 | The comparison is based exclusively on the numeric Unicode values | - | ||||||||||||||||||
| 8503 | of the characters and is very fast, but is not what a human would | - | ||||||||||||||||||
| 8504 | expect. Consider sorting user-interface strings using the | - | ||||||||||||||||||
| 8505 | QString::localeAwareCompare() function. | - | ||||||||||||||||||
| 8506 | */ | - | ||||||||||||||||||
| 8507 | - | |||||||||||||||||||
| 8508 | /*! | - | ||||||||||||||||||
| 8509 | \fn bool QLatin1String::operator<(const char *other) const | - | ||||||||||||||||||
| 8510 | \since 4.3 | - | ||||||||||||||||||
| 8511 | \overload | - | ||||||||||||||||||
| 8512 | - | |||||||||||||||||||
| 8513 | The \a other const char pointer is converted to a QString using | - | ||||||||||||||||||
| 8514 | the QString::fromUtf8() function. | - | ||||||||||||||||||
| 8515 | - | |||||||||||||||||||
| 8516 | You can disable this operator by defining \c | - | ||||||||||||||||||
| 8517 | QT_NO_CAST_FROM_ASCII when you compile your applications. This | - | ||||||||||||||||||
| 8518 | can be useful if you want to ensure that all user-visible strings | - | ||||||||||||||||||
| 8519 | go through QObject::tr(), for example. | - | ||||||||||||||||||
| 8520 | */ | - | ||||||||||||||||||
| 8521 | - | |||||||||||||||||||
| 8522 | /*! | - | ||||||||||||||||||
| 8523 | \fn bool QLatin1String::operator<(const QByteArray &other) const | - | ||||||||||||||||||
| 8524 | \since 5.0 | - | ||||||||||||||||||
| 8525 | \overload | - | ||||||||||||||||||
| 8526 | - | |||||||||||||||||||
| 8527 | The \a other const char pointer is converted to a QString using | - | ||||||||||||||||||
| 8528 | the QString::fromUtf8() function. | - | ||||||||||||||||||
| 8529 | - | |||||||||||||||||||
| 8530 | You can disable this operator by defining \c | - | ||||||||||||||||||
| 8531 | QT_NO_CAST_FROM_ASCII when you compile your applications. This | - | ||||||||||||||||||
| 8532 | can be useful if you want to ensure that all user-visible strings | - | ||||||||||||||||||
| 8533 | go through QObject::tr(), for example. | - | ||||||||||||||||||
| 8534 | */ | - | ||||||||||||||||||
| 8535 | - | |||||||||||||||||||
| 8536 | /*! | - | ||||||||||||||||||
| 8537 | \fn bool QLatin1String::operator>=(const QString &other) const | - | ||||||||||||||||||
| 8538 | - | |||||||||||||||||||
| 8539 | Returns \c true if this string is lexically greater than or equal | - | ||||||||||||||||||
| 8540 | to string \a other; otherwise returns \c false. | - | ||||||||||||||||||
| 8541 | - | |||||||||||||||||||
| 8542 | The comparison is based exclusively on the numeric Unicode values | - | ||||||||||||||||||
| 8543 | of the characters and is very fast, but is not what a human would | - | ||||||||||||||||||
| 8544 | expect. Consider sorting user-interface strings with | - | ||||||||||||||||||
| 8545 | QString::localeAwareCompare(). | - | ||||||||||||||||||
| 8546 | */ | - | ||||||||||||||||||
| 8547 | - | |||||||||||||||||||
| 8548 | /*! | - | ||||||||||||||||||
| 8549 | \fn bool QLatin1String::operator>=(const char *other) const | - | ||||||||||||||||||
| 8550 | \since 4.3 | - | ||||||||||||||||||
| 8551 | \overload | - | ||||||||||||||||||
| 8552 | - | |||||||||||||||||||
| 8553 | The \a other const char pointer is converted to a QString using | - | ||||||||||||||||||
| 8554 | the QString::fromUtf8() function. | - | ||||||||||||||||||
| 8555 | - | |||||||||||||||||||
| 8556 | You can disable this operator by defining \c | - | ||||||||||||||||||
| 8557 | QT_NO_CAST_FROM_ASCII when you compile your applications. This | - | ||||||||||||||||||
| 8558 | can be useful if you want to ensure that all user-visible strings | - | ||||||||||||||||||
| 8559 | go through QObject::tr(), for example. | - | ||||||||||||||||||
| 8560 | */ | - | ||||||||||||||||||
| 8561 | - | |||||||||||||||||||
| 8562 | /*! | - | ||||||||||||||||||
| 8563 | \fn bool QLatin1String::operator>=(const QByteArray &other) const | - | ||||||||||||||||||
| 8564 | \since 5.0 | - | ||||||||||||||||||
| 8565 | \overload | - | ||||||||||||||||||
| 8566 | - | |||||||||||||||||||
| 8567 | The \a other array is converted to a QString using | - | ||||||||||||||||||
| 8568 | the QString::fromUtf8() function. | - | ||||||||||||||||||
| 8569 | - | |||||||||||||||||||
| 8570 | You can disable this operator by defining \c | - | ||||||||||||||||||
| 8571 | QT_NO_CAST_FROM_ASCII when you compile your applications. This | - | ||||||||||||||||||
| 8572 | can be useful if you want to ensure that all user-visible strings | - | ||||||||||||||||||
| 8573 | go through QObject::tr(), for example. | - | ||||||||||||||||||
| 8574 | */ | - | ||||||||||||||||||
| 8575 | - | |||||||||||||||||||
| 8576 | /*! \fn bool QLatin1String::operator<=(const QString &other) const | - | ||||||||||||||||||
| 8577 | - | |||||||||||||||||||
| 8578 | Returns \c true if this string is lexically less than or equal | - | ||||||||||||||||||
| 8579 | to string \a other; otherwise returns \c false. | - | ||||||||||||||||||
| 8580 | - | |||||||||||||||||||
| 8581 | The comparison is based exclusively on the numeric Unicode values | - | ||||||||||||||||||
| 8582 | of the characters and is very fast, but is not what a human would | - | ||||||||||||||||||
| 8583 | expect. Consider sorting user-interface strings with | - | ||||||||||||||||||
| 8584 | QString::localeAwareCompare(). | - | ||||||||||||||||||
| 8585 | */ | - | ||||||||||||||||||
| 8586 | - | |||||||||||||||||||
| 8587 | /*! | - | ||||||||||||||||||
| 8588 | \fn bool QLatin1String::operator<=(const char *other) const | - | ||||||||||||||||||
| 8589 | \since 4.3 | - | ||||||||||||||||||
| 8590 | \overload | - | ||||||||||||||||||
| 8591 | - | |||||||||||||||||||
| 8592 | The \a other const char pointer is converted to a QString using | - | ||||||||||||||||||
| 8593 | the QString::fromUtf8() function. | - | ||||||||||||||||||
| 8594 | - | |||||||||||||||||||
| 8595 | You can disable this operator by defining \c | - | ||||||||||||||||||
| 8596 | QT_NO_CAST_FROM_ASCII when you compile your applications. This | - | ||||||||||||||||||
| 8597 | can be useful if you want to ensure that all user-visible strings | - | ||||||||||||||||||
| 8598 | go through QObject::tr(), for example. | - | ||||||||||||||||||
| 8599 | */ | - | ||||||||||||||||||
| 8600 | - | |||||||||||||||||||
| 8601 | /*! | - | ||||||||||||||||||
| 8602 | \fn bool QLatin1String::operator<=(const QByteArray &other) const | - | ||||||||||||||||||
| 8603 | \since 5.0 | - | ||||||||||||||||||
| 8604 | \overload | - | ||||||||||||||||||
| 8605 | - | |||||||||||||||||||
| 8606 | The \a other array is converted to a QString using | - | ||||||||||||||||||
| 8607 | the QString::fromUtf8() function. | - | ||||||||||||||||||
| 8608 | - | |||||||||||||||||||
| 8609 | You can disable this operator by defining \c | - | ||||||||||||||||||
| 8610 | QT_NO_CAST_FROM_ASCII when you compile your applications. This | - | ||||||||||||||||||
| 8611 | can be useful if you want to ensure that all user-visible strings | - | ||||||||||||||||||
| 8612 | go through QObject::tr(), for example. | - | ||||||||||||||||||
| 8613 | */ | - | ||||||||||||||||||
| 8614 | - | |||||||||||||||||||
| 8615 | - | |||||||||||||||||||
| 8616 | /*! \fn bool operator==(QLatin1String s1, QLatin1String s2) | - | ||||||||||||||||||
| 8617 | \relates QLatin1String | - | ||||||||||||||||||
| 8618 | - | |||||||||||||||||||
| 8619 | Returns \c true if string \a s1 is lexically equal to string \a s2; otherwise | - | ||||||||||||||||||
| 8620 | returns \c false. | - | ||||||||||||||||||
| 8621 | */ | - | ||||||||||||||||||
| 8622 | /*! \fn bool operator!=(QLatin1String s1, QLatin1String s2) | - | ||||||||||||||||||
| 8623 | \relates QLatin1String | - | ||||||||||||||||||
| 8624 | - | |||||||||||||||||||
| 8625 | Returns \c true if string \a s1 is lexically unequal to string \a s2; otherwise | - | ||||||||||||||||||
| 8626 | returns \c false. | - | ||||||||||||||||||
| 8627 | */ | - | ||||||||||||||||||
| 8628 | /*! \fn bool operator<(QLatin1String s1, QLatin1String s2) | - | ||||||||||||||||||
| 8629 | \relates QLatin1String | - | ||||||||||||||||||
| 8630 | - | |||||||||||||||||||
| 8631 | Returns \c true if string \a s1 is lexically smaller than string \a s2; otherwise | - | ||||||||||||||||||
| 8632 | returns \c false. | - | ||||||||||||||||||
| 8633 | */ | - | ||||||||||||||||||
| 8634 | /*! \fn bool operator<=(QLatin1String s1, QLatin1String s2) | - | ||||||||||||||||||
| 8635 | \relates QLatin1String | - | ||||||||||||||||||
| 8636 | - | |||||||||||||||||||
| 8637 | Returns \c true if string \a s1 is lexically smaller than or equal to string \a s2; otherwise | - | ||||||||||||||||||
| 8638 | returns \c false. | - | ||||||||||||||||||
| 8639 | */ | - | ||||||||||||||||||
| 8640 | /*! \fn bool operator>(QLatin1String s1, QLatin1String s2) | - | ||||||||||||||||||
| 8641 | \relates QLatin1String | - | ||||||||||||||||||
| 8642 | - | |||||||||||||||||||
| 8643 | Returns \c true if string \a s1 is lexically greater than string \a s2; otherwise | - | ||||||||||||||||||
| 8644 | returns \c false. | - | ||||||||||||||||||
| 8645 | */ | - | ||||||||||||||||||
| 8646 | /*! \fn bool operator>=(QLatin1String s1, QLatin1String s2) | - | ||||||||||||||||||
| 8647 | \relates QLatin1String | - | ||||||||||||||||||
| 8648 | - | |||||||||||||||||||
| 8649 | Returns \c true if string \a s1 is lexically greater than or equal to | - | ||||||||||||||||||
| 8650 | string \a s2; otherwise returns \c false. | - | ||||||||||||||||||
| 8651 | */ | - | ||||||||||||||||||
| 8652 | - | |||||||||||||||||||
| 8653 | - | |||||||||||||||||||
| 8654 | #if !defined(QT_NO_DATASTREAM) || (defined(QT_BOOTSTRAPPED) && !defined(QT_BUILD_QMAKE)) | - | ||||||||||||||||||
| 8655 | /*! | - | ||||||||||||||||||
| 8656 | \fn QDataStream &operator<<(QDataStream &stream, const QString &string) | - | ||||||||||||||||||
| 8657 | \relates QString | - | ||||||||||||||||||
| 8658 | - | |||||||||||||||||||
| 8659 | Writes the given \a string to the specified \a stream. | - | ||||||||||||||||||
| 8660 | - | |||||||||||||||||||
| 8661 | \sa {Serializing Qt Data Types} | - | ||||||||||||||||||
| 8662 | */ | - | ||||||||||||||||||
| 8663 | - | |||||||||||||||||||
| 8664 | QDataStream &operator<<(QDataStream &out, const QString &str) | - | ||||||||||||||||||
| 8665 | { | - | ||||||||||||||||||
| 8666 | if (out.version() == 1) {
| 0-15252 | ||||||||||||||||||
| 8667 | out << str.toLatin1(); | - | ||||||||||||||||||
| 8668 | } else { never executed: end of block | 0 | ||||||||||||||||||
| 8669 | if (!str.isNull() || out.version() < 3) {
| 1-14893 | ||||||||||||||||||
| 8670 | if ((out.byteOrder() == QDataStream::BigEndian) == (QSysInfo::ByteOrder == QSysInfo::BigEndian)) {
| 0-14894 | ||||||||||||||||||
| 8671 | out.writeBytes(reinterpret_cast<const char *>(str.unicode()), sizeof(QChar) * str.length()); | - | ||||||||||||||||||
| 8672 | } else { never executed: end of block | 0 | ||||||||||||||||||
| 8673 | QVarLengthArray<ushort> buffer(str.length()); | - | ||||||||||||||||||
| 8674 | const ushort *data = reinterpret_cast<const ushort *>(str.constData()); | - | ||||||||||||||||||
| 8675 | for (int i = 0; i < str.length(); i++) {
| 14894-46886 | ||||||||||||||||||
| 8676 | buffer[i] = qbswap(*data); | - | ||||||||||||||||||
| 8677 | ++data; | - | ||||||||||||||||||
| 8678 | } executed 46886 times by 28 tests: end of blockExecuted by:
| 46886 | ||||||||||||||||||
| 8679 | out.writeBytes(reinterpret_cast<const char *>(buffer.data()), sizeof(ushort) * buffer.size()); | - | ||||||||||||||||||
| 8680 | } executed 14894 times by 28 tests: end of blockExecuted by:
| 14894 | ||||||||||||||||||
| 8681 | } else { | - | ||||||||||||||||||
| 8682 | // write null marker | - | ||||||||||||||||||
| 8683 | out << (quint32)0xffffffff; | - | ||||||||||||||||||
| 8684 | } executed 358 times by 12 tests: end of blockExecuted by:
| 358 | ||||||||||||||||||
| 8685 | } | - | ||||||||||||||||||
| 8686 | return out; executed 15252 times by 28 tests: return out;Executed by:
| 15252 | ||||||||||||||||||
| 8687 | } | - | ||||||||||||||||||
| 8688 | - | |||||||||||||||||||
| 8689 | /*! | - | ||||||||||||||||||
| 8690 | \fn QDataStream &operator>>(QDataStream &stream, QString &string) | - | ||||||||||||||||||
| 8691 | \relates QString | - | ||||||||||||||||||
| 8692 | - | |||||||||||||||||||
| 8693 | Reads a string from the specified \a stream into the given \a string. | - | ||||||||||||||||||
| 8694 | - | |||||||||||||||||||
| 8695 | \sa {Serializing Qt Data Types} | - | ||||||||||||||||||
| 8696 | */ | - | ||||||||||||||||||
| 8697 | - | |||||||||||||||||||
| 8698 | QDataStream &operator>>(QDataStream &in, QString &str) | - | ||||||||||||||||||
| 8699 | { | - | ||||||||||||||||||
| 8700 | if (in.version() == 1) {
| 0-15640 | ||||||||||||||||||
| 8701 | QByteArray l; | - | ||||||||||||||||||
| 8702 | in >> l; | - | ||||||||||||||||||
| 8703 | str = QString::fromLatin1(l); | - | ||||||||||||||||||
| 8704 | } else { never executed: end of block | 0 | ||||||||||||||||||
| 8705 | quint32 bytes = 0; | - | ||||||||||||||||||
| 8706 | in >> bytes; // read size of string | - | ||||||||||||||||||
| 8707 | if (bytes == 0xffffffff) { // null string
| 354-15286 | ||||||||||||||||||
| 8708 | str.clear(); | - | ||||||||||||||||||
| 8709 | } else if (bytes > 0) { // not empty executed 354 times by 12 tests: end of blockExecuted by:
| 253-15033 | ||||||||||||||||||
| 8710 | if (bytes & 0x1) {
| 6-15027 | ||||||||||||||||||
| 8711 | str.clear(); | - | ||||||||||||||||||
| 8712 | in.setStatus(QDataStream::ReadCorruptData); | - | ||||||||||||||||||
| 8713 | return in; executed 6 times by 1 test: return in;Executed by:
| 6 | ||||||||||||||||||
| 8714 | } | - | ||||||||||||||||||
| 8715 | - | |||||||||||||||||||
| 8716 | const quint32 Step = 1024 * 1024; | - | ||||||||||||||||||
| 8717 | quint32 len = bytes / 2; | - | ||||||||||||||||||
| 8718 | quint32 allocated = 0; | - | ||||||||||||||||||
| 8719 | - | |||||||||||||||||||
| 8720 | while (allocated < len) {
| 15013-15039 | ||||||||||||||||||
| 8721 | int blockSize = qMin(Step, len - allocated); | - | ||||||||||||||||||
| 8722 | str.resize(allocated + blockSize); | - | ||||||||||||||||||
| 8723 | if (in.readRawData(reinterpret_cast<char *>(str.data()) + allocated * 2,
| 14-15025 | ||||||||||||||||||
| 8724 | blockSize * 2) != blockSize * 2) {
| 14-15025 | ||||||||||||||||||
| 8725 | str.clear(); | - | ||||||||||||||||||
| 8726 | in.setStatus(QDataStream::ReadPastEnd); | - | ||||||||||||||||||
| 8727 | return in; executed 14 times by 1 test: return in;Executed by:
| 14 | ||||||||||||||||||
| 8728 | } | - | ||||||||||||||||||
| 8729 | allocated += blockSize; | - | ||||||||||||||||||
| 8730 | } executed 15025 times by 28 tests: end of blockExecuted by:
| 15025 | ||||||||||||||||||
| 8731 | - | |||||||||||||||||||
| 8732 | if ((in.byteOrder() == QDataStream::BigEndian)
| 0-15013 | ||||||||||||||||||
| 8733 | != (QSysInfo::ByteOrder == QSysInfo::BigEndian)) {
| 0-15013 | ||||||||||||||||||
| 8734 | ushort *data = reinterpret_cast<ushort *>(str.data()); | - | ||||||||||||||||||
| 8735 | while (len--) {
| 15013-12630552 | ||||||||||||||||||
| 8736 | *data = qbswap(*data); | - | ||||||||||||||||||
| 8737 | ++data; | - | ||||||||||||||||||
| 8738 | } executed 12630552 times by 28 tests: end of blockExecuted by:
| 12630552 | ||||||||||||||||||
| 8739 | } executed 15013 times by 28 tests: end of blockExecuted by:
| 15013 | ||||||||||||||||||
| 8740 | } else { executed 15013 times by 28 tests: end of blockExecuted by:
| 15013 | ||||||||||||||||||
| 8741 | str = QString(QLatin1String("")); | - | ||||||||||||||||||
| 8742 | } executed 253 times by 5 tests: end of blockExecuted by:
| 253 | ||||||||||||||||||
| 8743 | } | - | ||||||||||||||||||
| 8744 | return in; executed 15620 times by 28 tests: return in;Executed by:
| 15620 | ||||||||||||||||||
| 8745 | } | - | ||||||||||||||||||
| 8746 | #endif // QT_NO_DATASTREAM | - | ||||||||||||||||||
| 8747 | - | |||||||||||||||||||
| 8748 | - | |||||||||||||||||||
| 8749 | - | |||||||||||||||||||
| 8750 | - | |||||||||||||||||||
| 8751 | /*! | - | ||||||||||||||||||
| 8752 | \class QStringRef | - | ||||||||||||||||||
| 8753 | \inmodule QtCore | - | ||||||||||||||||||
| 8754 | \since 4.3 | - | ||||||||||||||||||
| 8755 | \brief The QStringRef class provides a thin wrapper around QString substrings. | - | ||||||||||||||||||
| 8756 | \reentrant | - | ||||||||||||||||||
| 8757 | \ingroup tools | - | ||||||||||||||||||
| 8758 | \ingroup string-processing | - | ||||||||||||||||||
| 8759 | - | |||||||||||||||||||
| 8760 | QStringRef provides a read-only subset of the QString API. | - | ||||||||||||||||||
| 8761 | - | |||||||||||||||||||
| 8762 | A string reference explicitly references a portion of a string() | - | ||||||||||||||||||
| 8763 | with a given size(), starting at a specific position(). Calling | - | ||||||||||||||||||
| 8764 | toString() returns a copy of the data as a real QString instance. | - | ||||||||||||||||||
| 8765 | - | |||||||||||||||||||
| 8766 | This class is designed to improve the performance of substring | - | ||||||||||||||||||
| 8767 | handling when manipulating substrings obtained from existing QString | - | ||||||||||||||||||
| 8768 | instances. QStringRef avoids the memory allocation and reference | - | ||||||||||||||||||
| 8769 | counting overhead of a standard QString by simply referencing a | - | ||||||||||||||||||
| 8770 | part of the original string. This can prove to be advantageous in | - | ||||||||||||||||||
| 8771 | low level code, such as that used in a parser, at the expense of | - | ||||||||||||||||||
| 8772 | potentially more complex code. | - | ||||||||||||||||||
| 8773 | - | |||||||||||||||||||
| 8774 | For most users, there are no semantic benefits to using QStringRef | - | ||||||||||||||||||
| 8775 | instead of QString since QStringRef requires attention to be paid | - | ||||||||||||||||||
| 8776 | to memory management issues, potentially making code more complex | - | ||||||||||||||||||
| 8777 | to write and maintain. | - | ||||||||||||||||||
| 8778 | - | |||||||||||||||||||
| 8779 | \warning A QStringRef is only valid as long as the referenced | - | ||||||||||||||||||
| 8780 | string exists. If the original string is deleted, the string | - | ||||||||||||||||||
| 8781 | reference points to an invalid memory location. | - | ||||||||||||||||||
| 8782 | - | |||||||||||||||||||
| 8783 | We suggest that you only use this class in stable code where profiling | - | ||||||||||||||||||
| 8784 | has clearly identified that performance improvements can be made by | - | ||||||||||||||||||
| 8785 | replacing standard string operations with the optimized substring | - | ||||||||||||||||||
| 8786 | handling provided by this class. | - | ||||||||||||||||||
| 8787 | - | |||||||||||||||||||
| 8788 | \sa {Implicitly Shared Classes} | - | ||||||||||||||||||
| 8789 | */ | - | ||||||||||||||||||
| 8790 | - | |||||||||||||||||||
| 8791 | /*! | - | ||||||||||||||||||
| 8792 | \typedef QStringRef::size_type | - | ||||||||||||||||||
| 8793 | \internal | - | ||||||||||||||||||
| 8794 | */ | - | ||||||||||||||||||
| 8795 | - | |||||||||||||||||||
| 8796 | /*! | - | ||||||||||||||||||
| 8797 | \typedef QStringRef::value_type | - | ||||||||||||||||||
| 8798 | \internal | - | ||||||||||||||||||
| 8799 | */ | - | ||||||||||||||||||
| 8800 | - | |||||||||||||||||||
| 8801 | /*! | - | ||||||||||||||||||
| 8802 | \typedef QStringRef::const_pointer | - | ||||||||||||||||||
| 8803 | \internal | - | ||||||||||||||||||
| 8804 | */ | - | ||||||||||||||||||
| 8805 | - | |||||||||||||||||||
| 8806 | /*! | - | ||||||||||||||||||
| 8807 | \typedef QStringRef::const_reference | - | ||||||||||||||||||
| 8808 | \internal | - | ||||||||||||||||||
| 8809 | */ | - | ||||||||||||||||||
| 8810 | - | |||||||||||||||||||
| 8811 | /*! | - | ||||||||||||||||||
| 8812 | \typedef QStringRef::const_iterator | - | ||||||||||||||||||
| 8813 | \internal | - | ||||||||||||||||||
| 8814 | */ | - | ||||||||||||||||||
| 8815 | - | |||||||||||||||||||
| 8816 | /*! | - | ||||||||||||||||||
| 8817 | \fn QStringRef::QStringRef() | - | ||||||||||||||||||
| 8818 | - | |||||||||||||||||||
| 8819 | Constructs an empty string reference. | - | ||||||||||||||||||
| 8820 | */ | - | ||||||||||||||||||
| 8821 | - | |||||||||||||||||||
| 8822 | /*! \fn QStringRef::QStringRef(const QString *string, int position, int length) | - | ||||||||||||||||||
| 8823 | - | |||||||||||||||||||
| 8824 | Constructs a string reference to the range of characters in the given | - | ||||||||||||||||||
| 8825 | \a string specified by the starting \a position and \a length in characters. | - | ||||||||||||||||||
| 8826 | - | |||||||||||||||||||
| 8827 | \warning This function exists to improve performance as much as possible, | - | ||||||||||||||||||
| 8828 | and performs no bounds checking. For program correctness, \a position and | - | ||||||||||||||||||
| 8829 | \a length must describe a valid substring of \a string. | - | ||||||||||||||||||
| 8830 | - | |||||||||||||||||||
| 8831 | This means that the starting \a position must be positive or 0 and smaller | - | ||||||||||||||||||
| 8832 | than \a string's length, and \a length must be positive or 0 but smaller than | - | ||||||||||||||||||
| 8833 | the string's length minus the starting \a position; | - | ||||||||||||||||||
| 8834 | i.e, 0 <= position < string->length() and | - | ||||||||||||||||||
| 8835 | 0 <= length <= string->length() - position must both be satisfied. | - | ||||||||||||||||||
| 8836 | */ | - | ||||||||||||||||||
| 8837 | - | |||||||||||||||||||
| 8838 | /*! \fn QStringRef::QStringRef(const QString *string) | - | ||||||||||||||||||
| 8839 | - | |||||||||||||||||||
| 8840 | Constructs a string reference to the given \a string. | - | ||||||||||||||||||
| 8841 | */ | - | ||||||||||||||||||
| 8842 | - | |||||||||||||||||||
| 8843 | /*! \fn QStringRef::QStringRef(const QStringRef &other) | - | ||||||||||||||||||
| 8844 | - | |||||||||||||||||||
| 8845 | Constructs a copy of the \a other string reference. | - | ||||||||||||||||||
| 8846 | */ | - | ||||||||||||||||||
| 8847 | /*! | - | ||||||||||||||||||
| 8848 | \fn QStringRef::~QStringRef() | - | ||||||||||||||||||
| 8849 | - | |||||||||||||||||||
| 8850 | Destroys the string reference. | - | ||||||||||||||||||
| 8851 | - | |||||||||||||||||||
| 8852 | Since this class is only used to refer to string data, and does not take | - | ||||||||||||||||||
| 8853 | ownership of it, no memory is freed when instances are destroyed. | - | ||||||||||||||||||
| 8854 | */ | - | ||||||||||||||||||
| 8855 | - | |||||||||||||||||||
| 8856 | - | |||||||||||||||||||
| 8857 | /*! | - | ||||||||||||||||||
| 8858 | \fn int QStringRef::position() const | - | ||||||||||||||||||
| 8859 | - | |||||||||||||||||||
| 8860 | Returns the starting position in the referenced string that is referred to | - | ||||||||||||||||||
| 8861 | by the string reference. | - | ||||||||||||||||||
| 8862 | - | |||||||||||||||||||
| 8863 | \sa size(), string() | - | ||||||||||||||||||
| 8864 | */ | - | ||||||||||||||||||
| 8865 | - | |||||||||||||||||||
| 8866 | /*! | - | ||||||||||||||||||
| 8867 | \fn int QStringRef::size() const | - | ||||||||||||||||||
| 8868 | - | |||||||||||||||||||
| 8869 | Returns the number of characters referred to by the string reference. | - | ||||||||||||||||||
| 8870 | Equivalent to length() and count(). | - | ||||||||||||||||||
| 8871 | - | |||||||||||||||||||
| 8872 | \sa position(), string() | - | ||||||||||||||||||
| 8873 | */ | - | ||||||||||||||||||
| 8874 | /*! | - | ||||||||||||||||||
| 8875 | \fn int QStringRef::count() const | - | ||||||||||||||||||
| 8876 | Returns the number of characters referred to by the string reference. | - | ||||||||||||||||||
| 8877 | Equivalent to size() and length(). | - | ||||||||||||||||||
| 8878 | - | |||||||||||||||||||
| 8879 | \sa position(), string() | - | ||||||||||||||||||
| 8880 | */ | - | ||||||||||||||||||
| 8881 | /*! | - | ||||||||||||||||||
| 8882 | \fn int QStringRef::length() const | - | ||||||||||||||||||
| 8883 | Returns the number of characters referred to by the string reference. | - | ||||||||||||||||||
| 8884 | Equivalent to size() and count(). | - | ||||||||||||||||||
| 8885 | - | |||||||||||||||||||
| 8886 | \sa position(), string() | - | ||||||||||||||||||
| 8887 | */ | - | ||||||||||||||||||
| 8888 | - | |||||||||||||||||||
| 8889 | - | |||||||||||||||||||
| 8890 | /*! | - | ||||||||||||||||||
| 8891 | \fn bool QStringRef::isEmpty() const | - | ||||||||||||||||||
| 8892 | - | |||||||||||||||||||
| 8893 | Returns \c true if the string reference has no characters; otherwise returns | - | ||||||||||||||||||
| 8894 | \c false. | - | ||||||||||||||||||
| 8895 | - | |||||||||||||||||||
| 8896 | A string reference is empty if its size is zero. | - | ||||||||||||||||||
| 8897 | - | |||||||||||||||||||
| 8898 | \sa size() | - | ||||||||||||||||||
| 8899 | */ | - | ||||||||||||||||||
| 8900 | - | |||||||||||||||||||
| 8901 | /*! | - | ||||||||||||||||||
| 8902 | \fn bool QStringRef::isNull() const | - | ||||||||||||||||||
| 8903 | - | |||||||||||||||||||
| 8904 | Returns \c true if string() returns a null pointer or a pointer to a | - | ||||||||||||||||||
| 8905 | null string; otherwise returns \c true. | - | ||||||||||||||||||
| 8906 | - | |||||||||||||||||||
| 8907 | \sa size() | - | ||||||||||||||||||
| 8908 | */ | - | ||||||||||||||||||
| 8909 | - | |||||||||||||||||||
| 8910 | /*! | - | ||||||||||||||||||
| 8911 | \fn const QString *QStringRef::string() const | - | ||||||||||||||||||
| 8912 | - | |||||||||||||||||||
| 8913 | Returns a pointer to the string referred to by the string reference, or | - | ||||||||||||||||||
| 8914 | 0 if it does not reference a string. | - | ||||||||||||||||||
| 8915 | - | |||||||||||||||||||
| 8916 | \sa unicode() | - | ||||||||||||||||||
| 8917 | */ | - | ||||||||||||||||||
| 8918 | - | |||||||||||||||||||
| 8919 | - | |||||||||||||||||||
| 8920 | /*! | - | ||||||||||||||||||
| 8921 | \fn const QChar *QStringRef::unicode() const | - | ||||||||||||||||||
| 8922 | - | |||||||||||||||||||
| 8923 | Returns a Unicode representation of the string reference. Since | - | ||||||||||||||||||
| 8924 | the data stems directly from the referenced string, it is not | - | ||||||||||||||||||
| 8925 | null-terminated unless the string reference includes the string's | - | ||||||||||||||||||
| 8926 | null terminator. | - | ||||||||||||||||||
| 8927 | - | |||||||||||||||||||
| 8928 | \sa string() | - | ||||||||||||||||||
| 8929 | */ | - | ||||||||||||||||||
| 8930 | - | |||||||||||||||||||
| 8931 | /*! | - | ||||||||||||||||||
| 8932 | \fn const QChar *QStringRef::data() const | - | ||||||||||||||||||
| 8933 | - | |||||||||||||||||||
| 8934 | Same as unicode(). | - | ||||||||||||||||||
| 8935 | */ | - | ||||||||||||||||||
| 8936 | - | |||||||||||||||||||
| 8937 | /*! | - | ||||||||||||||||||
| 8938 | \fn const QChar *QStringRef::begin() const | - | ||||||||||||||||||
| 8939 | \since 5.4 | - | ||||||||||||||||||
| 8940 | - | |||||||||||||||||||
| 8941 | Same as unicode(). | - | ||||||||||||||||||
| 8942 | */ | - | ||||||||||||||||||
| 8943 | - | |||||||||||||||||||
| 8944 | /*! | - | ||||||||||||||||||
| 8945 | \fn const QChar *QStringRef::cbegin() const | - | ||||||||||||||||||
| 8946 | \since 5.4 | - | ||||||||||||||||||
| 8947 | - | |||||||||||||||||||
| 8948 | Same as unicode(). | - | ||||||||||||||||||
| 8949 | */ | - | ||||||||||||||||||
| 8950 | - | |||||||||||||||||||
| 8951 | /*! | - | ||||||||||||||||||
| 8952 | \fn const QChar *QStringRef::end() const | - | ||||||||||||||||||
| 8953 | \since 5.4 | - | ||||||||||||||||||
| 8954 | - | |||||||||||||||||||
| 8955 | Returns a pointer to one character past the last one in this string. | - | ||||||||||||||||||
| 8956 | (It is the same as \c {unicode() + size()}.) | - | ||||||||||||||||||
| 8957 | */ | - | ||||||||||||||||||
| 8958 | - | |||||||||||||||||||
| 8959 | /*! | - | ||||||||||||||||||
| 8960 | \fn const QChar *QStringRef::cend() const | - | ||||||||||||||||||
| 8961 | \since 5.4 | - | ||||||||||||||||||
| 8962 | - | |||||||||||||||||||
| 8963 | Returns a pointer to one character past the last one in this string. | - | ||||||||||||||||||
| 8964 | (It is the same as \c {unicode() + size()}.) | - | ||||||||||||||||||
| 8965 | */ | - | ||||||||||||||||||
| 8966 | - | |||||||||||||||||||
| 8967 | /*! | - | ||||||||||||||||||
| 8968 | \fn const QChar *QStringRef::constData() const | - | ||||||||||||||||||
| 8969 | - | |||||||||||||||||||
| 8970 | Same as unicode(). | - | ||||||||||||||||||
| 8971 | */ | - | ||||||||||||||||||
| 8972 | - | |||||||||||||||||||
| 8973 | /*! | - | ||||||||||||||||||
| 8974 | Returns a copy of the string reference as a QString object. | - | ||||||||||||||||||
| 8975 | - | |||||||||||||||||||
| 8976 | If the string reference is not a complete reference of the string | - | ||||||||||||||||||
| 8977 | (meaning that position() is 0 and size() equals string()->size()), | - | ||||||||||||||||||
| 8978 | this function will allocate a new string to return. | - | ||||||||||||||||||
| 8979 | - | |||||||||||||||||||
| 8980 | \sa string() | - | ||||||||||||||||||
| 8981 | */ | - | ||||||||||||||||||
| 8982 | - | |||||||||||||||||||
| 8983 | QString QStringRef::toString() const { | - | ||||||||||||||||||
| 8984 | if (!m_string)
| 17923-239563 | ||||||||||||||||||
| 8985 | return QString(); executed 17923 times by 16 tests: return QString();Executed by:
| 17923 | ||||||||||||||||||
| 8986 | if (m_size && m_position == 0 && m_size == m_string->size())
| 81-239482 | ||||||||||||||||||
| 8987 | return *m_string; executed 31905 times by 30 tests: return *m_string;Executed by:
| 31905 | ||||||||||||||||||
| 8988 | return QString(m_string->unicode() + m_position, m_size); executed 207658 times by 30 tests: return QString(m_string->unicode() + m_position, m_size);Executed by:
| 207658 | ||||||||||||||||||
| 8989 | } | - | ||||||||||||||||||
| 8990 | - | |||||||||||||||||||
| 8991 | - | |||||||||||||||||||
| 8992 | /*! \relates QStringRef | - | ||||||||||||||||||
| 8993 | - | |||||||||||||||||||
| 8994 | Returns \c true if string reference \a s1 is lexically equal to string reference \a s2; otherwise | - | ||||||||||||||||||
| 8995 | returns \c false. | - | ||||||||||||||||||
| 8996 | */ | - | ||||||||||||||||||
| 8997 | bool operator==(const QStringRef &s1,const QStringRef &s2) | - | ||||||||||||||||||
| 8998 | { executed 2052076 times by 24 tests: return (s1.size() == s2.size() && qMemEquals((const ushort *)s1.unicode(), (const ushort *)s2.unicode(), s1.size()));Executed by:
executed 2052076 times by 24 tests: return (s1.size() == s2.size() && qMemEquals((const ushort *)s1.unicode(), (const ushort *)s2.unicode(), s1.size()));Executed by:
| 637293-2052076 | ||||||||||||||||||
| 8999 | qMemEquals((const ushort *)s1.unicode(), (const ushort *)s2.unicode(), s1.size())); executed 2052076 times by 24 tests: return (s1.size() == s2.size() && qMemEquals((const ushort *)s1.unicode(), (const ushort *)s2.unicode(), s1.size()));Executed by:
| 113133-2052076 | ||||||||||||||||||
| 9000 | } | - | ||||||||||||||||||
| 9001 | - | |||||||||||||||||||
| 9002 | /*! \relates QStringRef | - | ||||||||||||||||||
| 9003 | - | |||||||||||||||||||
| 9004 | Returns \c true if string \a s1 is lexically equal to string reference \a s2; otherwise | - | ||||||||||||||||||
| 9005 | returns \c false. | - | ||||||||||||||||||
| 9006 | */ | - | ||||||||||||||||||
| 9007 | bool operator==(const QString &s1,const QStringRef &s2) | - | ||||||||||||||||||
| 9008 | { executed 288268 times by 118 tests: return (s1.size() == s2.size() && qMemEquals((const ushort *)s1.unicode(), (const ushort *)s2.unicode(), s1.size()));Executed by:
executed 288268 times by 118 tests: return (s1.size() == s2.size() && qMemEquals((const ushort *)s1.unicode(), (const ushort *)s2.unicode(), s1.size()));Executed by:
| 5572-288268 | ||||||||||||||||||
| 9009 | qMemEquals((const ushort *)s1.unicode(), (const ushort *)s2.unicode(), s1.size())); executed 288268 times by 118 tests: return (s1.size() == s2.size() && qMemEquals((const ushort *)s1.unicode(), (const ushort *)s2.unicode(), s1.size()));Executed by:
| 375-288268 | ||||||||||||||||||
| 9010 | } | - | ||||||||||||||||||
| 9011 | - | |||||||||||||||||||
| 9012 | /*! \relates QStringRef | - | ||||||||||||||||||
| 9013 | - | |||||||||||||||||||
| 9014 | Returns \c true if string \a s1 is lexically equal to string reference \a s2; otherwise | - | ||||||||||||||||||
| 9015 | returns \c false. | - | ||||||||||||||||||
| 9016 | */ | - | ||||||||||||||||||
| 9017 | bool operator==(QLatin1String s1, const QStringRef &s2) | - | ||||||||||||||||||
| 9018 | { | - | ||||||||||||||||||
| 9019 | if (s1.size() != s2.size())
| 408352-698948 | ||||||||||||||||||
| 9020 | return false; executed 698948 times by 21 tests: return false;Executed by:
| 698948 | ||||||||||||||||||
| 9021 | - | |||||||||||||||||||
| 9022 | const uchar *c = reinterpret_cast<const uchar *>(s1.latin1()); | - | ||||||||||||||||||
| 9023 | if (!c)
| 0-408352 | ||||||||||||||||||
| 9024 | return s2.isEmpty(); never executed: return s2.isEmpty(); | 0 | ||||||||||||||||||
| 9025 | return ucstrncmp(s2.unicode(), c, s2.size()) == 0; executed 408352 times by 36 tests: return ucstrncmp(s2.unicode(), c, s2.size()) == 0;Executed by:
| 408352 | ||||||||||||||||||
| 9026 | } | - | ||||||||||||||||||
| 9027 | - | |||||||||||||||||||
| 9028 | /*! | - | ||||||||||||||||||
| 9029 | \relates QStringRef | - | ||||||||||||||||||
| 9030 | - | |||||||||||||||||||
| 9031 | Returns \c true if string reference \a s1 is lexically less than | - | ||||||||||||||||||
| 9032 | string reference \a s2; otherwise returns \c false. | - | ||||||||||||||||||
| 9033 | - | |||||||||||||||||||
| 9034 | The comparison is based exclusively on the numeric Unicode values | - | ||||||||||||||||||
| 9035 | of the characters and is very fast, but is not what a human would | - | ||||||||||||||||||
| 9036 | expect. Consider sorting user-interface strings using the | - | ||||||||||||||||||
| 9037 | QString::localeAwareCompare() function. | - | ||||||||||||||||||
| 9038 | */ | - | ||||||||||||||||||
| 9039 | bool operator<(const QStringRef &s1,const QStringRef &s2) | - | ||||||||||||||||||
| 9040 | { | - | ||||||||||||||||||
| 9041 | return ucstrcmp(s1.constData(), s1.length(), s2.constData(), s2.length()) < 0; executed 2981 times by 14 tests: return ucstrcmp(s1.constData(), s1.length(), s2.constData(), s2.length()) < 0;Executed by:
| 2981 | ||||||||||||||||||
| 9042 | } | - | ||||||||||||||||||
| 9043 | - | |||||||||||||||||||
| 9044 | /*!\fn bool operator<=(const QStringRef &s1,const QStringRef &s2) | - | ||||||||||||||||||
| 9045 | - | |||||||||||||||||||
| 9046 | \relates QStringRef | - | ||||||||||||||||||
| 9047 | - | |||||||||||||||||||
| 9048 | Returns \c true if string reference \a s1 is lexically less than | - | ||||||||||||||||||
| 9049 | or equal to string reference \a s2; otherwise returns \c false. | - | ||||||||||||||||||
| 9050 | - | |||||||||||||||||||
| 9051 | The comparison is based exclusively on the numeric Unicode values | - | ||||||||||||||||||
| 9052 | of the characters and is very fast, but is not what a human would | - | ||||||||||||||||||
| 9053 | expect. Consider sorting user-interface strings using the | - | ||||||||||||||||||
| 9054 | QString::localeAwareCompare() function. | - | ||||||||||||||||||
| 9055 | */ | - | ||||||||||||||||||
| 9056 | - | |||||||||||||||||||
| 9057 | /*!\fn bool operator>=(const QStringRef &s1,const QStringRef &s2) | - | ||||||||||||||||||
| 9058 | - | |||||||||||||||||||
| 9059 | \relates QStringRef | - | ||||||||||||||||||
| 9060 | - | |||||||||||||||||||
| 9061 | Returns \c true if string reference \a s1 is lexically greater than | - | ||||||||||||||||||
| 9062 | or equal to string reference \a s2; otherwise returns \c false. | - | ||||||||||||||||||
| 9063 | - | |||||||||||||||||||
| 9064 | The comparison is based exclusively on the numeric Unicode values | - | ||||||||||||||||||
| 9065 | of the characters and is very fast, but is not what a human would | - | ||||||||||||||||||
| 9066 | expect. Consider sorting user-interface strings using the | - | ||||||||||||||||||
| 9067 | QString::localeAwareCompare() function. | - | ||||||||||||||||||
| 9068 | */ | - | ||||||||||||||||||
| 9069 | - | |||||||||||||||||||
| 9070 | /*!\fn bool operator>(const QStringRef &s1,const QStringRef &s2) | - | ||||||||||||||||||
| 9071 | - | |||||||||||||||||||
| 9072 | \relates QStringRef | - | ||||||||||||||||||
| 9073 | - | |||||||||||||||||||
| 9074 | Returns \c true if string reference \a s1 is lexically greater than | - | ||||||||||||||||||
| 9075 | string reference \a s2; otherwise returns \c false. | - | ||||||||||||||||||
| 9076 | - | |||||||||||||||||||
| 9077 | The comparison is based exclusively on the numeric Unicode values | - | ||||||||||||||||||
| 9078 | of the characters and is very fast, but is not what a human would | - | ||||||||||||||||||
| 9079 | expect. Consider sorting user-interface strings using the | - | ||||||||||||||||||
| 9080 | QString::localeAwareCompare() function. | - | ||||||||||||||||||
| 9081 | */ | - | ||||||||||||||||||
| 9082 | - | |||||||||||||||||||
| 9083 | - | |||||||||||||||||||
| 9084 | /*! | - | ||||||||||||||||||
| 9085 | \fn const QChar QStringRef::at(int position) const | - | ||||||||||||||||||
| 9086 | - | |||||||||||||||||||
| 9087 | Returns the character at the given index \a position in the | - | ||||||||||||||||||
| 9088 | string reference. | - | ||||||||||||||||||
| 9089 | - | |||||||||||||||||||
| 9090 | The \a position must be a valid index position in the string | - | ||||||||||||||||||
| 9091 | (i.e., 0 <= \a position < size()). | - | ||||||||||||||||||
| 9092 | */ | - | ||||||||||||||||||
| 9093 | - | |||||||||||||||||||
| 9094 | /*! | - | ||||||||||||||||||
| 9095 | \fn void QStringRef::clear() | - | ||||||||||||||||||
| 9096 | - | |||||||||||||||||||
| 9097 | Clears the contents of the string reference by making it null and empty. | - | ||||||||||||||||||
| 9098 | - | |||||||||||||||||||
| 9099 | \sa isEmpty(), isNull() | - | ||||||||||||||||||
| 9100 | */ | - | ||||||||||||||||||
| 9101 | - | |||||||||||||||||||
| 9102 | /*! | - | ||||||||||||||||||
| 9103 | \fn QStringRef &QStringRef::operator=(const QStringRef &other) | - | ||||||||||||||||||
| 9104 | - | |||||||||||||||||||
| 9105 | Assigns the \a other string reference to this string reference, and | - | ||||||||||||||||||
| 9106 | returns the result. | - | ||||||||||||||||||
| 9107 | */ | - | ||||||||||||||||||
| 9108 | - | |||||||||||||||||||
| 9109 | /*! | - | ||||||||||||||||||
| 9110 | \fn QStringRef &QStringRef::operator=(const QString *string) | - | ||||||||||||||||||
| 9111 | - | |||||||||||||||||||
| 9112 | Constructs a string reference to the given \a string and assigns it to | - | ||||||||||||||||||
| 9113 | this string reference, returning the result. | - | ||||||||||||||||||
| 9114 | */ | - | ||||||||||||||||||
| 9115 | - | |||||||||||||||||||
| 9116 | /*! | - | ||||||||||||||||||
| 9117 | \fn bool QStringRef::operator==(const char * s) const | - | ||||||||||||||||||
| 9118 | - | |||||||||||||||||||
| 9119 | \overload operator==() | - | ||||||||||||||||||
| 9120 | - | |||||||||||||||||||
| 9121 | The \a s byte array is converted to a QStringRef using the | - | ||||||||||||||||||
| 9122 | fromUtf8() function. This function stops conversion at the | - | ||||||||||||||||||
| 9123 | first NUL character found, or the end of the byte array. | - | ||||||||||||||||||
| 9124 | - | |||||||||||||||||||
| 9125 | You can disable this operator by defining \c | - | ||||||||||||||||||
| 9126 | QT_NO_CAST_FROM_ASCII when you compile your applications. This | - | ||||||||||||||||||
| 9127 | can be useful if you want to ensure that all user-visible strings | - | ||||||||||||||||||
| 9128 | go through QObject::tr(), for example. | - | ||||||||||||||||||
| 9129 | - | |||||||||||||||||||
| 9130 | Returns \c true if this string is lexically equal to the parameter | - | ||||||||||||||||||
| 9131 | string \a s. Otherwise returns \c false. | - | ||||||||||||||||||
| 9132 | - | |||||||||||||||||||
| 9133 | */ | - | ||||||||||||||||||
| 9134 | - | |||||||||||||||||||
| 9135 | /*! | - | ||||||||||||||||||
| 9136 | \fn bool QStringRef::operator!=(const char * s) const | - | ||||||||||||||||||
| 9137 | - | |||||||||||||||||||
| 9138 | \overload operator!=() | - | ||||||||||||||||||
| 9139 | - | |||||||||||||||||||
| 9140 | The \a s const char pointer is converted to a QStringRef using | - | ||||||||||||||||||
| 9141 | the fromUtf8() function. | - | ||||||||||||||||||
| 9142 | - | |||||||||||||||||||
| 9143 | You can disable this operator by defining \c | - | ||||||||||||||||||
| 9144 | QT_NO_CAST_FROM_ASCII when you compile your applications. This | - | ||||||||||||||||||
| 9145 | can be useful if you want to ensure that all user-visible strings | - | ||||||||||||||||||
| 9146 | go through QObject::tr(), for example. | - | ||||||||||||||||||
| 9147 | - | |||||||||||||||||||
| 9148 | Returns \c true if this string is not lexically equal to the parameter | - | ||||||||||||||||||
| 9149 | string \a s. Otherwise returns \c false. | - | ||||||||||||||||||
| 9150 | */ | - | ||||||||||||||||||
| 9151 | - | |||||||||||||||||||
| 9152 | /*! | - | ||||||||||||||||||
| 9153 | \fn bool QStringRef::operator<(const char * s) const | - | ||||||||||||||||||
| 9154 | - | |||||||||||||||||||
| 9155 | \overload operator<() | - | ||||||||||||||||||
| 9156 | - | |||||||||||||||||||
| 9157 | The \a s const char pointer is converted to a QStringRef using | - | ||||||||||||||||||
| 9158 | the fromUtf8() function. | - | ||||||||||||||||||
| 9159 | - | |||||||||||||||||||
| 9160 | You can disable this operator by defining \c | - | ||||||||||||||||||
| 9161 | QT_NO_CAST_FROM_ASCII when you compile your applications. This | - | ||||||||||||||||||
| 9162 | can be useful if you want to ensure that all user-visible strings | - | ||||||||||||||||||
| 9163 | go through QObject::tr(), for example. | - | ||||||||||||||||||
| 9164 | - | |||||||||||||||||||
| 9165 | Returns \c true if this string is lexically smaller than the parameter | - | ||||||||||||||||||
| 9166 | string \a s. Otherwise returns \c false. | - | ||||||||||||||||||
| 9167 | */ | - | ||||||||||||||||||
| 9168 | - | |||||||||||||||||||
| 9169 | /*! | - | ||||||||||||||||||
| 9170 | \fn bool QStringRef::operator<=(const char * s) const | - | ||||||||||||||||||
| 9171 | - | |||||||||||||||||||
| 9172 | \overload operator<=() | - | ||||||||||||||||||
| 9173 | - | |||||||||||||||||||
| 9174 | The \a s const char pointer is converted to a QStringRef using | - | ||||||||||||||||||
| 9175 | the fromUtf8() function. | - | ||||||||||||||||||
| 9176 | - | |||||||||||||||||||
| 9177 | You can disable this operator by defining \c | - | ||||||||||||||||||
| 9178 | QT_NO_CAST_FROM_ASCII when you compile your applications. This | - | ||||||||||||||||||
| 9179 | can be useful if you want to ensure that all user-visible strings | - | ||||||||||||||||||
| 9180 | go through QObject::tr(), for example. | - | ||||||||||||||||||
| 9181 | - | |||||||||||||||||||
| 9182 | Returns \c true if this string is lexically smaller than or equal to the parameter | - | ||||||||||||||||||
| 9183 | string \a s. Otherwise returns \c false. | - | ||||||||||||||||||
| 9184 | */ | - | ||||||||||||||||||
| 9185 | - | |||||||||||||||||||
| 9186 | /*! | - | ||||||||||||||||||
| 9187 | \fn bool QStringRef::operator>(const char * s) const | - | ||||||||||||||||||
| 9188 | - | |||||||||||||||||||
| 9189 | - | |||||||||||||||||||
| 9190 | \overload operator>() | - | ||||||||||||||||||
| 9191 | - | |||||||||||||||||||
| 9192 | The \a s const char pointer is converted to a QStringRef using | - | ||||||||||||||||||
| 9193 | the fromUtf8() function. | - | ||||||||||||||||||
| 9194 | - | |||||||||||||||||||
| 9195 | You can disable this operator by defining \c | - | ||||||||||||||||||
| 9196 | QT_NO_CAST_FROM_ASCII when you compile your applications. This | - | ||||||||||||||||||
| 9197 | can be useful if you want to ensure that all user-visible strings | - | ||||||||||||||||||
| 9198 | go through QObject::tr(), for example. | - | ||||||||||||||||||
| 9199 | - | |||||||||||||||||||
| 9200 | Returns \c true if this string is lexically greater than the parameter | - | ||||||||||||||||||
| 9201 | string \a s. Otherwise returns \c false. | - | ||||||||||||||||||
| 9202 | */ | - | ||||||||||||||||||
| 9203 | - | |||||||||||||||||||
| 9204 | /*! | - | ||||||||||||||||||
| 9205 | \fn bool QStringRef::operator>= (const char * s) const | - | ||||||||||||||||||
| 9206 | - | |||||||||||||||||||
| 9207 | \overload operator>=() | - | ||||||||||||||||||
| 9208 | - | |||||||||||||||||||
| 9209 | The \a s const char pointer is converted to a QStringRef using | - | ||||||||||||||||||
| 9210 | the fromUtf8() function. | - | ||||||||||||||||||
| 9211 | - | |||||||||||||||||||
| 9212 | You can disable this operator by defining \c | - | ||||||||||||||||||
| 9213 | QT_NO_CAST_FROM_ASCII when you compile your applications. This | - | ||||||||||||||||||
| 9214 | can be useful if you want to ensure that all user-visible strings | - | ||||||||||||||||||
| 9215 | go through QObject::tr(), for example. | - | ||||||||||||||||||
| 9216 | - | |||||||||||||||||||
| 9217 | Returns \c true if this string is lexically greater than or equal to the | - | ||||||||||||||||||
| 9218 | parameter string \a s. Otherwise returns \c false. | - | ||||||||||||||||||
| 9219 | */ | - | ||||||||||||||||||
| 9220 | /*! | - | ||||||||||||||||||
| 9221 | \typedef QString::Data | - | ||||||||||||||||||
| 9222 | \internal | - | ||||||||||||||||||
| 9223 | */ | - | ||||||||||||||||||
| 9224 | - | |||||||||||||||||||
| 9225 | /*! | - | ||||||||||||||||||
| 9226 | \typedef QString::DataPtr | - | ||||||||||||||||||
| 9227 | \internal | - | ||||||||||||||||||
| 9228 | */ | - | ||||||||||||||||||
| 9229 | - | |||||||||||||||||||
| 9230 | /*! | - | ||||||||||||||||||
| 9231 | \fn DataPtr & QString::data_ptr() | - | ||||||||||||||||||
| 9232 | \internal | - | ||||||||||||||||||
| 9233 | */ | - | ||||||||||||||||||
| 9234 | - | |||||||||||||||||||
| 9235 | - | |||||||||||||||||||
| 9236 | - | |||||||||||||||||||
| 9237 | /*! Appends the string reference to \a string, and returns a new | - | ||||||||||||||||||
| 9238 | reference to the combined string data. | - | ||||||||||||||||||
| 9239 | */ | - | ||||||||||||||||||
| 9240 | QStringRef QStringRef::appendTo(QString *string) const | - | ||||||||||||||||||
| 9241 | { | - | ||||||||||||||||||
| 9242 | if (!string)
| 0-8 | ||||||||||||||||||
| 9243 | return QStringRef(); never executed: return QStringRef(); | 0 | ||||||||||||||||||
| 9244 | int pos = string->size(); | - | ||||||||||||||||||
| 9245 | string->insert(pos, unicode(), size()); | - | ||||||||||||||||||
| 9246 | return QStringRef(string, pos, size()); executed 8 times by 1 test: return QStringRef(string, pos, size());Executed by:
| 8 | ||||||||||||||||||
| 9247 | } | - | ||||||||||||||||||
| 9248 | - | |||||||||||||||||||
| 9249 | /*! | - | ||||||||||||||||||
| 9250 | \fn int QStringRef::compare(const QStringRef &s1, const QString &s2, Qt::CaseSensitivity cs = Qt::CaseSensitive) | - | ||||||||||||||||||
| 9251 | \since 4.5 | - | ||||||||||||||||||
| 9252 | - | |||||||||||||||||||
| 9253 | Compares the string \a s1 with the string \a s2 and returns an | - | ||||||||||||||||||
| 9254 | integer less than, equal to, or greater than zero if \a s1 | - | ||||||||||||||||||
| 9255 | is less than, equal to, or greater than \a s2. | - | ||||||||||||||||||
| 9256 | - | |||||||||||||||||||
| 9257 | If \a cs is Qt::CaseSensitive, the comparison is case sensitive; | - | ||||||||||||||||||
| 9258 | otherwise the comparison is case insensitive. | - | ||||||||||||||||||
| 9259 | */ | - | ||||||||||||||||||
| 9260 | - | |||||||||||||||||||
| 9261 | /*! | - | ||||||||||||||||||
| 9262 | \fn int QStringRef::compare(const QStringRef &s1, const QStringRef &s2, Qt::CaseSensitivity cs = Qt::CaseSensitive) | - | ||||||||||||||||||
| 9263 | \since 4.5 | - | ||||||||||||||||||
| 9264 | \overload | - | ||||||||||||||||||
| 9265 | - | |||||||||||||||||||
| 9266 | Compares the string \a s1 with the string \a s2 and returns an | - | ||||||||||||||||||
| 9267 | integer less than, equal to, or greater than zero if \a s1 | - | ||||||||||||||||||
| 9268 | is less than, equal to, or greater than \a s2. | - | ||||||||||||||||||
| 9269 | - | |||||||||||||||||||
| 9270 | If \a cs is Qt::CaseSensitive, the comparison is case sensitive; | - | ||||||||||||||||||
| 9271 | otherwise the comparison is case insensitive. | - | ||||||||||||||||||
| 9272 | */ | - | ||||||||||||||||||
| 9273 | - | |||||||||||||||||||
| 9274 | /*! | - | ||||||||||||||||||
| 9275 | \fn int QStringRef::compare(const QStringRef &s1, QLatin1String s2, Qt::CaseSensitivity cs = Qt::CaseSensitive) | - | ||||||||||||||||||
| 9276 | \since 4.5 | - | ||||||||||||||||||
| 9277 | \overload | - | ||||||||||||||||||
| 9278 | - | |||||||||||||||||||
| 9279 | Compares the string \a s1 with the string \a s2 and returns an | - | ||||||||||||||||||
| 9280 | integer less than, equal to, or greater than zero if \a s1 | - | ||||||||||||||||||
| 9281 | is less than, equal to, or greater than \a s2. | - | ||||||||||||||||||
| 9282 | - | |||||||||||||||||||
| 9283 | If \a cs is Qt::CaseSensitive, the comparison is case sensitive; | - | ||||||||||||||||||
| 9284 | otherwise the comparison is case insensitive. | - | ||||||||||||||||||
| 9285 | */ | - | ||||||||||||||||||
| 9286 | - | |||||||||||||||||||
| 9287 | /*! | - | ||||||||||||||||||
| 9288 | \overload | - | ||||||||||||||||||
| 9289 | \fn int QStringRef::compare(const QString &other, Qt::CaseSensitivity cs = Qt::CaseSensitive) const | - | ||||||||||||||||||
| 9290 | \since 4.5 | - | ||||||||||||||||||
| 9291 | - | |||||||||||||||||||
| 9292 | Compares this string with the \a other string and returns an | - | ||||||||||||||||||
| 9293 | integer less than, equal to, or greater than zero if this string | - | ||||||||||||||||||
| 9294 | is less than, equal to, or greater than the \a other string. | - | ||||||||||||||||||
| 9295 | - | |||||||||||||||||||
| 9296 | If \a cs is Qt::CaseSensitive, the comparison is case sensitive; | - | ||||||||||||||||||
| 9297 | otherwise the comparison is case insensitive. | - | ||||||||||||||||||
| 9298 | - | |||||||||||||||||||
| 9299 | Equivalent to \c {compare(*this, other, cs)}. | - | ||||||||||||||||||
| 9300 | - | |||||||||||||||||||
| 9301 | \sa QString::compare() | - | ||||||||||||||||||
| 9302 | */ | - | ||||||||||||||||||
| 9303 | - | |||||||||||||||||||
| 9304 | /*! | - | ||||||||||||||||||
| 9305 | \overload | - | ||||||||||||||||||
| 9306 | \fn int QStringRef::compare(const QStringRef &other, Qt::CaseSensitivity cs = Qt::CaseSensitive) const | - | ||||||||||||||||||
| 9307 | \since 4.5 | - | ||||||||||||||||||
| 9308 | - | |||||||||||||||||||
| 9309 | Compares this string with the \a other string and returns an | - | ||||||||||||||||||
| 9310 | integer less than, equal to, or greater than zero if this string | - | ||||||||||||||||||
| 9311 | is less than, equal to, or greater than the \a other string. | - | ||||||||||||||||||
| 9312 | - | |||||||||||||||||||
| 9313 | If \a cs is Qt::CaseSensitive, the comparison is case sensitive; | - | ||||||||||||||||||
| 9314 | otherwise the comparison is case insensitive. | - | ||||||||||||||||||
| 9315 | - | |||||||||||||||||||
| 9316 | Equivalent to \c {compare(*this, other, cs)}. | - | ||||||||||||||||||
| 9317 | - | |||||||||||||||||||
| 9318 | \sa QString::compare() | - | ||||||||||||||||||
| 9319 | */ | - | ||||||||||||||||||
| 9320 | - | |||||||||||||||||||
| 9321 | /*! | - | ||||||||||||||||||
| 9322 | \overload | - | ||||||||||||||||||
| 9323 | \fn int QStringRef::compare(QLatin1String other, Qt::CaseSensitivity cs = Qt::CaseSensitive) const | - | ||||||||||||||||||
| 9324 | \since 4.5 | - | ||||||||||||||||||
| 9325 | - | |||||||||||||||||||
| 9326 | Compares this string with the \a other string and returns an | - | ||||||||||||||||||
| 9327 | integer less than, equal to, or greater than zero if this string | - | ||||||||||||||||||
| 9328 | is less than, equal to, or greater than the \a other string. | - | ||||||||||||||||||
| 9329 | - | |||||||||||||||||||
| 9330 | If \a cs is Qt::CaseSensitive, the comparison is case sensitive; | - | ||||||||||||||||||
| 9331 | otherwise the comparison is case insensitive. | - | ||||||||||||||||||
| 9332 | - | |||||||||||||||||||
| 9333 | Equivalent to \c {compare(*this, other, cs)}. | - | ||||||||||||||||||
| 9334 | - | |||||||||||||||||||
| 9335 | \sa QString::compare() | - | ||||||||||||||||||
| 9336 | */ | - | ||||||||||||||||||
| 9337 | - | |||||||||||||||||||
| 9338 | /*! | - | ||||||||||||||||||
| 9339 | \fn int QStringRef::localeAwareCompare(const QStringRef &s1, const QString & s2) | - | ||||||||||||||||||
| 9340 | \since 4.5 | - | ||||||||||||||||||
| 9341 | - | |||||||||||||||||||
| 9342 | Compares \a s1 with \a s2 and returns an integer less than, equal | - | ||||||||||||||||||
| 9343 | to, or greater than zero if \a s1 is less than, equal to, or | - | ||||||||||||||||||
| 9344 | greater than \a s2. | - | ||||||||||||||||||
| 9345 | - | |||||||||||||||||||
| 9346 | The comparison is performed in a locale- and also | - | ||||||||||||||||||
| 9347 | platform-dependent manner. Use this function to present sorted | - | ||||||||||||||||||
| 9348 | lists of strings to the user. | - | ||||||||||||||||||
| 9349 | - | |||||||||||||||||||
| 9350 | On \macos and iOS, this function compares according the | - | ||||||||||||||||||
| 9351 | "Order for sorted lists" setting in the International prefereces panel. | - | ||||||||||||||||||
| 9352 | - | |||||||||||||||||||
| 9353 | \sa compare(), QLocale | - | ||||||||||||||||||
| 9354 | */ | - | ||||||||||||||||||
| 9355 | - | |||||||||||||||||||
| 9356 | /*! | - | ||||||||||||||||||
| 9357 | \fn int QStringRef::localeAwareCompare(const QStringRef &s1, const QStringRef & s2) | - | ||||||||||||||||||
| 9358 | \since 4.5 | - | ||||||||||||||||||
| 9359 | \overload | - | ||||||||||||||||||
| 9360 | - | |||||||||||||||||||
| 9361 | Compares \a s1 with \a s2 and returns an integer less than, equal | - | ||||||||||||||||||
| 9362 | to, or greater than zero if \a s1 is less than, equal to, or | - | ||||||||||||||||||
| 9363 | greater than \a s2. | - | ||||||||||||||||||
| 9364 | - | |||||||||||||||||||
| 9365 | The comparison is performed in a locale- and also | - | ||||||||||||||||||
| 9366 | platform-dependent manner. Use this function to present sorted | - | ||||||||||||||||||
| 9367 | lists of strings to the user. | - | ||||||||||||||||||
| 9368 | - | |||||||||||||||||||
| 9369 | */ | - | ||||||||||||||||||
| 9370 | - | |||||||||||||||||||
| 9371 | /*! | - | ||||||||||||||||||
| 9372 | \fn int QStringRef::localeAwareCompare(const QString &other) const | - | ||||||||||||||||||
| 9373 | \since 4.5 | - | ||||||||||||||||||
| 9374 | \overload | - | ||||||||||||||||||
| 9375 | - | |||||||||||||||||||
| 9376 | Compares this string with the \a other string and returns an | - | ||||||||||||||||||
| 9377 | integer less than, equal to, or greater than zero if this string | - | ||||||||||||||||||
| 9378 | is less than, equal to, or greater than the \a other string. | - | ||||||||||||||||||
| 9379 | - | |||||||||||||||||||
| 9380 | The comparison is performed in a locale- and also | - | ||||||||||||||||||
| 9381 | platform-dependent manner. Use this function to present sorted | - | ||||||||||||||||||
| 9382 | lists of strings to the user. | - | ||||||||||||||||||
| 9383 | */ | - | ||||||||||||||||||
| 9384 | - | |||||||||||||||||||
| 9385 | /*! | - | ||||||||||||||||||
| 9386 | \fn int QStringRef::localeAwareCompare(const QStringRef &other) const | - | ||||||||||||||||||
| 9387 | \since 4.5 | - | ||||||||||||||||||
| 9388 | \overload | - | ||||||||||||||||||
| 9389 | - | |||||||||||||||||||
| 9390 | Compares this string with the \a other string and returns an | - | ||||||||||||||||||
| 9391 | integer less than, equal to, or greater than zero if this string | - | ||||||||||||||||||
| 9392 | is less than, equal to, or greater than the \a other string. | - | ||||||||||||||||||
| 9393 | - | |||||||||||||||||||
| 9394 | The comparison is performed in a locale- and also | - | ||||||||||||||||||
| 9395 | platform-dependent manner. Use this function to present sorted | - | ||||||||||||||||||
| 9396 | lists of strings to the user. | - | ||||||||||||||||||
| 9397 | */ | - | ||||||||||||||||||
| 9398 | - | |||||||||||||||||||
| 9399 | /*! | - | ||||||||||||||||||
| 9400 | \fn QString &QString::append(const QStringRef &reference) | - | ||||||||||||||||||
| 9401 | \since 4.4 | - | ||||||||||||||||||
| 9402 | - | |||||||||||||||||||
| 9403 | Appends the given string \a reference to this string and returns the result. | - | ||||||||||||||||||
| 9404 | */ | - | ||||||||||||||||||
| 9405 | QString &QString::append(const QStringRef &str) | - | ||||||||||||||||||
| 9406 | { | - | ||||||||||||||||||
| 9407 | if (str.string() == this) {
| 0-2947 | ||||||||||||||||||
| 9408 | str.appendTo(this); | - | ||||||||||||||||||
| 9409 | } else if (!str.isNull()) { never executed: end of block
| 0-2941 | ||||||||||||||||||
| 9410 | int oldSize = size(); | - | ||||||||||||||||||
| 9411 | resize(oldSize + str.size()); | - | ||||||||||||||||||
| 9412 | memcpy(data() + oldSize, str.unicode(), str.size() * sizeof(QChar)); | - | ||||||||||||||||||
| 9413 | } executed 2941 times by 16 tests: end of blockExecuted by:
| 2941 | ||||||||||||||||||
| 9414 | return *this; executed 2947 times by 16 tests: return *this;Executed by:
| 2947 | ||||||||||||||||||
| 9415 | } | - | ||||||||||||||||||
| 9416 | - | |||||||||||||||||||
| 9417 | /*! | - | ||||||||||||||||||
| 9418 | \fn QStringRef::left(int n) const | - | ||||||||||||||||||
| 9419 | \since 5.2 | - | ||||||||||||||||||
| 9420 | - | |||||||||||||||||||
| 9421 | Returns a substring reference to the \a n leftmost characters | - | ||||||||||||||||||
| 9422 | of the string. | - | ||||||||||||||||||
| 9423 | - | |||||||||||||||||||
| 9424 | If \a n is greater than or equal to size(), or less than zero, | - | ||||||||||||||||||
| 9425 | a reference to the entire string is returned. | - | ||||||||||||||||||
| 9426 | - | |||||||||||||||||||
| 9427 | \sa right(), mid(), startsWith() | - | ||||||||||||||||||
| 9428 | */ | - | ||||||||||||||||||
| 9429 | QStringRef QStringRef::left(int n) const | - | ||||||||||||||||||
| 9430 | { | - | ||||||||||||||||||
| 9431 | if (uint(n) >= uint(m_size))
| 42-104 | ||||||||||||||||||
| 9432 | return *this; executed 42 times by 3 tests: return *this;Executed by:
| 42 | ||||||||||||||||||
| 9433 | return QStringRef(m_string, m_position, n); executed 104 times by 4 tests: return QStringRef(m_string, m_position, n);Executed by:
| 104 | ||||||||||||||||||
| 9434 | } | - | ||||||||||||||||||
| 9435 | - | |||||||||||||||||||
| 9436 | /*! | - | ||||||||||||||||||
| 9437 | \since 4.4 | - | ||||||||||||||||||
| 9438 | - | |||||||||||||||||||
| 9439 | Returns a substring reference to the \a n leftmost characters | - | ||||||||||||||||||
| 9440 | of the string. | - | ||||||||||||||||||
| 9441 | - | |||||||||||||||||||
| 9442 | If \a n is greater than or equal to size(), or less than zero, | - | ||||||||||||||||||
| 9443 | a reference to the entire string is returned. | - | ||||||||||||||||||
| 9444 | - | |||||||||||||||||||
| 9445 | \snippet qstring/main.cpp leftRef | - | ||||||||||||||||||
| 9446 | - | |||||||||||||||||||
| 9447 | \sa left(), rightRef(), midRef(), startsWith() | - | ||||||||||||||||||
| 9448 | */ | - | ||||||||||||||||||
| 9449 | QStringRef QString::leftRef(int n) const | - | ||||||||||||||||||
| 9450 | { | - | ||||||||||||||||||
| 9451 | if (uint(n) >= uint(d->size))
| 24211-49221 | ||||||||||||||||||
| 9452 | n = d->size; executed 49221 times by 7 tests: n = d->size;Executed by:
| 49221 | ||||||||||||||||||
| 9453 | return QStringRef(this, 0, n); executed 73432 times by 14 tests: return QStringRef(this, 0, n);Executed by:
| 73432 | ||||||||||||||||||
| 9454 | } | - | ||||||||||||||||||
| 9455 | - | |||||||||||||||||||
| 9456 | /*! | - | ||||||||||||||||||
| 9457 | \fn QStringRef::right(int n) const | - | ||||||||||||||||||
| 9458 | \since 5.2 | - | ||||||||||||||||||
| 9459 | - | |||||||||||||||||||
| 9460 | Returns a substring reference to the \a n rightmost characters | - | ||||||||||||||||||
| 9461 | of the string. | - | ||||||||||||||||||
| 9462 | - | |||||||||||||||||||
| 9463 | If \a n is greater than or equal to size(), or less than zero, | - | ||||||||||||||||||
| 9464 | a reference to the entire string is returned. | - | ||||||||||||||||||
| 9465 | - | |||||||||||||||||||
| 9466 | \sa left(), mid(), endsWith() | - | ||||||||||||||||||
| 9467 | */ | - | ||||||||||||||||||
| 9468 | QStringRef QStringRef::right(int n) const | - | ||||||||||||||||||
| 9469 | { | - | ||||||||||||||||||
| 9470 | if (uint(n) >= uint(m_size))
| 9-59 | ||||||||||||||||||
| 9471 | return *this; executed 9 times by 1 test: return *this;Executed by:
| 9 | ||||||||||||||||||
| 9472 | return QStringRef(m_string, m_size - n + m_position, n); executed 59 times by 5 tests: return QStringRef(m_string, m_size - n + m_position, n);Executed by:
| 59 | ||||||||||||||||||
| 9473 | } | - | ||||||||||||||||||
| 9474 | - | |||||||||||||||||||
| 9475 | /*! | - | ||||||||||||||||||
| 9476 | \since 4.4 | - | ||||||||||||||||||
| 9477 | - | |||||||||||||||||||
| 9478 | Returns a substring reference to the \a n rightmost characters | - | ||||||||||||||||||
| 9479 | of the string. | - | ||||||||||||||||||
| 9480 | - | |||||||||||||||||||
| 9481 | If \a n is greater than or equal to size(), or less than zero, | - | ||||||||||||||||||
| 9482 | a reference to the entire string is returned. | - | ||||||||||||||||||
| 9483 | - | |||||||||||||||||||
| 9484 | \snippet qstring/main.cpp rightRef | - | ||||||||||||||||||
| 9485 | - | |||||||||||||||||||
| 9486 | \sa right(), leftRef(), midRef(), endsWith() | - | ||||||||||||||||||
| 9487 | */ | - | ||||||||||||||||||
| 9488 | QStringRef QString::rightRef(int n) const | - | ||||||||||||||||||
| 9489 | { | - | ||||||||||||||||||
| 9490 | if (uint(n) >= uint(d->size))
| 5-462 | ||||||||||||||||||
| 9491 | n = d->size; executed 5 times by 2 tests: n = d->size;Executed by:
| 5 | ||||||||||||||||||
| 9492 | return QStringRef(this, d->size - n, n); executed 467 times by 16 tests: return QStringRef(this, d->size - n, n);Executed by:
| 467 | ||||||||||||||||||
| 9493 | } | - | ||||||||||||||||||
| 9494 | - | |||||||||||||||||||
| 9495 | /*! | - | ||||||||||||||||||
| 9496 | \fn QStringRef::mid(int position, int n = -1) const | - | ||||||||||||||||||
| 9497 | \since 5.2 | - | ||||||||||||||||||
| 9498 | - | |||||||||||||||||||
| 9499 | Returns a substring reference to \a n characters of this string, | - | ||||||||||||||||||
| 9500 | starting at the specified \a position. | - | ||||||||||||||||||
| 9501 | - | |||||||||||||||||||
| 9502 | If the \a position exceeds the length of the string, a null | - | ||||||||||||||||||
| 9503 | reference is returned. | - | ||||||||||||||||||
| 9504 | - | |||||||||||||||||||
| 9505 | If there are less than \a n characters available in the string, | - | ||||||||||||||||||
| 9506 | starting at the given \a position, or if \a n is -1 (default), the | - | ||||||||||||||||||
| 9507 | function returns all characters from the specified \a position | - | ||||||||||||||||||
| 9508 | onwards. | - | ||||||||||||||||||
| 9509 | - | |||||||||||||||||||
| 9510 | \sa left(), right() | - | ||||||||||||||||||
| 9511 | */ | - | ||||||||||||||||||
| 9512 | QStringRef QStringRef::mid(int pos, int n) const | - | ||||||||||||||||||
| 9513 | { | - | ||||||||||||||||||
| 9514 | using namespace QtPrivate; | - | ||||||||||||||||||
| 9515 | switch (QContainerImplHelper::mid(m_size, &pos, &n)) { | - | ||||||||||||||||||
| 9516 | case QContainerImplHelper::Null: executed 31 times by 2 tests: case QContainerImplHelper::Null:Executed by:
| 31 | ||||||||||||||||||
| 9517 | return QStringRef(); executed 31 times by 2 tests: return QStringRef();Executed by:
| 31 | ||||||||||||||||||
| 9518 | case QContainerImplHelper::Empty: executed 2255 times by 4 tests: case QContainerImplHelper::Empty:Executed by:
| 2255 | ||||||||||||||||||
| 9519 | return QStringRef(m_string, 0, 0); executed 2255 times by 4 tests: return QStringRef(m_string, 0, 0);Executed by:
| 2255 | ||||||||||||||||||
| 9520 | case QContainerImplHelper::Full: executed 301 times by 15 tests: case QContainerImplHelper::Full:Executed by:
| 301 | ||||||||||||||||||
| 9521 | return *this; executed 301 times by 15 tests: return *this;Executed by:
| 301 | ||||||||||||||||||
| 9522 | case QContainerImplHelper::Subset: executed 15958 times by 19 tests: case QContainerImplHelper::Subset:Executed by:
| 15958 | ||||||||||||||||||
| 9523 | return QStringRef(m_string, pos + m_position, n); executed 15958 times by 19 tests: return QStringRef(m_string, pos + m_position, n);Executed by:
| 15958 | ||||||||||||||||||
| 9524 | } | - | ||||||||||||||||||
| 9525 | Q_UNREACHABLE(); | - | ||||||||||||||||||
| 9526 | return QStringRef(); never executed: return QStringRef(); | 0 | ||||||||||||||||||
| 9527 | } | - | ||||||||||||||||||
| 9528 | - | |||||||||||||||||||
| 9529 | /*! | - | ||||||||||||||||||
| 9530 | \since 4.4 | - | ||||||||||||||||||
| 9531 | - | |||||||||||||||||||
| 9532 | Returns a substring reference to \a n characters of this string, | - | ||||||||||||||||||
| 9533 | starting at the specified \a position. | - | ||||||||||||||||||
| 9534 | - | |||||||||||||||||||
| 9535 | If the \a position exceeds the length of the string, a null | - | ||||||||||||||||||
| 9536 | reference is returned. | - | ||||||||||||||||||
| 9537 | - | |||||||||||||||||||
| 9538 | If there are less than \a n characters available in the string, | - | ||||||||||||||||||
| 9539 | starting at the given \a position, or if \a n is -1 (default), the | - | ||||||||||||||||||
| 9540 | function returns all characters from the specified \a position | - | ||||||||||||||||||
| 9541 | onwards. | - | ||||||||||||||||||
| 9542 | - | |||||||||||||||||||
| 9543 | Example: | - | ||||||||||||||||||
| 9544 | - | |||||||||||||||||||
| 9545 | \snippet qstring/main.cpp midRef | - | ||||||||||||||||||
| 9546 | - | |||||||||||||||||||
| 9547 | \sa mid(), leftRef(), rightRef() | - | ||||||||||||||||||
| 9548 | */ | - | ||||||||||||||||||
| 9549 | QStringRef QString::midRef(int position, int n) const | - | ||||||||||||||||||
| 9550 | { | - | ||||||||||||||||||
| 9551 | using namespace QtPrivate; | - | ||||||||||||||||||
| 9552 | switch (QContainerImplHelper::mid(d->size, &position, &n)) { | - | ||||||||||||||||||
| 9553 | case QContainerImplHelper::Null: executed 273 times by 2 tests: case QContainerImplHelper::Null:Executed by:
| 273 | ||||||||||||||||||
| 9554 | return QStringRef(); executed 273 times by 2 tests: return QStringRef();Executed by:
| 273 | ||||||||||||||||||
| 9555 | case QContainerImplHelper::Empty: executed 482 times by 5 tests: case QContainerImplHelper::Empty:Executed by:
| 482 | ||||||||||||||||||
| 9556 | return QStringRef(this, 0, 0); executed 482 times by 5 tests: return QStringRef(this, 0, 0);Executed by:
| 482 | ||||||||||||||||||
| 9557 | case QContainerImplHelper::Full: executed 33042 times by 36 tests: case QContainerImplHelper::Full:Executed by:
| 33042 | ||||||||||||||||||
| 9558 | return QStringRef(this, 0, d->size); executed 33042 times by 36 tests: return QStringRef(this, 0, d->size);Executed by:
| 33042 | ||||||||||||||||||
| 9559 | case QContainerImplHelper::Subset: executed 34011 times by 47 tests: case QContainerImplHelper::Subset:Executed by:
| 34011 | ||||||||||||||||||
| 9560 | return QStringRef(this, position, n); executed 34011 times by 47 tests: return QStringRef(this, position, n);Executed by:
| 34011 | ||||||||||||||||||
| 9561 | } | - | ||||||||||||||||||
| 9562 | Q_UNREACHABLE(); | - | ||||||||||||||||||
| 9563 | return QStringRef(); never executed: return QStringRef(); | 0 | ||||||||||||||||||
| 9564 | } | - | ||||||||||||||||||
| 9565 | - | |||||||||||||||||||
| 9566 | /*! | - | ||||||||||||||||||
| 9567 | \fn void QStringRef::truncate(int position) | - | ||||||||||||||||||
| 9568 | \since 5.6 | - | ||||||||||||||||||
| 9569 | - | |||||||||||||||||||
| 9570 | Truncates the string at the given \a position index. | - | ||||||||||||||||||
| 9571 | - | |||||||||||||||||||
| 9572 | If the specified \a position index is beyond the end of the | - | ||||||||||||||||||
| 9573 | string, nothing happens. | - | ||||||||||||||||||
| 9574 | - | |||||||||||||||||||
| 9575 | If \a position is negative, it is equivalent to passing zero. | - | ||||||||||||||||||
| 9576 | - | |||||||||||||||||||
| 9577 | \sa QString::truncate() | - | ||||||||||||||||||
| 9578 | */ | - | ||||||||||||||||||
| 9579 | - | |||||||||||||||||||
| 9580 | /*! | - | ||||||||||||||||||
| 9581 | \since 4.8 | - | ||||||||||||||||||
| 9582 | - | |||||||||||||||||||
| 9583 | Returns the index position of the first occurrence of the string \a | - | ||||||||||||||||||
| 9584 | str in this string reference, searching forward from index position | - | ||||||||||||||||||
| 9585 | \a from. Returns -1 if \a str is not found. | - | ||||||||||||||||||
| 9586 | - | |||||||||||||||||||
| 9587 | If \a cs is Qt::CaseSensitive (default), the search is case | - | ||||||||||||||||||
| 9588 | sensitive; otherwise the search is case insensitive. | - | ||||||||||||||||||
| 9589 | - | |||||||||||||||||||
| 9590 | If \a from is -1, the search starts at the last character; if it is | - | ||||||||||||||||||
| 9591 | -2, at the next to last character and so on. | - | ||||||||||||||||||
| 9592 | - | |||||||||||||||||||
| 9593 | \sa QString::indexOf(), lastIndexOf(), contains(), count() | - | ||||||||||||||||||
| 9594 | */ | - | ||||||||||||||||||
| 9595 | int QStringRef::indexOf(const QString &str, int from, Qt::CaseSensitivity cs) const | - | ||||||||||||||||||
| 9596 | { | - | ||||||||||||||||||
| 9597 | return qFindString(unicode(), length(), from, str.unicode(), str.length(), cs); executed 197 times by 1 test: return qFindString(unicode(), length(), from, str.unicode(), str.length(), cs);Executed by:
| 197 | ||||||||||||||||||
| 9598 | } | - | ||||||||||||||||||
| 9599 | - | |||||||||||||||||||
| 9600 | /*! | - | ||||||||||||||||||
| 9601 | \since 4.8 | - | ||||||||||||||||||
| 9602 | \overload indexOf() | - | ||||||||||||||||||
| 9603 | - | |||||||||||||||||||
| 9604 | Returns the index position of the first occurrence of the | - | ||||||||||||||||||
| 9605 | character \a ch in the string reference, searching forward from | - | ||||||||||||||||||
| 9606 | index position \a from. Returns -1 if \a ch could not be found. | - | ||||||||||||||||||
| 9607 | - | |||||||||||||||||||
| 9608 | \sa QString::indexOf(), lastIndexOf(), contains(), count() | - | ||||||||||||||||||
| 9609 | */ | - | ||||||||||||||||||
| 9610 | int QStringRef::indexOf(QChar ch, int from, Qt::CaseSensitivity cs) const | - | ||||||||||||||||||
| 9611 | { | - | ||||||||||||||||||
| 9612 | return findChar(unicode(), length(), ch, from, cs); executed 51163 times by 12 tests: return findChar(unicode(), length(), ch, from, cs);Executed by:
| 51163 | ||||||||||||||||||
| 9613 | } | - | ||||||||||||||||||
| 9614 | - | |||||||||||||||||||
| 9615 | /*! | - | ||||||||||||||||||
| 9616 | \since 4.8 | - | ||||||||||||||||||
| 9617 | - | |||||||||||||||||||
| 9618 | Returns the index position of the first occurrence of the string \a | - | ||||||||||||||||||
| 9619 | str in this string reference, searching forward from index position | - | ||||||||||||||||||
| 9620 | \a from. Returns -1 if \a str is not found. | - | ||||||||||||||||||
| 9621 | - | |||||||||||||||||||
| 9622 | If \a cs is Qt::CaseSensitive (default), the search is case | - | ||||||||||||||||||
| 9623 | sensitive; otherwise the search is case insensitive. | - | ||||||||||||||||||
| 9624 | - | |||||||||||||||||||
| 9625 | If \a from is -1, the search starts at the last character; if it is | - | ||||||||||||||||||
| 9626 | -2, at the next to last character and so on. | - | ||||||||||||||||||
| 9627 | - | |||||||||||||||||||
| 9628 | \sa QString::indexOf(), lastIndexOf(), contains(), count() | - | ||||||||||||||||||
| 9629 | */ | - | ||||||||||||||||||
| 9630 | int QStringRef::indexOf(QLatin1String str, int from, Qt::CaseSensitivity cs) const | - | ||||||||||||||||||
| 9631 | { | - | ||||||||||||||||||
| 9632 | return qt_find_latin1_string(unicode(), size(), str, from, cs); never executed: return qt_find_latin1_string(unicode(), size(), str, from, cs); | 0 | ||||||||||||||||||
| 9633 | } | - | ||||||||||||||||||
| 9634 | - | |||||||||||||||||||
| 9635 | /*! | - | ||||||||||||||||||
| 9636 | \since 4.8 | - | ||||||||||||||||||
| 9637 | - | |||||||||||||||||||
| 9638 | \overload indexOf() | - | ||||||||||||||||||
| 9639 | - | |||||||||||||||||||
| 9640 | Returns the index position of the first occurrence of the string | - | ||||||||||||||||||
| 9641 | reference \a str in this string reference, searching forward from | - | ||||||||||||||||||
| 9642 | index position \a from. Returns -1 if \a str is not found. | - | ||||||||||||||||||
| 9643 | - | |||||||||||||||||||
| 9644 | If \a cs is Qt::CaseSensitive (default), the search is case | - | ||||||||||||||||||
| 9645 | sensitive; otherwise the search is case insensitive. | - | ||||||||||||||||||
| 9646 | - | |||||||||||||||||||
| 9647 | \sa QString::indexOf(), lastIndexOf(), contains(), count() | - | ||||||||||||||||||
| 9648 | */ | - | ||||||||||||||||||
| 9649 | int QStringRef::indexOf(const QStringRef &str, int from, Qt::CaseSensitivity cs) const | - | ||||||||||||||||||
| 9650 | { | - | ||||||||||||||||||
| 9651 | return qFindString(unicode(), size(), from, str.unicode(), str.size(), cs); executed 196 times by 1 test: return qFindString(unicode(), size(), from, str.unicode(), str.size(), cs);Executed by:
| 196 | ||||||||||||||||||
| 9652 | } | - | ||||||||||||||||||
| 9653 | - | |||||||||||||||||||
| 9654 | /*! | - | ||||||||||||||||||
| 9655 | \since 4.8 | - | ||||||||||||||||||
| 9656 | - | |||||||||||||||||||
| 9657 | Returns the index position of the last occurrence of the string \a | - | ||||||||||||||||||
| 9658 | str in this string reference, searching backward from index position | - | ||||||||||||||||||
| 9659 | \a from. If \a from is -1 (default), the search starts at the last | - | ||||||||||||||||||
| 9660 | character; if \a from is -2, at the next to last character and so | - | ||||||||||||||||||
| 9661 | on. Returns -1 if \a str is not found. | - | ||||||||||||||||||
| 9662 | - | |||||||||||||||||||
| 9663 | If \a cs is Qt::CaseSensitive (default), the search is case | - | ||||||||||||||||||
| 9664 | sensitive; otherwise the search is case insensitive. | - | ||||||||||||||||||
| 9665 | - | |||||||||||||||||||
| 9666 | \sa QString::lastIndexOf(), indexOf(), contains(), count() | - | ||||||||||||||||||
| 9667 | */ | - | ||||||||||||||||||
| 9668 | int QStringRef::lastIndexOf(const QString &str, int from, Qt::CaseSensitivity cs) const | - | ||||||||||||||||||
| 9669 | { | - | ||||||||||||||||||
| 9670 | const int sl = str.size(); | - | ||||||||||||||||||
| 9671 | if (sl == 1)
| 50-53 | ||||||||||||||||||
| 9672 | return lastIndexOf(str.at(0), from, cs); executed 53 times by 1 test: return lastIndexOf(str.at(0), from, cs);Executed by:
| 53 | ||||||||||||||||||
| 9673 | - | |||||||||||||||||||
| 9674 | const int l = size();; | - | ||||||||||||||||||
| 9675 | if (from < 0)
| 7-43 | ||||||||||||||||||
| 9676 | from += l; executed 43 times by 1 test: from += l;Executed by:
| 43 | ||||||||||||||||||
| 9677 | int delta = l - sl; | - | ||||||||||||||||||
| 9678 | if (from == l && sl == 0)
| 1-48 | ||||||||||||||||||
| 9679 | return from; executed 1 time by 1 test: return from;Executed by:
| 1 | ||||||||||||||||||
| 9680 | if (uint(from) >= uint(l) || delta < 0)
| 7-41 | ||||||||||||||||||
| 9681 | return -1; executed 15 times by 1 test: return -1;Executed by:
| 15 | ||||||||||||||||||
| 9682 | if (from > delta)
| 5-29 | ||||||||||||||||||
| 9683 | from = delta; executed 29 times by 1 test: from = delta;Executed by:
| 29 | ||||||||||||||||||
| 9684 | - | |||||||||||||||||||
| 9685 | return lastIndexOfHelper(reinterpret_cast<const ushort*>(unicode()), from, executed 34 times by 1 test: return lastIndexOfHelper(reinterpret_cast<const ushort*>(unicode()), from, reinterpret_cast<const ushort*>(str.unicode()), str.size(), cs);Executed by:
| 34 | ||||||||||||||||||
| 9686 | reinterpret_cast<const ushort*>(str.unicode()), str.size(), cs); executed 34 times by 1 test: return lastIndexOfHelper(reinterpret_cast<const ushort*>(unicode()), from, reinterpret_cast<const ushort*>(str.unicode()), str.size(), cs);Executed by:
| 34 | ||||||||||||||||||
| 9687 | } | - | ||||||||||||||||||
| 9688 | - | |||||||||||||||||||
| 9689 | /*! | - | ||||||||||||||||||
| 9690 | \since 4.8 | - | ||||||||||||||||||
| 9691 | \overload lastIndexOf() | - | ||||||||||||||||||
| 9692 | - | |||||||||||||||||||
| 9693 | Returns the index position of the last occurrence of the character | - | ||||||||||||||||||
| 9694 | \a ch, searching backward from position \a from. | - | ||||||||||||||||||
| 9695 | - | |||||||||||||||||||
| 9696 | \sa QString::lastIndexOf(), indexOf(), contains(), count() | - | ||||||||||||||||||
| 9697 | */ | - | ||||||||||||||||||
| 9698 | int QStringRef::lastIndexOf(QChar ch, int from, Qt::CaseSensitivity cs) const | - | ||||||||||||||||||
| 9699 | { | - | ||||||||||||||||||
| 9700 | return qt_last_index_of(unicode(), size(), ch, from, cs); executed 136 times by 1 test: return qt_last_index_of(unicode(), size(), ch, from, cs);Executed by:
| 136 | ||||||||||||||||||
| 9701 | } | - | ||||||||||||||||||
| 9702 | - | |||||||||||||||||||
| 9703 | /*! | - | ||||||||||||||||||
| 9704 | \since 4.8 | - | ||||||||||||||||||
| 9705 | \overload lastIndexOf() | - | ||||||||||||||||||
| 9706 | - | |||||||||||||||||||
| 9707 | Returns the index position of the last occurrence of the string \a | - | ||||||||||||||||||
| 9708 | str in this string reference, searching backward from index position | - | ||||||||||||||||||
| 9709 | \a from. If \a from is -1 (default), the search starts at the last | - | ||||||||||||||||||
| 9710 | character; if \a from is -2, at the next to last character and so | - | ||||||||||||||||||
| 9711 | on. Returns -1 if \a str is not found. | - | ||||||||||||||||||
| 9712 | - | |||||||||||||||||||
| 9713 | If \a cs is Qt::CaseSensitive (default), the search is case | - | ||||||||||||||||||
| 9714 | sensitive; otherwise the search is case insensitive. | - | ||||||||||||||||||
| 9715 | - | |||||||||||||||||||
| 9716 | \sa QString::lastIndexOf(), indexOf(), contains(), count() | - | ||||||||||||||||||
| 9717 | */ | - | ||||||||||||||||||
| 9718 | int QStringRef::lastIndexOf(QLatin1String str, int from, Qt::CaseSensitivity cs) const | - | ||||||||||||||||||
| 9719 | { | - | ||||||||||||||||||
| 9720 | const int sl = str.size(); | - | ||||||||||||||||||
| 9721 | if (sl == 1)
| 0 | ||||||||||||||||||
| 9722 | return lastIndexOf(QLatin1Char(str.latin1()[0]), from, cs); never executed: return lastIndexOf(QLatin1Char(str.latin1()[0]), from, cs); | 0 | ||||||||||||||||||
| 9723 | - | |||||||||||||||||||
| 9724 | const int l = size(); | - | ||||||||||||||||||
| 9725 | if (from < 0)
| 0 | ||||||||||||||||||
| 9726 | from += l; never executed: from += l; | 0 | ||||||||||||||||||
| 9727 | int delta = l - sl; | - | ||||||||||||||||||
| 9728 | if (from == l && sl == 0)
| 0 | ||||||||||||||||||
| 9729 | return from; never executed: return from; | 0 | ||||||||||||||||||
| 9730 | if (uint(from) >= uint(l) || delta < 0)
| 0 | ||||||||||||||||||
| 9731 | return -1; never executed: return -1; | 0 | ||||||||||||||||||
| 9732 | if (from > delta)
| 0 | ||||||||||||||||||
| 9733 | from = delta; never executed: from = delta; | 0 | ||||||||||||||||||
| 9734 | - | |||||||||||||||||||
| 9735 | QVarLengthArray<ushort> s(sl); | - | ||||||||||||||||||
| 9736 | qt_from_latin1(s.data(), str.latin1(), sl); | - | ||||||||||||||||||
| 9737 | - | |||||||||||||||||||
| 9738 | return lastIndexOfHelper(reinterpret_cast<const ushort*>(unicode()), from, s.data(), sl, cs); never executed: return lastIndexOfHelper(reinterpret_cast<const ushort*>(unicode()), from, s.data(), sl, cs); | 0 | ||||||||||||||||||
| 9739 | } | - | ||||||||||||||||||
| 9740 | - | |||||||||||||||||||
| 9741 | /*! | - | ||||||||||||||||||
| 9742 | \since 4.8 | - | ||||||||||||||||||
| 9743 | \overload lastIndexOf() | - | ||||||||||||||||||
| 9744 | - | |||||||||||||||||||
| 9745 | Returns the index position of the last occurrence of the string | - | ||||||||||||||||||
| 9746 | reference \a str in this string reference, searching backward from | - | ||||||||||||||||||
| 9747 | index position \a from. If \a from is -1 (default), the search | - | ||||||||||||||||||
| 9748 | starts at the last character; if \a from is -2, at the next to last | - | ||||||||||||||||||
| 9749 | character and so on. Returns -1 if \a str is not found. | - | ||||||||||||||||||
| 9750 | - | |||||||||||||||||||
| 9751 | If \a cs is Qt::CaseSensitive (default), the search is case | - | ||||||||||||||||||
| 9752 | sensitive; otherwise the search is case insensitive. | - | ||||||||||||||||||
| 9753 | - | |||||||||||||||||||
| 9754 | \sa QString::lastIndexOf(), indexOf(), contains(), count() | - | ||||||||||||||||||
| 9755 | */ | - | ||||||||||||||||||
| 9756 | int QStringRef::lastIndexOf(const QStringRef &str, int from, Qt::CaseSensitivity cs) const | - | ||||||||||||||||||
| 9757 | { | - | ||||||||||||||||||
| 9758 | const int sl = str.size(); | - | ||||||||||||||||||
| 9759 | if (sl == 1)
| 50-53 | ||||||||||||||||||
| 9760 | return lastIndexOf(str.at(0), from, cs); executed 53 times by 1 test: return lastIndexOf(str.at(0), from, cs);Executed by:
| 53 | ||||||||||||||||||
| 9761 | - | |||||||||||||||||||
| 9762 | const int l = size(); | - | ||||||||||||||||||
| 9763 | if (from < 0)
| 7-43 | ||||||||||||||||||
| 9764 | from += l; executed 43 times by 1 test: from += l;Executed by:
| 43 | ||||||||||||||||||
| 9765 | int delta = l - sl; | - | ||||||||||||||||||
| 9766 | if (from == l && sl == 0)
| 1-48 | ||||||||||||||||||
| 9767 | return from; executed 1 time by 1 test: return from;Executed by:
| 1 | ||||||||||||||||||
| 9768 | if (uint(from) >= uint(l) || delta < 0)
| 7-41 | ||||||||||||||||||
| 9769 | return -1; executed 15 times by 1 test: return -1;Executed by:
| 15 | ||||||||||||||||||
| 9770 | if (from > delta)
| 5-29 | ||||||||||||||||||
| 9771 | from = delta; executed 29 times by 1 test: from = delta;Executed by:
| 29 | ||||||||||||||||||
| 9772 | - | |||||||||||||||||||
| 9773 | return lastIndexOfHelper(reinterpret_cast<const ushort*>(unicode()), from, executed 34 times by 1 test: return lastIndexOfHelper(reinterpret_cast<const ushort*>(unicode()), from, reinterpret_cast<const ushort*>(str.unicode()), str.size(), cs);Executed by:
| 34 | ||||||||||||||||||
| 9774 | reinterpret_cast<const ushort*>(str.unicode()), executed 34 times by 1 test: return lastIndexOfHelper(reinterpret_cast<const ushort*>(unicode()), from, reinterpret_cast<const ushort*>(str.unicode()), str.size(), cs);Executed by:
| 34 | ||||||||||||||||||
| 9775 | str.size(), cs); executed 34 times by 1 test: return lastIndexOfHelper(reinterpret_cast<const ushort*>(unicode()), from, reinterpret_cast<const ushort*>(str.unicode()), str.size(), cs);Executed by:
| 34 | ||||||||||||||||||
| 9776 | } | - | ||||||||||||||||||
| 9777 | - | |||||||||||||||||||
| 9778 | /*! | - | ||||||||||||||||||
| 9779 | \since 4.8 | - | ||||||||||||||||||
| 9780 | Returns the number of (potentially overlapping) occurrences of | - | ||||||||||||||||||
| 9781 | the string \a str in this string reference. | - | ||||||||||||||||||
| 9782 | - | |||||||||||||||||||
| 9783 | If \a cs is Qt::CaseSensitive (default), the search is | - | ||||||||||||||||||
| 9784 | case sensitive; otherwise the search is case insensitive. | - | ||||||||||||||||||
| 9785 | - | |||||||||||||||||||
| 9786 | \sa QString::count(), contains(), indexOf() | - | ||||||||||||||||||
| 9787 | */ | - | ||||||||||||||||||
| 9788 | int QStringRef::count(const QString &str, Qt::CaseSensitivity cs) const | - | ||||||||||||||||||
| 9789 | { | - | ||||||||||||||||||
| 9790 | return qt_string_count(unicode(), size(), str.unicode(), str.size(), cs); executed 4 times by 1 test: return qt_string_count(unicode(), size(), str.unicode(), str.size(), cs);Executed by:
| 4 | ||||||||||||||||||
| 9791 | } | - | ||||||||||||||||||
| 9792 | - | |||||||||||||||||||
| 9793 | /*! | - | ||||||||||||||||||
| 9794 | \since 4.8 | - | ||||||||||||||||||
| 9795 | \overload count() | - | ||||||||||||||||||
| 9796 | - | |||||||||||||||||||
| 9797 | Returns the number of occurrences of the character \a ch in the | - | ||||||||||||||||||
| 9798 | string reference. | - | ||||||||||||||||||
| 9799 | - | |||||||||||||||||||
| 9800 | If \a cs is Qt::CaseSensitive (default), the search is | - | ||||||||||||||||||
| 9801 | case sensitive; otherwise the search is case insensitive. | - | ||||||||||||||||||
| 9802 | - | |||||||||||||||||||
| 9803 | \sa QString::count(), contains(), indexOf() | - | ||||||||||||||||||
| 9804 | */ | - | ||||||||||||||||||
| 9805 | int QStringRef::count(QChar ch, Qt::CaseSensitivity cs) const | - | ||||||||||||||||||
| 9806 | { | - | ||||||||||||||||||
| 9807 | return qt_string_count(unicode(), size(), ch, cs); executed 5 times by 1 test: return qt_string_count(unicode(), size(), ch, cs);Executed by:
| 5 | ||||||||||||||||||
| 9808 | } | - | ||||||||||||||||||
| 9809 | - | |||||||||||||||||||
| 9810 | /*! | - | ||||||||||||||||||
| 9811 | \since 4.8 | - | ||||||||||||||||||
| 9812 | \overload count() | - | ||||||||||||||||||
| 9813 | - | |||||||||||||||||||
| 9814 | Returns the number of (potentially overlapping) occurrences of the | - | ||||||||||||||||||
| 9815 | string reference \a str in this string reference. | - | ||||||||||||||||||
| 9816 | - | |||||||||||||||||||
| 9817 | If \a cs is Qt::CaseSensitive (default), the search is | - | ||||||||||||||||||
| 9818 | case sensitive; otherwise the search is case insensitive. | - | ||||||||||||||||||
| 9819 | - | |||||||||||||||||||
| 9820 | \sa QString::count(), contains(), indexOf() | - | ||||||||||||||||||
| 9821 | */ | - | ||||||||||||||||||
| 9822 | int QStringRef::count(const QStringRef &str, Qt::CaseSensitivity cs) const | - | ||||||||||||||||||
| 9823 | { | - | ||||||||||||||||||
| 9824 | return qt_string_count(unicode(), size(), str.unicode(), str.size(), cs); never executed: return qt_string_count(unicode(), size(), str.unicode(), str.size(), cs); | 0 | ||||||||||||||||||
| 9825 | } | - | ||||||||||||||||||
| 9826 | - | |||||||||||||||||||
| 9827 | /*! | - | ||||||||||||||||||
| 9828 | \since 4.8 | - | ||||||||||||||||||
| 9829 | - | |||||||||||||||||||
| 9830 | Returns \c true if the string reference starts with \a str; otherwise | - | ||||||||||||||||||
| 9831 | returns \c false. | - | ||||||||||||||||||
| 9832 | - | |||||||||||||||||||
| 9833 | If \a cs is Qt::CaseSensitive (default), the search is | - | ||||||||||||||||||
| 9834 | case sensitive; otherwise the search is case insensitive. | - | ||||||||||||||||||
| 9835 | - | |||||||||||||||||||
| 9836 | \sa QString::startsWith(), endsWith() | - | ||||||||||||||||||
| 9837 | */ | - | ||||||||||||||||||
| 9838 | bool QStringRef::startsWith(const QString &str, Qt::CaseSensitivity cs) const | - | ||||||||||||||||||
| 9839 | { | - | ||||||||||||||||||
| 9840 | return qt_starts_with(isNull() ? 0 : unicode(), size(), executed 25 times by 1 test: return qt_starts_with(isNull() ? 0 : unicode(), size(), str.isNull() ? 0 : str.unicode(), str.size(), cs);Executed by:
| 25 | ||||||||||||||||||
| 9841 | str.isNull() ? 0 : str.unicode(), str.size(), cs); executed 25 times by 1 test: return qt_starts_with(isNull() ? 0 : unicode(), size(), str.isNull() ? 0 : str.unicode(), str.size(), cs);Executed by:
| 25 | ||||||||||||||||||
| 9842 | } | - | ||||||||||||||||||
| 9843 | - | |||||||||||||||||||
| 9844 | /*! | - | ||||||||||||||||||
| 9845 | \since 4.8 | - | ||||||||||||||||||
| 9846 | \overload startsWith() | - | ||||||||||||||||||
| 9847 | \sa QString::startsWith(), endsWith() | - | ||||||||||||||||||
| 9848 | */ | - | ||||||||||||||||||
| 9849 | bool QStringRef::startsWith(QLatin1String str, Qt::CaseSensitivity cs) const | - | ||||||||||||||||||
| 9850 | { | - | ||||||||||||||||||
| 9851 | return qt_starts_with(isNull() ? 0 : unicode(), size(), str, cs); executed 38 times by 2 tests: return qt_starts_with(isNull() ? 0 : unicode(), size(), str, cs);Executed by:
| 38 | ||||||||||||||||||
| 9852 | } | - | ||||||||||||||||||
| 9853 | - | |||||||||||||||||||
| 9854 | /*! | - | ||||||||||||||||||
| 9855 | \since 4.8 | - | ||||||||||||||||||
| 9856 | \overload startsWith() | - | ||||||||||||||||||
| 9857 | \sa QString::startsWith(), endsWith() | - | ||||||||||||||||||
| 9858 | */ | - | ||||||||||||||||||
| 9859 | bool QStringRef::startsWith(const QStringRef &str, Qt::CaseSensitivity cs) const | - | ||||||||||||||||||
| 9860 | { | - | ||||||||||||||||||
| 9861 | return qt_starts_with(isNull() ? 0 : unicode(), size(), never executed: return qt_starts_with(isNull() ? 0 : unicode(), size(), str.isNull() ? 0 : str.unicode(), str.size(), cs); | 0 | ||||||||||||||||||
| 9862 | str.isNull() ? 0 : str.unicode(), str.size(), cs); never executed: return qt_starts_with(isNull() ? 0 : unicode(), size(), str.isNull() ? 0 : str.unicode(), str.size(), cs); | 0 | ||||||||||||||||||
| 9863 | } | - | ||||||||||||||||||
| 9864 | - | |||||||||||||||||||
| 9865 | /*! | - | ||||||||||||||||||
| 9866 | \since 4.8 | - | ||||||||||||||||||
| 9867 | \overload startsWith() | - | ||||||||||||||||||
| 9868 | - | |||||||||||||||||||
| 9869 | Returns \c true if the string reference starts with \a ch; otherwise | - | ||||||||||||||||||
| 9870 | returns \c false. | - | ||||||||||||||||||
| 9871 | - | |||||||||||||||||||
| 9872 | If \a cs is Qt::CaseSensitive (default), the search is case | - | ||||||||||||||||||
| 9873 | sensitive; otherwise the search is case insensitive. | - | ||||||||||||||||||
| 9874 | - | |||||||||||||||||||
| 9875 | \sa QString::startsWith(), endsWith() | - | ||||||||||||||||||
| 9876 | */ | - | ||||||||||||||||||
| 9877 | bool QStringRef::startsWith(QChar ch, Qt::CaseSensitivity cs) const | - | ||||||||||||||||||
| 9878 | { | - | ||||||||||||||||||
| 9879 | if (!isEmpty()) {
| 17-24063 | ||||||||||||||||||
| 9880 | const ushort *data = reinterpret_cast<const ushort*>(unicode()); | - | ||||||||||||||||||
| 9881 | return (cs == Qt::CaseSensitive executed 24063 times by 4 tests: return (cs == Qt::CaseSensitive ? data[0] == ch : foldCase(data[0]) == foldCase(ch.unicode()));Executed by:
| 7-24063 | ||||||||||||||||||
| 9882 | ? data[0] == ch executed 24063 times by 4 tests: return (cs == Qt::CaseSensitive ? data[0] == ch : foldCase(data[0]) == foldCase(ch.unicode()));Executed by:
| 24063 | ||||||||||||||||||
| 9883 | : foldCase(data[0]) == foldCase(ch.unicode())); executed 24063 times by 4 tests: return (cs == Qt::CaseSensitive ? data[0] == ch : foldCase(data[0]) == foldCase(ch.unicode()));Executed by:
| 24063 | ||||||||||||||||||
| 9884 | } else { | - | ||||||||||||||||||
| 9885 | return false; executed 17 times by 2 tests: return false;Executed by:
| 17 | ||||||||||||||||||
| 9886 | } | - | ||||||||||||||||||
| 9887 | } | - | ||||||||||||||||||
| 9888 | - | |||||||||||||||||||
| 9889 | /*! | - | ||||||||||||||||||
| 9890 | \since 4.8 | - | ||||||||||||||||||
| 9891 | Returns \c true if the string reference ends with \a str; otherwise | - | ||||||||||||||||||
| 9892 | returns \c false. | - | ||||||||||||||||||
| 9893 | - | |||||||||||||||||||
| 9894 | If \a cs is Qt::CaseSensitive (default), the search is case | - | ||||||||||||||||||
| 9895 | sensitive; otherwise the search is case insensitive. | - | ||||||||||||||||||
| 9896 | - | |||||||||||||||||||
| 9897 | \sa QString::endsWith(), startsWith() | - | ||||||||||||||||||
| 9898 | */ | - | ||||||||||||||||||
| 9899 | bool QStringRef::endsWith(const QString &str, Qt::CaseSensitivity cs) const | - | ||||||||||||||||||
| 9900 | { | - | ||||||||||||||||||
| 9901 | return qt_ends_with(isNull() ? 0 : unicode(), size(), executed 25 times by 1 test: return qt_ends_with(isNull() ? 0 : unicode(), size(), str.isNull() ? 0 : str.unicode(), str.size(), cs);Executed by:
| 25 | ||||||||||||||||||
| 9902 | str.isNull() ? 0 : str.unicode(), str.size(), cs); executed 25 times by 1 test: return qt_ends_with(isNull() ? 0 : unicode(), size(), str.isNull() ? 0 : str.unicode(), str.size(), cs);Executed by:
| 25 | ||||||||||||||||||
| 9903 | } | - | ||||||||||||||||||
| 9904 | - | |||||||||||||||||||
| 9905 | /*! | - | ||||||||||||||||||
| 9906 | \since 4.8 | - | ||||||||||||||||||
| 9907 | \overload endsWith() | - | ||||||||||||||||||
| 9908 | - | |||||||||||||||||||
| 9909 | Returns \c true if the string reference ends with \a ch; otherwise | - | ||||||||||||||||||
| 9910 | returns \c false. | - | ||||||||||||||||||
| 9911 | - | |||||||||||||||||||
| 9912 | If \a cs is Qt::CaseSensitive (default), the search is case | - | ||||||||||||||||||
| 9913 | sensitive; otherwise the search is case insensitive. | - | ||||||||||||||||||
| 9914 | - | |||||||||||||||||||
| 9915 | \sa QString::endsWith(), endsWith() | - | ||||||||||||||||||
| 9916 | */ | - | ||||||||||||||||||
| 9917 | bool QStringRef::endsWith(QChar ch, Qt::CaseSensitivity cs) const | - | ||||||||||||||||||
| 9918 | { | - | ||||||||||||||||||
| 9919 | if (!isEmpty()) {
| 6-24143 | ||||||||||||||||||
| 9920 | const ushort *data = reinterpret_cast<const ushort*>(unicode()); | - | ||||||||||||||||||
| 9921 | const int size = length(); | - | ||||||||||||||||||
| 9922 | return (cs == Qt::CaseSensitive executed 24143 times by 7 tests: return (cs == Qt::CaseSensitive ? data[size - 1] == ch : foldCase(data[size - 1]) == foldCase(ch.unicode()));Executed by:
| 7-24143 | ||||||||||||||||||
| 9923 | ? data[size - 1] == ch executed 24143 times by 7 tests: return (cs == Qt::CaseSensitive ? data[size - 1] == ch : foldCase(data[size - 1]) == foldCase(ch.unicode()));Executed by:
| 24143 | ||||||||||||||||||
| 9924 | : foldCase(data[size - 1]) == foldCase(ch.unicode())); executed 24143 times by 7 tests: return (cs == Qt::CaseSensitive ? data[size - 1] == ch : foldCase(data[size - 1]) == foldCase(ch.unicode()));Executed by:
| 24143 | ||||||||||||||||||
| 9925 | } else { | - | ||||||||||||||||||
| 9926 | return false; executed 6 times by 1 test: return false;Executed by:
| 6 | ||||||||||||||||||
| 9927 | } | - | ||||||||||||||||||
| 9928 | } | - | ||||||||||||||||||
| 9929 | - | |||||||||||||||||||
| 9930 | /*! | - | ||||||||||||||||||
| 9931 | \since 4.8 | - | ||||||||||||||||||
| 9932 | \overload endsWith() | - | ||||||||||||||||||
| 9933 | \sa QString::endsWith(), endsWith() | - | ||||||||||||||||||
| 9934 | */ | - | ||||||||||||||||||
| 9935 | bool QStringRef::endsWith(QLatin1String str, Qt::CaseSensitivity cs) const | - | ||||||||||||||||||
| 9936 | { | - | ||||||||||||||||||
| 9937 | return qt_ends_with(isNull() ? 0 : unicode(), size(), str, cs); executed 96430 times by 3 tests: return qt_ends_with(isNull() ? 0 : unicode(), size(), str, cs);Executed by:
| 96430 | ||||||||||||||||||
| 9938 | } | - | ||||||||||||||||||
| 9939 | - | |||||||||||||||||||
| 9940 | /*! | - | ||||||||||||||||||
| 9941 | \since 4.8 | - | ||||||||||||||||||
| 9942 | \overload endsWith() | - | ||||||||||||||||||
| 9943 | \sa QString::endsWith(), endsWith() | - | ||||||||||||||||||
| 9944 | */ | - | ||||||||||||||||||
| 9945 | bool QStringRef::endsWith(const QStringRef &str, Qt::CaseSensitivity cs) const | - | ||||||||||||||||||
| 9946 | { | - | ||||||||||||||||||
| 9947 | return qt_ends_with(isNull() ? 0 : unicode(), size(), never executed: return qt_ends_with(isNull() ? 0 : unicode(), size(), str.isNull() ? 0 : str.unicode(), str.size(), cs); | 0 | ||||||||||||||||||
| 9948 | str.isNull() ? 0 : str.unicode(), str.size(), cs); never executed: return qt_ends_with(isNull() ? 0 : unicode(), size(), str.isNull() ? 0 : str.unicode(), str.size(), cs); | 0 | ||||||||||||||||||
| 9949 | } | - | ||||||||||||||||||
| 9950 | - | |||||||||||||||||||
| 9951 | - | |||||||||||||||||||
| 9952 | /*! \fn bool QStringRef::contains(const QString &str, Qt::CaseSensitivity cs = Qt::CaseSensitive) const | - | ||||||||||||||||||
| 9953 | - | |||||||||||||||||||
| 9954 | \since 4.8 | - | ||||||||||||||||||
| 9955 | Returns \c true if this string reference contains an occurrence of | - | ||||||||||||||||||
| 9956 | the string \a str; otherwise returns \c false. | - | ||||||||||||||||||
| 9957 | - | |||||||||||||||||||
| 9958 | If \a cs is Qt::CaseSensitive (default), the search is | - | ||||||||||||||||||
| 9959 | case sensitive; otherwise the search is case insensitive. | - | ||||||||||||||||||
| 9960 | - | |||||||||||||||||||
| 9961 | \sa indexOf(), count() | - | ||||||||||||||||||
| 9962 | */ | - | ||||||||||||||||||
| 9963 | - | |||||||||||||||||||
| 9964 | /*! \fn bool QStringRef::contains(QChar ch, Qt::CaseSensitivity cs = Qt::CaseSensitive) const | - | ||||||||||||||||||
| 9965 | - | |||||||||||||||||||
| 9966 | \overload contains() | - | ||||||||||||||||||
| 9967 | \since 4.8 | - | ||||||||||||||||||
| 9968 | - | |||||||||||||||||||
| 9969 | Returns \c true if this string contains an occurrence of the | - | ||||||||||||||||||
| 9970 | character \a ch; otherwise returns \c false. | - | ||||||||||||||||||
| 9971 | - | |||||||||||||||||||
| 9972 | If \a cs is Qt::CaseSensitive (default), the search is | - | ||||||||||||||||||
| 9973 | case sensitive; otherwise the search is case insensitive. | - | ||||||||||||||||||
| 9974 | - | |||||||||||||||||||
| 9975 | */ | - | ||||||||||||||||||
| 9976 | - | |||||||||||||||||||
| 9977 | /*! \fn bool QStringRef::contains(const QStringRef &str, Qt::CaseSensitivity cs = Qt::CaseSensitive) const | - | ||||||||||||||||||
| 9978 | \overload contains() | - | ||||||||||||||||||
| 9979 | \since 4.8 | - | ||||||||||||||||||
| 9980 | - | |||||||||||||||||||
| 9981 | Returns \c true if this string reference contains an occurrence of | - | ||||||||||||||||||
| 9982 | the string reference \a str; otherwise returns \c false. | - | ||||||||||||||||||
| 9983 | - | |||||||||||||||||||
| 9984 | If \a cs is Qt::CaseSensitive (default), the search is | - | ||||||||||||||||||
| 9985 | case sensitive; otherwise the search is case insensitive. | - | ||||||||||||||||||
| 9986 | - | |||||||||||||||||||
| 9987 | \sa indexOf(), count() | - | ||||||||||||||||||
| 9988 | */ | - | ||||||||||||||||||
| 9989 | - | |||||||||||||||||||
| 9990 | /*! \fn bool QStringRef::contains(QLatin1String str, Qt::CaseSensitivity cs) const | - | ||||||||||||||||||
| 9991 | \since 4,8 | - | ||||||||||||||||||
| 9992 | \overload contains() | - | ||||||||||||||||||
| 9993 | - | |||||||||||||||||||
| 9994 | Returns \c true if this string reference contains an occurrence of | - | ||||||||||||||||||
| 9995 | the string \a str; otherwise returns \c false. | - | ||||||||||||||||||
| 9996 | - | |||||||||||||||||||
| 9997 | If \a cs is Qt::CaseSensitive (default), the search is | - | ||||||||||||||||||
| 9998 | case sensitive; otherwise the search is case insensitive. | - | ||||||||||||||||||
| 9999 | - | |||||||||||||||||||
| 10000 | \sa indexOf(), count() | - | ||||||||||||||||||
| 10001 | */ | - | ||||||||||||||||||
| 10002 | - | |||||||||||||||||||
| 10003 | static inline int qt_last_index_of(const QChar *haystack, int haystackLen, QChar needle, | - | ||||||||||||||||||
| 10004 | int from, Qt::CaseSensitivity cs) | - | ||||||||||||||||||
| 10005 | { | - | ||||||||||||||||||
| 10006 | ushort c = needle.unicode(); | - | ||||||||||||||||||
| 10007 | if (from < 0)
| 7292-252301 | ||||||||||||||||||
| 10008 | from += haystackLen; executed 252301 times by 303 tests: from += haystackLen;Executed by:
| 252301 | ||||||||||||||||||
| 10009 | if (uint(from) >= uint(haystackLen))
| 1126-258467 | ||||||||||||||||||
| 10010 | return -1; executed 1126 times by 18 tests: return -1;Executed by:
| 1126 | ||||||||||||||||||
| 10011 | if (from >= 0) {
| 0-258467 | ||||||||||||||||||
| 10012 | const ushort *b = reinterpret_cast<const ushort*>(haystack); | - | ||||||||||||||||||
| 10013 | const ushort *n = b + from; | - | ||||||||||||||||||
| 10014 | if (cs == Qt::CaseSensitive) {
| 32-258435 | ||||||||||||||||||
| 10015 | for (; n >= b; --n)
| 7251-4078365 | ||||||||||||||||||
| 10016 | if (*n == c)
| 251184-3827181 | ||||||||||||||||||
| 10017 | return n - b; executed 251184 times by 285 tests: return n - b;Executed by:
| 251184 | ||||||||||||||||||
| 10018 | } else { executed 7251 times by 191 tests: end of blockExecuted by:
| 7251 | ||||||||||||||||||
| 10019 | c = foldCase(c); | - | ||||||||||||||||||
| 10020 | for (; n >= b; --n)
| 8-56 | ||||||||||||||||||
| 10021 | if (foldCase(*n) == c)
| 24-32 | ||||||||||||||||||
| 10022 | return n - b; executed 24 times by 2 tests: return n - b;Executed by:
| 24 | ||||||||||||||||||
| 10023 | } executed 8 times by 2 tests: end of blockExecuted by:
| 8 | ||||||||||||||||||
| 10024 | } | - | ||||||||||||||||||
| 10025 | return -1; executed 7259 times by 191 tests: return -1;Executed by:
| 7259 | ||||||||||||||||||
| 10026 | - | |||||||||||||||||||
| 10027 | - | |||||||||||||||||||
| 10028 | } | - | ||||||||||||||||||
| 10029 | - | |||||||||||||||||||
| 10030 | static inline int qt_string_count(const QChar *haystack, int haystackLen, | - | ||||||||||||||||||
| 10031 | const QChar *needle, int needleLen, | - | ||||||||||||||||||
| 10032 | Qt::CaseSensitivity cs) | - | ||||||||||||||||||
| 10033 | { | - | ||||||||||||||||||
| 10034 | int num = 0; | - | ||||||||||||||||||
| 10035 | int i = -1; | - | ||||||||||||||||||
| 10036 | if (haystackLen > 500 && needleLen > 5) {
| 0-18 | ||||||||||||||||||
| 10037 | QStringMatcher matcher(needle, needleLen, cs); | - | ||||||||||||||||||
| 10038 | while ((i = matcher.indexIn(haystack, haystackLen, i + 1)) != -1)
| 0 | ||||||||||||||||||
| 10039 | ++num; never executed: ++num; | 0 | ||||||||||||||||||
| 10040 | } else { never executed: end of block | 0 | ||||||||||||||||||
| 10041 | while ((i = qFindString(haystack, haystackLen, i + 1, needle, needleLen, cs)) != -1)
| 20-20628 | ||||||||||||||||||
| 10042 | ++num; executed 20628 times by 5 tests: ++num;Executed by:
| 20628 | ||||||||||||||||||
| 10043 | } executed 20 times by 5 tests: end of blockExecuted by:
| 20 | ||||||||||||||||||
| 10044 | return num; executed 20 times by 5 tests: return num;Executed by:
| 20 | ||||||||||||||||||
| 10045 | } | - | ||||||||||||||||||
| 10046 | - | |||||||||||||||||||
| 10047 | static inline int qt_string_count(const QChar *unicode, int size, QChar ch, | - | ||||||||||||||||||
| 10048 | Qt::CaseSensitivity cs) | - | ||||||||||||||||||
| 10049 | { | - | ||||||||||||||||||
| 10050 | ushort c = ch.unicode(); | - | ||||||||||||||||||
| 10051 | int num = 0; | - | ||||||||||||||||||
| 10052 | const ushort *b = reinterpret_cast<const ushort*>(unicode); | - | ||||||||||||||||||
| 10053 | const ushort *i = b + size; | - | ||||||||||||||||||
| 10054 | if (cs == Qt::CaseSensitive) {
| 2-10953 | ||||||||||||||||||
| 10055 | while (i != b)
| 10953-139343 | ||||||||||||||||||
| 10056 | if (*--i == c)
| 7874-131469 | ||||||||||||||||||
| 10057 | ++num; executed 7874 times by 10 tests: ++num;Executed by:
| 7874 | ||||||||||||||||||
| 10058 | } else { executed 10953 times by 12 tests: end of blockExecuted by:
| 10953 | ||||||||||||||||||
| 10059 | c = foldCase(c); | - | ||||||||||||||||||
| 10060 | while (i != b)
| 2-30 | ||||||||||||||||||
| 10061 | if (foldCase(*(--i)) == c)
| 6-24 | ||||||||||||||||||
| 10062 | ++num; executed 6 times by 2 tests: ++num;Executed by:
| 6 | ||||||||||||||||||
| 10063 | } executed 2 times by 2 tests: end of blockExecuted by:
| 2 | ||||||||||||||||||
| 10064 | return num; executed 10955 times by 12 tests: return num;Executed by:
| 10955 | ||||||||||||||||||
| 10065 | } | - | ||||||||||||||||||
| 10066 | - | |||||||||||||||||||
| 10067 | static inline int qt_find_latin1_string(const QChar *haystack, int size, | - | ||||||||||||||||||
| 10068 | QLatin1String needle, | - | ||||||||||||||||||
| 10069 | int from, Qt::CaseSensitivity cs) | - | ||||||||||||||||||
| 10070 | { | - | ||||||||||||||||||
| 10071 | if (size < needle.size())
| 6912-7943 | ||||||||||||||||||
| 10072 | return -1; executed 6912 times by 125 tests: return -1;Executed by:
| 6912 | ||||||||||||||||||
| 10073 | - | |||||||||||||||||||
| 10074 | const char *latin1 = needle.latin1(); | - | ||||||||||||||||||
| 10075 | int len = needle.size(); | - | ||||||||||||||||||
| 10076 | QVarLengthArray<ushort> s(len); | - | ||||||||||||||||||
| 10077 | qt_from_latin1(s.data(), latin1, len); | - | ||||||||||||||||||
| 10078 | - | |||||||||||||||||||
| 10079 | return qFindString(haystack, size, from, executed 7943 times by 182 tests: return qFindString(haystack, size, from, reinterpret_cast<const QChar*>(s.constData()), len, cs);Executed by:
| 7943 | ||||||||||||||||||
| 10080 | reinterpret_cast<const QChar*>(s.constData()), len, cs); executed 7943 times by 182 tests: return qFindString(haystack, size, from, reinterpret_cast<const QChar*>(s.constData()), len, cs);Executed by:
| 7943 | ||||||||||||||||||
| 10081 | } | - | ||||||||||||||||||
| 10082 | - | |||||||||||||||||||
| 10083 | static inline bool qt_starts_with(const QChar *haystack, int haystackLen, | - | ||||||||||||||||||
| 10084 | const QChar *needle, int needleLen, Qt::CaseSensitivity cs) | - | ||||||||||||||||||
| 10085 | { | - | ||||||||||||||||||
| 10086 | if (!haystack)
| 264-260604 | ||||||||||||||||||
| 10087 | return !needle; executed 264 times by 8 tests: return !needle;Executed by:
| 264 | ||||||||||||||||||
| 10088 | if (haystackLen == 0)
| 23-260581 | ||||||||||||||||||
| 10089 | return needleLen == 0; executed 23 times by 5 tests: return needleLen == 0;Executed by:
| 23 | ||||||||||||||||||
| 10090 | if (needleLen > haystackLen)
| 53492-207089 | ||||||||||||||||||
| 10091 | return false; executed 53492 times by 28 tests: return false;Executed by:
| 53492 | ||||||||||||||||||
| 10092 | - | |||||||||||||||||||
| 10093 | const ushort *h = reinterpret_cast<const ushort*>(haystack); | - | ||||||||||||||||||
| 10094 | const ushort *n = reinterpret_cast<const ushort*>(needle); | - | ||||||||||||||||||
| 10095 | - | |||||||||||||||||||
| 10096 | if (cs == Qt::CaseSensitive) {
| 2128-204961 | ||||||||||||||||||
| 10097 | return qMemEquals(h, n, needleLen); executed 204961 times by 116 tests: return qMemEquals(h, n, needleLen);Executed by:
| 204961 | ||||||||||||||||||
| 10098 | } else { | - | ||||||||||||||||||
| 10099 | uint last = 0; | - | ||||||||||||||||||
| 10100 | uint olast = 0; | - | ||||||||||||||||||
| 10101 | for (int i = 0; i < needleLen; ++i)
| 609-5450 | ||||||||||||||||||
| 10102 | if (foldCase(h[i], last) != foldCase(n[i], olast))
| 1519-3931 | ||||||||||||||||||
| 10103 | return false; executed 1519 times by 13 tests: return false;Executed by:
| 1519 | ||||||||||||||||||
| 10104 | } executed 609 times by 21 tests: end of blockExecuted by:
| 609 | ||||||||||||||||||
| 10105 | return true; executed 609 times by 21 tests: return true;Executed by:
| 609 | ||||||||||||||||||
| 10106 | } | - | ||||||||||||||||||
| 10107 | - | |||||||||||||||||||
| 10108 | static inline bool qt_starts_with(const QChar *haystack, int haystackLen, | - | ||||||||||||||||||
| 10109 | QLatin1String needle, Qt::CaseSensitivity cs) | - | ||||||||||||||||||
| 10110 | { | - | ||||||||||||||||||
| 10111 | if (!haystack)
| 7027-264332 | ||||||||||||||||||
| 10112 | return !needle.latin1(); executed 7027 times by 55 tests: return !needle.latin1();Executed by:
| 7027 | ||||||||||||||||||
| 10113 | if (haystackLen == 0)
| 1834-262498 | ||||||||||||||||||
| 10114 | return !needle.latin1() || *needle.latin1() == 0; executed 1834 times by 11 tests: return !needle.latin1() || *needle.latin1() == 0;Executed by:
| 2-1834 | ||||||||||||||||||
| 10115 | const int slen = needle.size(); | - | ||||||||||||||||||
| 10116 | if (slen > haystackLen)
| 100359-162139 | ||||||||||||||||||
| 10117 | return false; executed 162139 times by 136 tests: return false;Executed by:
| 162139 | ||||||||||||||||||
| 10118 | const ushort *data = reinterpret_cast<const ushort*>(haystack); | - | ||||||||||||||||||
| 10119 | const uchar *latin = reinterpret_cast<const uchar*>(needle.latin1()); | - | ||||||||||||||||||
| 10120 | if (cs == Qt::CaseSensitive) {
| 3591-96768 | ||||||||||||||||||
| 10121 | return ucstrncmp(haystack, latin, slen) == 0; executed 96768 times by 232 tests: return ucstrncmp(haystack, latin, slen) == 0;Executed by:
| 96768 | ||||||||||||||||||
| 10122 | } else { | - | ||||||||||||||||||
| 10123 | for (int i = 0; i < slen; ++i)
| 31-3694 | ||||||||||||||||||
| 10124 | if (foldCase(data[i]) != foldCase((ushort)latin[i]))
| 134-3560 | ||||||||||||||||||
| 10125 | return false; executed 3560 times by 15 tests: return false;Executed by:
| 3560 | ||||||||||||||||||
| 10126 | } executed 31 times by 4 tests: end of blockExecuted by:
| 31 | ||||||||||||||||||
| 10127 | return true; executed 31 times by 4 tests: return true;Executed by:
| 31 | ||||||||||||||||||
| 10128 | } | - | ||||||||||||||||||
| 10129 | - | |||||||||||||||||||
| 10130 | static inline bool qt_ends_with(const QChar *haystack, int haystackLen, | - | ||||||||||||||||||
| 10131 | const QChar *needle, int needleLen, Qt::CaseSensitivity cs) | - | ||||||||||||||||||
| 10132 | { | - | ||||||||||||||||||
| 10133 | if (!haystack)
| 6-4652 | ||||||||||||||||||
| 10134 | return !needle; executed 6 times by 2 tests: return !needle;Executed by:
| 6 | ||||||||||||||||||
| 10135 | if (haystackLen == 0)
| 6-4646 | ||||||||||||||||||
| 10136 | return needleLen == 0; executed 6 times by 2 tests: return needleLen == 0;Executed by:
| 6 | ||||||||||||||||||
| 10137 | const int pos = haystackLen - needleLen; | - | ||||||||||||||||||
| 10138 | if (pos < 0)
| 212-4434 | ||||||||||||||||||
| 10139 | return false; executed 212 times by 24 tests: return false;Executed by:
| 212 | ||||||||||||||||||
| 10140 | - | |||||||||||||||||||
| 10141 | const ushort *h = reinterpret_cast<const ushort*>(haystack); | - | ||||||||||||||||||
| 10142 | const ushort *n = reinterpret_cast<const ushort*>(needle); | - | ||||||||||||||||||
| 10143 | - | |||||||||||||||||||
| 10144 | if (cs == Qt::CaseSensitive) {
| 23-4411 | ||||||||||||||||||
| 10145 | return qMemEquals(h + pos, n, needleLen); executed 4411 times by 60 tests: return qMemEquals(h + pos, n, needleLen);Executed by:
| 4411 | ||||||||||||||||||
| 10146 | } else { | - | ||||||||||||||||||
| 10147 | uint last = 0; | - | ||||||||||||||||||
| 10148 | uint olast = 0; | - | ||||||||||||||||||
| 10149 | for (int i = 0; i < needleLen; i++)
| 14-24 | ||||||||||||||||||
| 10150 | if (foldCase(h[pos+i], last) != foldCase(n[i], olast))
| 9-15 | ||||||||||||||||||
| 10151 | return false; executed 9 times by 4 tests: return false;Executed by:
| 9 | ||||||||||||||||||
| 10152 | } executed 14 times by 4 tests: end of blockExecuted by:
| 14 | ||||||||||||||||||
| 10153 | return true; executed 14 times by 4 tests: return true;Executed by:
| 14 | ||||||||||||||||||
| 10154 | } | - | ||||||||||||||||||
| 10155 | - | |||||||||||||||||||
| 10156 | - | |||||||||||||||||||
| 10157 | static inline bool qt_ends_with(const QChar *haystack, int haystackLen, | - | ||||||||||||||||||
| 10158 | QLatin1String needle, Qt::CaseSensitivity cs) | - | ||||||||||||||||||
| 10159 | { | - | ||||||||||||||||||
| 10160 | if (!haystack)
| 201-146061 | ||||||||||||||||||
| 10161 | return !needle.latin1(); executed 201 times by 13 tests: return !needle.latin1();Executed by:
| 201 | ||||||||||||||||||
| 10162 | if (haystackLen == 0)
| 14-146047 | ||||||||||||||||||
| 10163 | return !needle.latin1() || *needle.latin1() == 0; executed 14 times by 3 tests: return !needle.latin1() || *needle.latin1() == 0;Executed by:
| 2-14 | ||||||||||||||||||
| 10164 | const int slen = needle.size(); | - | ||||||||||||||||||
| 10165 | int pos = haystackLen - slen; | - | ||||||||||||||||||
| 10166 | if (pos < 0)
| 49748-96299 | ||||||||||||||||||
| 10167 | return false; executed 49748 times by 11 tests: return false;Executed by:
| 49748 | ||||||||||||||||||
| 10168 | const uchar *latin = reinterpret_cast<const uchar*>(needle.latin1()); | - | ||||||||||||||||||
| 10169 | const ushort *data = reinterpret_cast<const ushort*>(haystack); | - | ||||||||||||||||||
| 10170 | if (cs == Qt::CaseSensitive) {
| 524-95775 | ||||||||||||||||||
| 10171 | return ucstrncmp(haystack + pos, latin, slen) == 0; executed 95775 times by 120 tests: return ucstrncmp(haystack + pos, latin, slen) == 0;Executed by:
| 95775 | ||||||||||||||||||
| 10172 | } else { | - | ||||||||||||||||||
| 10173 | for (int i = 0; i < slen; i++)
| 469-1041 | ||||||||||||||||||
| 10174 | if (foldCase(data[pos+i]) != foldCase((ushort)latin[i]))
| 55-986 | ||||||||||||||||||
| 10175 | return false; executed 55 times by 7 tests: return false;Executed by:
| 55 | ||||||||||||||||||
| 10176 | } executed 469 times by 16 tests: end of blockExecuted by:
| 469 | ||||||||||||||||||
| 10177 | return true; executed 469 times by 16 tests: return true;Executed by:
| 469 | ||||||||||||||||||
| 10178 | } | - | ||||||||||||||||||
| 10179 | - | |||||||||||||||||||
| 10180 | /*! | - | ||||||||||||||||||
| 10181 | \since 4.8 | - | ||||||||||||||||||
| 10182 | - | |||||||||||||||||||
| 10183 | Returns a Latin-1 representation of the string as a QByteArray. | - | ||||||||||||||||||
| 10184 | - | |||||||||||||||||||
| 10185 | The returned byte array is undefined if the string contains non-Latin1 | - | ||||||||||||||||||
| 10186 | characters. Those characters may be suppressed or replaced with a | - | ||||||||||||||||||
| 10187 | question mark. | - | ||||||||||||||||||
| 10188 | - | |||||||||||||||||||
| 10189 | \sa toUtf8(), toLocal8Bit(), QTextCodec | - | ||||||||||||||||||
| 10190 | */ | - | ||||||||||||||||||
| 10191 | QByteArray QStringRef::toLatin1() const | - | ||||||||||||||||||
| 10192 | { | - | ||||||||||||||||||
| 10193 | return QString::toLatin1_helper(unicode(), length()); executed 256 times by 6 tests: return QString::toLatin1_helper(unicode(), length());Executed by:
| 256 | ||||||||||||||||||
| 10194 | } | - | ||||||||||||||||||
| 10195 | - | |||||||||||||||||||
| 10196 | /*! | - | ||||||||||||||||||
| 10197 | \fn QByteArray QStringRef::toAscii() const | - | ||||||||||||||||||
| 10198 | \since 4.8 | - | ||||||||||||||||||
| 10199 | \deprecated | - | ||||||||||||||||||
| 10200 | - | |||||||||||||||||||
| 10201 | Returns an 8-bit representation of the string as a QByteArray. | - | ||||||||||||||||||
| 10202 | - | |||||||||||||||||||
| 10203 | This function does the same as toLatin1(). | - | ||||||||||||||||||
| 10204 | - | |||||||||||||||||||
| 10205 | Note that, despite the name, this function does not necessarily return an US-ASCII | - | ||||||||||||||||||
| 10206 | (ANSI X3.4-1986) string and its result may not be US-ASCII compatible. | - | ||||||||||||||||||
| 10207 | - | |||||||||||||||||||
| 10208 | \sa toLatin1(), toUtf8(), toLocal8Bit(), QTextCodec | - | ||||||||||||||||||
| 10209 | */ | - | ||||||||||||||||||
| 10210 | - | |||||||||||||||||||
| 10211 | /*! | - | ||||||||||||||||||
| 10212 | \since 4.8 | - | ||||||||||||||||||
| 10213 | - | |||||||||||||||||||
| 10214 | Returns the local 8-bit representation of the string as a | - | ||||||||||||||||||
| 10215 | QByteArray. The returned byte array is undefined if the string | - | ||||||||||||||||||
| 10216 | contains characters not supported by the local 8-bit encoding. | - | ||||||||||||||||||
| 10217 | - | |||||||||||||||||||
| 10218 | QTextCodec::codecForLocale() is used to perform the conversion from | - | ||||||||||||||||||
| 10219 | Unicode. If the locale encoding could not be determined, this function | - | ||||||||||||||||||
| 10220 | does the same as toLatin1(). | - | ||||||||||||||||||
| 10221 | - | |||||||||||||||||||
| 10222 | If this string contains any characters that cannot be encoded in the | - | ||||||||||||||||||
| 10223 | locale, the returned byte array is undefined. Those characters may be | - | ||||||||||||||||||
| 10224 | suppressed or replaced by another. | - | ||||||||||||||||||
| 10225 | - | |||||||||||||||||||
| 10226 | \sa toLatin1(), toUtf8(), QTextCodec | - | ||||||||||||||||||
| 10227 | */ | - | ||||||||||||||||||
| 10228 | QByteArray QStringRef::toLocal8Bit() const | - | ||||||||||||||||||
| 10229 | { | - | ||||||||||||||||||
| 10230 | #ifndef QT_NO_TEXTCODEC | - | ||||||||||||||||||
| 10231 | QTextCodec *localeCodec = QTextCodec::codecForLocale(); | - | ||||||||||||||||||
| 10232 | if (localeCodec)
| 0-5 | ||||||||||||||||||
| 10233 | return localeCodec->fromUnicode(unicode(), length()); executed 5 times by 1 test: return localeCodec->fromUnicode(unicode(), length());Executed by:
| 5 | ||||||||||||||||||
| 10234 | #endif // QT_NO_TEXTCODEC | - | ||||||||||||||||||
| 10235 | return toLatin1(); never executed: return toLatin1(); | 0 | ||||||||||||||||||
| 10236 | } | - | ||||||||||||||||||
| 10237 | - | |||||||||||||||||||
| 10238 | /*! | - | ||||||||||||||||||
| 10239 | \since 4.8 | - | ||||||||||||||||||
| 10240 | - | |||||||||||||||||||
| 10241 | Returns a UTF-8 representation of the string as a QByteArray. | - | ||||||||||||||||||
| 10242 | - | |||||||||||||||||||
| 10243 | UTF-8 is a Unicode codec and can represent all characters in a Unicode | - | ||||||||||||||||||
| 10244 | string like QString. | - | ||||||||||||||||||
| 10245 | - | |||||||||||||||||||
| 10246 | \sa toLatin1(), toLocal8Bit(), QTextCodec | - | ||||||||||||||||||
| 10247 | */ | - | ||||||||||||||||||
| 10248 | QByteArray QStringRef::toUtf8() const | - | ||||||||||||||||||
| 10249 | { | - | ||||||||||||||||||
| 10250 | if (isNull())
| 0-5 | ||||||||||||||||||
| 10251 | return QByteArray(); never executed: return QByteArray(); | 0 | ||||||||||||||||||
| 10252 | - | |||||||||||||||||||
| 10253 | return QUtf8::convertFromUnicode(constData(), length()); executed 5 times by 1 test: return QUtf8::convertFromUnicode(constData(), length());Executed by:
| 5 | ||||||||||||||||||
| 10254 | } | - | ||||||||||||||||||
| 10255 | - | |||||||||||||||||||
| 10256 | /*! | - | ||||||||||||||||||
| 10257 | \since 4.8 | - | ||||||||||||||||||
| 10258 | - | |||||||||||||||||||
| 10259 | Returns a UCS-4/UTF-32 representation of the string as a QVector<uint>. | - | ||||||||||||||||||
| 10260 | - | |||||||||||||||||||
| 10261 | UCS-4 is a Unicode codec and therefore it is lossless. All characters from | - | ||||||||||||||||||
| 10262 | this string will be encoded in UCS-4. Any invalid sequence of code units in | - | ||||||||||||||||||
| 10263 | this string is replaced by the Unicode's replacement character | - | ||||||||||||||||||
| 10264 | (QChar::ReplacementCharacter, which corresponds to \c{U+FFFD}). | - | ||||||||||||||||||
| 10265 | - | |||||||||||||||||||
| 10266 | The returned vector is not NUL terminated. | - | ||||||||||||||||||
| 10267 | - | |||||||||||||||||||
| 10268 | \sa toUtf8(), toLatin1(), toLocal8Bit(), QTextCodec | - | ||||||||||||||||||
| 10269 | */ | - | ||||||||||||||||||
| 10270 | QVector<uint> QStringRef::toUcs4() const | - | ||||||||||||||||||
| 10271 | { | - | ||||||||||||||||||
| 10272 | QVector<uint> v(length()); | - | ||||||||||||||||||
| 10273 | uint *a = v.data(); | - | ||||||||||||||||||
| 10274 | int len = QString::toUcs4_helper(reinterpret_cast<const ushort *>(unicode()), length(), a); | - | ||||||||||||||||||
| 10275 | v.resize(len); | - | ||||||||||||||||||
| 10276 | return v; never executed: return v; | 0 | ||||||||||||||||||
| 10277 | } | - | ||||||||||||||||||
| 10278 | - | |||||||||||||||||||
| 10279 | /*! | - | ||||||||||||||||||
| 10280 | Returns a string that has whitespace removed from the start and | - | ||||||||||||||||||
| 10281 | the end. | - | ||||||||||||||||||
| 10282 | - | |||||||||||||||||||
| 10283 | Whitespace means any character for which QChar::isSpace() returns | - | ||||||||||||||||||
| 10284 | \c true. This includes the ASCII characters '\\t', '\\n', '\\v', | - | ||||||||||||||||||
| 10285 | '\\f', '\\r', and ' '. | - | ||||||||||||||||||
| 10286 | - | |||||||||||||||||||
| 10287 | Unlike QString::simplified(), trimmed() leaves internal whitespace alone. | - | ||||||||||||||||||
| 10288 | - | |||||||||||||||||||
| 10289 | \since 5.1 | - | ||||||||||||||||||
| 10290 | - | |||||||||||||||||||
| 10291 | \sa QString::trimmed() | - | ||||||||||||||||||
| 10292 | */ | - | ||||||||||||||||||
| 10293 | QStringRef QStringRef::trimmed() const | - | ||||||||||||||||||
| 10294 | { | - | ||||||||||||||||||
| 10295 | const QChar *begin = cbegin(); | - | ||||||||||||||||||
| 10296 | const QChar *end = cend(); | - | ||||||||||||||||||
| 10297 | QStringAlgorithms<const QStringRef>::trimmed_helper_positions(begin, end); | - | ||||||||||||||||||
| 10298 | if (begin == cbegin() && end == cend())
| 0-3 | ||||||||||||||||||
| 10299 | return *this; executed 1 time by 1 test: return *this;Executed by:
| 1 | ||||||||||||||||||
| 10300 | if (begin == end)
| 1-2 | ||||||||||||||||||
| 10301 | return QStringRef(); executed 1 time by 1 test: return QStringRef();Executed by:
| 1 | ||||||||||||||||||
| 10302 | int position = m_position + (begin - cbegin()); | - | ||||||||||||||||||
| 10303 | return QStringRef(m_string, position, end - begin); executed 2 times by 1 test: return QStringRef(m_string, position, end - begin);Executed by:
| 2 | ||||||||||||||||||
| 10304 | } | - | ||||||||||||||||||
| 10305 | - | |||||||||||||||||||
| 10306 | /*! | - | ||||||||||||||||||
| 10307 | Returns the string converted to a \c{long long} using base \a | - | ||||||||||||||||||
| 10308 | base, which is 10 by default and must be between 2 and 36, or 0. | - | ||||||||||||||||||
| 10309 | Returns 0 if the conversion fails. | - | ||||||||||||||||||
| 10310 | - | |||||||||||||||||||
| 10311 | If a conversion error occurs, *\a{ok} is set to \c false; otherwise | - | ||||||||||||||||||
| 10312 | *\a{ok} is set to \c true. | - | ||||||||||||||||||
| 10313 | - | |||||||||||||||||||
| 10314 | If \a base is 0, the C language convention is used: If the string | - | ||||||||||||||||||
| 10315 | begins with "0x", base 16 is used; if the string begins with "0", | - | ||||||||||||||||||
| 10316 | base 8 is used; otherwise, base 10 is used. | - | ||||||||||||||||||
| 10317 | - | |||||||||||||||||||
| 10318 | The string conversion will always happen in the 'C' locale. For locale | - | ||||||||||||||||||
| 10319 | dependent conversion use QLocale::toLongLong() | - | ||||||||||||||||||
| 10320 | - | |||||||||||||||||||
| 10321 | \sa QString::toLongLong() | - | ||||||||||||||||||
| 10322 | - | |||||||||||||||||||
| 10323 | \since 5.1 | - | ||||||||||||||||||
| 10324 | */ | - | ||||||||||||||||||
| 10325 | - | |||||||||||||||||||
| 10326 | qint64 QStringRef::toLongLong(bool *ok, int base) const | - | ||||||||||||||||||
| 10327 | { | - | ||||||||||||||||||
| 10328 | return QString::toIntegral_helper<qint64>(constData(), size(), ok, base); executed 46761 times by 1 test: return QString::toIntegral_helper<qint64>(constData(), size(), ok, base);Executed by:
| 46761 | ||||||||||||||||||
| 10329 | } | - | ||||||||||||||||||
| 10330 | - | |||||||||||||||||||
| 10331 | /*! | - | ||||||||||||||||||
| 10332 | Returns the string converted to an \c{unsigned long long} using base \a | - | ||||||||||||||||||
| 10333 | base, which is 10 by default and must be between 2 and 36, or 0. | - | ||||||||||||||||||
| 10334 | Returns 0 if the conversion fails. | - | ||||||||||||||||||
| 10335 | - | |||||||||||||||||||
| 10336 | If a conversion error occurs, *\a{ok} is set to \c false; otherwise | - | ||||||||||||||||||
| 10337 | *\a{ok} is set to \c true. | - | ||||||||||||||||||
| 10338 | - | |||||||||||||||||||
| 10339 | If \a base is 0, the C language convention is used: If the string | - | ||||||||||||||||||
| 10340 | begins with "0x", base 16 is used; if the string begins with "0", | - | ||||||||||||||||||
| 10341 | base 8 is used; otherwise, base 10 is used. | - | ||||||||||||||||||
| 10342 | - | |||||||||||||||||||
| 10343 | The string conversion will always happen in the 'C' locale. For locale | - | ||||||||||||||||||
| 10344 | dependent conversion use QLocale::toULongLong() | - | ||||||||||||||||||
| 10345 | - | |||||||||||||||||||
| 10346 | \sa QString::toULongLong() | - | ||||||||||||||||||
| 10347 | - | |||||||||||||||||||
| 10348 | \since 5.1 | - | ||||||||||||||||||
| 10349 | */ | - | ||||||||||||||||||
| 10350 | - | |||||||||||||||||||
| 10351 | quint64 QStringRef::toULongLong(bool *ok, int base) const | - | ||||||||||||||||||
| 10352 | { | - | ||||||||||||||||||
| 10353 | return QString::toIntegral_helper<quint64>(constData(), size(), ok, base); executed 41 times by 1 test: return QString::toIntegral_helper<quint64>(constData(), size(), ok, base);Executed by:
| 41 | ||||||||||||||||||
| 10354 | } | - | ||||||||||||||||||
| 10355 | - | |||||||||||||||||||
| 10356 | /*! | - | ||||||||||||||||||
| 10357 | \fn long QStringRef::toLong(bool *ok, int base) const | - | ||||||||||||||||||
| 10358 | - | |||||||||||||||||||
| 10359 | Returns the string converted to a \c long using base \a | - | ||||||||||||||||||
| 10360 | base, which is 10 by default and must be between 2 and 36, or 0. | - | ||||||||||||||||||
| 10361 | Returns 0 if the conversion fails. | - | ||||||||||||||||||
| 10362 | - | |||||||||||||||||||
| 10363 | If a conversion error occurs, *\a{ok} is set to \c false; otherwise | - | ||||||||||||||||||
| 10364 | *\a{ok} is set to \c true. | - | ||||||||||||||||||
| 10365 | - | |||||||||||||||||||
| 10366 | If \a base is 0, the C language convention is used: If the string | - | ||||||||||||||||||
| 10367 | begins with "0x", base 16 is used; if the string begins with "0", | - | ||||||||||||||||||
| 10368 | base 8 is used; otherwise, base 10 is used. | - | ||||||||||||||||||
| 10369 | - | |||||||||||||||||||
| 10370 | The string conversion will always happen in the 'C' locale. For locale | - | ||||||||||||||||||
| 10371 | dependent conversion use QLocale::toLong() | - | ||||||||||||||||||
| 10372 | - | |||||||||||||||||||
| 10373 | \sa QString::toLong() | - | ||||||||||||||||||
| 10374 | - | |||||||||||||||||||
| 10375 | \since 5.1 | - | ||||||||||||||||||
| 10376 | */ | - | ||||||||||||||||||
| 10377 | - | |||||||||||||||||||
| 10378 | long QStringRef::toLong(bool *ok, int base) const | - | ||||||||||||||||||
| 10379 | { | - | ||||||||||||||||||
| 10380 | return QString::toIntegral_helper<long>(constData(), size(), ok, base); executed 58 times by 3 tests: return QString::toIntegral_helper<long>(constData(), size(), ok, base);Executed by:
| 58 | ||||||||||||||||||
| 10381 | } | - | ||||||||||||||||||
| 10382 | - | |||||||||||||||||||
| 10383 | /*! | - | ||||||||||||||||||
| 10384 | \fn ulong QStringRef::toULong(bool *ok, int base) const | - | ||||||||||||||||||
| 10385 | - | |||||||||||||||||||
| 10386 | Returns the string converted to an \c{unsigned long} using base \a | - | ||||||||||||||||||
| 10387 | base, which is 10 by default and must be between 2 and 36, or 0. | - | ||||||||||||||||||
| 10388 | Returns 0 if the conversion fails. | - | ||||||||||||||||||
| 10389 | - | |||||||||||||||||||
| 10390 | If a conversion error occurs, *\a{ok} is set to \c false; otherwise | - | ||||||||||||||||||
| 10391 | *\a{ok} is set to \c true. | - | ||||||||||||||||||
| 10392 | - | |||||||||||||||||||
| 10393 | If \a base is 0, the C language convention is used: If the string | - | ||||||||||||||||||
| 10394 | begins with "0x", base 16 is used; if the string begins with "0", | - | ||||||||||||||||||
| 10395 | base 8 is used; otherwise, base 10 is used. | - | ||||||||||||||||||
| 10396 | - | |||||||||||||||||||
| 10397 | The string conversion will always happen in the 'C' locale. For locale | - | ||||||||||||||||||
| 10398 | dependent conversion use QLocale::toULongLong() | - | ||||||||||||||||||
| 10399 | - | |||||||||||||||||||
| 10400 | \sa QString::toULong() | - | ||||||||||||||||||
| 10401 | - | |||||||||||||||||||
| 10402 | \since 5.1 | - | ||||||||||||||||||
| 10403 | */ | - | ||||||||||||||||||
| 10404 | - | |||||||||||||||||||
| 10405 | ulong QStringRef::toULong(bool *ok, int base) const | - | ||||||||||||||||||
| 10406 | { | - | ||||||||||||||||||
| 10407 | return QString::toIntegral_helper<ulong>(constData(), size(), ok, base); executed 40 times by 1 test: return QString::toIntegral_helper<ulong>(constData(), size(), ok, base);Executed by:
| 40 | ||||||||||||||||||
| 10408 | } | - | ||||||||||||||||||
| 10409 | - | |||||||||||||||||||
| 10410 | - | |||||||||||||||||||
| 10411 | /*! | - | ||||||||||||||||||
| 10412 | Returns the string converted to an \c int using base \a | - | ||||||||||||||||||
| 10413 | base, which is 10 by default and must be between 2 and 36, or 0. | - | ||||||||||||||||||
| 10414 | Returns 0 if the conversion fails. | - | ||||||||||||||||||
| 10415 | - | |||||||||||||||||||
| 10416 | If a conversion error occurs, *\a{ok} is set to \c false; otherwise | - | ||||||||||||||||||
| 10417 | *\a{ok} is set to \c true. | - | ||||||||||||||||||
| 10418 | - | |||||||||||||||||||
| 10419 | If \a base is 0, the C language convention is used: If the string | - | ||||||||||||||||||
| 10420 | begins with "0x", base 16 is used; if the string begins with "0", | - | ||||||||||||||||||
| 10421 | base 8 is used; otherwise, base 10 is used. | - | ||||||||||||||||||
| 10422 | - | |||||||||||||||||||
| 10423 | The string conversion will always happen in the 'C' locale. For locale | - | ||||||||||||||||||
| 10424 | dependent conversion use QLocale::toInt() | - | ||||||||||||||||||
| 10425 | - | |||||||||||||||||||
| 10426 | \sa QString::toInt() | - | ||||||||||||||||||
| 10427 | - | |||||||||||||||||||
| 10428 | \since 5.1 | - | ||||||||||||||||||
| 10429 | */ | - | ||||||||||||||||||
| 10430 | - | |||||||||||||||||||
| 10431 | int QStringRef::toInt(bool *ok, int base) const | - | ||||||||||||||||||
| 10432 | { | - | ||||||||||||||||||
| 10433 | return QString::toIntegral_helper<int>(constData(), size(), ok, base); executed 786 times by 9 tests: return QString::toIntegral_helper<int>(constData(), size(), ok, base);Executed by:
| 786 | ||||||||||||||||||
| 10434 | } | - | ||||||||||||||||||
| 10435 | - | |||||||||||||||||||
| 10436 | /*! | - | ||||||||||||||||||
| 10437 | Returns the string converted to an \c{unsigned int} using base \a | - | ||||||||||||||||||
| 10438 | base, which is 10 by default and must be between 2 and 36, or 0. | - | ||||||||||||||||||
| 10439 | Returns 0 if the conversion fails. | - | ||||||||||||||||||
| 10440 | - | |||||||||||||||||||
| 10441 | If a conversion error occurs, *\a{ok} is set to \c false; otherwise | - | ||||||||||||||||||
| 10442 | *\a{ok} is set to \c true. | - | ||||||||||||||||||
| 10443 | - | |||||||||||||||||||
| 10444 | If \a base is 0, the C language convention is used: If the string | - | ||||||||||||||||||
| 10445 | begins with "0x", base 16 is used; if the string begins with "0", | - | ||||||||||||||||||
| 10446 | base 8 is used; otherwise, base 10 is used. | - | ||||||||||||||||||
| 10447 | - | |||||||||||||||||||
| 10448 | The string conversion will always happen in the 'C' locale. For locale | - | ||||||||||||||||||
| 10449 | dependent conversion use QLocale::toUInt() | - | ||||||||||||||||||
| 10450 | - | |||||||||||||||||||
| 10451 | \sa QString::toUInt() | - | ||||||||||||||||||
| 10452 | - | |||||||||||||||||||
| 10453 | \since 5.1 | - | ||||||||||||||||||
| 10454 | */ | - | ||||||||||||||||||
| 10455 | - | |||||||||||||||||||
| 10456 | uint QStringRef::toUInt(bool *ok, int base) const | - | ||||||||||||||||||
| 10457 | { | - | ||||||||||||||||||
| 10458 | return QString::toIntegral_helper<uint>(constData(), size(), ok, base); executed 1467 times by 3 tests: return QString::toIntegral_helper<uint>(constData(), size(), ok, base);Executed by:
| 1467 | ||||||||||||||||||
| 10459 | } | - | ||||||||||||||||||
| 10460 | - | |||||||||||||||||||
| 10461 | /*! | - | ||||||||||||||||||
| 10462 | Returns the string converted to a \c short using base \a | - | ||||||||||||||||||
| 10463 | base, which is 10 by default and must be between 2 and 36, or 0. | - | ||||||||||||||||||
| 10464 | Returns 0 if the conversion fails. | - | ||||||||||||||||||
| 10465 | - | |||||||||||||||||||
| 10466 | If a conversion error occurs, *\a{ok} is set to \c false; otherwise | - | ||||||||||||||||||
| 10467 | *\a{ok} is set to \c true. | - | ||||||||||||||||||
| 10468 | - | |||||||||||||||||||
| 10469 | If \a base is 0, the C language convention is used: If the string | - | ||||||||||||||||||
| 10470 | begins with "0x", base 16 is used; if the string begins with "0", | - | ||||||||||||||||||
| 10471 | base 8 is used; otherwise, base 10 is used. | - | ||||||||||||||||||
| 10472 | - | |||||||||||||||||||
| 10473 | The string conversion will always happen in the 'C' locale. For locale | - | ||||||||||||||||||
| 10474 | dependent conversion use QLocale::toShort() | - | ||||||||||||||||||
| 10475 | - | |||||||||||||||||||
| 10476 | \sa QString::toShort() | - | ||||||||||||||||||
| 10477 | - | |||||||||||||||||||
| 10478 | \since 5.1 | - | ||||||||||||||||||
| 10479 | */ | - | ||||||||||||||||||
| 10480 | - | |||||||||||||||||||
| 10481 | short QStringRef::toShort(bool *ok, int base) const | - | ||||||||||||||||||
| 10482 | { | - | ||||||||||||||||||
| 10483 | return QString::toIntegral_helper<short>(constData(), size(), ok, base); executed 70 times by 1 test: return QString::toIntegral_helper<short>(constData(), size(), ok, base);Executed by:
| 70 | ||||||||||||||||||
| 10484 | } | - | ||||||||||||||||||
| 10485 | - | |||||||||||||||||||
| 10486 | /*! | - | ||||||||||||||||||
| 10487 | Returns the string converted to an \c{unsigned short} using base \a | - | ||||||||||||||||||
| 10488 | base, which is 10 by default and must be between 2 and 36, or 0. | - | ||||||||||||||||||
| 10489 | Returns 0 if the conversion fails. | - | ||||||||||||||||||
| 10490 | - | |||||||||||||||||||
| 10491 | If a conversion error occurs, *\a{ok} is set to \c false; otherwise | - | ||||||||||||||||||
| 10492 | *\a{ok} is set to \c true. | - | ||||||||||||||||||
| 10493 | - | |||||||||||||||||||
| 10494 | If \a base is 0, the C language convention is used: If the string | - | ||||||||||||||||||
| 10495 | begins with "0x", base 16 is used; if the string begins with "0", | - | ||||||||||||||||||
| 10496 | base 8 is used; otherwise, base 10 is used. | - | ||||||||||||||||||
| 10497 | - | |||||||||||||||||||
| 10498 | The string conversion will always happen in the 'C' locale. For locale | - | ||||||||||||||||||
| 10499 | dependent conversion use QLocale::toUShort() | - | ||||||||||||||||||
| 10500 | - | |||||||||||||||||||
| 10501 | \sa QString::toUShort() | - | ||||||||||||||||||
| 10502 | - | |||||||||||||||||||
| 10503 | \since 5.1 | - | ||||||||||||||||||
| 10504 | */ | - | ||||||||||||||||||
| 10505 | - | |||||||||||||||||||
| 10506 | ushort QStringRef::toUShort(bool *ok, int base) const | - | ||||||||||||||||||
| 10507 | { | - | ||||||||||||||||||
| 10508 | return QString::toIntegral_helper<ushort>(constData(), size(), ok, base); executed 61 times by 1 test: return QString::toIntegral_helper<ushort>(constData(), size(), ok, base);Executed by:
| 61 | ||||||||||||||||||
| 10509 | } | - | ||||||||||||||||||
| 10510 | - | |||||||||||||||||||
| 10511 | - | |||||||||||||||||||
| 10512 | /*! | - | ||||||||||||||||||
| 10513 | Returns the string converted to a \c double value. | - | ||||||||||||||||||
| 10514 | - | |||||||||||||||||||
| 10515 | Returns 0.0 if the conversion fails. | - | ||||||||||||||||||
| 10516 | - | |||||||||||||||||||
| 10517 | If a conversion error occurs, \c{*}\a{ok} is set to \c false; | - | ||||||||||||||||||
| 10518 | otherwise \c{*}\a{ok} is set to \c true. | - | ||||||||||||||||||
| 10519 | - | |||||||||||||||||||
| 10520 | The string conversion will always happen in the 'C' locale. For locale | - | ||||||||||||||||||
| 10521 | dependent conversion use QLocale::toDouble() | - | ||||||||||||||||||
| 10522 | - | |||||||||||||||||||
| 10523 | For historic reasons, this function does not handle | - | ||||||||||||||||||
| 10524 | thousands group separators. If you need to convert such numbers, | - | ||||||||||||||||||
| 10525 | use QLocale::toDouble(). | - | ||||||||||||||||||
| 10526 | - | |||||||||||||||||||
| 10527 | \sa QString::toDouble() | - | ||||||||||||||||||
| 10528 | - | |||||||||||||||||||
| 10529 | \since 5.1 | - | ||||||||||||||||||
| 10530 | */ | - | ||||||||||||||||||
| 10531 | - | |||||||||||||||||||
| 10532 | double QStringRef::toDouble(bool *ok) const | - | ||||||||||||||||||
| 10533 | { | - | ||||||||||||||||||
| 10534 | return QLocaleData::c()->stringToDouble(constData(), size(), ok, QLocaleData::FailOnGroupSeparators); executed 79 times by 1 test: return QLocaleData::c()->stringToDouble(constData(), size(), ok, QLocaleData::FailOnGroupSeparators);Executed by:
| 79 | ||||||||||||||||||
| 10535 | } | - | ||||||||||||||||||
| 10536 | - | |||||||||||||||||||
| 10537 | /*! | - | ||||||||||||||||||
| 10538 | Returns the string converted to a \c float value. | - | ||||||||||||||||||
| 10539 | - | |||||||||||||||||||
| 10540 | If a conversion error occurs, *\a{ok} is set to \c false; otherwise | - | ||||||||||||||||||
| 10541 | *\a{ok} is set to \c true. Returns 0.0 if the conversion fails. | - | ||||||||||||||||||
| 10542 | - | |||||||||||||||||||
| 10543 | The string conversion will always happen in the 'C' locale. For locale | - | ||||||||||||||||||
| 10544 | dependent conversion use QLocale::toFloat() | - | ||||||||||||||||||
| 10545 | - | |||||||||||||||||||
| 10546 | \sa QString::toFloat() | - | ||||||||||||||||||
| 10547 | - | |||||||||||||||||||
| 10548 | \since 5.1 | - | ||||||||||||||||||
| 10549 | */ | - | ||||||||||||||||||
| 10550 | - | |||||||||||||||||||
| 10551 | float QStringRef::toFloat(bool *ok) const | - | ||||||||||||||||||
| 10552 | { | - | ||||||||||||||||||
| 10553 | return QLocaleData::convertDoubleToFloat(toDouble(ok), ok); executed 15 times by 1 test: return QLocaleData::convertDoubleToFloat(toDouble(ok), ok);Executed by:
| 15 | ||||||||||||||||||
| 10554 | } | - | ||||||||||||||||||
| 10555 | - | |||||||||||||||||||
| 10556 | /*! | - | ||||||||||||||||||
| 10557 | \obsolete | - | ||||||||||||||||||
| 10558 | \fn QString Qt::escape(const QString &plain) | - | ||||||||||||||||||
| 10559 | - | |||||||||||||||||||
| 10560 | Use QString::toHtmlEscaped() instead. | - | ||||||||||||||||||
| 10561 | */ | - | ||||||||||||||||||
| 10562 | - | |||||||||||||||||||
| 10563 | /*! | - | ||||||||||||||||||
| 10564 | \since 5.0 | - | ||||||||||||||||||
| 10565 | - | |||||||||||||||||||
| 10566 | Converts a plain text string to an HTML string with | - | ||||||||||||||||||
| 10567 | HTML metacharacters \c{<}, \c{>}, \c{&}, and \c{"} replaced by HTML | - | ||||||||||||||||||
| 10568 | entities. | - | ||||||||||||||||||
| 10569 | - | |||||||||||||||||||
| 10570 | Example: | - | ||||||||||||||||||
| 10571 | - | |||||||||||||||||||
| 10572 | \snippet code/src_corelib_tools_qstring.cpp 7 | - | ||||||||||||||||||
| 10573 | */ | - | ||||||||||||||||||
| 10574 | QString QString::toHtmlEscaped() const | - | ||||||||||||||||||
| 10575 | { | - | ||||||||||||||||||
| 10576 | QString rich; | - | ||||||||||||||||||
| 10577 | const int len = length(); | - | ||||||||||||||||||
| 10578 | rich.reserve(int(len * 1.1)); | - | ||||||||||||||||||
| 10579 | for (int i = 0; i < len; ++i) {
| 2656-23789 | ||||||||||||||||||
| 10580 | if (at(i) == QLatin1Char('<'))
| 737-23052 | ||||||||||||||||||
| 10581 | rich += QLatin1String("<"); executed 737 times by 4 tests: rich += QLatin1String("<");Executed by:
| 737 | ||||||||||||||||||
| 10582 | else if (at(i) == QLatin1Char('>'))
| 737-22315 | ||||||||||||||||||
| 10583 | rich += QLatin1String(">"); executed 737 times by 4 tests: rich += QLatin1String(">");Executed by:
| 737 | ||||||||||||||||||
| 10584 | else if (at(i) == QLatin1Char('&'))
| 5-22310 | ||||||||||||||||||
| 10585 | rich += QLatin1String("&"); executed 5 times by 2 tests: rich += QLatin1String("&");Executed by:
| 5 | ||||||||||||||||||
| 10586 | else if (at(i) == QLatin1Char('"'))
| 6-22304 | ||||||||||||||||||
| 10587 | rich += QLatin1String("""); executed 6 times by 2 tests: rich += QLatin1String(""");Executed by:
| 6 | ||||||||||||||||||
| 10588 | else | - | ||||||||||||||||||
| 10589 | rich += at(i); executed 22304 times by 20 tests: rich += at(i);Executed by:
| 22304 | ||||||||||||||||||
| 10590 | } | - | ||||||||||||||||||
| 10591 | rich.squeeze(); | - | ||||||||||||||||||
| 10592 | return rich; executed 2656 times by 20 tests: return rich;Executed by:
| 2656 | ||||||||||||||||||
| 10593 | } | - | ||||||||||||||||||
| 10594 | - | |||||||||||||||||||
| 10595 | /*! | - | ||||||||||||||||||
| 10596 | \macro QStringLiteral(str) | - | ||||||||||||||||||
| 10597 | \relates QString | - | ||||||||||||||||||
| 10598 | - | |||||||||||||||||||
| 10599 | The macro generates the data for a QString out of \a str at compile time if the compiler supports it. | - | ||||||||||||||||||
| 10600 | Creating a QString from it is free in this case, and the generated string data is stored in | - | ||||||||||||||||||
| 10601 | the read-only segment of the compiled object file. | - | ||||||||||||||||||
| 10602 | - | |||||||||||||||||||
| 10603 | For compilers not supporting the creation of compile time strings, QStringLiteral will fall back to | - | ||||||||||||||||||
| 10604 | QString::fromUtf8(). | - | ||||||||||||||||||
| 10605 | - | |||||||||||||||||||
| 10606 | If you have code looking like: | - | ||||||||||||||||||
| 10607 | \code | - | ||||||||||||||||||
| 10608 | if (node.hasAttribute("http-contents-length")) //... | - | ||||||||||||||||||
| 10609 | \endcode | - | ||||||||||||||||||
| 10610 | One temporary QString will be created to be passed as the hasAttribute function parameter. | - | ||||||||||||||||||
| 10611 | This can be quite expensive, as it involves a memory allocation and the copy and the conversion | - | ||||||||||||||||||
| 10612 | of the data into QString's internal encoding. | - | ||||||||||||||||||
| 10613 | - | |||||||||||||||||||
| 10614 | This can be avoided by doing | - | ||||||||||||||||||
| 10615 | \code | - | ||||||||||||||||||
| 10616 | if (node.hasAttribute(QStringLiteral("http-contents-length"))) //... | - | ||||||||||||||||||
| 10617 | \endcode | - | ||||||||||||||||||
| 10618 | Then the QString's internal data will be generated at compile time and no conversion or allocation | - | ||||||||||||||||||
| 10619 | will occur at runtime | - | ||||||||||||||||||
| 10620 | - | |||||||||||||||||||
| 10621 | Using QStringLiteral instead of a double quoted ascii literal can significantly speed up creation | - | ||||||||||||||||||
| 10622 | of QString's from data known at compile time. | - | ||||||||||||||||||
| 10623 | - | |||||||||||||||||||
| 10624 | If the compiler is C++11 enabled the string \a str can actually contain unicode data. | - | ||||||||||||||||||
| 10625 | - | |||||||||||||||||||
| 10626 | \note There are still a few cases in which QLatin1String is more efficient than QStringLiteral: | - | ||||||||||||||||||
| 10627 | If it is passed to a function that has an overload that takes the QLatin1String directly, without | - | ||||||||||||||||||
| 10628 | conversion to QString. For instance, this is the case of QString::operator== | - | ||||||||||||||||||
| 10629 | \code | - | ||||||||||||||||||
| 10630 | if (attribute.name() == QLatin1String("http-contents-length")) //... | - | ||||||||||||||||||
| 10631 | \endcode | - | ||||||||||||||||||
| 10632 | - | |||||||||||||||||||
| 10633 | \note There are some restrictions when using the MSVC 2010 or 2012 compilers. The example snippets | - | ||||||||||||||||||
| 10634 | provided here fail to compile with them. | - | ||||||||||||||||||
| 10635 | \list | - | ||||||||||||||||||
| 10636 | \li Concatenated string literals cannot be used with QStringLiteral. | - | ||||||||||||||||||
| 10637 | \code | - | ||||||||||||||||||
| 10638 | QString s = QStringLiteral("a" "b"); | - | ||||||||||||||||||
| 10639 | \endcode | - | ||||||||||||||||||
| 10640 | \li QStringLiteral cannot be used to initialize lists or arrays of QString. | - | ||||||||||||||||||
| 10641 | \code | - | ||||||||||||||||||
| 10642 | QString a[] = { QStringLiteral("a"), QStringLiteral("b") }; | - | ||||||||||||||||||
| 10643 | \endcode | - | ||||||||||||||||||
| 10644 | \endlist | - | ||||||||||||||||||
| 10645 | */ | - | ||||||||||||||||||
| 10646 | - | |||||||||||||||||||
| 10647 | /*! | - | ||||||||||||||||||
| 10648 | \internal | - | ||||||||||||||||||
| 10649 | */ | - | ||||||||||||||||||
| 10650 | void QAbstractConcatenable::appendLatin1To(const char *a, int len, QChar *out) | - | ||||||||||||||||||
| 10651 | { | - | ||||||||||||||||||
| 10652 | qt_from_latin1(reinterpret_cast<ushort *>(out), a, uint(len)); | - | ||||||||||||||||||
| 10653 | } executed 92320 times by 180 tests: end of blockExecuted by:
| 92320 | ||||||||||||||||||
| 10654 | - | |||||||||||||||||||
| 10655 | QT_END_NAMESPACE | - | ||||||||||||||||||
| Source code | Switch to Preprocessed file |