| 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) 2016 The Qt Company Ltd. | - | ||||||||||||||||||
| 4 | ** Copyright (C) 2016 Intel Corporation. | - | ||||||||||||||||||
| 5 | ** Contact: https://www.qt.io/licensing/ | - | ||||||||||||||||||
| 6 | ** | - | ||||||||||||||||||
| 7 | ** This file is part of the QtCore module of the Qt Toolkit. | - | ||||||||||||||||||
| 8 | ** | - | ||||||||||||||||||
| 9 | ** $QT_BEGIN_LICENSE:LGPL$ | - | ||||||||||||||||||
| 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 https://www.qt.io/terms-conditions. For further | - | ||||||||||||||||||
| 16 | ** information use the contact form at https://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 3 as published by the Free Software | - | ||||||||||||||||||
| 21 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the | - | ||||||||||||||||||
| 22 | ** packaging of this file. Please review the following information to | - | ||||||||||||||||||
| 23 | ** ensure the GNU Lesser General Public License version 3 requirements | - | ||||||||||||||||||
| 24 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. | - | ||||||||||||||||||
| 25 | ** | - | ||||||||||||||||||
| 26 | ** GNU General Public License Usage | - | ||||||||||||||||||
| 27 | ** Alternatively, this file may be used under the terms of the GNU | - | ||||||||||||||||||
| 28 | ** General Public License version 2.0 or (at your option) the GNU General | - | ||||||||||||||||||
| 29 | ** Public license version 3 or any later version approved by the KDE Free | - | ||||||||||||||||||
| 30 | ** Qt Foundation. The licenses are as published by the Free Software | - | ||||||||||||||||||
| 31 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 | - | ||||||||||||||||||
| 32 | ** included in the packaging of this file. Please review the following | - | ||||||||||||||||||
| 33 | ** information to ensure the GNU General Public License requirements will | - | ||||||||||||||||||
| 34 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and | - | ||||||||||||||||||
| 35 | ** https://www.gnu.org/licenses/gpl-3.0.html. | - | ||||||||||||||||||
| 36 | ** | - | ||||||||||||||||||
| 37 | ** $QT_END_LICENSE$ | - | ||||||||||||||||||
| 38 | ** | - | ||||||||||||||||||
| 39 | ****************************************************************************/ | - | ||||||||||||||||||
| 40 | - | |||||||||||||||||||
| 41 | #include "qstringlist.h" | - | ||||||||||||||||||
| 42 | #include "qregexp.h" | - | ||||||||||||||||||
| 43 | #include "qregularexpression.h" | - | ||||||||||||||||||
| 44 | #include "qunicodetables_p.h" | - | ||||||||||||||||||
| 45 | #ifndef QT_NO_TEXTCODEC | - | ||||||||||||||||||
| 46 | #include <qtextcodec.h> | - | ||||||||||||||||||
| 47 | #endif | - | ||||||||||||||||||
| 48 | #include <private/qutfcodec_p.h> | - | ||||||||||||||||||
| 49 | #include <private/qlocale_tools_p.h> | - | ||||||||||||||||||
| 50 | #include "qsimd_p.h" | - | ||||||||||||||||||
| 51 | #include <qnumeric.h> | - | ||||||||||||||||||
| 52 | #include <qdatastream.h> | - | ||||||||||||||||||
| 53 | #include <qlist.h> | - | ||||||||||||||||||
| 54 | #include "qlocale.h" | - | ||||||||||||||||||
| 55 | #include "qlocale_p.h" | - | ||||||||||||||||||
| 56 | #include "qstringbuilder.h" | - | ||||||||||||||||||
| 57 | #include "qstringmatcher.h" | - | ||||||||||||||||||
| 58 | #include "qvarlengtharray.h" | - | ||||||||||||||||||
| 59 | #include "qtools_p.h" | - | ||||||||||||||||||
| 60 | #include "qdebug.h" | - | ||||||||||||||||||
| 61 | #include "qendian.h" | - | ||||||||||||||||||
| 62 | #include "qcollator.h" | - | ||||||||||||||||||
| 63 | - | |||||||||||||||||||
| 64 | #ifdef Q_OS_MAC | - | ||||||||||||||||||
| 65 | #include <private/qcore_mac_p.h> | - | ||||||||||||||||||
| 66 | #endif | - | ||||||||||||||||||
| 67 | - | |||||||||||||||||||
| 68 | #include <private/qfunctions_p.h> | - | ||||||||||||||||||
| 69 | - | |||||||||||||||||||
| 70 | #include <limits.h> | - | ||||||||||||||||||
| 71 | #include <string.h> | - | ||||||||||||||||||
| 72 | #include <stdlib.h> | - | ||||||||||||||||||
| 73 | #include <stdio.h> | - | ||||||||||||||||||
| 74 | #include <stdarg.h> | - | ||||||||||||||||||
| 75 | - | |||||||||||||||||||
| 76 | #include "qchar.cpp" | - | ||||||||||||||||||
| 77 | #include "qstringmatcher.cpp" | - | ||||||||||||||||||
| 78 | #include "qstringiterator_p.h" | - | ||||||||||||||||||
| 79 | #include "qstringalgorithms_p.h" | - | ||||||||||||||||||
| 80 | #include "qthreadstorage.h" | - | ||||||||||||||||||
| 81 | - | |||||||||||||||||||
| 82 | #ifdef Q_OS_WIN | - | ||||||||||||||||||
| 83 | # include <qt_windows.h> | - | ||||||||||||||||||
| 84 | # ifdef Q_OS_WINCE | - | ||||||||||||||||||
| 85 | # include <winnls.h> | - | ||||||||||||||||||
| 86 | # endif | - | ||||||||||||||||||
| 87 | #endif | - | ||||||||||||||||||
| 88 | - | |||||||||||||||||||
| 89 | #ifdef truncate | - | ||||||||||||||||||
| 90 | # undef truncate | - | ||||||||||||||||||
| 91 | #endif | - | ||||||||||||||||||
| 92 | - | |||||||||||||||||||
| 93 | #ifndef LLONG_MAX | - | ||||||||||||||||||
| 94 | #define LLONG_MAX qint64_C(9223372036854775807) | - | ||||||||||||||||||
| 95 | #endif | - | ||||||||||||||||||
| 96 | #ifndef LLONG_MIN | - | ||||||||||||||||||
| 97 | #define LLONG_MIN (-LLONG_MAX - qint64_C(1)) | - | ||||||||||||||||||
| 98 | #endif | - | ||||||||||||||||||
| 99 | #ifndef ULLONG_MAX | - | ||||||||||||||||||
| 100 | #define ULLONG_MAX quint64_C(18446744073709551615) | - | ||||||||||||||||||
| 101 | #endif | - | ||||||||||||||||||
| 102 | - | |||||||||||||||||||
| 103 | #define IS_RAW_DATA(d) ((d)->offset != sizeof(QStringData)) | - | ||||||||||||||||||
| 104 | - | |||||||||||||||||||
| 105 | QT_BEGIN_NAMESPACE | - | ||||||||||||||||||
| 106 | - | |||||||||||||||||||
| 107 | /* | - | ||||||||||||||||||
| 108 | * Note on the use of SIMD in qstring.cpp: | - | ||||||||||||||||||
| 109 | * | - | ||||||||||||||||||
| 110 | * Several operations with strings are improved with the use of SIMD code, | - | ||||||||||||||||||
| 111 | * since they are repetitive. For MIPS, we have hand-written assembly code | - | ||||||||||||||||||
| 112 | * outside of qstring.cpp targeting MIPS DSP and MIPS DSPr2. For ARM and for | - | ||||||||||||||||||
| 113 | * x86, we can only use intrinsics and therefore everything is contained in | - | ||||||||||||||||||
| 114 | * qstring.cpp. We need to use intrinsics only for those platforms due to the | - | ||||||||||||||||||
| 115 | * different compilers and toolchains used, which have different syntax for | - | ||||||||||||||||||
| 116 | * assembly sources. | - | ||||||||||||||||||
| 117 | * | - | ||||||||||||||||||
| 118 | * ** SSE notes: ** | - | ||||||||||||||||||
| 119 | * | - | ||||||||||||||||||
| 120 | * Whenever multiple alternatives are equivalent or near so, we prefer the one | - | ||||||||||||||||||
| 121 | * using instructions from SSE2, since SSE2 is guaranteed to be enabled for all | - | ||||||||||||||||||
| 122 | * 64-bit builds and we enable it for 32-bit builds by default. Use of higher | - | ||||||||||||||||||
| 123 | * SSE versions should be done when there's a clear performance benefit and | - | ||||||||||||||||||
| 124 | * requires fallback code to SSE2, if it exists. | - | ||||||||||||||||||
| 125 | * | - | ||||||||||||||||||
| 126 | * Performance measurement in the past shows that most strings are short in | - | ||||||||||||||||||
| 127 | * size and, therefore, do not benefit from alignment prologues. That is, | - | ||||||||||||||||||
| 128 | * trying to find a 16-byte-aligned boundary to operate on is often more | - | ||||||||||||||||||
| 129 | * expensive than executing the unaligned operation directly. In addition, note | - | ||||||||||||||||||
| 130 | * that the QString private data is designed so that the data is stored on | - | ||||||||||||||||||
| 131 | * 16-byte boundaries if the system malloc() returns 16-byte aligned pointers | - | ||||||||||||||||||
| 132 | * on its own (64-bit glibc on Linux does; 32-bit glibc on Linux returns them | - | ||||||||||||||||||
| 133 | * 50% of the time), so skipping the alignment prologue is actually optimizing | - | ||||||||||||||||||
| 134 | * for the common case. | - | ||||||||||||||||||
| 135 | */ | - | ||||||||||||||||||
| 136 | - | |||||||||||||||||||
| 137 | #if defined(__mips_dsp) | - | ||||||||||||||||||
| 138 | // From qstring_mips_dsp_asm.S | - | ||||||||||||||||||
| 139 | extern "C" void qt_fromlatin1_mips_asm_unroll4 (ushort*, const char*, uint); | - | ||||||||||||||||||
| 140 | extern "C" void qt_fromlatin1_mips_asm_unroll8 (ushort*, const char*, uint); | - | ||||||||||||||||||
| 141 | extern "C" void qt_toLatin1_mips_dsp_asm(uchar *dst, const ushort *src, int length); | - | ||||||||||||||||||
| 142 | #endif | - | ||||||||||||||||||
| 143 | - | |||||||||||||||||||
| 144 | // internal | - | ||||||||||||||||||
| 145 | int qFindString(const QChar *haystack, int haystackLen, int from, | - | ||||||||||||||||||
| 146 | const QChar *needle, int needleLen, Qt::CaseSensitivity cs); | - | ||||||||||||||||||
| 147 | int qFindStringBoyerMoore(const QChar *haystack, int haystackLen, int from, | - | ||||||||||||||||||
| 148 | const QChar *needle, int needleLen, Qt::CaseSensitivity cs); | - | ||||||||||||||||||
| 149 | static inline int qt_last_index_of(const QChar *haystack, int haystackLen, QChar needle, | - | ||||||||||||||||||
| 150 | int from, Qt::CaseSensitivity cs); | - | ||||||||||||||||||
| 151 | static inline int qt_string_count(const QChar *haystack, int haystackLen, | - | ||||||||||||||||||
| 152 | const QChar *needle, int needleLen, | - | ||||||||||||||||||
| 153 | Qt::CaseSensitivity cs); | - | ||||||||||||||||||
| 154 | static inline int qt_string_count(const QChar *haystack, int haystackLen, | - | ||||||||||||||||||
| 155 | QChar needle, Qt::CaseSensitivity cs); | - | ||||||||||||||||||
| 156 | static inline int qt_find_latin1_string(const QChar *hay, int size, QLatin1String needle, | - | ||||||||||||||||||
| 157 | int from, Qt::CaseSensitivity cs); | - | ||||||||||||||||||
| 158 | static inline bool qt_starts_with(const QChar *haystack, int haystackLen, | - | ||||||||||||||||||
| 159 | const QChar *needle, int needleLen, Qt::CaseSensitivity cs); | - | ||||||||||||||||||
| 160 | static inline bool qt_starts_with(const QChar *haystack, int haystackLen, | - | ||||||||||||||||||
| 161 | QLatin1String needle, Qt::CaseSensitivity cs); | - | ||||||||||||||||||
| 162 | static inline bool qt_ends_with(const QChar *haystack, int haystackLen, | - | ||||||||||||||||||
| 163 | const QChar *needle, int needleLen, Qt::CaseSensitivity cs); | - | ||||||||||||||||||
| 164 | static inline bool qt_ends_with(const QChar *haystack, int haystackLen, | - | ||||||||||||||||||
| 165 | QLatin1String needle, Qt::CaseSensitivity cs); | - | ||||||||||||||||||
| 166 | - | |||||||||||||||||||
| 167 | #if defined(Q_COMPILER_LAMBDA) && !defined(__OPTIMIZE_SIZE__) | - | ||||||||||||||||||
| 168 | namespace { | - | ||||||||||||||||||
| 169 | template <uint MaxCount> struct UnrollTailLoop | - | ||||||||||||||||||
| 170 | { | - | ||||||||||||||||||
| 171 | template <typename RetType, typename Functor1, typename Functor2> | - | ||||||||||||||||||
| 172 | static inline RetType exec(int count, RetType returnIfExited, Functor1 loopCheck, Functor2 returnIfFailed, int i = 0) | - | ||||||||||||||||||
| 173 | { | - | ||||||||||||||||||
| 174 | /* equivalent to: | - | ||||||||||||||||||
| 175 | * while (count--) { | - | ||||||||||||||||||
| 176 | * if (loopCheck(i)) | - | ||||||||||||||||||
| 177 | * return returnIfFailed(i); | - | ||||||||||||||||||
| 178 | * } | - | ||||||||||||||||||
| 179 | * return returnIfExited; | - | ||||||||||||||||||
| 180 | */ | - | ||||||||||||||||||
| 181 | - | |||||||||||||||||||
| 182 | if (!count)
| 6730103-35953269 | ||||||||||||||||||
| 183 | return returnIfExited; executed 6730106 times by 686 tests: return returnIfExited;Executed by:
| 6730106 | ||||||||||||||||||
| 184 | - | |||||||||||||||||||
| 185 | bool check = loopCheck(i); | - | ||||||||||||||||||
| 186 | if (check) {
| 1370215-34583054 | ||||||||||||||||||
| 187 | const RetType &retval = returnIfFailed(i); | - | ||||||||||||||||||
| 188 | return retval; executed 1370215 times by 552 tests: return retval;Executed by:
| 1370215 | ||||||||||||||||||
| 189 | } | - | ||||||||||||||||||
| 190 | - | |||||||||||||||||||
| 191 | return UnrollTailLoop<MaxCount - 1>::exec(count - 1, returnIfExited, loopCheck, returnIfFailed, i + 1); executed 34583054 times by 773 tests: return UnrollTailLoop<MaxCount - 1>::exec(count - 1, returnIfExited, loopCheck, returnIfFailed, i + 1);Executed by:
| 34583054 | ||||||||||||||||||
| 192 | } | - | ||||||||||||||||||
| 193 | - | |||||||||||||||||||
| 194 | template <typename Functor> | - | ||||||||||||||||||
| 195 | static inline void exec(int count, Functor code) | - | ||||||||||||||||||
| 196 | { | - | ||||||||||||||||||
| 197 | /* equivalent to: | - | ||||||||||||||||||
| 198 | * for (int i = 0; i < count; ++i) | - | ||||||||||||||||||
| 199 | * code(i); | - | ||||||||||||||||||
| 200 | */ | - | ||||||||||||||||||
| 201 | exec(count, 0, [=](int i) -> bool { code(i); return false; }, [](int) { return 0; }); executed 17278209 times by 686 tests: return false;Executed by:
never executed: return 0; | 0-17278209 | ||||||||||||||||||
| 202 | } executed 2644017 times by 686 tests: end of blockExecuted by:
| 2644017 | ||||||||||||||||||
| 203 | }; | - | ||||||||||||||||||
| 204 | template <> template <typename RetType, typename Functor1, typename Functor2> | - | ||||||||||||||||||
| 205 | inline RetType UnrollTailLoop<0>::exec(int, RetType returnIfExited, Functor1, Functor2, int) | - | ||||||||||||||||||
| 206 | { | - | ||||||||||||||||||
| 207 | return returnIfExited; executed 778568 times by 446 tests: return returnIfExited;Executed by:
| 778568 | ||||||||||||||||||
| 208 | } | - | ||||||||||||||||||
| 209 | } | - | ||||||||||||||||||
| 210 | #endif | - | ||||||||||||||||||
| 211 | - | |||||||||||||||||||
| 212 | // conversion between Latin 1 and UTF-16 | - | ||||||||||||||||||
| 213 | void qt_from_latin1(ushort *dst, const char *str, size_t size) Q_DECL_NOTHROW | - | ||||||||||||||||||
| 214 | { | - | ||||||||||||||||||
| 215 | /* SIMD: | - | ||||||||||||||||||
| 216 | * Unpacking with SSE has been shown to improve performance on recent CPUs | - | ||||||||||||||||||
| 217 | * The same method gives no improvement with NEON. | - | ||||||||||||||||||
| 218 | */ | - | ||||||||||||||||||
| 219 | #if defined(__SSE2__) | - | ||||||||||||||||||
| 220 | const char *e = str + size; | - | ||||||||||||||||||
| 221 | qptrdiff offset = 0; | - | ||||||||||||||||||
| 222 | - | |||||||||||||||||||
| 223 | // we're going to read str[offset..offset+15] (16 bytes) | - | ||||||||||||||||||
| 224 | for ( ; str + offset + 15 < e; offset += 16) {
| 1702045-2360203 | ||||||||||||||||||
| 225 | const __m128i chunk = _mm_loadu_si128((const __m128i*)(str + offset)); // load | - | ||||||||||||||||||
| 226 | #ifdef __AVX2__ | - | ||||||||||||||||||
| 227 | // zero extend to an YMM register | - | ||||||||||||||||||
| 228 | const __m256i extended = _mm256_cvtepu8_epi16(chunk); | - | ||||||||||||||||||
| 229 | - | |||||||||||||||||||
| 230 | // store | - | ||||||||||||||||||
| 231 | _mm256_storeu_si256((__m256i*)(dst + offset), extended); | - | ||||||||||||||||||
| 232 | #else | - | ||||||||||||||||||
| 233 | const __m128i nullMask = _mm_set1_epi32(0); | - | ||||||||||||||||||
| 234 | - | |||||||||||||||||||
| 235 | // unpack the first 8 bytes, padding with zeros | - | ||||||||||||||||||
| 236 | const __m128i firstHalf = _mm_unpacklo_epi8(chunk, nullMask); | - | ||||||||||||||||||
| 237 | _mm_storeu_si128((__m128i*)(dst + offset), firstHalf); // store | - | ||||||||||||||||||
| 238 | - | |||||||||||||||||||
| 239 | // unpack the last 8 bytes, padding with zeros | - | ||||||||||||||||||
| 240 | const __m128i secondHalf = _mm_unpackhi_epi8 (chunk, nullMask); | - | ||||||||||||||||||
| 241 | _mm_storeu_si128((__m128i*)(dst + offset + 8), secondHalf); // store | - | ||||||||||||||||||
| 242 | #endif | - | ||||||||||||||||||
| 243 | } executed 1702045 times by 504 tests: end of blockExecuted by:
| 1702045 | ||||||||||||||||||
| 244 | - | |||||||||||||||||||
| 245 | size = size % 16; | - | ||||||||||||||||||
| 246 | dst += offset; | - | ||||||||||||||||||
| 247 | str += offset; | - | ||||||||||||||||||
| 248 | # if defined(Q_COMPILER_LAMBDA) && !defined(__OPTIMIZE_SIZE__) | - | ||||||||||||||||||
| 249 | return UnrollTailLoop<15>::exec(int(size), [=](int i) { dst[i] = (uchar)str[i]; }); executed 15853376 times by 686 tests: end of blockExecuted by:
executed 2360203 times by 686 tests: return UnrollTailLoop<15>::exec(int(size), [=](int i) { dst[i] = (uchar)str[i]; });Executed by:
| 2360203-15853376 | ||||||||||||||||||
| 250 | # endif | - | ||||||||||||||||||
| 251 | #endif | - | ||||||||||||||||||
| 252 | #if defined(__mips_dsp) | - | ||||||||||||||||||
| 253 | if (size > 20) | - | ||||||||||||||||||
| 254 | qt_fromlatin1_mips_asm_unroll8(dst, str, size); | - | ||||||||||||||||||
| 255 | else | - | ||||||||||||||||||
| 256 | qt_fromlatin1_mips_asm_unroll4(dst, str, size); | - | ||||||||||||||||||
| 257 | #else | - | ||||||||||||||||||
| 258 | while (size--) dead code: while (size--) *dst++ = (uchar)*str++; | - | ||||||||||||||||||
| 259 | *dst++ = (uchar)*str++; dead code: while (size--) *dst++ = (uchar)*str++; | - | ||||||||||||||||||
| 260 | #endif | - | ||||||||||||||||||
| 261 | } | - | ||||||||||||||||||
| 262 | - | |||||||||||||||||||
| 263 | #if defined(__SSE2__) | - | ||||||||||||||||||
| 264 | static inline __m128i mergeQuestionMarks(__m128i chunk) | - | ||||||||||||||||||
| 265 | { | - | ||||||||||||||||||
| 266 | const __m128i questionMark = _mm_set1_epi16('?'); | - | ||||||||||||||||||
| 267 | - | |||||||||||||||||||
| 268 | # ifdef __SSE4_2__ | - | ||||||||||||||||||
| 269 | // compare the unsigned shorts for the range 0x0100-0xFFFF | - | ||||||||||||||||||
| 270 | // note on the use of _mm_cmpestrm: | - | ||||||||||||||||||
| 271 | // The MSDN documentation online (http://technet.microsoft.com/en-us/library/bb514080.aspx) | - | ||||||||||||||||||
| 272 | // says for range search the following: | - | ||||||||||||||||||
| 273 | // For each character c in a, determine whether b0 <= c <= b1 or b2 <= c <= b3 | - | ||||||||||||||||||
| 274 | // | - | ||||||||||||||||||
| 275 | // However, all examples on the Internet, including from Intel | - | ||||||||||||||||||
| 276 | // (see http://software.intel.com/en-us/articles/xml-parsing-accelerator-with-intel-streaming-simd-extensions-4-intel-sse4/) | - | ||||||||||||||||||
| 277 | // put the range to be searched first | - | ||||||||||||||||||
| 278 | // | - | ||||||||||||||||||
| 279 | // Disassembly and instruction-level debugging with GCC and ICC show | - | ||||||||||||||||||
| 280 | // that they are doing the right thing. Inverting the arguments in the | - | ||||||||||||||||||
| 281 | // instruction does cause a bunch of test failures. | - | ||||||||||||||||||
| 282 | - | |||||||||||||||||||
| 283 | const __m128i rangeMatch = _mm_cvtsi32_si128(0xffff0100); | - | ||||||||||||||||||
| 284 | const __m128i offLimitMask = _mm_cmpestrm(rangeMatch, 2, chunk, 8, | - | ||||||||||||||||||
| 285 | _SIDD_UWORD_OPS | _SIDD_CMP_RANGES | _SIDD_UNIT_MASK); | - | ||||||||||||||||||
| 286 | - | |||||||||||||||||||
| 287 | // replace the non-Latin 1 characters in the chunk with question marks | - | ||||||||||||||||||
| 288 | chunk = _mm_blendv_epi8(chunk, questionMark, offLimitMask); | - | ||||||||||||||||||
| 289 | # else | - | ||||||||||||||||||
| 290 | // SSE has no compare instruction for unsigned comparison. | - | ||||||||||||||||||
| 291 | // The variables must be shiffted + 0x8000 to be compared | - | ||||||||||||||||||
| 292 | const __m128i signedBitOffset = _mm_set1_epi16(short(0x8000)); | - | ||||||||||||||||||
| 293 | const __m128i thresholdMask = _mm_set1_epi16(short(0xff + 0x8000)); | - | ||||||||||||||||||
| 294 | - | |||||||||||||||||||
| 295 | const __m128i signedChunk = _mm_add_epi16(chunk, signedBitOffset); | - | ||||||||||||||||||
| 296 | const __m128i offLimitMask = _mm_cmpgt_epi16(signedChunk, thresholdMask); | - | ||||||||||||||||||
| 297 | - | |||||||||||||||||||
| 298 | # ifdef __SSE4_1__ | - | ||||||||||||||||||
| 299 | // replace the non-Latin 1 characters in the chunk with question marks | - | ||||||||||||||||||
| 300 | chunk = _mm_blendv_epi8(chunk, questionMark, offLimitMask); | - | ||||||||||||||||||
| 301 | # else | - | ||||||||||||||||||
| 302 | // offLimitQuestionMark contains '?' for each 16 bits that was off-limit | - | ||||||||||||||||||
| 303 | // the 16 bits that were correct contains zeros | - | ||||||||||||||||||
| 304 | const __m128i offLimitQuestionMark = _mm_and_si128(offLimitMask, questionMark); | - | ||||||||||||||||||
| 305 | - | |||||||||||||||||||
| 306 | // correctBytes contains the bytes that were in limit | - | ||||||||||||||||||
| 307 | // the 16 bits that were off limits contains zeros | - | ||||||||||||||||||
| 308 | const __m128i correctBytes = _mm_andnot_si128(offLimitMask, chunk); | - | ||||||||||||||||||
| 309 | - | |||||||||||||||||||
| 310 | // merge offLimitQuestionMark and correctBytes to have the result | - | ||||||||||||||||||
| 311 | chunk = _mm_or_si128(correctBytes, offLimitQuestionMark); | - | ||||||||||||||||||
| 312 | # endif | - | ||||||||||||||||||
| 313 | # endif | - | ||||||||||||||||||
| 314 | return chunk; executed 804590 times by 383 tests: return chunk;Executed by:
| 804590 | ||||||||||||||||||
| 315 | } | - | ||||||||||||||||||
| 316 | #endif | - | ||||||||||||||||||
| 317 | - | |||||||||||||||||||
| 318 | static void qt_to_latin1(uchar *dst, const ushort *src, int length) | - | ||||||||||||||||||
| 319 | { | - | ||||||||||||||||||
| 320 | #if defined(__SSE2__) | - | ||||||||||||||||||
| 321 | uchar *e = dst + length; | - | ||||||||||||||||||
| 322 | qptrdiff offset = 0; | - | ||||||||||||||||||
| 323 | - | |||||||||||||||||||
| 324 | // we're going to write to dst[offset..offset+15] (16 bytes) | - | ||||||||||||||||||
| 325 | for ( ; dst + offset + 15 < e; offset += 16) {
| 283814-402295 | ||||||||||||||||||
| 326 | __m128i chunk1 = _mm_loadu_si128((const __m128i*)(src + offset)); // load | - | ||||||||||||||||||
| 327 | chunk1 = mergeQuestionMarks(chunk1); | - | ||||||||||||||||||
| 328 | - | |||||||||||||||||||
| 329 | __m128i chunk2 = _mm_loadu_si128((const __m128i*)(src + offset + 8)); // load | - | ||||||||||||||||||
| 330 | chunk2 = mergeQuestionMarks(chunk2); | - | ||||||||||||||||||
| 331 | - | |||||||||||||||||||
| 332 | // pack the two vector to 16 x 8bits elements | - | ||||||||||||||||||
| 333 | const __m128i result = _mm_packus_epi16(chunk1, chunk2); | - | ||||||||||||||||||
| 334 | _mm_storeu_si128((__m128i*)(dst + offset), result); // store | - | ||||||||||||||||||
| 335 | } executed 402295 times by 383 tests: end of blockExecuted by:
| 402295 | ||||||||||||||||||
| 336 | - | |||||||||||||||||||
| 337 | length = length % 16; | - | ||||||||||||||||||
| 338 | dst += offset; | - | ||||||||||||||||||
| 339 | src += offset; | - | ||||||||||||||||||
| 340 | - | |||||||||||||||||||
| 341 | # if defined(Q_COMPILER_LAMBDA) && !defined(__OPTIMIZE_SIZE__) | - | ||||||||||||||||||
| 342 | return UnrollTailLoop<15>::exec(length, [=](int i) { dst[i] = (src[i]>0xff) ? '?' : (uchar) src[i]; }); executed 1424833 times by 444 tests: end of blockExecuted by:
executed 283814 times by 445 tests: return UnrollTailLoop<15>::exec(length, [=](int i) { dst[i] = (src[i]>0xff) ? '?' : (uchar) src[i]; });Executed by:
| 11-1424833 | ||||||||||||||||||
| 343 | # endif | - | ||||||||||||||||||
| 344 | #elif defined(__ARM_NEON__) | - | ||||||||||||||||||
| 345 | // Refer to the documentation of the SSE2 implementation | - | ||||||||||||||||||
| 346 | // this use eactly the same method as for SSE except: | - | ||||||||||||||||||
| 347 | // 1) neon has unsigned comparison | - | ||||||||||||||||||
| 348 | // 2) packing is done to 64 bits (8 x 8bits component). | - | ||||||||||||||||||
| 349 | if (length >= 16) { | - | ||||||||||||||||||
| 350 | const int chunkCount = length >> 3; // divided by 8 | - | ||||||||||||||||||
| 351 | const uint16x8_t questionMark = vdupq_n_u16('?'); // set | - | ||||||||||||||||||
| 352 | const uint16x8_t thresholdMask = vdupq_n_u16(0xff); // set | - | ||||||||||||||||||
| 353 | for (int i = 0; i < chunkCount; ++i) { | - | ||||||||||||||||||
| 354 | uint16x8_t chunk = vld1q_u16((uint16_t *)src); // load | - | ||||||||||||||||||
| 355 | src += 8; | - | ||||||||||||||||||
| 356 | - | |||||||||||||||||||
| 357 | const uint16x8_t offLimitMask = vcgtq_u16(chunk, thresholdMask); // chunk > thresholdMask | - | ||||||||||||||||||
| 358 | const uint16x8_t offLimitQuestionMark = vandq_u16(offLimitMask, questionMark); // offLimitMask & questionMark | - | ||||||||||||||||||
| 359 | const uint16x8_t correctBytes = vbicq_u16(chunk, offLimitMask); // !offLimitMask & chunk | - | ||||||||||||||||||
| 360 | chunk = vorrq_u16(correctBytes, offLimitQuestionMark); // correctBytes | offLimitQuestionMark | - | ||||||||||||||||||
| 361 | const uint8x8_t result = vmovn_u16(chunk); // narrowing move->packing | - | ||||||||||||||||||
| 362 | vst1_u8(dst, result); // store | - | ||||||||||||||||||
| 363 | dst += 8; | - | ||||||||||||||||||
| 364 | } | - | ||||||||||||||||||
| 365 | length = length % 8; | - | ||||||||||||||||||
| 366 | } | - | ||||||||||||||||||
| 367 | #endif | - | ||||||||||||||||||
| 368 | #if defined(__mips_dsp) | - | ||||||||||||||||||
| 369 | qt_toLatin1_mips_dsp_asm(dst, src, length); | - | ||||||||||||||||||
| 370 | #else | - | ||||||||||||||||||
| 371 | while (length--) { dead code: while (length--) { *dst++ = (*src>0xff) ? '?' : (uchar) *src; ++src; } | - | ||||||||||||||||||
| 372 | *dst++ = (*src>0xff) ? '?' : (uchar) *src; dead code: while (length--) { *dst++ = (*src>0xff) ? '?' : (uchar) *src; ++src; } | - | ||||||||||||||||||
| 373 | ++src; dead code: while (length--) { *dst++ = (*src>0xff) ? '?' : (uchar) *src; ++src; } | - | ||||||||||||||||||
| 374 | } dead code: while (length--) { *dst++ = (*src>0xff) ? '?' : (uchar) *src; ++src; } | - | ||||||||||||||||||
| 375 | #endif | - | ||||||||||||||||||
| 376 | } | - | ||||||||||||||||||
| 377 | - | |||||||||||||||||||
| 378 | // Unicode case-insensitive comparison | - | ||||||||||||||||||
| 379 | static int ucstricmp(const ushort *a, const ushort *ae, const ushort *b, const ushort *be) | - | ||||||||||||||||||
| 380 | { | - | ||||||||||||||||||
| 381 | if (a == b)
| 4330-513417 | ||||||||||||||||||
| 382 | return (ae - be); executed 4330 times by 125 tests: return (ae - be);Executed by:
| 4330 | ||||||||||||||||||
| 383 | if (a == 0)
| 0-513417 | ||||||||||||||||||
| 384 | return 1; never executed: return 1; | 0 | ||||||||||||||||||
| 385 | if (b == 0)
| 0-513417 | ||||||||||||||||||
| 386 | return -1; never executed: return -1; | 0 | ||||||||||||||||||
| 387 | - | |||||||||||||||||||
| 388 | const ushort *e = ae; | - | ||||||||||||||||||
| 389 | if (be - b < ae - a)
| 254847-258570 | ||||||||||||||||||
| 390 | e = a + (be - b); executed 254847 times by 134 tests: e = a + (be - b);Executed by:
| 254847 | ||||||||||||||||||
| 391 | - | |||||||||||||||||||
| 392 | uint alast = 0; | - | ||||||||||||||||||
| 393 | uint blast = 0; | - | ||||||||||||||||||
| 394 | while (a < e) {
| 75123-1726112 | ||||||||||||||||||
| 395 | // qDebug() << hex << alast << blast; | - | ||||||||||||||||||
| 396 | // qDebug() << hex << "*a=" << *a << "alast=" << alast << "folded=" << foldCase (*a, alast); | - | ||||||||||||||||||
| 397 | // qDebug() << hex << "*b=" << *b << "blast=" << blast << "folded=" << foldCase (*b, blast); | - | ||||||||||||||||||
| 398 | int diff = foldCase(*a, alast) - foldCase(*b, blast); | - | ||||||||||||||||||
| 399 | if ((diff))
| 438294-1287818 | ||||||||||||||||||
| 400 | return diff; executed 438294 times by 155 tests: return diff;Executed by:
| 438294 | ||||||||||||||||||
| 401 | ++a; | - | ||||||||||||||||||
| 402 | ++b; | - | ||||||||||||||||||
| 403 | } executed 1287818 times by 166 tests: end of blockExecuted by:
| 1287818 | ||||||||||||||||||
| 404 | if (a == ae) {
| 5759-69364 | ||||||||||||||||||
| 405 | if (b == be)
| 9681-59683 | ||||||||||||||||||
| 406 | return 0; executed 59683 times by 165 tests: return 0;Executed by:
| 59683 | ||||||||||||||||||
| 407 | return -1; executed 9681 times by 126 tests: return -1;Executed by:
| 9681 | ||||||||||||||||||
| 408 | } | - | ||||||||||||||||||
| 409 | return 1; executed 5759 times by 126 tests: return 1;Executed by:
| 5759 | ||||||||||||||||||
| 410 | } | - | ||||||||||||||||||
| 411 | - | |||||||||||||||||||
| 412 | // Case-insensitive comparison between a Unicode string and a QLatin1String | - | ||||||||||||||||||
| 413 | static int ucstricmp(const ushort *a, const ushort *ae, const uchar *b, const uchar *be) | - | ||||||||||||||||||
| 414 | { | - | ||||||||||||||||||
| 415 | if (a == 0) {
| 0-17633 | ||||||||||||||||||
| 416 | if (b == 0)
| 0 | ||||||||||||||||||
| 417 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
| 418 | return 1; never executed: return 1; | 0 | ||||||||||||||||||
| 419 | } | - | ||||||||||||||||||
| 420 | if (b == 0)
| 0-17633 | ||||||||||||||||||
| 421 | return -1; never executed: return -1; | 0 | ||||||||||||||||||
| 422 | - | |||||||||||||||||||
| 423 | const ushort *e = ae; | - | ||||||||||||||||||
| 424 | if (be - b < ae - a)
| 4341-13292 | ||||||||||||||||||
| 425 | e = a + (be - b); executed 4341 times by 25 tests: e = a + (be - b);Executed by:
| 4341 | ||||||||||||||||||
| 426 | - | |||||||||||||||||||
| 427 | while (a < e) {
| 4645-69971 | ||||||||||||||||||
| 428 | int diff = foldCase(*a) - foldCase(*b); | - | ||||||||||||||||||
| 429 | if ((diff))
| 12988-56983 | ||||||||||||||||||
| 430 | return diff; executed 12988 times by 35 tests: return diff;Executed by:
| 12988 | ||||||||||||||||||
| 431 | ++a; | - | ||||||||||||||||||
| 432 | ++b; | - | ||||||||||||||||||
| 433 | } executed 56983 times by 41 tests: end of blockExecuted by:
| 56983 | ||||||||||||||||||
| 434 | if (a == ae) {
| 351-4294 | ||||||||||||||||||
| 435 | if (b == be)
| 400-3894 | ||||||||||||||||||
| 436 | return 0; executed 3894 times by 41 tests: return 0;Executed by:
| 3894 | ||||||||||||||||||
| 437 | return -1; executed 400 times by 14 tests: return -1;Executed by:
| 400 | ||||||||||||||||||
| 438 | } | - | ||||||||||||||||||
| 439 | return 1; executed 351 times by 15 tests: return 1;Executed by:
| 351 | ||||||||||||||||||
| 440 | } | - | ||||||||||||||||||
| 441 | - | |||||||||||||||||||
| 442 | #if defined(__mips_dsp) | - | ||||||||||||||||||
| 443 | // From qstring_mips_dsp_asm.S | - | ||||||||||||||||||
| 444 | extern "C" int qt_ucstrncmp_mips_dsp_asm(const ushort *a, | - | ||||||||||||||||||
| 445 | const ushort *b, | - | ||||||||||||||||||
| 446 | unsigned len); | - | ||||||||||||||||||
| 447 | #endif | - | ||||||||||||||||||
| 448 | - | |||||||||||||||||||
| 449 | // Unicode case-sensitive compare two same-sized strings | - | ||||||||||||||||||
| 450 | static int ucstrncmp(const QChar *a, const QChar *b, int l) | - | ||||||||||||||||||
| 451 | { | - | ||||||||||||||||||
| 452 | #if defined(__mips_dsp) | - | ||||||||||||||||||
| 453 | if (l >= 8) { | - | ||||||||||||||||||
| 454 | return qt_ucstrncmp_mips_dsp_asm(reinterpret_cast<const ushort*>(a), | - | ||||||||||||||||||
| 455 | reinterpret_cast<const ushort*>(b), | - | ||||||||||||||||||
| 456 | l); | - | ||||||||||||||||||
| 457 | } | - | ||||||||||||||||||
| 458 | #endif // __mips_dsp | - | ||||||||||||||||||
| 459 | #ifdef __SSE2__ | - | ||||||||||||||||||
| 460 | const char *ptr = reinterpret_cast<const char*>(a); | - | ||||||||||||||||||
| 461 | qptrdiff distance = reinterpret_cast<const char*>(b) - ptr; | - | ||||||||||||||||||
| 462 | a += l & ~7; | - | ||||||||||||||||||
| 463 | b += l & ~7; | - | ||||||||||||||||||
| 464 | l &= 7; | - | ||||||||||||||||||
| 465 | - | |||||||||||||||||||
| 466 | // we're going to read ptr[0..15] (16 bytes) | - | ||||||||||||||||||
| 467 | for ( ; ptr + 15 < reinterpret_cast<const char *>(a); ptr += 16) {
| 4168074-6295678 | ||||||||||||||||||
| 468 | __m128i a_data = _mm_loadu_si128((const __m128i*)ptr); | - | ||||||||||||||||||
| 469 | __m128i b_data = _mm_loadu_si128((const __m128i*)(ptr + distance)); | - | ||||||||||||||||||
| 470 | __m128i result = _mm_cmpeq_epi16(a_data, b_data); | - | ||||||||||||||||||
| 471 | uint mask = ~_mm_movemask_epi8(result); | - | ||||||||||||||||||
| 472 | if (ushort(mask)) {
| 1562574-4733104 | ||||||||||||||||||
| 473 | // found a different byte | - | ||||||||||||||||||
| 474 | uint idx = uint(_bit_scan_forward(mask)); | - | ||||||||||||||||||
| 475 | return reinterpret_cast<const QChar *>(ptr + idx)->unicode() executed 1562574 times by 466 tests: return reinterpret_cast<const QChar *>(ptr + idx)->unicode() - reinterpret_cast<const QChar *>(ptr + distance + idx)->unicode();Executed by:
| 1562574 | ||||||||||||||||||
| 476 | - reinterpret_cast<const QChar *>(ptr + distance + idx)->unicode(); executed 1562574 times by 466 tests: return reinterpret_cast<const QChar *>(ptr + idx)->unicode() - reinterpret_cast<const QChar *>(ptr + distance + idx)->unicode();Executed by:
| 1562574 | ||||||||||||||||||
| 477 | } | - | ||||||||||||||||||
| 478 | } executed 4733104 times by 597 tests: end of blockExecuted by:
| 4733104 | ||||||||||||||||||
| 479 | # if defined(Q_COMPILER_LAMBDA) && !defined(__OPTIMIZE_SIZE__) | - | ||||||||||||||||||
| 480 | const auto &lambda = [=](int i) -> int { | - | ||||||||||||||||||
| 481 | return reinterpret_cast<const QChar *>(ptr)[i].unicode() executed 14175902 times by 612 tests: return reinterpret_cast<const QChar *>(ptr)[i].unicode() - reinterpret_cast<const QChar *>(ptr + distance)[i].unicode();Executed by:
| 14175902 | ||||||||||||||||||
| 482 | - reinterpret_cast<const QChar *>(ptr + distance)[i].unicode(); executed 14175902 times by 612 tests: return reinterpret_cast<const QChar *>(ptr)[i].unicode() - reinterpret_cast<const QChar *>(ptr + distance)[i].unicode();Executed by:
| 14175902 | ||||||||||||||||||
| 483 | }; | - | ||||||||||||||||||
| 484 | return UnrollTailLoop<7>::exec(l, 0, lambda, lambda); executed 4168074 times by 613 tests: return UnrollTailLoop<7>::exec(l, 0, lambda, lambda);Executed by:
| 4168074 | ||||||||||||||||||
| 485 | # endif | - | ||||||||||||||||||
| 486 | #endif | - | ||||||||||||||||||
| 487 | if (!l) dead code: if (!l) return 0; | - | ||||||||||||||||||
| 488 | return 0; dead code: if (!l) return 0; | - | ||||||||||||||||||
| 489 | - | |||||||||||||||||||
| 490 | // check alignment | - | ||||||||||||||||||
| 491 | 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(); } } | - | ||||||||||||||||||
| 492 | // 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(); } } | - | ||||||||||||||||||
| 493 | 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(); } } | - | ||||||||||||||||||
| 494 | // 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(); } } | - | ||||||||||||||||||
| 495 | // 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(); } } | - | ||||||||||||||||||
| 496 | 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(); } } | - | ||||||||||||||||||
| 497 | 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(); } } | - | ||||||||||||||||||
| 498 | --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(); } } | - | ||||||||||||||||||
| 499 | ++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(); } } | - | ||||||||||||||||||
| 500 | ++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(); } } | - | ||||||||||||||||||
| 501 | - | |||||||||||||||||||
| 502 | // 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(); } } | - | ||||||||||||||||||
| 503 | } 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 | - | |||||||||||||||||||
| 505 | // 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(); } } | - | ||||||||||||||||||
| 506 | // 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(); } } | - | ||||||||||||||||||
| 507 | 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(); } } | - | ||||||||||||||||||
| 508 | 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(); } } | - | ||||||||||||||||||
| 509 | 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(); } } | - | ||||||||||||||||||
| 510 | 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(); } } | - | ||||||||||||||||||
| 511 | 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(); } } | - | ||||||||||||||||||
| 512 | 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(); } } | - | ||||||||||||||||||
| 513 | 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(); } } | - | ||||||||||||||||||
| 514 | 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(); } } | - | ||||||||||||||||||
| 515 | 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(); } } | - | ||||||||||||||||||
| 516 | 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(); } } | - | ||||||||||||||||||
| 517 | } 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 | } 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 | - | |||||||||||||||||||
| 520 | // 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(); } } | - | ||||||||||||||||||
| 521 | 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(); } } | - | ||||||||||||||||||
| 522 | 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(); } } | - | ||||||||||||||||||
| 523 | 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(); } } | - | ||||||||||||||||||
| 524 | } 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(); } } | - | ||||||||||||||||||
| 525 | // 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(); } } | - | ||||||||||||||||||
| 526 | 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(); } } | - | ||||||||||||||||||
| 527 | 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(); } } | - | ||||||||||||||||||
| 528 | 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(); } } | - | ||||||||||||||||||
| 529 | 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(); } } | - | ||||||||||||||||||
| 530 | } 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(); } } | - | ||||||||||||||||||
| 531 | } 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(); } } | - | ||||||||||||||||||
| 532 | return 0; dead code: return 0; | - | ||||||||||||||||||
| 533 | } | - | ||||||||||||||||||
| 534 | - | |||||||||||||||||||
| 535 | static int ucstrncmp(const QChar *a, const uchar *c, int l) | - | ||||||||||||||||||
| 536 | { | - | ||||||||||||||||||
| 537 | const ushort *uc = reinterpret_cast<const ushort *>(a); | - | ||||||||||||||||||
| 538 | const ushort *e = uc + l; | - | ||||||||||||||||||
| 539 | - | |||||||||||||||||||
| 540 | #ifdef __SSE2__ | - | ||||||||||||||||||
| 541 | __m128i nullmask = _mm_setzero_si128(); | - | ||||||||||||||||||
| 542 | qptrdiff offset = 0; | - | ||||||||||||||||||
| 543 | - | |||||||||||||||||||
| 544 | // we're going to read uc[offset..offset+15] (32 bytes) | - | ||||||||||||||||||
| 545 | // and c[offset..offset+15] (16 bytes) | - | ||||||||||||||||||
| 546 | for ( ; uc + offset + 15 < e; offset += 16) {
| 51214-1029669 | ||||||||||||||||||
| 547 | // similar to fromLatin1_helper: | - | ||||||||||||||||||
| 548 | // load 16 bytes of Latin 1 data | - | ||||||||||||||||||
| 549 | __m128i chunk = _mm_loadu_si128((const __m128i*)(c + offset)); | - | ||||||||||||||||||
| 550 | - | |||||||||||||||||||
| 551 | # ifdef __AVX2__ | - | ||||||||||||||||||
| 552 | // expand Latin 1 data via zero extension | - | ||||||||||||||||||
| 553 | __m256i ldata = _mm256_cvtepu8_epi16(chunk); | - | ||||||||||||||||||
| 554 | - | |||||||||||||||||||
| 555 | // load UTF-16 data and compare | - | ||||||||||||||||||
| 556 | __m256i ucdata = _mm256_loadu_si256((const __m256i*)(uc + offset)); | - | ||||||||||||||||||
| 557 | __m256i result = _mm256_cmpeq_epi16(ldata, ucdata); | - | ||||||||||||||||||
| 558 | - | |||||||||||||||||||
| 559 | uint mask = ~_mm256_movemask_epi8(result); | - | ||||||||||||||||||
| 560 | # else | - | ||||||||||||||||||
| 561 | // expand via unpacking | - | ||||||||||||||||||
| 562 | __m128i firstHalf = _mm_unpacklo_epi8(chunk, nullmask); | - | ||||||||||||||||||
| 563 | __m128i secondHalf = _mm_unpackhi_epi8(chunk, nullmask); | - | ||||||||||||||||||
| 564 | - | |||||||||||||||||||
| 565 | // load UTF-16 data and compare | - | ||||||||||||||||||
| 566 | __m128i ucdata1 = _mm_loadu_si128((const __m128i*)(uc + offset)); | - | ||||||||||||||||||
| 567 | __m128i ucdata2 = _mm_loadu_si128((const __m128i*)(uc + offset + 8)); | - | ||||||||||||||||||
| 568 | __m128i result1 = _mm_cmpeq_epi16(firstHalf, ucdata1); | - | ||||||||||||||||||
| 569 | __m128i result2 = _mm_cmpeq_epi16(secondHalf, ucdata2); | - | ||||||||||||||||||
| 570 | - | |||||||||||||||||||
| 571 | uint mask = ~(_mm_movemask_epi8(result1) | _mm_movemask_epi8(result2) << 16); | - | ||||||||||||||||||
| 572 | # endif | - | ||||||||||||||||||
| 573 | if (mask) {
| 21005-30209 | ||||||||||||||||||
| 574 | // found a different character | - | ||||||||||||||||||
| 575 | uint idx = uint(_bit_scan_forward(mask)); | - | ||||||||||||||||||
| 576 | return uc[offset + idx / 2] - c[offset + idx / 2]; executed 21005 times by 60 tests: return uc[offset + idx / 2] - c[offset + idx / 2];Executed by:
| 21005 | ||||||||||||||||||
| 577 | } | - | ||||||||||||||||||
| 578 | } executed 30209 times by 341 tests: end of blockExecuted by:
| 30209 | ||||||||||||||||||
| 579 | - | |||||||||||||||||||
| 580 | # ifdef Q_PROCESSOR_X86_64 | - | ||||||||||||||||||
| 581 | enum { MaxTailLength = 7 }; | - | ||||||||||||||||||
| 582 | // we'll read uc[offset..offset+7] (16 bytes) and c[offset..offset+7] (8 bytes) | - | ||||||||||||||||||
| 583 | if (uc + offset + 7 < e) {
| 355489-674180 | ||||||||||||||||||
| 584 | // same, but we're using an 8-byte load | - | ||||||||||||||||||
| 585 | __m128i chunk = _mm_cvtsi64_si128(qFromUnaligned<long long>(c + offset)); | - | ||||||||||||||||||
| 586 | __m128i secondHalf = _mm_unpacklo_epi8(chunk, nullmask); | - | ||||||||||||||||||
| 587 | - | |||||||||||||||||||
| 588 | __m128i ucdata = _mm_loadu_si128((const __m128i*)(uc + offset)); | - | ||||||||||||||||||
| 589 | __m128i result = _mm_cmpeq_epi16(secondHalf, ucdata); | - | ||||||||||||||||||
| 590 | uint mask = ~_mm_movemask_epi8(result); | - | ||||||||||||||||||
| 591 | if (ushort(mask)) {
| 39170-316319 | ||||||||||||||||||
| 592 | // found a different character | - | ||||||||||||||||||
| 593 | uint idx = uint(_bit_scan_forward(mask)); | - | ||||||||||||||||||
| 594 | return uc[offset + idx / 2] - c[offset + idx / 2]; executed 39170 times by 211 tests: return uc[offset + idx / 2] - c[offset + idx / 2];Executed by:
| 39170 | ||||||||||||||||||
| 595 | } | - | ||||||||||||||||||
| 596 | - | |||||||||||||||||||
| 597 | // still matched | - | ||||||||||||||||||
| 598 | offset += 8; | - | ||||||||||||||||||
| 599 | } executed 316319 times by 237 tests: end of blockExecuted by:
| 316319 | ||||||||||||||||||
| 600 | # else | - | ||||||||||||||||||
| 601 | // 32-bit, we can't do MOVQ to load 8 bytes | - | ||||||||||||||||||
| 602 | Q_UNUSED(nullmask); | - | ||||||||||||||||||
| 603 | enum { MaxTailLength = 15 }; | - | ||||||||||||||||||
| 604 | # endif | - | ||||||||||||||||||
| 605 | - | |||||||||||||||||||
| 606 | // reset uc and c | - | ||||||||||||||||||
| 607 | uc += offset; | - | ||||||||||||||||||
| 608 | c += offset; | - | ||||||||||||||||||
| 609 | - | |||||||||||||||||||
| 610 | # if defined(Q_COMPILER_LAMBDA) && !defined(__OPTIMIZE_SIZE__) | - | ||||||||||||||||||
| 611 | const auto &lambda = [=](int i) { return uc[i] - ushort(c[i]); }; executed 3238334 times by 462 tests: return uc[i] - ushort(c[i]);Executed by:
| 3238334 | ||||||||||||||||||
| 612 | return UnrollTailLoop<MaxTailLength>::exec(e - uc, 0, lambda, lambda); executed 990499 times by 462 tests: return UnrollTailLoop<MaxTailLength>::exec(e - uc, 0, lambda, lambda);Executed by:
| 990499 | ||||||||||||||||||
| 613 | # endif | - | ||||||||||||||||||
| 614 | #endif | - | ||||||||||||||||||
| 615 | - | |||||||||||||||||||
| 616 | while (uc < e) { dead code: while (uc < e) { int diff = *uc - *c; if (diff) return diff; uc++, c++; } | - | ||||||||||||||||||
| 617 | int diff = *uc - *c; dead code: while (uc < e) { int diff = *uc - *c; if (diff) return diff; uc++, c++; } | - | ||||||||||||||||||
| 618 | if (diff) dead code: while (uc < e) { int diff = *uc - *c; if (diff) return diff; uc++, c++; } | - | ||||||||||||||||||
| 619 | return diff; dead code: while (uc < e) { int diff = *uc - *c; if (diff) return diff; uc++, c++; } | - | ||||||||||||||||||
| 620 | uc++, c++; dead code: while (uc < e) { int diff = *uc - *c; if (diff) return diff; uc++, c++; } | - | ||||||||||||||||||
| 621 | } dead code: while (uc < e) { int diff = *uc - *c; if (diff) return diff; uc++, c++; } | - | ||||||||||||||||||
| 622 | - | |||||||||||||||||||
| 623 | return 0; dead code: return 0; | - | ||||||||||||||||||
| 624 | } | - | ||||||||||||||||||
| 625 | - | |||||||||||||||||||
| 626 | // Unicode case-sensitive comparison | - | ||||||||||||||||||
| 627 | static int ucstrcmp(const QChar *a, int alen, const QChar *b, int blen) | - | ||||||||||||||||||
| 628 | { | - | ||||||||||||||||||
| 629 | if (a == b && alen == blen)
| 1-2435359 | ||||||||||||||||||
| 630 | return 0; executed 80137 times by 430 tests: return 0;Executed by:
| 80137 | ||||||||||||||||||
| 631 | int l = qMin(alen, blen); | - | ||||||||||||||||||
| 632 | int cmp = ucstrncmp(a, b, l); | - | ||||||||||||||||||
| 633 | return cmp ? cmp : (alen-blen); executed 2435360 times by 457 tests: return cmp ? cmp : (alen-blen);Executed by:
| 2435360 | ||||||||||||||||||
| 634 | } | - | ||||||||||||||||||
| 635 | - | |||||||||||||||||||
| 636 | // Unicode case-insensitive compare two same-sized strings | - | ||||||||||||||||||
| 637 | static int ucstrnicmp(const ushort *a, const ushort *b, int l) | - | ||||||||||||||||||
| 638 | { | - | ||||||||||||||||||
| 639 | 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 | ||||||||||||||||||
| 640 | } | - | ||||||||||||||||||
| 641 | - | |||||||||||||||||||
| 642 | static bool qMemEquals(const quint16 *a, const quint16 *b, int length) | - | ||||||||||||||||||
| 643 | { | - | ||||||||||||||||||
| 644 | if (a == b || !length)
| 339741-3343386 | ||||||||||||||||||
| 645 | return true; executed 1271556 times by 476 tests: return true;Executed by:
| 1271556 | ||||||||||||||||||
| 646 | - | |||||||||||||||||||
| 647 | return ucstrncmp(reinterpret_cast<const QChar *>(a), reinterpret_cast<const QChar *>(b), length) == 0; executed 3003645 times by 399 tests: return ucstrncmp(reinterpret_cast<const QChar *>(a), reinterpret_cast<const QChar *>(b), length) == 0;Executed by:
| 3003645 | ||||||||||||||||||
| 648 | } | - | ||||||||||||||||||
| 649 | - | |||||||||||||||||||
| 650 | static int ucstrcmp(const QChar *a, int alen, const uchar *b, int blen) | - | ||||||||||||||||||
| 651 | { | - | ||||||||||||||||||
| 652 | int l = qMin(alen, blen); | - | ||||||||||||||||||
| 653 | int cmp = ucstrncmp(a, b, l); | - | ||||||||||||||||||
| 654 | return cmp ? cmp : (alen-blen); executed 217591 times by 445 tests: return cmp ? cmp : (alen-blen);Executed by:
| 217591 | ||||||||||||||||||
| 655 | } | - | ||||||||||||||||||
| 656 | - | |||||||||||||||||||
| 657 | /*! | - | ||||||||||||||||||
| 658 | \internal | - | ||||||||||||||||||
| 659 | - | |||||||||||||||||||
| 660 | Returns the index position of the first occurrence of the | - | ||||||||||||||||||
| 661 | character \a ch in the string given by \a str and \a len, | - | ||||||||||||||||||
| 662 | searching forward from index | - | ||||||||||||||||||
| 663 | position \a from. Returns -1 if \a ch could not be found. | - | ||||||||||||||||||
| 664 | */ | - | ||||||||||||||||||
| 665 | static int findChar(const QChar *str, int len, QChar ch, int from, | - | ||||||||||||||||||
| 666 | Qt::CaseSensitivity cs) | - | ||||||||||||||||||
| 667 | { | - | ||||||||||||||||||
| 668 | const ushort *s = (const ushort *)str; | - | ||||||||||||||||||
| 669 | ushort c = ch.unicode(); | - | ||||||||||||||||||
| 670 | if (from < 0)
| 1-1483189 | ||||||||||||||||||
| 671 | from = qMax(from + len, 0); executed 1 time by 1 test: from = qMax(from + len, 0);Executed by:
| 1 | ||||||||||||||||||
| 672 | if (from < len) {
| 3888-1479302 | ||||||||||||||||||
| 673 | const ushort *n = s + from; | - | ||||||||||||||||||
| 674 | const ushort *e = s + len; | - | ||||||||||||||||||
| 675 | if (cs == Qt::CaseSensitive) {
| 461-1478841 | ||||||||||||||||||
| 676 | #ifdef __SSE2__ | - | ||||||||||||||||||
| 677 | __m128i mch = _mm_set1_epi32(c | (c << 16)); | - | ||||||||||||||||||
| 678 | - | |||||||||||||||||||
| 679 | // we're going to read n[0..7] (16 bytes) | - | ||||||||||||||||||
| 680 | for (const ushort *next = n + 8; next <= e; n = next, next += 8) {
| 1076299-1107407 | ||||||||||||||||||
| 681 | __m128i data = _mm_loadu_si128((const __m128i*)n); | - | ||||||||||||||||||
| 682 | __m128i result = _mm_cmpeq_epi16(data, mch); | - | ||||||||||||||||||
| 683 | uint mask = _mm_movemask_epi8(result); | - | ||||||||||||||||||
| 684 | if (ushort(mask)) {
| 402542-704865 | ||||||||||||||||||
| 685 | // found a match | - | ||||||||||||||||||
| 686 | // same as: return n - s + _bit_scan_forward(mask) / 2 | - | ||||||||||||||||||
| 687 | return (reinterpret_cast<const char *>(n) - reinterpret_cast<const char *>(s) executed 402542 times by 273 tests: return (reinterpret_cast<const char *>(n) - reinterpret_cast<const char *>(s) + __bsfd(mask)) >> 1;Executed by:
| 402542 | ||||||||||||||||||
| 688 | + _bit_scan_forward(mask)) >> 1; executed 402542 times by 273 tests: return (reinterpret_cast<const char *>(n) - reinterpret_cast<const char *>(s) + __bsfd(mask)) >> 1;Executed by:
| 402542 | ||||||||||||||||||
| 689 | } | - | ||||||||||||||||||
| 690 | } executed 704865 times by 299 tests: end of blockExecuted by:
| 704865 | ||||||||||||||||||
| 691 | - | |||||||||||||||||||
| 692 | # if defined(Q_COMPILER_LAMBDA) && !defined(__OPTIMIZE_SIZE__) | - | ||||||||||||||||||
| 693 | return UnrollTailLoop<7>::exec(e - n, -1, executed 1076299 times by 310 tests: return UnrollTailLoop<7>::exec(e - n, -1, [=](int i) { return n[i] == c; }, [=](int i) { return n - s + i; });Executed by:
| 1076299 | ||||||||||||||||||
| 694 | [=](int i) { return n[i] == c; }, executed 1076299 times by 310 tests: return UnrollTailLoop<7>::exec(e - n, -1, [=](int i) { return n[i] == c; }, [=](int i) { return n - s + i; });Executed by:
executed 2552540 times by 308 tests: return n[i] == c;Executed by:
| 1076299-2552540 | ||||||||||||||||||
| 695 | [=](int i) { return n - s + i; }); executed 1076299 times by 310 tests: return UnrollTailLoop<7>::exec(e - n, -1, [=](int i) { return n[i] == c; }, [=](int i) { return n - s + i; });Executed by:
executed 73549 times by 135 tests: return n - s + i;Executed by:
| 73549-1076299 | ||||||||||||||||||
| 696 | # endif | - | ||||||||||||||||||
| 697 | #endif | - | ||||||||||||||||||
| 698 | --n; dead code: --n; | - | ||||||||||||||||||
| 699 | while (++n != e) dead code: while (++n != e) if (*n == c) return n - s; | - | ||||||||||||||||||
| 700 | if (*n == c) dead code: while (++n != e) if (*n == c) return n - s; | - | ||||||||||||||||||
| 701 | return n - s; dead code: while (++n != e) if (*n == c) return n - s; | - | ||||||||||||||||||
| 702 | } else { | - | ||||||||||||||||||
| 703 | c = foldCase(c); | - | ||||||||||||||||||
| 704 | --n; | - | ||||||||||||||||||
| 705 | while (++n != e)
| 125-800 | ||||||||||||||||||
| 706 | if (foldCase(*n) == c)
| 336-464 | ||||||||||||||||||
| 707 | return n - s; executed 336 times by 6 tests: return n - s;Executed by:
| 336 | ||||||||||||||||||
| 708 | } executed 125 times by 4 tests: end of blockExecuted by:
| 125 | ||||||||||||||||||
| 709 | } | - | ||||||||||||||||||
| 710 | return -1; executed 4013 times by 73 tests: return -1;Executed by:
| 4013 | ||||||||||||||||||
| 711 | } | - | ||||||||||||||||||
| 712 | - | |||||||||||||||||||
| 713 | #define REHASH(a) \ | - | ||||||||||||||||||
| 714 | if (sl_minus_1 < sizeof(uint) * CHAR_BIT) \ | - | ||||||||||||||||||
| 715 | hashHaystack -= uint(a) << sl_minus_1; \ | - | ||||||||||||||||||
| 716 | hashHaystack <<= 1 | - | ||||||||||||||||||
| 717 | - | |||||||||||||||||||
| 718 | inline bool qIsUpper(char ch) | - | ||||||||||||||||||
| 719 | { | - | ||||||||||||||||||
| 720 | return ch >= 'A' && ch <= 'Z'; executed 114853 times by 49 tests: return ch >= 'A' && ch <= 'Z';Executed by:
| 114853 | ||||||||||||||||||
| 721 | } | - | ||||||||||||||||||
| 722 | - | |||||||||||||||||||
| 723 | inline bool qIsDigit(char ch) | - | ||||||||||||||||||
| 724 | { | - | ||||||||||||||||||
| 725 | return ch >= '0' && ch <= '9'; executed 453450 times by 110 tests: return ch >= '0' && ch <= '9';Executed by:
| 453450 | ||||||||||||||||||
| 726 | } | - | ||||||||||||||||||
| 727 | - | |||||||||||||||||||
| 728 | inline char qToLower(char ch) | - | ||||||||||||||||||
| 729 | { | - | ||||||||||||||||||
| 730 | if (ch >= 'A' && ch <= 'Z')
| 0-114853 | ||||||||||||||||||
| 731 | return ch - 'A' + 'a'; executed 4992 times by 1 test: return ch - 'A' + 'a';Executed by:
| 4992 | ||||||||||||||||||
| 732 | else | - | ||||||||||||||||||
| 733 | return ch; executed 109861 times by 49 tests: return ch;Executed by:
| 109861 | ||||||||||||||||||
| 734 | } | - | ||||||||||||||||||
| 735 | - | |||||||||||||||||||
| 736 | - | |||||||||||||||||||
| 737 | const QString::Null QString::null = { }; | - | ||||||||||||||||||
| 738 | - | |||||||||||||||||||
| 739 | /*! | - | ||||||||||||||||||
| 740 | \macro QT_RESTRICTED_CAST_FROM_ASCII | - | ||||||||||||||||||
| 741 | \relates QString | - | ||||||||||||||||||
| 742 | - | |||||||||||||||||||
| 743 | Defining this macro disables most automatic conversions from source | - | ||||||||||||||||||
| 744 | literals and 8-bit data to unicode QStrings, but allows the use of | - | ||||||||||||||||||
| 745 | the \c{QChar(char)} and \c{QString(const char (&ch)[N]} constructors, | - | ||||||||||||||||||
| 746 | and the \c{QString::operator=(const char (&ch)[N])} assignment operator | - | ||||||||||||||||||
| 747 | giving most of the type-safety benefits of QT_NO_CAST_FROM_ASCII | - | ||||||||||||||||||
| 748 | but does not require user code to wrap character and string literals | - | ||||||||||||||||||
| 749 | with QLatin1Char, QLatin1String or similar. | - | ||||||||||||||||||
| 750 | - | |||||||||||||||||||
| 751 | Using this macro together with source strings outside the 7-bit range, | - | ||||||||||||||||||
| 752 | non-literals, or literals with embedded NUL characters is undefined. | - | ||||||||||||||||||
| 753 | - | |||||||||||||||||||
| 754 | \sa QT_NO_CAST_FROM_ASCII, QT_NO_CAST_TO_ASCII | - | ||||||||||||||||||
| 755 | */ | - | ||||||||||||||||||
| 756 | - | |||||||||||||||||||
| 757 | /*! | - | ||||||||||||||||||
| 758 | \macro QT_NO_CAST_FROM_ASCII | - | ||||||||||||||||||
| 759 | \relates QString | - | ||||||||||||||||||
| 760 | - | |||||||||||||||||||
| 761 | Disables automatic conversions from 8-bit strings (char *) to unicode QStrings | - | ||||||||||||||||||
| 762 | - | |||||||||||||||||||
| 763 | \sa QT_NO_CAST_TO_ASCII, QT_RESTRICTED_CAST_FROM_ASCII, QT_NO_CAST_FROM_BYTEARRAY | - | ||||||||||||||||||
| 764 | */ | - | ||||||||||||||||||
| 765 | - | |||||||||||||||||||
| 766 | /*! | - | ||||||||||||||||||
| 767 | \macro QT_NO_CAST_TO_ASCII | - | ||||||||||||||||||
| 768 | \relates QString | - | ||||||||||||||||||
| 769 | - | |||||||||||||||||||
| 770 | disables automatic conversion from QString to 8-bit strings (char *) | - | ||||||||||||||||||
| 771 | - | |||||||||||||||||||
| 772 | \sa QT_NO_CAST_FROM_ASCII, QT_RESTRICTED_CAST_FROM_ASCII, QT_NO_CAST_FROM_BYTEARRAY | - | ||||||||||||||||||
| 773 | */ | - | ||||||||||||||||||
| 774 | - | |||||||||||||||||||
| 775 | /*! | - | ||||||||||||||||||
| 776 | \macro QT_ASCII_CAST_WARNINGS | - | ||||||||||||||||||
| 777 | \internal | - | ||||||||||||||||||
| 778 | \relates QString | - | ||||||||||||||||||
| 779 | - | |||||||||||||||||||
| 780 | This macro can be defined to force a warning whenever a function is | - | ||||||||||||||||||
| 781 | called that automatically converts between unicode and 8-bit encodings. | - | ||||||||||||||||||
| 782 | - | |||||||||||||||||||
| 783 | Note: This only works for compilers that support warnings for | - | ||||||||||||||||||
| 784 | deprecated API. | - | ||||||||||||||||||
| 785 | - | |||||||||||||||||||
| 786 | \sa QT_NO_CAST_TO_ASCII, QT_NO_CAST_FROM_ASCII, QT_RESTRICTED_CAST_FROM_ASCII | - | ||||||||||||||||||
| 787 | */ | - | ||||||||||||||||||
| 788 | - | |||||||||||||||||||
| 789 | /*! | - | ||||||||||||||||||
| 790 | \class QCharRef | - | ||||||||||||||||||
| 791 | \inmodule QtCore | - | ||||||||||||||||||
| 792 | \reentrant | - | ||||||||||||||||||
| 793 | \brief The QCharRef class is a helper class for QString. | - | ||||||||||||||||||
| 794 | - | |||||||||||||||||||
| 795 | \internal | - | ||||||||||||||||||
| 796 | - | |||||||||||||||||||
| 797 | \ingroup string-processing | - | ||||||||||||||||||
| 798 | - | |||||||||||||||||||
| 799 | When you get an object of type QCharRef, if you can assign to it, | - | ||||||||||||||||||
| 800 | the assignment will apply to the character in the string from | - | ||||||||||||||||||
| 801 | which you got the reference. That is its whole purpose in life. | - | ||||||||||||||||||
| 802 | The QCharRef becomes invalid once modifications are made to the | - | ||||||||||||||||||
| 803 | string: if you want to keep the character, copy it into a QChar. | - | ||||||||||||||||||
| 804 | - | |||||||||||||||||||
| 805 | Most of the QChar member functions also exist in QCharRef. | - | ||||||||||||||||||
| 806 | However, they are not explicitly documented here. | - | ||||||||||||||||||
| 807 | - | |||||||||||||||||||
| 808 | \sa QString::operator[](), QString::at(), QChar | - | ||||||||||||||||||
| 809 | */ | - | ||||||||||||||||||
| 810 | - | |||||||||||||||||||
| 811 | /*! | - | ||||||||||||||||||
| 812 | \class QString | - | ||||||||||||||||||
| 813 | \inmodule QtCore | - | ||||||||||||||||||
| 814 | \reentrant | - | ||||||||||||||||||
| 815 | - | |||||||||||||||||||
| 816 | \brief The QString class provides a Unicode character string. | - | ||||||||||||||||||
| 817 | - | |||||||||||||||||||
| 818 | \ingroup tools | - | ||||||||||||||||||
| 819 | \ingroup shared | - | ||||||||||||||||||
| 820 | \ingroup string-processing | - | ||||||||||||||||||
| 821 | - | |||||||||||||||||||
| 822 | QString stores a string of 16-bit \l{QChar}s, where each QChar | - | ||||||||||||||||||
| 823 | corresponds one Unicode 4.0 character. (Unicode characters | - | ||||||||||||||||||
| 824 | with code values above 65535 are stored using surrogate pairs, | - | ||||||||||||||||||
| 825 | i.e., two consecutive \l{QChar}s.) | - | ||||||||||||||||||
| 826 | - | |||||||||||||||||||
| 827 | \l{Unicode} is an international standard that supports most of the | - | ||||||||||||||||||
| 828 | writing systems in use today. It is a superset of US-ASCII (ANSI | - | ||||||||||||||||||
| 829 | X3.4-1986) and Latin-1 (ISO 8859-1), and all the US-ASCII/Latin-1 | - | ||||||||||||||||||
| 830 | characters are available at the same code positions. | - | ||||||||||||||||||
| 831 | - | |||||||||||||||||||
| 832 | Behind the scenes, QString uses \l{implicit sharing} | - | ||||||||||||||||||
| 833 | (copy-on-write) to reduce memory usage and to avoid the needless | - | ||||||||||||||||||
| 834 | copying of data. This also helps reduce the inherent overhead of | - | ||||||||||||||||||
| 835 | storing 16-bit characters instead of 8-bit characters. | - | ||||||||||||||||||
| 836 | - | |||||||||||||||||||
| 837 | In addition to QString, Qt also provides the QByteArray class to | - | ||||||||||||||||||
| 838 | store raw bytes and traditional 8-bit '\\0'-terminated strings. | - | ||||||||||||||||||
| 839 | For most purposes, QString is the class you want to use. It is | - | ||||||||||||||||||
| 840 | used throughout the Qt API, and the Unicode support ensures that | - | ||||||||||||||||||
| 841 | your applications will be easy to translate if you want to expand | - | ||||||||||||||||||
| 842 | your application's market at some point. The two main cases where | - | ||||||||||||||||||
| 843 | QByteArray is appropriate are when you need to store raw binary | - | ||||||||||||||||||
| 844 | data, and when memory conservation is critical (like in embedded | - | ||||||||||||||||||
| 845 | systems). | - | ||||||||||||||||||
| 846 | - | |||||||||||||||||||
| 847 | \tableofcontents | - | ||||||||||||||||||
| 848 | - | |||||||||||||||||||
| 849 | \section1 Initializing a String | - | ||||||||||||||||||
| 850 | - | |||||||||||||||||||
| 851 | One way to initialize a QString is simply to pass a \c{const char | - | ||||||||||||||||||
| 852 | *} to its constructor. For example, the following code creates a | - | ||||||||||||||||||
| 853 | QString of size 5 containing the data "Hello": | - | ||||||||||||||||||
| 854 | - | |||||||||||||||||||
| 855 | \snippet qstring/main.cpp 0 | - | ||||||||||||||||||
| 856 | - | |||||||||||||||||||
| 857 | QString converts the \c{const char *} data into Unicode using the | - | ||||||||||||||||||
| 858 | fromUtf8() function. | - | ||||||||||||||||||
| 859 | - | |||||||||||||||||||
| 860 | In all of the QString functions that take \c{const char *} | - | ||||||||||||||||||
| 861 | parameters, the \c{const char *} is interpreted as a classic | - | ||||||||||||||||||
| 862 | C-style '\\0'-terminated string encoded in UTF-8. It is legal for | - | ||||||||||||||||||
| 863 | the \c{const char *} parameter to be 0. | - | ||||||||||||||||||
| 864 | - | |||||||||||||||||||
| 865 | You can also provide string data as an array of \l{QChar}s: | - | ||||||||||||||||||
| 866 | - | |||||||||||||||||||
| 867 | \snippet qstring/main.cpp 1 | - | ||||||||||||||||||
| 868 | - | |||||||||||||||||||
| 869 | QString makes a deep copy of the QChar data, so you can modify it | - | ||||||||||||||||||
| 870 | later without experiencing side effects. (If for performance | - | ||||||||||||||||||
| 871 | reasons you don't want to take a deep copy of the character data, | - | ||||||||||||||||||
| 872 | use QString::fromRawData() instead.) | - | ||||||||||||||||||
| 873 | - | |||||||||||||||||||
| 874 | Another approach is to set the size of the string using resize() | - | ||||||||||||||||||
| 875 | and to initialize the data character per character. QString uses | - | ||||||||||||||||||
| 876 | 0-based indexes, just like C++ arrays. To access the character at | - | ||||||||||||||||||
| 877 | a particular index position, you can use \l operator[](). On | - | ||||||||||||||||||
| 878 | non-const strings, \l operator[]() returns a reference to a | - | ||||||||||||||||||
| 879 | character that can be used on the left side of an assignment. For | - | ||||||||||||||||||
| 880 | example: | - | ||||||||||||||||||
| 881 | - | |||||||||||||||||||
| 882 | \snippet qstring/main.cpp 2 | - | ||||||||||||||||||
| 883 | - | |||||||||||||||||||
| 884 | For read-only access, an alternative syntax is to use the at() | - | ||||||||||||||||||
| 885 | function: | - | ||||||||||||||||||
| 886 | - | |||||||||||||||||||
| 887 | \snippet qstring/main.cpp 3 | - | ||||||||||||||||||
| 888 | - | |||||||||||||||||||
| 889 | The at() function can be faster than \l operator[](), because it | - | ||||||||||||||||||
| 890 | never causes a \l{deep copy} to occur. Alternatively, use the | - | ||||||||||||||||||
| 891 | left(), right(), or mid() functions to extract several characters | - | ||||||||||||||||||
| 892 | at a time. | - | ||||||||||||||||||
| 893 | - | |||||||||||||||||||
| 894 | A QString can embed '\\0' characters (QChar::Null). The size() | - | ||||||||||||||||||
| 895 | function always returns the size of the whole string, including | - | ||||||||||||||||||
| 896 | embedded '\\0' characters. | - | ||||||||||||||||||
| 897 | - | |||||||||||||||||||
| 898 | After a call to the resize() function, newly allocated characters | - | ||||||||||||||||||
| 899 | have undefined values. To set all the characters in the string to | - | ||||||||||||||||||
| 900 | a particular value, use the fill() function. | - | ||||||||||||||||||
| 901 | - | |||||||||||||||||||
| 902 | QString provides dozens of overloads designed to simplify string | - | ||||||||||||||||||
| 903 | usage. For example, if you want to compare a QString with a string | - | ||||||||||||||||||
| 904 | literal, you can write code like this and it will work as expected: | - | ||||||||||||||||||
| 905 | - | |||||||||||||||||||
| 906 | \snippet qstring/main.cpp 4 | - | ||||||||||||||||||
| 907 | - | |||||||||||||||||||
| 908 | You can also pass string literals to functions that take QStrings | - | ||||||||||||||||||
| 909 | as arguments, invoking the QString(const char *) | - | ||||||||||||||||||
| 910 | constructor. Similarly, you can pass a QString to a function that | - | ||||||||||||||||||
| 911 | takes a \c{const char *} argument using the \l qPrintable() macro | - | ||||||||||||||||||
| 912 | which returns the given QString as a \c{const char *}. This is | - | ||||||||||||||||||
| 913 | equivalent to calling <QString>.toLocal8Bit().constData(). | - | ||||||||||||||||||
| 914 | - | |||||||||||||||||||
| 915 | \section1 Manipulating String Data | - | ||||||||||||||||||
| 916 | - | |||||||||||||||||||
| 917 | QString provides the following basic functions for modifying the | - | ||||||||||||||||||
| 918 | character data: append(), prepend(), insert(), replace(), and | - | ||||||||||||||||||
| 919 | remove(). For example: | - | ||||||||||||||||||
| 920 | - | |||||||||||||||||||
| 921 | \snippet qstring/main.cpp 5 | - | ||||||||||||||||||
| 922 | - | |||||||||||||||||||
| 923 | If you are building a QString gradually and know in advance | - | ||||||||||||||||||
| 924 | approximately how many characters the QString will contain, you | - | ||||||||||||||||||
| 925 | can call reserve(), asking QString to preallocate a certain amount | - | ||||||||||||||||||
| 926 | of memory. You can also call capacity() to find out how much | - | ||||||||||||||||||
| 927 | memory QString actually allocated. | - | ||||||||||||||||||
| 928 | - | |||||||||||||||||||
| 929 | The replace() and remove() functions' first two arguments are the | - | ||||||||||||||||||
| 930 | position from which to start erasing and the number of characters | - | ||||||||||||||||||
| 931 | that should be erased. If you want to replace all occurrences of | - | ||||||||||||||||||
| 932 | a particular substring with another, use one of the two-parameter | - | ||||||||||||||||||
| 933 | replace() overloads. | - | ||||||||||||||||||
| 934 | - | |||||||||||||||||||
| 935 | A frequent requirement is to remove whitespace characters from a | - | ||||||||||||||||||
| 936 | string ('\\n', '\\t', ' ', etc.). If you want to remove whitespace | - | ||||||||||||||||||
| 937 | from both ends of a QString, use the trimmed() function. If you | - | ||||||||||||||||||
| 938 | want to remove whitespace from both ends and replace multiple | - | ||||||||||||||||||
| 939 | consecutive whitespaces with a single space character within the | - | ||||||||||||||||||
| 940 | string, use simplified(). | - | ||||||||||||||||||
| 941 | - | |||||||||||||||||||
| 942 | If you want to find all occurrences of a particular character or | - | ||||||||||||||||||
| 943 | substring in a QString, use the indexOf() or lastIndexOf() | - | ||||||||||||||||||
| 944 | functions. The former searches forward starting from a given index | - | ||||||||||||||||||
| 945 | position, the latter searches backward. Both return the index | - | ||||||||||||||||||
| 946 | position of the character or substring if they find it; otherwise, | - | ||||||||||||||||||
| 947 | they return -1. For example, here's a typical loop that finds all | - | ||||||||||||||||||
| 948 | occurrences of a particular substring: | - | ||||||||||||||||||
| 949 | - | |||||||||||||||||||
| 950 | \snippet qstring/main.cpp 6 | - | ||||||||||||||||||
| 951 | - | |||||||||||||||||||
| 952 | QString provides many functions for converting numbers into | - | ||||||||||||||||||
| 953 | strings and strings into numbers. See the arg() functions, the | - | ||||||||||||||||||
| 954 | setNum() functions, the number() static functions, and the | - | ||||||||||||||||||
| 955 | toInt(), toDouble(), and similar functions. | - | ||||||||||||||||||
| 956 | - | |||||||||||||||||||
| 957 | To get an upper- or lowercase version of a string use toUpper() or | - | ||||||||||||||||||
| 958 | toLower(). | - | ||||||||||||||||||
| 959 | - | |||||||||||||||||||
| 960 | Lists of strings are handled by the QStringList class. You can | - | ||||||||||||||||||
| 961 | split a string into a list of strings using the split() function, | - | ||||||||||||||||||
| 962 | and join a list of strings into a single string with an optional | - | ||||||||||||||||||
| 963 | separator using QStringList::join(). You can obtain a list of | - | ||||||||||||||||||
| 964 | strings from a string list that contain a particular substring or | - | ||||||||||||||||||
| 965 | that match a particular QRegExp using the QStringList::filter() | - | ||||||||||||||||||
| 966 | function. | - | ||||||||||||||||||
| 967 | - | |||||||||||||||||||
| 968 | \section1 Querying String Data | - | ||||||||||||||||||
| 969 | - | |||||||||||||||||||
| 970 | If you want to see if a QString starts or ends with a particular | - | ||||||||||||||||||
| 971 | substring use startsWith() or endsWith(). If you simply want to | - | ||||||||||||||||||
| 972 | check whether a QString contains a particular character or | - | ||||||||||||||||||
| 973 | substring, use the contains() function. If you want to find out | - | ||||||||||||||||||
| 974 | how many times a particular character or substring occurs in the | - | ||||||||||||||||||
| 975 | string, use count(). | - | ||||||||||||||||||
| 976 | - | |||||||||||||||||||
| 977 | QStrings can be compared using overloaded operators such as \l | - | ||||||||||||||||||
| 978 | operator<(), \l operator<=(), \l operator==(), \l operator>=(), | - | ||||||||||||||||||
| 979 | and so on. Note that the comparison is based exclusively on the | - | ||||||||||||||||||
| 980 | numeric Unicode values of the characters. It is very fast, but is | - | ||||||||||||||||||
| 981 | not what a human would expect; the QString::localeAwareCompare() | - | ||||||||||||||||||
| 982 | function is a better choice for sorting user-interface strings. | - | ||||||||||||||||||
| 983 | - | |||||||||||||||||||
| 984 | To obtain a pointer to the actual character data, call data() or | - | ||||||||||||||||||
| 985 | constData(). These functions return a pointer to the beginning of | - | ||||||||||||||||||
| 986 | the QChar data. The pointer is guaranteed to remain valid until a | - | ||||||||||||||||||
| 987 | non-const function is called on the QString. | - | ||||||||||||||||||
| 988 | - | |||||||||||||||||||
| 989 | \section1 Converting Between 8-Bit Strings and Unicode Strings | - | ||||||||||||||||||
| 990 | - | |||||||||||||||||||
| 991 | QString provides the following three functions that return a | - | ||||||||||||||||||
| 992 | \c{const char *} version of the string as QByteArray: toUtf8(), | - | ||||||||||||||||||
| 993 | toLatin1(), and toLocal8Bit(). | - | ||||||||||||||||||
| 994 | - | |||||||||||||||||||
| 995 | \list | - | ||||||||||||||||||
| 996 | \li toLatin1() returns a Latin-1 (ISO 8859-1) encoded 8-bit string. | - | ||||||||||||||||||
| 997 | \li toUtf8() returns a UTF-8 encoded 8-bit string. UTF-8 is a | - | ||||||||||||||||||
| 998 | superset of US-ASCII (ANSI X3.4-1986) that supports the entire | - | ||||||||||||||||||
| 999 | Unicode character set through multibyte sequences. | - | ||||||||||||||||||
| 1000 | \li toLocal8Bit() returns an 8-bit string using the system's local | - | ||||||||||||||||||
| 1001 | encoding. | - | ||||||||||||||||||
| 1002 | \endlist | - | ||||||||||||||||||
| 1003 | - | |||||||||||||||||||
| 1004 | To convert from one of these encodings, QString provides | - | ||||||||||||||||||
| 1005 | fromLatin1(), fromUtf8(), and fromLocal8Bit(). Other | - | ||||||||||||||||||
| 1006 | encodings are supported through the QTextCodec class. | - | ||||||||||||||||||
| 1007 | - | |||||||||||||||||||
| 1008 | As mentioned above, QString provides a lot of functions and | - | ||||||||||||||||||
| 1009 | operators that make it easy to interoperate with \c{const char *} | - | ||||||||||||||||||
| 1010 | strings. But this functionality is a double-edged sword: It makes | - | ||||||||||||||||||
| 1011 | QString more convenient to use if all strings are US-ASCII or | - | ||||||||||||||||||
| 1012 | Latin-1, but there is always the risk that an implicit conversion | - | ||||||||||||||||||
| 1013 | from or to \c{const char *} is done using the wrong 8-bit | - | ||||||||||||||||||
| 1014 | encoding. To minimize these risks, you can turn off these implicit | - | ||||||||||||||||||
| 1015 | conversions by defining the following two preprocessor symbols: | - | ||||||||||||||||||
| 1016 | - | |||||||||||||||||||
| 1017 | \list | - | ||||||||||||||||||
| 1018 | \li \c QT_NO_CAST_FROM_ASCII disables automatic conversions from | - | ||||||||||||||||||
| 1019 | C string literals and pointers to Unicode. | - | ||||||||||||||||||
| 1020 | \li \c QT_RESTRICTED_CAST_FROM_ASCII allows automatic conversions | - | ||||||||||||||||||
| 1021 | from C characters and character arrays, but disables automatic | - | ||||||||||||||||||
| 1022 | conversions from character pointers to Unicode. | - | ||||||||||||||||||
| 1023 | \li \c QT_NO_CAST_TO_ASCII disables automatic conversion from QString | - | ||||||||||||||||||
| 1024 | to C strings. | - | ||||||||||||||||||
| 1025 | \endlist | - | ||||||||||||||||||
| 1026 | - | |||||||||||||||||||
| 1027 | One way to define these preprocessor symbols globally for your | - | ||||||||||||||||||
| 1028 | application is to add the following entry to your \l {Creating Project Files}{qmake project file}: | - | ||||||||||||||||||
| 1029 | - | |||||||||||||||||||
| 1030 | \snippet code/src_corelib_tools_qstring.cpp 0 | - | ||||||||||||||||||
| 1031 | - | |||||||||||||||||||
| 1032 | You then need to explicitly call fromUtf8(), fromLatin1(), | - | ||||||||||||||||||
| 1033 | or fromLocal8Bit() to construct a QString from an | - | ||||||||||||||||||
| 1034 | 8-bit string, or use the lightweight QLatin1String class, for | - | ||||||||||||||||||
| 1035 | example: | - | ||||||||||||||||||
| 1036 | - | |||||||||||||||||||
| 1037 | \snippet code/src_corelib_tools_qstring.cpp 1 | - | ||||||||||||||||||
| 1038 | - | |||||||||||||||||||
| 1039 | Similarly, you must call toLatin1(), toUtf8(), or | - | ||||||||||||||||||
| 1040 | toLocal8Bit() explicitly to convert the QString to an 8-bit | - | ||||||||||||||||||
| 1041 | string. (Other encodings are supported through the QTextCodec | - | ||||||||||||||||||
| 1042 | class.) | - | ||||||||||||||||||
| 1043 | - | |||||||||||||||||||
| 1044 | \table 100 % | - | ||||||||||||||||||
| 1045 | \header | - | ||||||||||||||||||
| 1046 | \li Note for C Programmers | - | ||||||||||||||||||
| 1047 | - | |||||||||||||||||||
| 1048 | \row | - | ||||||||||||||||||
| 1049 | \li | - | ||||||||||||||||||
| 1050 | Due to C++'s type system and the fact that QString is | - | ||||||||||||||||||
| 1051 | \l{implicitly shared}, QStrings may be treated like \c{int}s or | - | ||||||||||||||||||
| 1052 | other basic types. For example: | - | ||||||||||||||||||
| 1053 | - | |||||||||||||||||||
| 1054 | \snippet qstring/main.cpp 7 | - | ||||||||||||||||||
| 1055 | - | |||||||||||||||||||
| 1056 | The \c result variable, is a normal variable allocated on the | - | ||||||||||||||||||
| 1057 | stack. When \c return is called, and because we're returning by | - | ||||||||||||||||||
| 1058 | value, the copy constructor is called and a copy of the string is | - | ||||||||||||||||||
| 1059 | returned. No actual copying takes place thanks to the implicit | - | ||||||||||||||||||
| 1060 | sharing. | - | ||||||||||||||||||
| 1061 | - | |||||||||||||||||||
| 1062 | \endtable | - | ||||||||||||||||||
| 1063 | - | |||||||||||||||||||
| 1064 | \section1 Distinction Between Null and Empty Strings | - | ||||||||||||||||||
| 1065 | - | |||||||||||||||||||
| 1066 | For historical reasons, QString distinguishes between a null | - | ||||||||||||||||||
| 1067 | string and an empty string. A \e null string is a string that is | - | ||||||||||||||||||
| 1068 | initialized using QString's default constructor or by passing | - | ||||||||||||||||||
| 1069 | (const char *)0 to the constructor. An \e empty string is any | - | ||||||||||||||||||
| 1070 | string with size 0. A null string is always empty, but an empty | - | ||||||||||||||||||
| 1071 | string isn't necessarily null: | - | ||||||||||||||||||
| 1072 | - | |||||||||||||||||||
| 1073 | \snippet qstring/main.cpp 8 | - | ||||||||||||||||||
| 1074 | - | |||||||||||||||||||
| 1075 | All functions except isNull() treat null strings the same as empty | - | ||||||||||||||||||
| 1076 | strings. For example, toUtf8().constData() returns a pointer to a | - | ||||||||||||||||||
| 1077 | '\\0' character for a null string (\e not a null pointer), and | - | ||||||||||||||||||
| 1078 | QString() compares equal to QString(""). We recommend that you | - | ||||||||||||||||||
| 1079 | always use the isEmpty() function and avoid isNull(). | - | ||||||||||||||||||
| 1080 | - | |||||||||||||||||||
| 1081 | \section1 Argument Formats | - | ||||||||||||||||||
| 1082 | - | |||||||||||||||||||
| 1083 | In member functions where an argument \e format can be specified | - | ||||||||||||||||||
| 1084 | (e.g., arg(), number()), the argument \e format can be one of the | - | ||||||||||||||||||
| 1085 | following: | - | ||||||||||||||||||
| 1086 | - | |||||||||||||||||||
| 1087 | \table | - | ||||||||||||||||||
| 1088 | \header \li Format \li Meaning | - | ||||||||||||||||||
| 1089 | \row \li \c e \li format as [-]9.9e[+|-]999 | - | ||||||||||||||||||
| 1090 | \row \li \c E \li format as [-]9.9E[+|-]999 | - | ||||||||||||||||||
| 1091 | \row \li \c f \li format as [-]9.9 | - | ||||||||||||||||||
| 1092 | \row \li \c g \li use \c e or \c f format, whichever is the most concise | - | ||||||||||||||||||
| 1093 | \row \li \c G \li use \c E or \c f format, whichever is the most concise | - | ||||||||||||||||||
| 1094 | \endtable | - | ||||||||||||||||||
| 1095 | - | |||||||||||||||||||
| 1096 | A \e precision is also specified with the argument \e format. For | - | ||||||||||||||||||
| 1097 | the 'e', 'E', and 'f' formats, the \e precision represents the | - | ||||||||||||||||||
| 1098 | number of digits \e after the decimal point. For the 'g' and 'G' | - | ||||||||||||||||||
| 1099 | formats, the \e precision represents the maximum number of | - | ||||||||||||||||||
| 1100 | significant digits (trailing zeroes are omitted). | - | ||||||||||||||||||
| 1101 | - | |||||||||||||||||||
| 1102 | \section1 More Efficient String Construction | - | ||||||||||||||||||
| 1103 | - | |||||||||||||||||||
| 1104 | Many strings are known at compile time. But the trivial | - | ||||||||||||||||||
| 1105 | constructor QString("Hello"), will copy the contents of the string, | - | ||||||||||||||||||
| 1106 | treating the contents as Latin-1. To avoid this one can use the | - | ||||||||||||||||||
| 1107 | QStringLiteral macro to directly create the required data at compile | - | ||||||||||||||||||
| 1108 | time. Constructing a QString out of the literal does then not cause | - | ||||||||||||||||||
| 1109 | any overhead at runtime. | - | ||||||||||||||||||
| 1110 | - | |||||||||||||||||||
| 1111 | A slightly less efficient way is to use QLatin1String. This class wraps | - | ||||||||||||||||||
| 1112 | a C string literal, precalculates it length at compile time and can | - | ||||||||||||||||||
| 1113 | then be used for faster comparison with QStrings and conversion to | - | ||||||||||||||||||
| 1114 | QStrings than a regular C string literal. | - | ||||||||||||||||||
| 1115 | - | |||||||||||||||||||
| 1116 | Using the QString \c{'+'} operator, it is easy to construct a | - | ||||||||||||||||||
| 1117 | complex string from multiple substrings. You will often write code | - | ||||||||||||||||||
| 1118 | like this: | - | ||||||||||||||||||
| 1119 | - | |||||||||||||||||||
| 1120 | \snippet qstring/stringbuilder.cpp 0 | - | ||||||||||||||||||
| 1121 | - | |||||||||||||||||||
| 1122 | There is nothing wrong with either of these string constructions, | - | ||||||||||||||||||
| 1123 | but there are a few hidden inefficiencies. Beginning with Qt 4.6, | - | ||||||||||||||||||
| 1124 | you can eliminate them. | - | ||||||||||||||||||
| 1125 | - | |||||||||||||||||||
| 1126 | First, multiple uses of the \c{'+'} operator usually means | - | ||||||||||||||||||
| 1127 | multiple memory allocations. When concatenating \e{n} substrings, | - | ||||||||||||||||||
| 1128 | where \e{n > 2}, there can be as many as \e{n - 1} calls to the | - | ||||||||||||||||||
| 1129 | memory allocator. | - | ||||||||||||||||||
| 1130 | - | |||||||||||||||||||
| 1131 | In 4.6, an internal template class \c{QStringBuilder} has been | - | ||||||||||||||||||
| 1132 | added along with a few helper functions. This class is marked | - | ||||||||||||||||||
| 1133 | internal and does not appear in the documentation, because you | - | ||||||||||||||||||
| 1134 | aren't meant to instantiate it in your code. Its use will be | - | ||||||||||||||||||
| 1135 | automatic, as described below. The class is found in | - | ||||||||||||||||||
| 1136 | \c {src/corelib/tools/qstringbuilder.cpp} if you want to have a | - | ||||||||||||||||||
| 1137 | look at it. | - | ||||||||||||||||||
| 1138 | - | |||||||||||||||||||
| 1139 | \c{QStringBuilder} uses expression templates and reimplements the | - | ||||||||||||||||||
| 1140 | \c{'%'} operator so that when you use \c{'%'} for string | - | ||||||||||||||||||
| 1141 | concatenation instead of \c{'+'}, multiple substring | - | ||||||||||||||||||
| 1142 | concatenations will be postponed until the final result is about | - | ||||||||||||||||||
| 1143 | to be assigned to a QString. At this point, the amount of memory | - | ||||||||||||||||||
| 1144 | required for the final result is known. The memory allocator is | - | ||||||||||||||||||
| 1145 | then called \e{once} to get the required space, and the substrings | - | ||||||||||||||||||
| 1146 | are copied into it one by one. | - | ||||||||||||||||||
| 1147 | - | |||||||||||||||||||
| 1148 | Additional efficiency is gained by inlining and reduced reference | - | ||||||||||||||||||
| 1149 | counting (the QString created from a \c{QStringBuilder} typically | - | ||||||||||||||||||
| 1150 | has a ref count of 1, whereas QString::append() needs an extra | - | ||||||||||||||||||
| 1151 | test). | - | ||||||||||||||||||
| 1152 | - | |||||||||||||||||||
| 1153 | There are three ways you can access this improved method of string | - | ||||||||||||||||||
| 1154 | construction. The straightforward way is to include | - | ||||||||||||||||||
| 1155 | \c{QStringBuilder} wherever you want to use it, and use the | - | ||||||||||||||||||
| 1156 | \c{'%'} operator instead of \c{'+'} when concatenating strings: | - | ||||||||||||||||||
| 1157 | - | |||||||||||||||||||
| 1158 | \snippet qstring/stringbuilder.cpp 5 | - | ||||||||||||||||||
| 1159 | - | |||||||||||||||||||
| 1160 | A more global approach which is the most convenient but | - | ||||||||||||||||||
| 1161 | not entirely source compatible, is to this define in your | - | ||||||||||||||||||
| 1162 | .pro file: | - | ||||||||||||||||||
| 1163 | - | |||||||||||||||||||
| 1164 | \snippet qstring/stringbuilder.cpp 3 | - | ||||||||||||||||||
| 1165 | - | |||||||||||||||||||
| 1166 | and the \c{'+'} will automatically be performed as the | - | ||||||||||||||||||
| 1167 | \c{QStringBuilder} \c{'%'} everywhere. | - | ||||||||||||||||||
| 1168 | - | |||||||||||||||||||
| 1169 | \sa fromRawData(), QChar, QLatin1String, QByteArray, QStringRef | - | ||||||||||||||||||
| 1170 | */ | - | ||||||||||||||||||
| 1171 | - | |||||||||||||||||||
| 1172 | /*! | - | ||||||||||||||||||
| 1173 | \enum QString::SplitBehavior | - | ||||||||||||||||||
| 1174 | - | |||||||||||||||||||
| 1175 | This enum specifies how the split() function should behave with | - | ||||||||||||||||||
| 1176 | respect to empty strings. | - | ||||||||||||||||||
| 1177 | - | |||||||||||||||||||
| 1178 | \value KeepEmptyParts If a field is empty, keep it in the result. | - | ||||||||||||||||||
| 1179 | \value SkipEmptyParts If a field is empty, don't include it in the result. | - | ||||||||||||||||||
| 1180 | - | |||||||||||||||||||
| 1181 | \sa split() | - | ||||||||||||||||||
| 1182 | */ | - | ||||||||||||||||||
| 1183 | - | |||||||||||||||||||
| 1184 | /*! \typedef QString::ConstIterator | - | ||||||||||||||||||
| 1185 | - | |||||||||||||||||||
| 1186 | Qt-style synonym for QString::const_iterator. | - | ||||||||||||||||||
| 1187 | */ | - | ||||||||||||||||||
| 1188 | - | |||||||||||||||||||
| 1189 | /*! \typedef QString::Iterator | - | ||||||||||||||||||
| 1190 | - | |||||||||||||||||||
| 1191 | Qt-style synonym for QString::iterator. | - | ||||||||||||||||||
| 1192 | */ | - | ||||||||||||||||||
| 1193 | - | |||||||||||||||||||
| 1194 | /*! \typedef QString::const_iterator | - | ||||||||||||||||||
| 1195 | - | |||||||||||||||||||
| 1196 | This typedef provides an STL-style const iterator for QString. | - | ||||||||||||||||||
| 1197 | - | |||||||||||||||||||
| 1198 | \sa QString::iterator | - | ||||||||||||||||||
| 1199 | */ | - | ||||||||||||||||||
| 1200 | - | |||||||||||||||||||
| 1201 | /*! \typedef QString::iterator | - | ||||||||||||||||||
| 1202 | - | |||||||||||||||||||
| 1203 | The QString::iterator typedef provides an STL-style non-const | - | ||||||||||||||||||
| 1204 | iterator for QString. | - | ||||||||||||||||||
| 1205 | - | |||||||||||||||||||
| 1206 | \sa QString::const_iterator | - | ||||||||||||||||||
| 1207 | */ | - | ||||||||||||||||||
| 1208 | - | |||||||||||||||||||
| 1209 | /*! \typedef QString::const_reverse_iterator | - | ||||||||||||||||||
| 1210 | \since 5.6 | - | ||||||||||||||||||
| 1211 | - | |||||||||||||||||||
| 1212 | This typedef provides an STL-style const reverse iterator for QString. | - | ||||||||||||||||||
| 1213 | - | |||||||||||||||||||
| 1214 | \sa QString::reverse_iterator, QString::const_iterator | - | ||||||||||||||||||
| 1215 | */ | - | ||||||||||||||||||
| 1216 | - | |||||||||||||||||||
| 1217 | /*! \typedef QString::reverse_iterator | - | ||||||||||||||||||
| 1218 | \since 5.6 | - | ||||||||||||||||||
| 1219 | - | |||||||||||||||||||
| 1220 | This typedef provides an STL-style non-const reverse iterator for QString. | - | ||||||||||||||||||
| 1221 | - | |||||||||||||||||||
| 1222 | \sa QString::const_reverse_iterator, QString::iterator | - | ||||||||||||||||||
| 1223 | */ | - | ||||||||||||||||||
| 1224 | - | |||||||||||||||||||
| 1225 | /*! | - | ||||||||||||||||||
| 1226 | \typedef QString::size_type | - | ||||||||||||||||||
| 1227 | - | |||||||||||||||||||
| 1228 | The QString::size_type typedef provides an STL-style type for sizes (int). | - | ||||||||||||||||||
| 1229 | */ | - | ||||||||||||||||||
| 1230 | - | |||||||||||||||||||
| 1231 | /*! | - | ||||||||||||||||||
| 1232 | \typedef QString::difference_type | - | ||||||||||||||||||
| 1233 | - | |||||||||||||||||||
| 1234 | The QString::size_type typedef provides an STL-style type for difference between pointers. | - | ||||||||||||||||||
| 1235 | */ | - | ||||||||||||||||||
| 1236 | - | |||||||||||||||||||
| 1237 | /*! | - | ||||||||||||||||||
| 1238 | \typedef QString::const_reference | - | ||||||||||||||||||
| 1239 | - | |||||||||||||||||||
| 1240 | This typedef provides an STL-style const reference for a QString element (QChar). | - | ||||||||||||||||||
| 1241 | */ | - | ||||||||||||||||||
| 1242 | /*! | - | ||||||||||||||||||
| 1243 | \typedef QString::reference | - | ||||||||||||||||||
| 1244 | - | |||||||||||||||||||
| 1245 | This typedef provides an STL-style | - | ||||||||||||||||||
| 1246 | reference for a QString element (QChar). | - | ||||||||||||||||||
| 1247 | */ | - | ||||||||||||||||||
| 1248 | - | |||||||||||||||||||
| 1249 | /*! | - | ||||||||||||||||||
| 1250 | \typedef QString::const_pointer | - | ||||||||||||||||||
| 1251 | - | |||||||||||||||||||
| 1252 | The QString::const_pointer typedef provides an STL-style | - | ||||||||||||||||||
| 1253 | const pointer to a QString element (QChar). | - | ||||||||||||||||||
| 1254 | */ | - | ||||||||||||||||||
| 1255 | /*! | - | ||||||||||||||||||
| 1256 | \typedef QString::pointer | - | ||||||||||||||||||
| 1257 | - | |||||||||||||||||||
| 1258 | The QString::const_pointer typedef provides an STL-style | - | ||||||||||||||||||
| 1259 | pointer to a QString element (QChar). | - | ||||||||||||||||||
| 1260 | */ | - | ||||||||||||||||||
| 1261 | - | |||||||||||||||||||
| 1262 | /*! | - | ||||||||||||||||||
| 1263 | \typedef QString::value_type | - | ||||||||||||||||||
| 1264 | - | |||||||||||||||||||
| 1265 | This typedef provides an STL-style value type for QString. | - | ||||||||||||||||||
| 1266 | */ | - | ||||||||||||||||||
| 1267 | - | |||||||||||||||||||
| 1268 | /*! \fn QString::iterator QString::begin() | - | ||||||||||||||||||
| 1269 | - | |||||||||||||||||||
| 1270 | Returns an \l{STL-style iterators}{STL-style iterator} pointing to the first character in | - | ||||||||||||||||||
| 1271 | the string. | - | ||||||||||||||||||
| 1272 | - | |||||||||||||||||||
| 1273 | \sa constBegin(), end() | - | ||||||||||||||||||
| 1274 | */ | - | ||||||||||||||||||
| 1275 | - | |||||||||||||||||||
| 1276 | /*! \fn QString::const_iterator QString::begin() const | - | ||||||||||||||||||
| 1277 | - | |||||||||||||||||||
| 1278 | \overload begin() | - | ||||||||||||||||||
| 1279 | */ | - | ||||||||||||||||||
| 1280 | - | |||||||||||||||||||
| 1281 | /*! \fn QString::const_iterator QString::cbegin() const | - | ||||||||||||||||||
| 1282 | \since 5.0 | - | ||||||||||||||||||
| 1283 | - | |||||||||||||||||||
| 1284 | Returns a const \l{STL-style iterators}{STL-style iterator} pointing to the first character | - | ||||||||||||||||||
| 1285 | in the string. | - | ||||||||||||||||||
| 1286 | - | |||||||||||||||||||
| 1287 | \sa begin(), cend() | - | ||||||||||||||||||
| 1288 | */ | - | ||||||||||||||||||
| 1289 | - | |||||||||||||||||||
| 1290 | /*! \fn QString::const_iterator QString::constBegin() const | - | ||||||||||||||||||
| 1291 | - | |||||||||||||||||||
| 1292 | Returns a const \l{STL-style iterators}{STL-style iterator} pointing to the first character | - | ||||||||||||||||||
| 1293 | in the string. | - | ||||||||||||||||||
| 1294 | - | |||||||||||||||||||
| 1295 | \sa begin(), constEnd() | - | ||||||||||||||||||
| 1296 | */ | - | ||||||||||||||||||
| 1297 | - | |||||||||||||||||||
| 1298 | /*! \fn QString::iterator QString::end() | - | ||||||||||||||||||
| 1299 | - | |||||||||||||||||||
| 1300 | Returns an \l{STL-style iterators}{STL-style iterator} pointing to the imaginary character | - | ||||||||||||||||||
| 1301 | after the last character in the string. | - | ||||||||||||||||||
| 1302 | - | |||||||||||||||||||
| 1303 | \sa begin(), constEnd() | - | ||||||||||||||||||
| 1304 | */ | - | ||||||||||||||||||
| 1305 | - | |||||||||||||||||||
| 1306 | /*! \fn QString::const_iterator QString::end() const | - | ||||||||||||||||||
| 1307 | - | |||||||||||||||||||
| 1308 | \overload end() | - | ||||||||||||||||||
| 1309 | */ | - | ||||||||||||||||||
| 1310 | - | |||||||||||||||||||
| 1311 | /*! \fn QString::const_iterator QString::cend() const | - | ||||||||||||||||||
| 1312 | \since 5.0 | - | ||||||||||||||||||
| 1313 | - | |||||||||||||||||||
| 1314 | Returns a const \l{STL-style iterators}{STL-style iterator} pointing to the imaginary | - | ||||||||||||||||||
| 1315 | character after the last character in the list. | - | ||||||||||||||||||
| 1316 | - | |||||||||||||||||||
| 1317 | \sa cbegin(), end() | - | ||||||||||||||||||
| 1318 | */ | - | ||||||||||||||||||
| 1319 | - | |||||||||||||||||||
| 1320 | /*! \fn QString::const_iterator QString::constEnd() const | - | ||||||||||||||||||
| 1321 | - | |||||||||||||||||||
| 1322 | Returns a const \l{STL-style iterators}{STL-style iterator} pointing to the imaginary | - | ||||||||||||||||||
| 1323 | character after the last character in the list. | - | ||||||||||||||||||
| 1324 | - | |||||||||||||||||||
| 1325 | \sa constBegin(), end() | - | ||||||||||||||||||
| 1326 | */ | - | ||||||||||||||||||
| 1327 | - | |||||||||||||||||||
| 1328 | /*! \fn QString::reverse_iterator QString::rbegin() | - | ||||||||||||||||||
| 1329 | \since 5.6 | - | ||||||||||||||||||
| 1330 | - | |||||||||||||||||||
| 1331 | Returns a \l{STL-style iterators}{STL-style} reverse iterator pointing to the first | - | ||||||||||||||||||
| 1332 | character in the string, in reverse order. | - | ||||||||||||||||||
| 1333 | - | |||||||||||||||||||
| 1334 | \sa begin(), crbegin(), rend() | - | ||||||||||||||||||
| 1335 | */ | - | ||||||||||||||||||
| 1336 | - | |||||||||||||||||||
| 1337 | /*! \fn QString::const_reverse_iterator QString::rbegin() const | - | ||||||||||||||||||
| 1338 | \since 5.6 | - | ||||||||||||||||||
| 1339 | \overload | - | ||||||||||||||||||
| 1340 | */ | - | ||||||||||||||||||
| 1341 | - | |||||||||||||||||||
| 1342 | /*! \fn QString::const_reverse_iterator QString::crbegin() const | - | ||||||||||||||||||
| 1343 | \since 5.6 | - | ||||||||||||||||||
| 1344 | - | |||||||||||||||||||
| 1345 | Returns a const \l{STL-style iterators}{STL-style} reverse iterator pointing to the first | - | ||||||||||||||||||
| 1346 | character in the string, in reverse order. | - | ||||||||||||||||||
| 1347 | - | |||||||||||||||||||
| 1348 | \sa begin(), rbegin(), rend() | - | ||||||||||||||||||
| 1349 | */ | - | ||||||||||||||||||
| 1350 | - | |||||||||||||||||||
| 1351 | /*! \fn QString::reverse_iterator QString::rend() | - | ||||||||||||||||||
| 1352 | \since 5.6 | - | ||||||||||||||||||
| 1353 | - | |||||||||||||||||||
| 1354 | Returns a \l{STL-style iterators}{STL-style} reverse iterator pointing to one past | - | ||||||||||||||||||
| 1355 | the last character in the string, in reverse order. | - | ||||||||||||||||||
| 1356 | - | |||||||||||||||||||
| 1357 | \sa end(), crend(), rbegin() | - | ||||||||||||||||||
| 1358 | */ | - | ||||||||||||||||||
| 1359 | - | |||||||||||||||||||
| 1360 | /*! \fn QString::const_reverse_iterator QString::rend() const | - | ||||||||||||||||||
| 1361 | \since 5.6 | - | ||||||||||||||||||
| 1362 | \overload | - | ||||||||||||||||||
| 1363 | */ | - | ||||||||||||||||||
| 1364 | - | |||||||||||||||||||
| 1365 | /*! \fn QString::const_reverse_iterator QString::crend() const | - | ||||||||||||||||||
| 1366 | \since 5.6 | - | ||||||||||||||||||
| 1367 | - | |||||||||||||||||||
| 1368 | Returns a const \l{STL-style iterators}{STL-style} reverse iterator pointing to one | - | ||||||||||||||||||
| 1369 | past the last character in the string, in reverse order. | - | ||||||||||||||||||
| 1370 | - | |||||||||||||||||||
| 1371 | \sa end(), rend(), rbegin() | - | ||||||||||||||||||
| 1372 | */ | - | ||||||||||||||||||
| 1373 | - | |||||||||||||||||||
| 1374 | /*! | - | ||||||||||||||||||
| 1375 | \fn QString::QString() | - | ||||||||||||||||||
| 1376 | - | |||||||||||||||||||
| 1377 | Constructs a null string. Null strings are also empty. | - | ||||||||||||||||||
| 1378 | - | |||||||||||||||||||
| 1379 | \sa isEmpty() | - | ||||||||||||||||||
| 1380 | */ | - | ||||||||||||||||||
| 1381 | - | |||||||||||||||||||
| 1382 | /*! | - | ||||||||||||||||||
| 1383 | \fn QString::QString(QString &&other) | - | ||||||||||||||||||
| 1384 | - | |||||||||||||||||||
| 1385 | Move-constructs a QString instance, making it point at the same | - | ||||||||||||||||||
| 1386 | object that \a other was pointing to. | - | ||||||||||||||||||
| 1387 | - | |||||||||||||||||||
| 1388 | \since 5.2 | - | ||||||||||||||||||
| 1389 | */ | - | ||||||||||||||||||
| 1390 | - | |||||||||||||||||||
| 1391 | /*! \fn QString::QString(const char *str) | - | ||||||||||||||||||
| 1392 | - | |||||||||||||||||||
| 1393 | Constructs a string initialized with the 8-bit string \a str. The | - | ||||||||||||||||||
| 1394 | given const char pointer is converted to Unicode using the | - | ||||||||||||||||||
| 1395 | fromUtf8() function. | - | ||||||||||||||||||
| 1396 | - | |||||||||||||||||||
| 1397 | You can disable this constructor by defining \c | - | ||||||||||||||||||
| 1398 | QT_NO_CAST_FROM_ASCII when you compile your applications. This | - | ||||||||||||||||||
| 1399 | can be useful if you want to ensure that all user-visible strings | - | ||||||||||||||||||
| 1400 | go through QObject::tr(), for example. | - | ||||||||||||||||||
| 1401 | - | |||||||||||||||||||
| 1402 | \note Defining QT_RESTRICTED_CAST_FROM_ASCII also disables | - | ||||||||||||||||||
| 1403 | this constructor, but enables a \c{QString(const char (&ch)[N])} | - | ||||||||||||||||||
| 1404 | constructor instead. Using non-literal input, or input with | - | ||||||||||||||||||
| 1405 | embedded NUL characters, or non-7-bit characters is undefined | - | ||||||||||||||||||
| 1406 | in this case. | - | ||||||||||||||||||
| 1407 | - | |||||||||||||||||||
| 1408 | \sa fromLatin1(), fromLocal8Bit(), fromUtf8() | - | ||||||||||||||||||
| 1409 | */ | - | ||||||||||||||||||
| 1410 | - | |||||||||||||||||||
| 1411 | /*! \fn QString QString::fromStdString(const std::string &str) | - | ||||||||||||||||||
| 1412 | - | |||||||||||||||||||
| 1413 | Returns a copy of the \a str string. The given string is converted | - | ||||||||||||||||||
| 1414 | to Unicode using the fromUtf8() function. | - | ||||||||||||||||||
| 1415 | - | |||||||||||||||||||
| 1416 | \sa fromLatin1(), fromLocal8Bit(), fromUtf8(), QByteArray::fromStdString() | - | ||||||||||||||||||
| 1417 | */ | - | ||||||||||||||||||
| 1418 | - | |||||||||||||||||||
| 1419 | /*! \fn QString QString::fromStdWString(const std::wstring &str) | - | ||||||||||||||||||
| 1420 | - | |||||||||||||||||||
| 1421 | Returns a copy of the \a str string. The given string is assumed | - | ||||||||||||||||||
| 1422 | to be encoded in utf16 if the size of wchar_t is 2 bytes (e.g. on | - | ||||||||||||||||||
| 1423 | windows) and ucs4 if the size of wchar_t is 4 bytes (most Unix | - | ||||||||||||||||||
| 1424 | systems). | - | ||||||||||||||||||
| 1425 | - | |||||||||||||||||||
| 1426 | \sa fromUtf16(), fromLatin1(), fromLocal8Bit(), fromUtf8(), fromUcs4(), fromStdU16String(), fromStdU32String() | - | ||||||||||||||||||
| 1427 | */ | - | ||||||||||||||||||
| 1428 | - | |||||||||||||||||||
| 1429 | /*! \fn QString QString::fromWCharArray(const wchar_t *string, int size) | - | ||||||||||||||||||
| 1430 | \since 4.2 | - | ||||||||||||||||||
| 1431 | - | |||||||||||||||||||
| 1432 | Returns a copy of the \a string, where the encoding of \a string depends on | - | ||||||||||||||||||
| 1433 | the size of wchar. If wchar is 4 bytes, the \a string is interpreted as UCS-4, | - | ||||||||||||||||||
| 1434 | if wchar is 2 bytes it is interpreted as UTF-16. | - | ||||||||||||||||||
| 1435 | - | |||||||||||||||||||
| 1436 | If \a size is -1 (default), the \a string has to be 0 terminated. | - | ||||||||||||||||||
| 1437 | - | |||||||||||||||||||
| 1438 | \sa fromUtf16(), fromLatin1(), fromLocal8Bit(), fromUtf8(), fromUcs4(), fromStdWString() | - | ||||||||||||||||||
| 1439 | */ | - | ||||||||||||||||||
| 1440 | - | |||||||||||||||||||
| 1441 | /*! \fn std::wstring QString::toStdWString() const | - | ||||||||||||||||||
| 1442 | - | |||||||||||||||||||
| 1443 | Returns a std::wstring object with the data contained in this | - | ||||||||||||||||||
| 1444 | QString. The std::wstring is encoded in utf16 on platforms where | - | ||||||||||||||||||
| 1445 | wchar_t is 2 bytes wide (e.g. windows) and in ucs4 on platforms | - | ||||||||||||||||||
| 1446 | where wchar_t is 4 bytes wide (most Unix systems). | - | ||||||||||||||||||
| 1447 | - | |||||||||||||||||||
| 1448 | This method is mostly useful to pass a QString to a function | - | ||||||||||||||||||
| 1449 | that accepts a std::wstring object. | - | ||||||||||||||||||
| 1450 | - | |||||||||||||||||||
| 1451 | \sa utf16(), toLatin1(), toUtf8(), toLocal8Bit(), toStdU16String(), toStdU32String() | - | ||||||||||||||||||
| 1452 | */ | - | ||||||||||||||||||
| 1453 | - | |||||||||||||||||||
| 1454 | int QString::toUcs4_helper(const ushort *uc, int length, uint *out) | - | ||||||||||||||||||
| 1455 | { | - | ||||||||||||||||||
| 1456 | int count = 0; | - | ||||||||||||||||||
| 1457 | - | |||||||||||||||||||
| 1458 | QStringIterator i(reinterpret_cast<const QChar *>(uc), reinterpret_cast<const QChar *>(uc + length)); | - | ||||||||||||||||||
| 1459 | while (i.hasNext())
| 12-44 | ||||||||||||||||||
| 1460 | out[count++] = i.next(); executed 44 times by 1 test: out[count++] = i.next();Executed by:
| 44 | ||||||||||||||||||
| 1461 | - | |||||||||||||||||||
| 1462 | return count; executed 12 times by 1 test: return count;Executed by:
| 12 | ||||||||||||||||||
| 1463 | } | - | ||||||||||||||||||
| 1464 | - | |||||||||||||||||||
| 1465 | /*! \fn int QString::toWCharArray(wchar_t *array) const | - | ||||||||||||||||||
| 1466 | \since 4.2 | - | ||||||||||||||||||
| 1467 | - | |||||||||||||||||||
| 1468 | Fills the \a array with the data contained in this QString object. | - | ||||||||||||||||||
| 1469 | The array is encoded in UTF-16 on platforms where | - | ||||||||||||||||||
| 1470 | wchar_t is 2 bytes wide (e.g. windows) and in UCS-4 on platforms | - | ||||||||||||||||||
| 1471 | where wchar_t is 4 bytes wide (most Unix systems). | - | ||||||||||||||||||
| 1472 | - | |||||||||||||||||||
| 1473 | \a array has to be allocated by the caller and contain enough space to | - | ||||||||||||||||||
| 1474 | hold the complete string (allocating the array with the same length as the | - | ||||||||||||||||||
| 1475 | string is always sufficient). | - | ||||||||||||||||||
| 1476 | - | |||||||||||||||||||
| 1477 | This function returns the actual length of the string in \a array. | - | ||||||||||||||||||
| 1478 | - | |||||||||||||||||||
| 1479 | \note This function does not append a null character to the array. | - | ||||||||||||||||||
| 1480 | - | |||||||||||||||||||
| 1481 | \sa utf16(), toUcs4(), toLatin1(), toUtf8(), toLocal8Bit(), toStdWString() | - | ||||||||||||||||||
| 1482 | */ | - | ||||||||||||||||||
| 1483 | - | |||||||||||||||||||
| 1484 | /*! \fn QString::QString(const QString &other) | - | ||||||||||||||||||
| 1485 | - | |||||||||||||||||||
| 1486 | Constructs a copy of \a other. | - | ||||||||||||||||||
| 1487 | - | |||||||||||||||||||
| 1488 | This operation takes \l{constant time}, because QString is | - | ||||||||||||||||||
| 1489 | \l{implicitly shared}. This makes returning a QString from a | - | ||||||||||||||||||
| 1490 | function very fast. If a shared instance is modified, it will be | - | ||||||||||||||||||
| 1491 | copied (copy-on-write), and that takes \l{linear time}. | - | ||||||||||||||||||
| 1492 | - | |||||||||||||||||||
| 1493 | \sa operator=() | - | ||||||||||||||||||
| 1494 | */ | - | ||||||||||||||||||
| 1495 | - | |||||||||||||||||||
| 1496 | /*! | - | ||||||||||||||||||
| 1497 | Constructs a string initialized with the first \a size characters | - | ||||||||||||||||||
| 1498 | of the QChar array \a unicode. | - | ||||||||||||||||||
| 1499 | - | |||||||||||||||||||
| 1500 | If \a unicode is 0, a null string is constructed. | - | ||||||||||||||||||
| 1501 | - | |||||||||||||||||||
| 1502 | If \a size is negative, \a unicode is assumed to point to a nul-terminated | - | ||||||||||||||||||
| 1503 | array and its length is determined dynamically. The terminating | - | ||||||||||||||||||
| 1504 | nul-character is not considered part of the string. | - | ||||||||||||||||||
| 1505 | - | |||||||||||||||||||
| 1506 | QString makes a deep copy of the string data. The unicode data is copied as | - | ||||||||||||||||||
| 1507 | is and the Byte Order Mark is preserved if present. | - | ||||||||||||||||||
| 1508 | - | |||||||||||||||||||
| 1509 | \sa fromRawData() | - | ||||||||||||||||||
| 1510 | */ | - | ||||||||||||||||||
| 1511 | QString::QString(const QChar *unicode, int size) | - | ||||||||||||||||||
| 1512 | { | - | ||||||||||||||||||
| 1513 | if (!unicode) {
| 3143-6486100 | ||||||||||||||||||
| 1514 | d = Data::sharedNull(); | - | ||||||||||||||||||
| 1515 | } else { executed 3143 times by 9 tests: end of blockExecuted by:
| 3143 | ||||||||||||||||||
| 1516 | if (size < 0) {
| 101041-6385059 | ||||||||||||||||||
| 1517 | size = 0; | - | ||||||||||||||||||
| 1518 | while (!unicode[size].isNull())
| 101041-3080917 | ||||||||||||||||||
| 1519 | ++size; executed 3080917 times by 9 tests: ++size;Executed by:
| 3080917 | ||||||||||||||||||
| 1520 | } executed 101041 times by 9 tests: end of blockExecuted by:
| 101041 | ||||||||||||||||||
| 1521 | if (!size) {
| 204954-6281146 | ||||||||||||||||||
| 1522 | d = Data::allocate(0); | - | ||||||||||||||||||
| 1523 | } else { executed 204954 times by 394 tests: end of blockExecuted by:
| 204954 | ||||||||||||||||||
| 1524 | d = Data::allocate(size + 1); | - | ||||||||||||||||||
| 1525 | Q_CHECK_PTR(d); never executed: qBadAlloc();
| 0-6281146 | ||||||||||||||||||
| 1526 | d->size = size; | - | ||||||||||||||||||
| 1527 | memcpy(d->data(), unicode, size * sizeof(QChar)); | - | ||||||||||||||||||
| 1528 | d->data()[size] = '\0'; | - | ||||||||||||||||||
| 1529 | } executed 6281146 times by 400 tests: end of blockExecuted by:
| 6281146 | ||||||||||||||||||
| 1530 | } | - | ||||||||||||||||||
| 1531 | } | - | ||||||||||||||||||
| 1532 | - | |||||||||||||||||||
| 1533 | /*! | - | ||||||||||||||||||
| 1534 | Constructs a string of the given \a size with every character set | - | ||||||||||||||||||
| 1535 | to \a ch. | - | ||||||||||||||||||
| 1536 | - | |||||||||||||||||||
| 1537 | \sa fill() | - | ||||||||||||||||||
| 1538 | */ | - | ||||||||||||||||||
| 1539 | QString::QString(int size, QChar ch) | - | ||||||||||||||||||
| 1540 | { | - | ||||||||||||||||||
| 1541 | if (size <= 0) {
| 201-253266 | ||||||||||||||||||
| 1542 | d = Data::allocate(0); | - | ||||||||||||||||||
| 1543 | } else { executed 201 times by 3 tests: end of blockExecuted by:
| 201 | ||||||||||||||||||
| 1544 | d = Data::allocate(size + 1); | - | ||||||||||||||||||
| 1545 | Q_CHECK_PTR(d); never executed: qBadAlloc();
| 0-253266 | ||||||||||||||||||
| 1546 | d->size = size; | - | ||||||||||||||||||
| 1547 | d->data()[size] = '\0'; | - | ||||||||||||||||||
| 1548 | ushort *i = d->data() + size; | - | ||||||||||||||||||
| 1549 | ushort *b = d->data(); | - | ||||||||||||||||||
| 1550 | const ushort value = ch.unicode(); | - | ||||||||||||||||||
| 1551 | while (i != b)
| 253266-408257 | ||||||||||||||||||
| 1552 | *--i = value; executed 408257 times by 47 tests: *--i = value;Executed by:
| 408257 | ||||||||||||||||||
| 1553 | } executed 253266 times by 47 tests: end of blockExecuted by:
| 253266 | ||||||||||||||||||
| 1554 | } | - | ||||||||||||||||||
| 1555 | - | |||||||||||||||||||
| 1556 | /*! \fn QString::QString(int size, Qt::Initialization) | - | ||||||||||||||||||
| 1557 | \internal | - | ||||||||||||||||||
| 1558 | - | |||||||||||||||||||
| 1559 | Constructs a string of the given \a size without initializing the | - | ||||||||||||||||||
| 1560 | characters. This is only used in \c QStringBuilder::toString(). | - | ||||||||||||||||||
| 1561 | */ | - | ||||||||||||||||||
| 1562 | QString::QString(int size, Qt::Initialization) | - | ||||||||||||||||||
| 1563 | { | - | ||||||||||||||||||
| 1564 | d = Data::allocate(size + 1); | - | ||||||||||||||||||
| 1565 | Q_CHECK_PTR(d); never executed: qBadAlloc();
| 0-46522442 | ||||||||||||||||||
| 1566 | d->size = size; | - | ||||||||||||||||||
| 1567 | d->data()[size] = '\0'; | - | ||||||||||||||||||
| 1568 | } executed 46522072 times by 686 tests: end of blockExecuted by:
| 46522072 | ||||||||||||||||||
| 1569 | - | |||||||||||||||||||
| 1570 | /*! \fn QString::QString(QLatin1String str) | - | ||||||||||||||||||
| 1571 | - | |||||||||||||||||||
| 1572 | Constructs a copy of the Latin-1 string \a str. | - | ||||||||||||||||||
| 1573 | - | |||||||||||||||||||
| 1574 | \sa fromLatin1() | - | ||||||||||||||||||
| 1575 | */ | - | ||||||||||||||||||
| 1576 | - | |||||||||||||||||||
| 1577 | /*! | - | ||||||||||||||||||
| 1578 | Constructs a string of size 1 containing the character \a ch. | - | ||||||||||||||||||
| 1579 | */ | - | ||||||||||||||||||
| 1580 | QString::QString(QChar ch) | - | ||||||||||||||||||
| 1581 | { | - | ||||||||||||||||||
| 1582 | d = Data::allocate(2); | - | ||||||||||||||||||
| 1583 | Q_CHECK_PTR(d); never executed: qBadAlloc();
| 0-495998 | ||||||||||||||||||
| 1584 | d->size = 1; | - | ||||||||||||||||||
| 1585 | d->data()[0] = ch.unicode(); | - | ||||||||||||||||||
| 1586 | d->data()[1] = '\0'; | - | ||||||||||||||||||
| 1587 | } executed 495998 times by 267 tests: end of blockExecuted by:
| 495998 | ||||||||||||||||||
| 1588 | - | |||||||||||||||||||
| 1589 | /*! \fn QString::QString(const QByteArray &ba) | - | ||||||||||||||||||
| 1590 | - | |||||||||||||||||||
| 1591 | Constructs a string initialized with the byte array \a ba. The | - | ||||||||||||||||||
| 1592 | given byte array is converted to Unicode using fromUtf8(). Stops | - | ||||||||||||||||||
| 1593 | copying at the first 0 character, otherwise copies the entire byte | - | ||||||||||||||||||
| 1594 | array. | - | ||||||||||||||||||
| 1595 | - | |||||||||||||||||||
| 1596 | You can disable this constructor by defining \c | - | ||||||||||||||||||
| 1597 | QT_NO_CAST_FROM_ASCII when you compile your applications. This | - | ||||||||||||||||||
| 1598 | can be useful if you want to ensure that all user-visible strings | - | ||||||||||||||||||
| 1599 | go through QObject::tr(), for example. | - | ||||||||||||||||||
| 1600 | - | |||||||||||||||||||
| 1601 | \sa fromLatin1(), fromLocal8Bit(), fromUtf8() | - | ||||||||||||||||||
| 1602 | */ | - | ||||||||||||||||||
| 1603 | - | |||||||||||||||||||
| 1604 | /*! \fn QString::QString(const Null &) | - | ||||||||||||||||||
| 1605 | \internal | - | ||||||||||||||||||
| 1606 | */ | - | ||||||||||||||||||
| 1607 | - | |||||||||||||||||||
| 1608 | /*! \fn QString::QString(QStringDataPtr) | - | ||||||||||||||||||
| 1609 | \internal | - | ||||||||||||||||||
| 1610 | */ | - | ||||||||||||||||||
| 1611 | - | |||||||||||||||||||
| 1612 | /*! \fn QString &QString::operator=(const Null &) | - | ||||||||||||||||||
| 1613 | \internal | - | ||||||||||||||||||
| 1614 | */ | - | ||||||||||||||||||
| 1615 | - | |||||||||||||||||||
| 1616 | /*! | - | ||||||||||||||||||
| 1617 | \fn QString::~QString() | - | ||||||||||||||||||
| 1618 | - | |||||||||||||||||||
| 1619 | Destroys the string. | - | ||||||||||||||||||
| 1620 | */ | - | ||||||||||||||||||
| 1621 | - | |||||||||||||||||||
| 1622 | - | |||||||||||||||||||
| 1623 | /*! \fn void QString::swap(QString &other) | - | ||||||||||||||||||
| 1624 | \since 4.8 | - | ||||||||||||||||||
| 1625 | - | |||||||||||||||||||
| 1626 | Swaps string \a other with this string. This operation is very fast and | - | ||||||||||||||||||
| 1627 | never fails. | - | ||||||||||||||||||
| 1628 | */ | - | ||||||||||||||||||
| 1629 | - | |||||||||||||||||||
| 1630 | /*! \fn void QString::detach() | - | ||||||||||||||||||
| 1631 | - | |||||||||||||||||||
| 1632 | \internal | - | ||||||||||||||||||
| 1633 | */ | - | ||||||||||||||||||
| 1634 | - | |||||||||||||||||||
| 1635 | /*! \fn bool QString::isDetached() const | - | ||||||||||||||||||
| 1636 | - | |||||||||||||||||||
| 1637 | \internal | - | ||||||||||||||||||
| 1638 | */ | - | ||||||||||||||||||
| 1639 | - | |||||||||||||||||||
| 1640 | /*! \fn bool QString::isSharedWith(const QString &other) const | - | ||||||||||||||||||
| 1641 | - | |||||||||||||||||||
| 1642 | \internal | - | ||||||||||||||||||
| 1643 | */ | - | ||||||||||||||||||
| 1644 | - | |||||||||||||||||||
| 1645 | /*! | - | ||||||||||||||||||
| 1646 | Sets the size of the string to \a size characters. | - | ||||||||||||||||||
| 1647 | - | |||||||||||||||||||
| 1648 | If \a size is greater than the current size, the string is | - | ||||||||||||||||||
| 1649 | extended to make it \a size characters long with the extra | - | ||||||||||||||||||
| 1650 | characters added to the end. The new characters are uninitialized. | - | ||||||||||||||||||
| 1651 | - | |||||||||||||||||||
| 1652 | If \a size is less than the current size, characters are removed | - | ||||||||||||||||||
| 1653 | from the end. | - | ||||||||||||||||||
| 1654 | - | |||||||||||||||||||
| 1655 | Example: | - | ||||||||||||||||||
| 1656 | - | |||||||||||||||||||
| 1657 | \snippet qstring/main.cpp 45 | - | ||||||||||||||||||
| 1658 | - | |||||||||||||||||||
| 1659 | If you want to append a certain number of identical characters to | - | ||||||||||||||||||
| 1660 | the string, use the \l {QString::}{resize(int, QChar)} overload. | - | ||||||||||||||||||
| 1661 | - | |||||||||||||||||||
| 1662 | If you want to expand the string so that it reaches a certain | - | ||||||||||||||||||
| 1663 | width and fill the new positions with a particular character, use | - | ||||||||||||||||||
| 1664 | the leftJustified() function: | - | ||||||||||||||||||
| 1665 | - | |||||||||||||||||||
| 1666 | If \a size is negative, it is equivalent to passing zero. | - | ||||||||||||||||||
| 1667 | - | |||||||||||||||||||
| 1668 | \snippet qstring/main.cpp 47 | - | ||||||||||||||||||
| 1669 | - | |||||||||||||||||||
| 1670 | \sa truncate(), reserve() | - | ||||||||||||||||||
| 1671 | */ | - | ||||||||||||||||||
| 1672 | - | |||||||||||||||||||
| 1673 | void QString::resize(int size) | - | ||||||||||||||||||
| 1674 | { | - | ||||||||||||||||||
| 1675 | if (size < 0)
| 28-89208133 | ||||||||||||||||||
| 1676 | size = 0; executed 28 times by 4 tests: size = 0;Executed by:
| 28 | ||||||||||||||||||
| 1677 | - | |||||||||||||||||||
| 1678 | if (IS_RAW_DATA(d) && !d->ref.isShared() && size < d->size) {
| 0-89208157 | ||||||||||||||||||
| 1679 | d->size = size; | - | ||||||||||||||||||
| 1680 | return; executed 2 times by 2 tests: return;Executed by:
| 2 | ||||||||||||||||||
| 1681 | } | - | ||||||||||||||||||
| 1682 | - | |||||||||||||||||||
| 1683 | if (d->ref.isShared() || uint(size) + 1u > d->alloc)
| 240775-87528905 | ||||||||||||||||||
| 1684 | reallocData(uint(size) + 1u, true); executed 1920029 times by 485 tests: reallocData(uint(size) + 1u, true);Executed by:
| 1920029 | ||||||||||||||||||
| 1685 | if (d->alloc) {
| 0-89208159 | ||||||||||||||||||
| 1686 | d->size = size; | - | ||||||||||||||||||
| 1687 | d->data()[size] = '\0'; | - | ||||||||||||||||||
| 1688 | } executed 89208159 times by 563 tests: end of blockExecuted by:
| 89208159 | ||||||||||||||||||
| 1689 | } executed 89208159 times by 563 tests: end of blockExecuted by:
| 89208159 | ||||||||||||||||||
| 1690 | - | |||||||||||||||||||
| 1691 | /*! | - | ||||||||||||||||||
| 1692 | \overload | - | ||||||||||||||||||
| 1693 | \since 5.7 | - | ||||||||||||||||||
| 1694 | - | |||||||||||||||||||
| 1695 | Unlike \l {QString::}{resize(int)}, this overload | - | ||||||||||||||||||
| 1696 | initializes the new characters to \a fillChar: | - | ||||||||||||||||||
| 1697 | - | |||||||||||||||||||
| 1698 | \snippet qstring/main.cpp 46 | - | ||||||||||||||||||
| 1699 | */ | - | ||||||||||||||||||
| 1700 | - | |||||||||||||||||||
| 1701 | void QString::resize(int size, QChar fillChar) | - | ||||||||||||||||||
| 1702 | { | - | ||||||||||||||||||
| 1703 | const int oldSize = length(); | - | ||||||||||||||||||
| 1704 | resize(size); | - | ||||||||||||||||||
| 1705 | const int difference = length() - oldSize; | - | ||||||||||||||||||
| 1706 | if (difference > 0)
| 2239-28747 | ||||||||||||||||||
| 1707 | std::fill_n(d->begin() + oldSize, difference, fillChar.unicode()); executed 28747 times by 13 tests: std::fill_n(d->begin() + oldSize, difference, fillChar.unicode());Executed by:
| 28747 | ||||||||||||||||||
| 1708 | } executed 30986 times by 13 tests: end of blockExecuted by:
| 30986 | ||||||||||||||||||
| 1709 | - | |||||||||||||||||||
| 1710 | /*! \fn int QString::capacity() const | - | ||||||||||||||||||
| 1711 | - | |||||||||||||||||||
| 1712 | Returns the maximum number of characters that can be stored in | - | ||||||||||||||||||
| 1713 | the string without forcing a reallocation. | - | ||||||||||||||||||
| 1714 | - | |||||||||||||||||||
| 1715 | The sole purpose of this function is to provide a means of fine | - | ||||||||||||||||||
| 1716 | tuning QString's memory usage. In general, you will rarely ever | - | ||||||||||||||||||
| 1717 | need to call this function. If you want to know how many | - | ||||||||||||||||||
| 1718 | characters are in the string, call size(). | - | ||||||||||||||||||
| 1719 | - | |||||||||||||||||||
| 1720 | \sa reserve(), squeeze() | - | ||||||||||||||||||
| 1721 | */ | - | ||||||||||||||||||
| 1722 | - | |||||||||||||||||||
| 1723 | /*! | - | ||||||||||||||||||
| 1724 | \fn void QString::reserve(int size) | - | ||||||||||||||||||
| 1725 | - | |||||||||||||||||||
| 1726 | Attempts to allocate memory for at least \a size characters. If | - | ||||||||||||||||||
| 1727 | you know in advance how large the string will be, you can call | - | ||||||||||||||||||
| 1728 | this function, and if you resize the string often you are likely | - | ||||||||||||||||||
| 1729 | to get better performance. If \a size is an underestimate, the | - | ||||||||||||||||||
| 1730 | worst that will happen is that the QString will be a bit slower. | - | ||||||||||||||||||
| 1731 | - | |||||||||||||||||||
| 1732 | The sole purpose of this function is to provide a means of fine | - | ||||||||||||||||||
| 1733 | tuning QString's memory usage. In general, you will rarely ever | - | ||||||||||||||||||
| 1734 | need to call this function. If you want to change the size of the | - | ||||||||||||||||||
| 1735 | string, call resize(). | - | ||||||||||||||||||
| 1736 | - | |||||||||||||||||||
| 1737 | This function is useful for code that needs to build up a long | - | ||||||||||||||||||
| 1738 | string and wants to avoid repeated reallocation. In this example, | - | ||||||||||||||||||
| 1739 | we want to add to the string until some condition is \c true, and | - | ||||||||||||||||||
| 1740 | we're fairly sure that size is large enough to make a call to | - | ||||||||||||||||||
| 1741 | reserve() worthwhile: | - | ||||||||||||||||||
| 1742 | - | |||||||||||||||||||
| 1743 | \snippet qstring/main.cpp 44 | - | ||||||||||||||||||
| 1744 | - | |||||||||||||||||||
| 1745 | \sa squeeze(), capacity() | - | ||||||||||||||||||
| 1746 | */ | - | ||||||||||||||||||
| 1747 | - | |||||||||||||||||||
| 1748 | /*! | - | ||||||||||||||||||
| 1749 | \fn void QString::squeeze() | - | ||||||||||||||||||
| 1750 | - | |||||||||||||||||||
| 1751 | Releases any memory not required to store the character data. | - | ||||||||||||||||||
| 1752 | - | |||||||||||||||||||
| 1753 | The sole purpose of this function is to provide a means of fine | - | ||||||||||||||||||
| 1754 | tuning QString's memory usage. In general, you will rarely ever | - | ||||||||||||||||||
| 1755 | need to call this function. | - | ||||||||||||||||||
| 1756 | - | |||||||||||||||||||
| 1757 | \sa reserve(), capacity() | - | ||||||||||||||||||
| 1758 | */ | - | ||||||||||||||||||
| 1759 | - | |||||||||||||||||||
| 1760 | void QString::reallocData(uint alloc, bool grow) | - | ||||||||||||||||||
| 1761 | { | - | ||||||||||||||||||
| 1762 | size_t blockSize; | - | ||||||||||||||||||
| 1763 | if (grow) {
| 1024048-17320378 | ||||||||||||||||||
| 1764 | auto r = qCalculateGrowingBlockSize(alloc, sizeof(QChar), sizeof(Data)); | - | ||||||||||||||||||
| 1765 | blockSize = r.size; | - | ||||||||||||||||||
| 1766 | alloc = uint(r.elementCount); | - | ||||||||||||||||||
| 1767 | } else { executed 17320378 times by 539 tests: end of blockExecuted by:
| 17320378 | ||||||||||||||||||
| 1768 | blockSize = qCalculateBlockSize(alloc, sizeof(QChar), sizeof(Data)); | - | ||||||||||||||||||
| 1769 | } executed 1024049 times by 311 tests: end of blockExecuted by:
| 1024049 | ||||||||||||||||||
| 1770 | - | |||||||||||||||||||
| 1771 | if (d->ref.isShared() || IS_RAW_DATA(d)) {
| 1718-17139594 | ||||||||||||||||||
| 1772 | Data::AllocationOptions allocOptions(d->capacityReserved ? Data::CapacityReserved : 0); | - | ||||||||||||||||||
| 1773 | Data *x = Data::allocate(alloc, allocOptions); | - | ||||||||||||||||||
| 1774 | Q_CHECK_PTR(x); never executed: qBadAlloc();
| 0-17141536 | ||||||||||||||||||
| 1775 | x->size = qMin(int(alloc) - 1, d->size); | - | ||||||||||||||||||
| 1776 | ::memcpy(x->data(), d->data(), x->size * sizeof(QChar)); | - | ||||||||||||||||||
| 1777 | x->data()[x->size] = 0; | - | ||||||||||||||||||
| 1778 | if (!d->ref.deref())
| 1718-17139818 | ||||||||||||||||||
| 1779 | Data::deallocate(d); executed 1718 times by 12 tests: Data::deallocate(d);Executed by:
| 1718 | ||||||||||||||||||
| 1780 | d = x; | - | ||||||||||||||||||
| 1781 | } else { executed 17141536 times by 543 tests: end of blockExecuted by:
| 17141536 | ||||||||||||||||||
| 1782 | Data *p = static_cast<Data *>(::realloc(d, blockSize)); | - | ||||||||||||||||||
| 1783 | Q_CHECK_PTR(p); never executed: qBadAlloc();
| 0-1202891 | ||||||||||||||||||
| 1784 | d = p; | - | ||||||||||||||||||
| 1785 | d->alloc = alloc; | - | ||||||||||||||||||
| 1786 | d->offset = sizeof(QStringData); | - | ||||||||||||||||||
| 1787 | } executed 1202891 times by 500 tests: end of blockExecuted by:
| 1202891 | ||||||||||||||||||
| 1788 | } | - | ||||||||||||||||||
| 1789 | - | |||||||||||||||||||
| 1790 | #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) | - | ||||||||||||||||||
| 1791 | void QString::expand(int i) | - | ||||||||||||||||||
| 1792 | { | - | ||||||||||||||||||
| 1793 | resize(qMax(i + 1, d->size), QLatin1Char(' ')); | - | ||||||||||||||||||
| 1794 | } never executed: end of block | 0 | ||||||||||||||||||
| 1795 | #endif | - | ||||||||||||||||||
| 1796 | - | |||||||||||||||||||
| 1797 | /*! \fn void QString::clear() | - | ||||||||||||||||||
| 1798 | - | |||||||||||||||||||
| 1799 | Clears the contents of the string and makes it null. | - | ||||||||||||||||||
| 1800 | - | |||||||||||||||||||
| 1801 | \sa resize(), isNull() | - | ||||||||||||||||||
| 1802 | */ | - | ||||||||||||||||||
| 1803 | - | |||||||||||||||||||
| 1804 | /*! \fn QString &QString::operator=(const QString &other) | - | ||||||||||||||||||
| 1805 | - | |||||||||||||||||||
| 1806 | Assigns \a other to this string and returns a reference to this | - | ||||||||||||||||||
| 1807 | string. | - | ||||||||||||||||||
| 1808 | */ | - | ||||||||||||||||||
| 1809 | - | |||||||||||||||||||
| 1810 | QString &QString::operator=(const QString &other) Q_DECL_NOTHROW | - | ||||||||||||||||||
| 1811 | { | - | ||||||||||||||||||
| 1812 | other.d->ref.ref(); | - | ||||||||||||||||||
| 1813 | if (!d->ref.deref())
| 853249-6633512 | ||||||||||||||||||
| 1814 | Data::deallocate(d); executed 853249 times by 265 tests: Data::deallocate(d);Executed by:
| 853249 | ||||||||||||||||||
| 1815 | d = other.d; | - | ||||||||||||||||||
| 1816 | return *this; executed 7486761 times by 451 tests: return *this;Executed by:
| 7486761 | ||||||||||||||||||
| 1817 | } | - | ||||||||||||||||||
| 1818 | - | |||||||||||||||||||
| 1819 | /*! | - | ||||||||||||||||||
| 1820 | \fn QString &QString::operator=(QString &&other) | - | ||||||||||||||||||
| 1821 | - | |||||||||||||||||||
| 1822 | Move-assigns \a other to this QString instance. | - | ||||||||||||||||||
| 1823 | - | |||||||||||||||||||
| 1824 | \since 5.2 | - | ||||||||||||||||||
| 1825 | */ | - | ||||||||||||||||||
| 1826 | - | |||||||||||||||||||
| 1827 | /*! \fn QString &QString::operator=(QLatin1String str) | - | ||||||||||||||||||
| 1828 | - | |||||||||||||||||||
| 1829 | \overload operator=() | - | ||||||||||||||||||
| 1830 | - | |||||||||||||||||||
| 1831 | Assigns the Latin-1 string \a str to this string. | - | ||||||||||||||||||
| 1832 | */ | - | ||||||||||||||||||
| 1833 | QString &QString::operator=(QLatin1String other) | - | ||||||||||||||||||
| 1834 | { | - | ||||||||||||||||||
| 1835 | if (isDetached() && other.size() <= capacity()) { // assumes d->alloc == 0 → !isDetached() (sharedNull)
| 3072-136704 | ||||||||||||||||||
| 1836 | d->size = other.size(); | - | ||||||||||||||||||
| 1837 | d->data()[other.size()] = 0; | - | ||||||||||||||||||
| 1838 | qt_from_latin1(d->data(), other.latin1(), other.size()); | - | ||||||||||||||||||
| 1839 | } else { executed 133632 times by 329 tests: end of blockExecuted by:
| 133632 | ||||||||||||||||||
| 1840 | *this = fromLatin1(other.latin1(), other.size()); | - | ||||||||||||||||||
| 1841 | } executed 89640 times by 657 tests: end of blockExecuted by:
| 89640 | ||||||||||||||||||
| 1842 | return *this; executed 223272 times by 657 tests: return *this;Executed by:
| 223272 | ||||||||||||||||||
| 1843 | } | - | ||||||||||||||||||
| 1844 | - | |||||||||||||||||||
| 1845 | /*! \fn QString &QString::operator=(const QByteArray &ba) | - | ||||||||||||||||||
| 1846 | - | |||||||||||||||||||
| 1847 | \overload operator=() | - | ||||||||||||||||||
| 1848 | - | |||||||||||||||||||
| 1849 | Assigns \a ba to this string. The byte array is converted to Unicode | - | ||||||||||||||||||
| 1850 | using the fromUtf8() function. This function stops conversion at the | - | ||||||||||||||||||
| 1851 | first NUL character found, or the end of the \a ba byte array. | - | ||||||||||||||||||
| 1852 | - | |||||||||||||||||||
| 1853 | You can disable this operator by defining \c | - | ||||||||||||||||||
| 1854 | QT_NO_CAST_FROM_ASCII when you compile your applications. This | - | ||||||||||||||||||
| 1855 | can be useful if you want to ensure that all user-visible strings | - | ||||||||||||||||||
| 1856 | go through QObject::tr(), for example. | - | ||||||||||||||||||
| 1857 | */ | - | ||||||||||||||||||
| 1858 | - | |||||||||||||||||||
| 1859 | /*! \fn QString &QString::operator=(const char *str) | - | ||||||||||||||||||
| 1860 | - | |||||||||||||||||||
| 1861 | \overload operator=() | - | ||||||||||||||||||
| 1862 | - | |||||||||||||||||||
| 1863 | Assigns \a str to this string. The const char pointer is converted | - | ||||||||||||||||||
| 1864 | to Unicode using the fromUtf8() function. | - | ||||||||||||||||||
| 1865 | - | |||||||||||||||||||
| 1866 | You can disable this operator by defining \c QT_NO_CAST_FROM_ASCII | - | ||||||||||||||||||
| 1867 | or \c QT_RESTRICTED_CAST_FROM_ASCII when you compile your applications. | - | ||||||||||||||||||
| 1868 | This can be useful if you want to ensure that all user-visible strings | - | ||||||||||||||||||
| 1869 | go through QObject::tr(), for example. | - | ||||||||||||||||||
| 1870 | - | |||||||||||||||||||
| 1871 | */ | - | ||||||||||||||||||
| 1872 | - | |||||||||||||||||||
| 1873 | /*! \fn QString &QString::operator=(char ch) | - | ||||||||||||||||||
| 1874 | - | |||||||||||||||||||
| 1875 | \overload operator=() | - | ||||||||||||||||||
| 1876 | - | |||||||||||||||||||
| 1877 | Assigns character \a ch to this string. Note that the character is | - | ||||||||||||||||||
| 1878 | converted to Unicode using the fromLatin1() function, unlike other 8-bit | - | ||||||||||||||||||
| 1879 | functions that operate on UTF-8 data. | - | ||||||||||||||||||
| 1880 | - | |||||||||||||||||||
| 1881 | You can disable this operator by defining \c | - | ||||||||||||||||||
| 1882 | QT_NO_CAST_FROM_ASCII when you compile your applications. This | - | ||||||||||||||||||
| 1883 | can be useful if you want to ensure that all user-visible strings | - | ||||||||||||||||||
| 1884 | go through QObject::tr(), for example. | - | ||||||||||||||||||
| 1885 | */ | - | ||||||||||||||||||
| 1886 | - | |||||||||||||||||||
| 1887 | /*! | - | ||||||||||||||||||
| 1888 | \overload operator=() | - | ||||||||||||||||||
| 1889 | - | |||||||||||||||||||
| 1890 | Sets the string to contain the single character \a ch. | - | ||||||||||||||||||
| 1891 | */ | - | ||||||||||||||||||
| 1892 | QString &QString::operator=(QChar ch) | - | ||||||||||||||||||
| 1893 | { | - | ||||||||||||||||||
| 1894 | if (isDetached() && capacity() >= 1) { // assumes d->alloc == 0 → !isDetached() (sharedNull)
| 1-77060 | ||||||||||||||||||
| 1895 | // re-use existing capacity: | - | ||||||||||||||||||
| 1896 | ushort *dat = d->data(); | - | ||||||||||||||||||
| 1897 | dat[0] = ch.unicode(); | - | ||||||||||||||||||
| 1898 | dat[1] = 0; | - | ||||||||||||||||||
| 1899 | d->size = 1; | - | ||||||||||||||||||
| 1900 | } else { executed 697 times by 162 tests: end of blockExecuted by:
| 697 | ||||||||||||||||||
| 1901 | operator=(QString(ch)); | - | ||||||||||||||||||
| 1902 | } executed 77061 times by 117 tests: end of blockExecuted by:
| 77061 | ||||||||||||||||||
| 1903 | return *this; executed 77758 times by 218 tests: return *this;Executed by:
| 77758 | ||||||||||||||||||
| 1904 | } | - | ||||||||||||||||||
| 1905 | - | |||||||||||||||||||
| 1906 | /*! | - | ||||||||||||||||||
| 1907 | \fn QString& QString::insert(int position, const QString &str) | - | ||||||||||||||||||
| 1908 | - | |||||||||||||||||||
| 1909 | Inserts the string \a str at the given index \a position and | - | ||||||||||||||||||
| 1910 | returns a reference to this string. | - | ||||||||||||||||||
| 1911 | - | |||||||||||||||||||
| 1912 | Example: | - | ||||||||||||||||||
| 1913 | - | |||||||||||||||||||
| 1914 | \snippet qstring/main.cpp 26 | - | ||||||||||||||||||
| 1915 | - | |||||||||||||||||||
| 1916 | If the given \a position is greater than size(), the array is | - | ||||||||||||||||||
| 1917 | first extended using resize(). | - | ||||||||||||||||||
| 1918 | - | |||||||||||||||||||
| 1919 | \sa append(), prepend(), replace(), remove() | - | ||||||||||||||||||
| 1920 | */ | - | ||||||||||||||||||
| 1921 | - | |||||||||||||||||||
| 1922 | - | |||||||||||||||||||
| 1923 | /*! | - | ||||||||||||||||||
| 1924 | \fn QString& QString::insert(int position, const QStringRef &str) | - | ||||||||||||||||||
| 1925 | \since 5.5 | - | ||||||||||||||||||
| 1926 | \overload insert() | - | ||||||||||||||||||
| 1927 | - | |||||||||||||||||||
| 1928 | Inserts the string reference \a str at the given index \a position and | - | ||||||||||||||||||
| 1929 | returns a reference to this string. | - | ||||||||||||||||||
| 1930 | - | |||||||||||||||||||
| 1931 | If the given \a position is greater than size(), the array is | - | ||||||||||||||||||
| 1932 | first extended using resize(). | - | ||||||||||||||||||
| 1933 | */ | - | ||||||||||||||||||
| 1934 | - | |||||||||||||||||||
| 1935 | - | |||||||||||||||||||
| 1936 | /*! | - | ||||||||||||||||||
| 1937 | \fn QString& QString::insert(int position, const char *str) | - | ||||||||||||||||||
| 1938 | \since 5.5 | - | ||||||||||||||||||
| 1939 | \overload insert() | - | ||||||||||||||||||
| 1940 | - | |||||||||||||||||||
| 1941 | Inserts the C string \a str at the given index \a position and | - | ||||||||||||||||||
| 1942 | returns a reference to this string. | - | ||||||||||||||||||
| 1943 | - | |||||||||||||||||||
| 1944 | If the given \a position is greater than size(), the array is | - | ||||||||||||||||||
| 1945 | first extended using resize(). | - | ||||||||||||||||||
| 1946 | - | |||||||||||||||||||
| 1947 | This function is not available when QT_NO_CAST_FROM_ASCII is | - | ||||||||||||||||||
| 1948 | defined. | - | ||||||||||||||||||
| 1949 | */ | - | ||||||||||||||||||
| 1950 | - | |||||||||||||||||||
| 1951 | - | |||||||||||||||||||
| 1952 | /*! | - | ||||||||||||||||||
| 1953 | \fn QString& QString::insert(int position, const QByteArray &str) | - | ||||||||||||||||||
| 1954 | \since 5.5 | - | ||||||||||||||||||
| 1955 | \overload insert() | - | ||||||||||||||||||
| 1956 | - | |||||||||||||||||||
| 1957 | Inserts the byte array \a str at the given index \a position and | - | ||||||||||||||||||
| 1958 | returns a reference to this string. | - | ||||||||||||||||||
| 1959 | - | |||||||||||||||||||
| 1960 | If the given \a position is greater than size(), the array is | - | ||||||||||||||||||
| 1961 | first extended using resize(). | - | ||||||||||||||||||
| 1962 | - | |||||||||||||||||||
| 1963 | This function is not available when QT_NO_CAST_FROM_ASCII is | - | ||||||||||||||||||
| 1964 | defined. | - | ||||||||||||||||||
| 1965 | */ | - | ||||||||||||||||||
| 1966 | - | |||||||||||||||||||
| 1967 | - | |||||||||||||||||||
| 1968 | /*! | - | ||||||||||||||||||
| 1969 | \fn QString &QString::insert(int position, QLatin1String str) | - | ||||||||||||||||||
| 1970 | \overload insert() | - | ||||||||||||||||||
| 1971 | - | |||||||||||||||||||
| 1972 | Inserts the Latin-1 string \a str at the given index \a position. | - | ||||||||||||||||||
| 1973 | */ | - | ||||||||||||||||||
| 1974 | QString &QString::insert(int i, QLatin1String str) | - | ||||||||||||||||||
| 1975 | { | - | ||||||||||||||||||
| 1976 | const char *s = str.latin1(); | - | ||||||||||||||||||
| 1977 | if (i < 0 || !s || !(*s))
| 0-17409 | ||||||||||||||||||
| 1978 | return *this; executed 16 times by 1 test: return *this;Executed by:
| 16 | ||||||||||||||||||
| 1979 | - | |||||||||||||||||||
| 1980 | int len = str.size(); | - | ||||||||||||||||||
| 1981 | if (Q_UNLIKELY(i > d->size))
| 0-17393 | ||||||||||||||||||
| 1982 | resize(i + len, QLatin1Char(' ')); never executed: resize(i + len, QLatin1Char(' ')); | 0 | ||||||||||||||||||
| 1983 | else | - | ||||||||||||||||||
| 1984 | resize(d->size + len); executed 17393 times by 58 tests: resize(d->size + len);Executed by:
| 17393 | ||||||||||||||||||
| 1985 | - | |||||||||||||||||||
| 1986 | ::memmove(d->data() + i + len, d->data() + i, (d->size - i - len) * sizeof(QChar)); | - | ||||||||||||||||||
| 1987 | qt_from_latin1(d->data() + i, s, uint(len)); | - | ||||||||||||||||||
| 1988 | return *this; executed 17393 times by 58 tests: return *this;Executed by:
| 17393 | ||||||||||||||||||
| 1989 | } | - | ||||||||||||||||||
| 1990 | - | |||||||||||||||||||
| 1991 | /*! | - | ||||||||||||||||||
| 1992 | \fn QString& QString::insert(int position, const QChar *unicode, int size) | - | ||||||||||||||||||
| 1993 | \overload insert() | - | ||||||||||||||||||
| 1994 | - | |||||||||||||||||||
| 1995 | Inserts the first \a size characters of the QChar array \a unicode | - | ||||||||||||||||||
| 1996 | at the given index \a position in the string. | - | ||||||||||||||||||
| 1997 | */ | - | ||||||||||||||||||
| 1998 | QString& QString::insert(int i, const QChar *unicode, int size) | - | ||||||||||||||||||
| 1999 | { | - | ||||||||||||||||||
| 2000 | if (i < 0 || size <= 0)
| 0-1414856 | ||||||||||||||||||
| 2001 | return *this; executed 353295 times by 39 tests: return *this;Executed by:
| 353295 | ||||||||||||||||||
| 2002 | - | |||||||||||||||||||
| 2003 | const ushort *s = (const ushort *)unicode; | - | ||||||||||||||||||
| 2004 | if (s >= d->data() && s < d->data() + d->alloc) {
| 3-587789 | ||||||||||||||||||
| 2005 | // Part of me - take a copy | - | ||||||||||||||||||
| 2006 | ushort *tmp = static_cast<ushort *>(::malloc(size * sizeof(QChar))); | - | ||||||||||||||||||
| 2007 | Q_CHECK_PTR(tmp); never executed: qBadAlloc();
| 0-3 | ||||||||||||||||||
| 2008 | memcpy(tmp, s, size * sizeof(QChar)); | - | ||||||||||||||||||
| 2009 | insert(i, reinterpret_cast<const QChar *>(tmp), size); | - | ||||||||||||||||||
| 2010 | ::free(tmp); | - | ||||||||||||||||||
| 2011 | return *this; executed 3 times by 2 tests: return *this;Executed by:
| 3 | ||||||||||||||||||
| 2012 | } | - | ||||||||||||||||||
| 2013 | - | |||||||||||||||||||
| 2014 | if (Q_UNLIKELY(i > d->size))
| 2-1061556 | ||||||||||||||||||
| 2015 | resize(i + size, QLatin1Char(' ')); executed 2 times by 2 tests: resize(i + size, QLatin1Char(' '));Executed by:
| 2 | ||||||||||||||||||
| 2016 | else | - | ||||||||||||||||||
| 2017 | resize(d->size + size); executed 1061556 times by 75 tests: resize(d->size + size);Executed by:
| 1061556 | ||||||||||||||||||
| 2018 | - | |||||||||||||||||||
| 2019 | ::memmove(d->data() + i + size, d->data() + i, (d->size - i - size) * sizeof(QChar)); | - | ||||||||||||||||||
| 2020 | memcpy(d->data() + i, s, size * sizeof(QChar)); | - | ||||||||||||||||||
| 2021 | return *this; executed 1061558 times by 75 tests: return *this;Executed by:
| 1061558 | ||||||||||||||||||
| 2022 | } | - | ||||||||||||||||||
| 2023 | - | |||||||||||||||||||
| 2024 | /*! | - | ||||||||||||||||||
| 2025 | \fn QString& QString::insert(int position, QChar ch) | - | ||||||||||||||||||
| 2026 | \overload insert() | - | ||||||||||||||||||
| 2027 | - | |||||||||||||||||||
| 2028 | Inserts \a ch at the given index \a position in the string. | - | ||||||||||||||||||
| 2029 | */ | - | ||||||||||||||||||
| 2030 | - | |||||||||||||||||||
| 2031 | QString& QString::insert(int i, QChar ch) | - | ||||||||||||||||||
| 2032 | { | - | ||||||||||||||||||
| 2033 | if (i < 0)
| 0-510830 | ||||||||||||||||||
| 2034 | i += d->size; never executed: i += d->size; | 0 | ||||||||||||||||||
| 2035 | if (i < 0)
| 0-510830 | ||||||||||||||||||
| 2036 | return *this; never executed: return *this; | 0 | ||||||||||||||||||
| 2037 | if (Q_UNLIKELY(i > d->size))
| 2-510828 | ||||||||||||||||||
| 2038 | resize(i + 1, QLatin1Char(' ')); executed 2 times by 2 tests: resize(i + 1, QLatin1Char(' '));Executed by:
| 2 | ||||||||||||||||||
| 2039 | else | - | ||||||||||||||||||
| 2040 | resize(d->size + 1); executed 510828 times by 413 tests: resize(d->size + 1);Executed by:
| 510828 | ||||||||||||||||||
| 2041 | ::memmove(d->data() + i + 1, d->data() + i, (d->size - i - 1) * sizeof(QChar)); | - | ||||||||||||||||||
| 2042 | d->data()[i] = ch.unicode(); | - | ||||||||||||||||||
| 2043 | return *this; executed 510830 times by 413 tests: return *this;Executed by:
| 510830 | ||||||||||||||||||
| 2044 | } | - | ||||||||||||||||||
| 2045 | - | |||||||||||||||||||
| 2046 | /*! | - | ||||||||||||||||||
| 2047 | Appends the string \a str onto the end of this string. | - | ||||||||||||||||||
| 2048 | - | |||||||||||||||||||
| 2049 | Example: | - | ||||||||||||||||||
| 2050 | - | |||||||||||||||||||
| 2051 | \snippet qstring/main.cpp 9 | - | ||||||||||||||||||
| 2052 | - | |||||||||||||||||||
| 2053 | This is the same as using the insert() function: | - | ||||||||||||||||||
| 2054 | - | |||||||||||||||||||
| 2055 | \snippet qstring/main.cpp 10 | - | ||||||||||||||||||
| 2056 | - | |||||||||||||||||||
| 2057 | The append() function is typically very fast (\l{constant time}), | - | ||||||||||||||||||
| 2058 | because QString preallocates extra space at the end of the string | - | ||||||||||||||||||
| 2059 | data so it can grow without reallocating the entire string each | - | ||||||||||||||||||
| 2060 | time. | - | ||||||||||||||||||
| 2061 | - | |||||||||||||||||||
| 2062 | \sa operator+=(), prepend(), insert() | - | ||||||||||||||||||
| 2063 | */ | - | ||||||||||||||||||
| 2064 | QString &QString::append(const QString &str) | - | ||||||||||||||||||
| 2065 | { | - | ||||||||||||||||||
| 2066 | if (str.d != Data::sharedNull()) {
| 41421-51070895 | ||||||||||||||||||
| 2067 | if (d == Data::sharedNull()) {
| 387409-50683486 | ||||||||||||||||||
| 2068 | operator=(str); | - | ||||||||||||||||||
| 2069 | } else { executed 387409 times by 226 tests: end of blockExecuted by:
| 387409 | ||||||||||||||||||
| 2070 | if (d->ref.isShared() || uint(d->size + str.d->size) + 1u > d->alloc)
| 570071-43369653 | ||||||||||||||||||
| 2071 | reallocData(uint(d->size + str.d->size) + 1u, true); executed 7883904 times by 482 tests: reallocData(uint(d->size + str.d->size) + 1u, true);Executed by:
| 7883904 | ||||||||||||||||||
| 2072 | memcpy(d->data() + d->size, str.d->data(), str.d->size * sizeof(QChar)); | - | ||||||||||||||||||
| 2073 | d->size += str.d->size; | - | ||||||||||||||||||
| 2074 | d->data()[d->size] = '\0'; | - | ||||||||||||||||||
| 2075 | } executed 50683486 times by 508 tests: end of blockExecuted by:
| 50683486 | ||||||||||||||||||
| 2076 | } | - | ||||||||||||||||||
| 2077 | return *this; executed 51112316 times by 522 tests: return *this;Executed by:
| 51112316 | ||||||||||||||||||
| 2078 | } | - | ||||||||||||||||||
| 2079 | - | |||||||||||||||||||
| 2080 | /*! | - | ||||||||||||||||||
| 2081 | \overload append() | - | ||||||||||||||||||
| 2082 | \since 5.0 | - | ||||||||||||||||||
| 2083 | - | |||||||||||||||||||
| 2084 | Appends \a len characters from the QChar array \a str to this string. | - | ||||||||||||||||||
| 2085 | */ | - | ||||||||||||||||||
| 2086 | QString &QString::append(const QChar *str, int len) | - | ||||||||||||||||||
| 2087 | { | - | ||||||||||||||||||
| 2088 | if (str && len > 0) {
| 1-262545 | ||||||||||||||||||
| 2089 | if (d->ref.isShared() || uint(d->size + len) + 1u > d->alloc)
| 37420-207735 | ||||||||||||||||||
| 2090 | reallocData(uint(d->size + len) + 1u, true); executed 91473 times by 84 tests: reallocData(uint(d->size + len) + 1u, true);Executed by:
| 91473 | ||||||||||||||||||
| 2091 | memcpy(d->data() + d->size, str, len * sizeof(QChar)); | - | ||||||||||||||||||
| 2092 | d->size += len; | - | ||||||||||||||||||
| 2093 | d->data()[d->size] = '\0'; | - | ||||||||||||||||||
| 2094 | } executed 261788 times by 97 tests: end of blockExecuted by:
| 261788 | ||||||||||||||||||
| 2095 | return *this; executed 262546 times by 97 tests: return *this;Executed by:
| 262546 | ||||||||||||||||||
| 2096 | } | - | ||||||||||||||||||
| 2097 | - | |||||||||||||||||||
| 2098 | /*! | - | ||||||||||||||||||
| 2099 | \overload append() | - | ||||||||||||||||||
| 2100 | - | |||||||||||||||||||
| 2101 | Appends the Latin-1 string \a str to this string. | - | ||||||||||||||||||
| 2102 | */ | - | ||||||||||||||||||
| 2103 | QString &QString::append(QLatin1String str) | - | ||||||||||||||||||
| 2104 | { | - | ||||||||||||||||||
| 2105 | const char *s = str.latin1(); | - | ||||||||||||||||||
| 2106 | if (s) {
| 57-126592 | ||||||||||||||||||
| 2107 | int len = str.size(); | - | ||||||||||||||||||
| 2108 | if (d->ref.isShared() || uint(d->size + len) + 1u > d->alloc)
| 24169-102423 | ||||||||||||||||||
| 2109 | reallocData(uint(d->size + len) + 1u, true); executed 54925 times by 234 tests: reallocData(uint(d->size + len) + 1u, true);Executed by:
| 54925 | ||||||||||||||||||
| 2110 | ushort *i = d->data() + d->size; | - | ||||||||||||||||||
| 2111 | qt_from_latin1(i, s, uint(len)); | - | ||||||||||||||||||
| 2112 | i[len] = '\0'; | - | ||||||||||||||||||
| 2113 | d->size += len; | - | ||||||||||||||||||
| 2114 | } executed 126592 times by 235 tests: end of blockExecuted by:
| 126592 | ||||||||||||||||||
| 2115 | return *this; executed 126649 times by 235 tests: return *this;Executed by:
| 126649 | ||||||||||||||||||
| 2116 | } | - | ||||||||||||||||||
| 2117 | - | |||||||||||||||||||
| 2118 | /*! \fn QString &QString::append(const QByteArray &ba) | - | ||||||||||||||||||
| 2119 | - | |||||||||||||||||||
| 2120 | \overload append() | - | ||||||||||||||||||
| 2121 | - | |||||||||||||||||||
| 2122 | Appends the byte array \a ba to this string. The given byte array | - | ||||||||||||||||||
| 2123 | is converted to Unicode using the fromUtf8() function. | - | ||||||||||||||||||
| 2124 | - | |||||||||||||||||||
| 2125 | You can disable this function by defining \c QT_NO_CAST_FROM_ASCII | - | ||||||||||||||||||
| 2126 | when you compile your applications. This can be useful if you want | - | ||||||||||||||||||
| 2127 | to ensure that all user-visible strings go through QObject::tr(), | - | ||||||||||||||||||
| 2128 | for example. | - | ||||||||||||||||||
| 2129 | */ | - | ||||||||||||||||||
| 2130 | - | |||||||||||||||||||
| 2131 | /*! \fn QString &QString::append(const char *str) | - | ||||||||||||||||||
| 2132 | - | |||||||||||||||||||
| 2133 | \overload append() | - | ||||||||||||||||||
| 2134 | - | |||||||||||||||||||
| 2135 | Appends the string \a str to this string. The given const char | - | ||||||||||||||||||
| 2136 | pointer is converted to Unicode using the fromUtf8() function. | - | ||||||||||||||||||
| 2137 | - | |||||||||||||||||||
| 2138 | You can disable this function by defining \c QT_NO_CAST_FROM_ASCII | - | ||||||||||||||||||
| 2139 | when you compile your applications. This can be useful if you want | - | ||||||||||||||||||
| 2140 | to ensure that all user-visible strings go through QObject::tr(), | - | ||||||||||||||||||
| 2141 | for example. | - | ||||||||||||||||||
| 2142 | */ | - | ||||||||||||||||||
| 2143 | - | |||||||||||||||||||
| 2144 | /*! | - | ||||||||||||||||||
| 2145 | \overload append() | - | ||||||||||||||||||
| 2146 | - | |||||||||||||||||||
| 2147 | Appends the character \a ch to this string. | - | ||||||||||||||||||
| 2148 | */ | - | ||||||||||||||||||
| 2149 | QString &QString::append(QChar ch) | - | ||||||||||||||||||
| 2150 | { | - | ||||||||||||||||||
| 2151 | if (d->ref.isShared() || uint(d->size) + 2u > d->alloc)
| 46500-555989 | ||||||||||||||||||
| 2152 | reallocData(uint(d->size) + 2u, true); executed 181565 times by 196 tests: reallocData(uint(d->size) + 2u, true);Executed by:
| 181565 | ||||||||||||||||||
| 2153 | d->data()[d->size++] = ch.unicode(); | - | ||||||||||||||||||
| 2154 | d->data()[d->size] = '\0'; | - | ||||||||||||||||||
| 2155 | return *this; executed 691054 times by 216 tests: return *this;Executed by:
| 691054 | ||||||||||||||||||
| 2156 | } | - | ||||||||||||||||||
| 2157 | - | |||||||||||||||||||
| 2158 | /*! \fn QString &QString::prepend(const QString &str) | - | ||||||||||||||||||
| 2159 | - | |||||||||||||||||||
| 2160 | Prepends the string \a str to the beginning of this string and | - | ||||||||||||||||||
| 2161 | returns a reference to this string. | - | ||||||||||||||||||
| 2162 | - | |||||||||||||||||||
| 2163 | Example: | - | ||||||||||||||||||
| 2164 | - | |||||||||||||||||||
| 2165 | \snippet qstring/main.cpp 36 | - | ||||||||||||||||||
| 2166 | - | |||||||||||||||||||
| 2167 | \sa append(), insert() | - | ||||||||||||||||||
| 2168 | */ | - | ||||||||||||||||||
| 2169 | - | |||||||||||||||||||
| 2170 | /*! \fn QString &QString::prepend(QLatin1String str) | - | ||||||||||||||||||
| 2171 | - | |||||||||||||||||||
| 2172 | \overload prepend() | - | ||||||||||||||||||
| 2173 | - | |||||||||||||||||||
| 2174 | Prepends the Latin-1 string \a str to this string. | - | ||||||||||||||||||
| 2175 | */ | - | ||||||||||||||||||
| 2176 | - | |||||||||||||||||||
| 2177 | /*! \fn QString &QString::prepend(const QChar *str, int len) | - | ||||||||||||||||||
| 2178 | \since 5.5 | - | ||||||||||||||||||
| 2179 | \overload prepend() | - | ||||||||||||||||||
| 2180 | - | |||||||||||||||||||
| 2181 | Prepends \a len characters from the QChar array \a str to this string and | - | ||||||||||||||||||
| 2182 | returns a reference to this string. | - | ||||||||||||||||||
| 2183 | */ | - | ||||||||||||||||||
| 2184 | - | |||||||||||||||||||
| 2185 | /*! \fn QString &QString::prepend(const QStringRef &str) | - | ||||||||||||||||||
| 2186 | \since 5.5 | - | ||||||||||||||||||
| 2187 | \overload prepend() | - | ||||||||||||||||||
| 2188 | - | |||||||||||||||||||
| 2189 | Prepends the string reference \a str to the beginning of this string and | - | ||||||||||||||||||
| 2190 | returns a reference to this string. | - | ||||||||||||||||||
| 2191 | */ | - | ||||||||||||||||||
| 2192 | - | |||||||||||||||||||
| 2193 | /*! \fn QString &QString::prepend(const QByteArray &ba) | - | ||||||||||||||||||
| 2194 | - | |||||||||||||||||||
| 2195 | \overload prepend() | - | ||||||||||||||||||
| 2196 | - | |||||||||||||||||||
| 2197 | Prepends the byte array \a ba to this string. The byte array is | - | ||||||||||||||||||
| 2198 | converted to Unicode using the fromUtf8() function. | - | ||||||||||||||||||
| 2199 | - | |||||||||||||||||||
| 2200 | You can disable this function by defining \c | - | ||||||||||||||||||
| 2201 | QT_NO_CAST_FROM_ASCII when you compile your applications. This | - | ||||||||||||||||||
| 2202 | can be useful if you want to ensure that all user-visible strings | - | ||||||||||||||||||
| 2203 | go through QObject::tr(), for example. | - | ||||||||||||||||||
| 2204 | */ | - | ||||||||||||||||||
| 2205 | - | |||||||||||||||||||
| 2206 | /*! \fn QString &QString::prepend(const char *str) | - | ||||||||||||||||||
| 2207 | - | |||||||||||||||||||
| 2208 | \overload prepend() | - | ||||||||||||||||||
| 2209 | - | |||||||||||||||||||
| 2210 | Prepends the string \a str to this string. The const char pointer | - | ||||||||||||||||||
| 2211 | is converted to Unicode using the fromUtf8() function. | - | ||||||||||||||||||
| 2212 | - | |||||||||||||||||||
| 2213 | You can disable this function by defining \c | - | ||||||||||||||||||
| 2214 | QT_NO_CAST_FROM_ASCII when you compile your applications. This | - | ||||||||||||||||||
| 2215 | can be useful if you want to ensure that all user-visible strings | - | ||||||||||||||||||
| 2216 | go through QObject::tr(), for example. | - | ||||||||||||||||||
| 2217 | */ | - | ||||||||||||||||||
| 2218 | - | |||||||||||||||||||
| 2219 | /*! \fn QString &QString::prepend(QChar ch) | - | ||||||||||||||||||
| 2220 | - | |||||||||||||||||||
| 2221 | \overload prepend() | - | ||||||||||||||||||
| 2222 | - | |||||||||||||||||||
| 2223 | Prepends the character \a ch to this string. | - | ||||||||||||||||||
| 2224 | */ | - | ||||||||||||||||||
| 2225 | - | |||||||||||||||||||
| 2226 | /*! | - | ||||||||||||||||||
| 2227 | \fn QString &QString::remove(int position, int n) | - | ||||||||||||||||||
| 2228 | - | |||||||||||||||||||
| 2229 | Removes \a n characters from the string, starting at the given \a | - | ||||||||||||||||||
| 2230 | position index, and returns a reference to the string. | - | ||||||||||||||||||
| 2231 | - | |||||||||||||||||||
| 2232 | If the specified \a position index is within the string, but \a | - | ||||||||||||||||||
| 2233 | position + \a n is beyond the end of the string, the string is | - | ||||||||||||||||||
| 2234 | truncated at the specified \a position. | - | ||||||||||||||||||
| 2235 | - | |||||||||||||||||||
| 2236 | \snippet qstring/main.cpp 37 | - | ||||||||||||||||||
| 2237 | - | |||||||||||||||||||
| 2238 | \sa insert(), replace() | - | ||||||||||||||||||
| 2239 | */ | - | ||||||||||||||||||
| 2240 | QString &QString::remove(int pos, int len) | - | ||||||||||||||||||
| 2241 | { | - | ||||||||||||||||||
| 2242 | if (pos < 0) // count from end of string
| 0-173715 | ||||||||||||||||||
| 2243 | pos += d->size; never executed: pos += d->size; | 0 | ||||||||||||||||||
| 2244 | if (uint(pos) >= uint(d->size)) {
| 0-173843 | ||||||||||||||||||
| 2245 | // range problems | - | ||||||||||||||||||
| 2246 | } else if (len >= d->size - pos) { never executed: end of block
| 0-123814 | ||||||||||||||||||
| 2247 | resize(pos); // truncate | - | ||||||||||||||||||
| 2248 | } else if (len > 0) { executed 50029 times by 24 tests: end of blockExecuted by:
| 1-123813 | ||||||||||||||||||
| 2249 | detach(); | - | ||||||||||||||||||
| 2250 | memmove(d->data() + pos, d->data() + pos + len, | - | ||||||||||||||||||
| 2251 | (d->size - pos - len + 1) * sizeof(ushort)); | - | ||||||||||||||||||
| 2252 | d->size -= len; | - | ||||||||||||||||||
| 2253 | } executed 123813 times by 149 tests: end of blockExecuted by:
| 123813 | ||||||||||||||||||
| 2254 | return *this; executed 173843 times by 149 tests: return *this;Executed by:
| 173843 | ||||||||||||||||||
| 2255 | } | - | ||||||||||||||||||
| 2256 | - | |||||||||||||||||||
| 2257 | /*! | - | ||||||||||||||||||
| 2258 | Removes every occurrence of the given \a str string in this | - | ||||||||||||||||||
| 2259 | string, and returns a reference to this string. | - | ||||||||||||||||||
| 2260 | - | |||||||||||||||||||
| 2261 | If \a cs is Qt::CaseSensitive (default), the search is | - | ||||||||||||||||||
| 2262 | case sensitive; otherwise the search is case insensitive. | - | ||||||||||||||||||
| 2263 | - | |||||||||||||||||||
| 2264 | This is the same as \c replace(str, "", cs). | - | ||||||||||||||||||
| 2265 | - | |||||||||||||||||||
| 2266 | \sa replace() | - | ||||||||||||||||||
| 2267 | */ | - | ||||||||||||||||||
| 2268 | QString &QString::remove(const QString &str, Qt::CaseSensitivity cs) | - | ||||||||||||||||||
| 2269 | { | - | ||||||||||||||||||
| 2270 | if (str.d->size) {
| 4-24541 | ||||||||||||||||||
| 2271 | int i = 0; | - | ||||||||||||||||||
| 2272 | while ((i = indexOf(str, i, cs)) != -1)
| 18-24541 | ||||||||||||||||||
| 2273 | remove(i, str.d->size); executed 18 times by 2 tests: remove(i, str.d->size);Executed by:
| 18 | ||||||||||||||||||
| 2274 | } executed 24541 times by 11 tests: end of blockExecuted by:
| 24541 | ||||||||||||||||||
| 2275 | return *this; executed 24545 times by 11 tests: return *this;Executed by:
| 24545 | ||||||||||||||||||
| 2276 | } | - | ||||||||||||||||||
| 2277 | - | |||||||||||||||||||
| 2278 | /*! | - | ||||||||||||||||||
| 2279 | Removes every occurrence of the character \a ch in this string, and | - | ||||||||||||||||||
| 2280 | returns a reference to this string. | - | ||||||||||||||||||
| 2281 | - | |||||||||||||||||||
| 2282 | If \a cs is Qt::CaseSensitive (default), the search is case | - | ||||||||||||||||||
| 2283 | sensitive; otherwise the search is case insensitive. | - | ||||||||||||||||||
| 2284 | - | |||||||||||||||||||
| 2285 | Example: | - | ||||||||||||||||||
| 2286 | - | |||||||||||||||||||
| 2287 | \snippet qstring/main.cpp 38 | - | ||||||||||||||||||
| 2288 | - | |||||||||||||||||||
| 2289 | This is the same as \c replace(ch, "", cs). | - | ||||||||||||||||||
| 2290 | - | |||||||||||||||||||
| 2291 | \sa replace() | - | ||||||||||||||||||
| 2292 | */ | - | ||||||||||||||||||
| 2293 | QString &QString::remove(QChar ch, Qt::CaseSensitivity cs) | - | ||||||||||||||||||
| 2294 | { | - | ||||||||||||||||||
| 2295 | int i = 0; | - | ||||||||||||||||||
| 2296 | ushort c = ch.unicode(); | - | ||||||||||||||||||
| 2297 | if (cs == Qt::CaseSensitive) {
| 11-30102 | ||||||||||||||||||
| 2298 | while (i < d->size)
| 30102-760854 | ||||||||||||||||||
| 2299 | if (d->data()[i] == ch)
| 48434-712420 | ||||||||||||||||||
| 2300 | remove(i, 1); executed 48434 times by 11 tests: remove(i, 1);Executed by:
| 48434 | ||||||||||||||||||
| 2301 | else | - | ||||||||||||||||||
| 2302 | i++; executed 712420 times by 26 tests: i++;Executed by:
| 712420 | ||||||||||||||||||
| 2303 | } else { executed 30102 times by 27 tests: end of blockExecuted by:
| 30102 | ||||||||||||||||||
| 2304 | c = foldCase(c); | - | ||||||||||||||||||
| 2305 | while (i < d->size)
| 11-36 | ||||||||||||||||||
| 2306 | if (foldCase(d->data()[i]) == c)
| 14-22 | ||||||||||||||||||
| 2307 | remove(i, 1); executed 14 times by 1 test: remove(i, 1);Executed by:
| 14 | ||||||||||||||||||
| 2308 | else | - | ||||||||||||||||||
| 2309 | i++; executed 22 times by 1 test: i++;Executed by:
| 22 | ||||||||||||||||||
| 2310 | } executed 11 times by 1 test: end of blockExecuted by:
| 11 | ||||||||||||||||||
| 2311 | return *this; executed 30113 times by 27 tests: return *this;Executed by:
| 30113 | ||||||||||||||||||
| 2312 | } | - | ||||||||||||||||||
| 2313 | - | |||||||||||||||||||
| 2314 | /*! | - | ||||||||||||||||||
| 2315 | \fn QString &QString::remove(const QRegExp &rx) | - | ||||||||||||||||||
| 2316 | - | |||||||||||||||||||
| 2317 | Removes every occurrence of the regular expression \a rx in the | - | ||||||||||||||||||
| 2318 | string, and returns a reference to the string. For example: | - | ||||||||||||||||||
| 2319 | - | |||||||||||||||||||
| 2320 | \snippet qstring/main.cpp 39 | - | ||||||||||||||||||
| 2321 | - | |||||||||||||||||||
| 2322 | \sa indexOf(), lastIndexOf(), replace() | - | ||||||||||||||||||
| 2323 | */ | - | ||||||||||||||||||
| 2324 | - | |||||||||||||||||||
| 2325 | /*! | - | ||||||||||||||||||
| 2326 | \fn QString &QString::remove(const QRegularExpression &re) | - | ||||||||||||||||||
| 2327 | \since 5.0 | - | ||||||||||||||||||
| 2328 | - | |||||||||||||||||||
| 2329 | Removes every occurrence of the regular expression \a re in the | - | ||||||||||||||||||
| 2330 | string, and returns a reference to the string. For example: | - | ||||||||||||||||||
| 2331 | - | |||||||||||||||||||
| 2332 | \snippet qstring/main.cpp 96 | - | ||||||||||||||||||
| 2333 | - | |||||||||||||||||||
| 2334 | \sa indexOf(), lastIndexOf(), replace() | - | ||||||||||||||||||
| 2335 | */ | - | ||||||||||||||||||
| 2336 | - | |||||||||||||||||||
| 2337 | /*! | - | ||||||||||||||||||
| 2338 | \fn QString &QString::replace(int position, int n, const QString &after) | - | ||||||||||||||||||
| 2339 | - | |||||||||||||||||||
| 2340 | Replaces \a n characters beginning at index \a position with | - | ||||||||||||||||||
| 2341 | the string \a after and returns a reference to this string. | - | ||||||||||||||||||
| 2342 | - | |||||||||||||||||||
| 2343 | \note If the specified \a position index is within the string, | - | ||||||||||||||||||
| 2344 | but \a position + \a n goes outside the strings range, | - | ||||||||||||||||||
| 2345 | then \a n will be adjusted to stop at the end of the string. | - | ||||||||||||||||||
| 2346 | - | |||||||||||||||||||
| 2347 | Example: | - | ||||||||||||||||||
| 2348 | - | |||||||||||||||||||
| 2349 | \snippet qstring/main.cpp 40 | - | ||||||||||||||||||
| 2350 | - | |||||||||||||||||||
| 2351 | \sa insert(), remove() | - | ||||||||||||||||||
| 2352 | */ | - | ||||||||||||||||||
| 2353 | QString &QString::replace(int pos, int len, const QString &after) | - | ||||||||||||||||||
| 2354 | { | - | ||||||||||||||||||
| 2355 | return replace(pos, len, after.constData(), after.length()); executed 2000587 times by 9 tests: return replace(pos, len, after.constData(), after.length());Executed by:
| 2000587 | ||||||||||||||||||
| 2356 | } | - | ||||||||||||||||||
| 2357 | - | |||||||||||||||||||
| 2358 | /*! | - | ||||||||||||||||||
| 2359 | \fn QString &QString::replace(int position, int n, const QChar *unicode, int size) | - | ||||||||||||||||||
| 2360 | \overload replace() | - | ||||||||||||||||||
| 2361 | Replaces \a n characters beginning at index \a position with the | - | ||||||||||||||||||
| 2362 | first \a size characters of the QChar array \a unicode and returns a | - | ||||||||||||||||||
| 2363 | reference to this string. | - | ||||||||||||||||||
| 2364 | */ | - | ||||||||||||||||||
| 2365 | QString &QString::replace(int pos, int len, const QChar *unicode, int size) | - | ||||||||||||||||||
| 2366 | { | - | ||||||||||||||||||
| 2367 | if (uint(pos) > uint(d->size))
| 0-2109498 | ||||||||||||||||||
| 2368 | return *this; never executed: return *this; | 0 | ||||||||||||||||||
| 2369 | if (len > d->size - pos)
| 25-2109473 | ||||||||||||||||||
| 2370 | len = d->size - pos; executed 25 times by 1 test: len = d->size - pos;Executed by:
| 25 | ||||||||||||||||||
| 2371 | - | |||||||||||||||||||
| 2372 | uint index = pos; | - | ||||||||||||||||||
| 2373 | replace_helper(&index, 1, len, unicode, size); | - | ||||||||||||||||||
| 2374 | return *this; executed 2109498 times by 22 tests: return *this;Executed by:
| 2109498 | ||||||||||||||||||
| 2375 | } | - | ||||||||||||||||||
| 2376 | - | |||||||||||||||||||
| 2377 | /*! | - | ||||||||||||||||||
| 2378 | \fn QString &QString::replace(int position, int n, QChar after) | - | ||||||||||||||||||
| 2379 | \overload replace() | - | ||||||||||||||||||
| 2380 | - | |||||||||||||||||||
| 2381 | Replaces \a n characters beginning at index \a position with the | - | ||||||||||||||||||
| 2382 | character \a after and returns a reference to this string. | - | ||||||||||||||||||
| 2383 | */ | - | ||||||||||||||||||
| 2384 | QString &QString::replace(int pos, int len, QChar after) | - | ||||||||||||||||||
| 2385 | { | - | ||||||||||||||||||
| 2386 | return replace(pos, len, &after, 1); executed 12 times by 3 tests: return replace(pos, len, &after, 1);Executed by:
| 12 | ||||||||||||||||||
| 2387 | } | - | ||||||||||||||||||
| 2388 | - | |||||||||||||||||||
| 2389 | /*! | - | ||||||||||||||||||
| 2390 | \overload replace() | - | ||||||||||||||||||
| 2391 | Replaces every occurrence of the string \a before with the string \a | - | ||||||||||||||||||
| 2392 | after and returns a reference to this string. | - | ||||||||||||||||||
| 2393 | - | |||||||||||||||||||
| 2394 | If \a cs is Qt::CaseSensitive (default), the search is case | - | ||||||||||||||||||
| 2395 | sensitive; otherwise the search is case insensitive. | - | ||||||||||||||||||
| 2396 | - | |||||||||||||||||||
| 2397 | Example: | - | ||||||||||||||||||
| 2398 | - | |||||||||||||||||||
| 2399 | \snippet qstring/main.cpp 41 | - | ||||||||||||||||||
| 2400 | - | |||||||||||||||||||
| 2401 | \note The replacement text is not rescanned after it is inserted. | - | ||||||||||||||||||
| 2402 | - | |||||||||||||||||||
| 2403 | Example: | - | ||||||||||||||||||
| 2404 | - | |||||||||||||||||||
| 2405 | \snippet qstring/main.cpp 86 | - | ||||||||||||||||||
| 2406 | */ | - | ||||||||||||||||||
| 2407 | QString &QString::replace(const QString &before, const QString &after, Qt::CaseSensitivity cs) | - | ||||||||||||||||||
| 2408 | { | - | ||||||||||||||||||
| 2409 | return replace(before.constData(), before.size(), after.constData(), after.size(), cs); executed 168802 times by 19 tests: return replace(before.constData(), before.size(), after.constData(), after.size(), cs);Executed by:
| 168802 | ||||||||||||||||||
| 2410 | } | - | ||||||||||||||||||
| 2411 | - | |||||||||||||||||||
| 2412 | namespace { // helpers for replace and its helper: | - | ||||||||||||||||||
| 2413 | QChar *textCopy(const QChar *start, int len) | - | ||||||||||||||||||
| 2414 | { | - | ||||||||||||||||||
| 2415 | const size_t size = len * sizeof(QChar); | - | ||||||||||||||||||
| 2416 | QChar *const copy = static_cast<QChar *>(::malloc(size)); | - | ||||||||||||||||||
| 2417 | Q_CHECK_PTR(copy); never executed: qBadAlloc();
| 0-28 | ||||||||||||||||||
| 2418 | ::memcpy(copy, start, size); | - | ||||||||||||||||||
| 2419 | return copy; executed 28 times by 4 tests: return copy;Executed by:
| 28 | ||||||||||||||||||
| 2420 | } | - | ||||||||||||||||||
| 2421 | - | |||||||||||||||||||
| 2422 | bool pointsIntoRange(const QChar *ptr, const ushort *base, int len) | - | ||||||||||||||||||
| 2423 | { | - | ||||||||||||||||||
| 2424 | const QChar *const start = reinterpret_cast<const QChar *>(base); | - | ||||||||||||||||||
| 2425 | return start <= ptr && ptr < start + len; executed 2111199 times by 50 tests: return start <= ptr && ptr < start + len;Executed by:
| 2111199 | ||||||||||||||||||
| 2426 | } | - | ||||||||||||||||||
| 2427 | } // end namespace | - | ||||||||||||||||||
| 2428 | - | |||||||||||||||||||
| 2429 | /*! | - | ||||||||||||||||||
| 2430 | \internal | - | ||||||||||||||||||
| 2431 | */ | - | ||||||||||||||||||
| 2432 | void QString::replace_helper(uint *indices, int nIndices, int blen, const QChar *after, int alen) | - | ||||||||||||||||||
| 2433 | { | - | ||||||||||||||||||
| 2434 | // Copy after if it lies inside our own d->data() area (which we could | - | ||||||||||||||||||
| 2435 | // possibly invalidate via a realloc or modify by replacement). | - | ||||||||||||||||||
| 2436 | QChar *afterBuffer = 0; | - | ||||||||||||||||||
| 2437 | if (pointsIntoRange(after, d->data(), d->size)) // Use copy in place of vulnerable original:
| 26-2111171 | ||||||||||||||||||
| 2438 | after = afterBuffer = textCopy(after, alen); executed 26 times by 4 tests: after = afterBuffer = textCopy(after, alen);Executed by:
| 26 | ||||||||||||||||||
| 2439 | - | |||||||||||||||||||
| 2440 | QT_TRY { | - | ||||||||||||||||||
| 2441 | if (blen == alen) {
| 96919-2014278 | ||||||||||||||||||
| 2442 | // replace in place | - | ||||||||||||||||||
| 2443 | detach(); | - | ||||||||||||||||||
| 2444 | for (int i = 0; i < nIndices; ++i)
| 2014278-2014285 | ||||||||||||||||||
| 2445 | memcpy(d->data() + indices[i], after, alen * sizeof(QChar)); executed 2014285 times by 21 tests: memcpy(d->data() + indices[i], after, alen * sizeof(QChar));Executed by:
| 2014285 | ||||||||||||||||||
| 2446 | } else if (alen < blen) { executed 2014278 times by 21 tests: end of blockExecuted by:
| 10372-2014278 | ||||||||||||||||||
| 2447 | // replace from front | - | ||||||||||||||||||
| 2448 | detach(); | - | ||||||||||||||||||
| 2449 | uint to = indices[0]; | - | ||||||||||||||||||
| 2450 | if (alen)
| 32-10340 | ||||||||||||||||||
| 2451 | memcpy(d->data()+to, after, alen*sizeof(QChar)); executed 10340 times by 16 tests: memcpy(d->data()+to, after, alen*sizeof(QChar));Executed by:
| 10340 | ||||||||||||||||||
| 2452 | to += alen; | - | ||||||||||||||||||
| 2453 | uint movestart = indices[0] + blen; | - | ||||||||||||||||||
| 2454 | for (int i = 1; i < nIndices; ++i) {
| 1031-10372 | ||||||||||||||||||
| 2455 | int msize = indices[i] - movestart; | - | ||||||||||||||||||
| 2456 | if (msize > 0) {
| 2-1029 | ||||||||||||||||||
| 2457 | memmove(d->data() + to, d->data() + movestart, msize * sizeof(QChar)); | - | ||||||||||||||||||
| 2458 | to += msize; | - | ||||||||||||||||||
| 2459 | } executed 1029 times by 1 test: end of blockExecuted by:
| 1029 | ||||||||||||||||||
| 2460 | if (alen) {
| 5-1026 | ||||||||||||||||||
| 2461 | memcpy(d->data() + to, after, alen * sizeof(QChar)); | - | ||||||||||||||||||
| 2462 | to += alen; | - | ||||||||||||||||||
| 2463 | } executed 1026 times by 1 test: end of blockExecuted by:
| 1026 | ||||||||||||||||||
| 2464 | movestart = indices[i] + blen; | - | ||||||||||||||||||
| 2465 | } executed 1031 times by 1 test: end of blockExecuted by:
| 1031 | ||||||||||||||||||
| 2466 | int msize = d->size - movestart; | - | ||||||||||||||||||
| 2467 | if (msize > 0)
| 1283-9089 | ||||||||||||||||||
| 2468 | 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 | ||||||||||||||||||
| 2469 | resize(d->size - nIndices*(blen-alen)); | - | ||||||||||||||||||
| 2470 | } else { executed 10372 times by 16 tests: end of blockExecuted by:
| 10372 | ||||||||||||||||||
| 2471 | // replace from back | - | ||||||||||||||||||
| 2472 | int adjust = nIndices*(alen-blen); | - | ||||||||||||||||||
| 2473 | int newLen = d->size + adjust; | - | ||||||||||||||||||
| 2474 | int moveend = d->size; | - | ||||||||||||||||||
| 2475 | resize(newLen); | - | ||||||||||||||||||
| 2476 | - | |||||||||||||||||||
| 2477 | while (nIndices) {
| 86547-86663 | ||||||||||||||||||
| 2478 | --nIndices; | - | ||||||||||||||||||
| 2479 | int movestart = indices[nIndices] + blen; | - | ||||||||||||||||||
| 2480 | int insertstart = indices[nIndices] + nIndices*(alen-blen); | - | ||||||||||||||||||
| 2481 | int moveto = insertstart + alen; | - | ||||||||||||||||||
| 2482 | memmove(d->data() + moveto, d->data() + movestart, | - | ||||||||||||||||||
| 2483 | (moveend - movestart)*sizeof(QChar)); | - | ||||||||||||||||||
| 2484 | memcpy(d->data() + insertstart, after, alen * sizeof(QChar)); | - | ||||||||||||||||||
| 2485 | moveend = movestart-blen; | - | ||||||||||||||||||
| 2486 | } executed 86663 times by 32 tests: end of blockExecuted by:
| 86663 | ||||||||||||||||||
| 2487 | } executed 86547 times by 32 tests: end of blockExecuted by:
| 86547 | ||||||||||||||||||
| 2488 | } QT_CATCH(const std::bad_alloc &) { | - | ||||||||||||||||||
| 2489 | ::free(afterBuffer); | - | ||||||||||||||||||
| 2490 | QT_RETHROW; never executed: throw; | 0 | ||||||||||||||||||
| 2491 | } | - | ||||||||||||||||||
| 2492 | ::free(afterBuffer); | - | ||||||||||||||||||
| 2493 | } executed 2111197 times by 50 tests: end of blockExecuted by:
| 2111197 | ||||||||||||||||||
| 2494 | - | |||||||||||||||||||
| 2495 | /*! | - | ||||||||||||||||||
| 2496 | \since 4.5 | - | ||||||||||||||||||
| 2497 | \overload replace() | - | ||||||||||||||||||
| 2498 | - | |||||||||||||||||||
| 2499 | Replaces each occurrence in this string of the first \a blen | - | ||||||||||||||||||
| 2500 | characters of \a before with the first \a alen characters of \a | - | ||||||||||||||||||
| 2501 | after and returns a reference to this string. | - | ||||||||||||||||||
| 2502 | - | |||||||||||||||||||
| 2503 | If \a cs is Qt::CaseSensitive (default), the search is case | - | ||||||||||||||||||
| 2504 | sensitive; otherwise the search is case insensitive. | - | ||||||||||||||||||
| 2505 | */ | - | ||||||||||||||||||
| 2506 | QString &QString::replace(const QChar *before, int blen, | - | ||||||||||||||||||
| 2507 | const QChar *after, int alen, | - | ||||||||||||||||||
| 2508 | Qt::CaseSensitivity cs) | - | ||||||||||||||||||
| 2509 | { | - | ||||||||||||||||||
| 2510 | if (d->size == 0) {
| 2844-192107 | ||||||||||||||||||
| 2511 | if (blen)
| 6-2838 | ||||||||||||||||||
| 2512 | return *this; executed 2838 times by 28 tests: return *this;Executed by:
| 2838 | ||||||||||||||||||
| 2513 | } else { executed 6 times by 1 test: end of blockExecuted by:
| 6 | ||||||||||||||||||
| 2514 | if (cs == Qt::CaseSensitive && before == after && blen == alen)
| 0-192092 | ||||||||||||||||||
| 2515 | return *this; executed 2 times by 1 test: return *this;Executed by:
| 2 | ||||||||||||||||||
| 2516 | } executed 192105 times by 104 tests: end of blockExecuted by:
| 192105 | ||||||||||||||||||
| 2517 | if (alen == 0 && blen == 0)
| 4-192090 | ||||||||||||||||||
| 2518 | return *this; executed 4 times by 1 test: return *this;Executed by:
| 4 | ||||||||||||||||||
| 2519 | - | |||||||||||||||||||
| 2520 | QStringMatcher matcher(before, blen, cs); | - | ||||||||||||||||||
| 2521 | QChar *beforeBuffer = 0, *afterBuffer = 0; | - | ||||||||||||||||||
| 2522 | - | |||||||||||||||||||
| 2523 | int index = 0; | - | ||||||||||||||||||
| 2524 | while (1) { | - | ||||||||||||||||||
| 2525 | uint indices[1024]; | - | ||||||||||||||||||
| 2526 | uint pos = 0; | - | ||||||||||||||||||
| 2527 | while (pos < 1024) {
| 1-194936 | ||||||||||||||||||
| 2528 | index = matcher.indexIn(*this, index); | - | ||||||||||||||||||
| 2529 | if (index == -1)
| 2829-192107 | ||||||||||||||||||
| 2530 | break; executed 192107 times by 104 tests: break;Executed by:
| 192107 | ||||||||||||||||||
| 2531 | indices[pos++] = index; | - | ||||||||||||||||||
| 2532 | if (blen) // Step over before:
| 10-2819 | ||||||||||||||||||
| 2533 | index += blen; executed 2819 times by 35 tests: index += blen;Executed by:
| 2819 | ||||||||||||||||||
| 2534 | else // Only count one instance of empty between any two characters: | - | ||||||||||||||||||
| 2535 | index++; executed 10 times by 1 test: index++;Executed by:
| 10 | ||||||||||||||||||
| 2536 | } | - | ||||||||||||||||||
| 2537 | if (!pos) // Nothing to replace
| 1690-190418 | ||||||||||||||||||
| 2538 | break; executed 190418 times by 93 tests: break;Executed by:
| 190418 | ||||||||||||||||||
| 2539 | - | |||||||||||||||||||
| 2540 | if (Q_UNLIKELY(index != -1)) {
| 1-1689 | ||||||||||||||||||
| 2541 | /* | - | ||||||||||||||||||
| 2542 | We're about to change data, that before and after might point | - | ||||||||||||||||||
| 2543 | into, and we'll need that data for our next batch of indices. | - | ||||||||||||||||||
| 2544 | */ | - | ||||||||||||||||||
| 2545 | if (!afterBuffer && pointsIntoRange(after, d->data(), d->size))
| 0-1 | ||||||||||||||||||
| 2546 | after = afterBuffer = textCopy(after, alen); executed 1 time by 1 test: after = afterBuffer = textCopy(after, alen);Executed by:
| 1 | ||||||||||||||||||
| 2547 | - | |||||||||||||||||||
| 2548 | if (!beforeBuffer && pointsIntoRange(before, d->data(), d->size)) {
| 0-1 | ||||||||||||||||||
| 2549 | beforeBuffer = textCopy(before, blen); | - | ||||||||||||||||||
| 2550 | matcher = QStringMatcher(beforeBuffer, blen, cs); | - | ||||||||||||||||||
| 2551 | } executed 1 time by 1 test: end of blockExecuted by:
| 1 | ||||||||||||||||||
| 2552 | } executed 1 time by 1 test: end of blockExecuted by:
| 1 | ||||||||||||||||||
| 2553 | - | |||||||||||||||||||
| 2554 | replace_helper(indices, pos, blen, after, alen); | - | ||||||||||||||||||
| 2555 | - | |||||||||||||||||||
| 2556 | if (Q_LIKELY(index == -1)) // Nothing left to replace
| 1-1689 | ||||||||||||||||||
| 2557 | break; executed 1689 times by 35 tests: break;Executed by:
| 1689 | ||||||||||||||||||
| 2558 | // The call to replace_helper just moved what index points at: | - | ||||||||||||||||||
| 2559 | index += pos*(alen-blen); | - | ||||||||||||||||||
| 2560 | } executed 1 time by 1 test: end of blockExecuted by:
| 1 | ||||||||||||||||||
| 2561 | ::free(afterBuffer); | - | ||||||||||||||||||
| 2562 | ::free(beforeBuffer); | - | ||||||||||||||||||
| 2563 | - | |||||||||||||||||||
| 2564 | return *this; executed 192107 times by 104 tests: return *this;Executed by:
| 192107 | ||||||||||||||||||
| 2565 | } | - | ||||||||||||||||||
| 2566 | - | |||||||||||||||||||
| 2567 | /*! | - | ||||||||||||||||||
| 2568 | \overload replace() | - | ||||||||||||||||||
| 2569 | Replaces every occurrence of the character \a ch in the string with | - | ||||||||||||||||||
| 2570 | \a after and returns a reference to this string. | - | ||||||||||||||||||
| 2571 | - | |||||||||||||||||||
| 2572 | If \a cs is Qt::CaseSensitive (default), the search is case | - | ||||||||||||||||||
| 2573 | sensitive; otherwise the search is case insensitive. | - | ||||||||||||||||||
| 2574 | */ | - | ||||||||||||||||||
| 2575 | QString& QString::replace(QChar ch, const QString &after, Qt::CaseSensitivity cs) | - | ||||||||||||||||||
| 2576 | { | - | ||||||||||||||||||
| 2577 | if (after.d->size == 0)
| 33-37 | ||||||||||||||||||
| 2578 | return remove(ch, cs); executed 37 times by 1 test: return remove(ch, cs);Executed by:
| 37 | ||||||||||||||||||
| 2579 | - | |||||||||||||||||||
| 2580 | if (after.d->size == 1)
| 11-22 | ||||||||||||||||||
| 2581 | 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 | ||||||||||||||||||
| 2582 | - | |||||||||||||||||||
| 2583 | if (d->size == 0)
| 0-11 | ||||||||||||||||||
| 2584 | return *this; never executed: return *this; | 0 | ||||||||||||||||||
| 2585 | - | |||||||||||||||||||
| 2586 | ushort cc = (cs == Qt::CaseSensitive ? ch.unicode() : ch.toCaseFolded().unicode());
| 4-7 | ||||||||||||||||||
| 2587 | - | |||||||||||||||||||
| 2588 | int index = 0; | - | ||||||||||||||||||
| 2589 | while (1) { | - | ||||||||||||||||||
| 2590 | uint indices[1024]; | - | ||||||||||||||||||
| 2591 | uint pos = 0; | - | ||||||||||||||||||
| 2592 | if (cs == Qt::CaseSensitive) {
| 7-13 | ||||||||||||||||||
| 2593 | while (pos < 1024 && index < d->size) {
| 0-71 | ||||||||||||||||||
| 2594 | if (d->data()[index] == cc)
| 16-42 | ||||||||||||||||||
| 2595 | indices[pos++] = index; executed 16 times by 2 tests: indices[pos++] = index;Executed by:
| 16 | ||||||||||||||||||
| 2596 | index++; | - | ||||||||||||||||||
| 2597 | } executed 58 times by 2 tests: end of blockExecuted by:
| 58 | ||||||||||||||||||
| 2598 | } else { executed 13 times by 2 tests: end of blockExecuted by:
| 13 | ||||||||||||||||||
| 2599 | while (pos < 1024 && index < d->size) {
| 0-29 | ||||||||||||||||||
| 2600 | if (QChar::toCaseFolded(d->data()[index]) == cc)
| 8-14 | ||||||||||||||||||
| 2601 | indices[pos++] = index; executed 8 times by 1 test: indices[pos++] = index;Executed by:
| 8 | ||||||||||||||||||
| 2602 | index++; | - | ||||||||||||||||||
| 2603 | } executed 22 times by 1 test: end of blockExecuted by:
| 22 | ||||||||||||||||||
| 2604 | } executed 7 times by 1 test: end of blockExecuted by:
| 7 | ||||||||||||||||||
| 2605 | if (!pos) // Nothing to replace
| 9-11 | ||||||||||||||||||
| 2606 | break; executed 11 times by 2 tests: break;Executed by:
| 11 | ||||||||||||||||||
| 2607 | - | |||||||||||||||||||
| 2608 | replace_helper(indices, pos, 1, after.constData(), after.d->size); | - | ||||||||||||||||||
| 2609 | - | |||||||||||||||||||
| 2610 | if (Q_LIKELY(index == -1)) // Nothing left to replace
| 0-9 | ||||||||||||||||||
| 2611 | break; never executed: break; | 0 | ||||||||||||||||||
| 2612 | // The call to replace_helper just moved what index points at: | - | ||||||||||||||||||
| 2613 | index += pos*(after.d->size - 1); | - | ||||||||||||||||||
| 2614 | } executed 9 times by 2 tests: end of blockExecuted by:
| 9 | ||||||||||||||||||
| 2615 | return *this; executed 11 times by 2 tests: return *this;Executed by:
| 11 | ||||||||||||||||||
| 2616 | } | - | ||||||||||||||||||
| 2617 | - | |||||||||||||||||||
| 2618 | /*! | - | ||||||||||||||||||
| 2619 | \overload replace() | - | ||||||||||||||||||
| 2620 | Replaces every occurrence of the character \a before with the | - | ||||||||||||||||||
| 2621 | character \a after and returns a reference to this string. | - | ||||||||||||||||||
| 2622 | - | |||||||||||||||||||
| 2623 | If \a cs is Qt::CaseSensitive (default), the search is case | - | ||||||||||||||||||
| 2624 | sensitive; otherwise the search is case insensitive. | - | ||||||||||||||||||
| 2625 | */ | - | ||||||||||||||||||
| 2626 | QString& QString::replace(QChar before, QChar after, Qt::CaseSensitivity cs) | - | ||||||||||||||||||
| 2627 | { | - | ||||||||||||||||||
| 2628 | ushort a = after.unicode(); | - | ||||||||||||||||||
| 2629 | ushort b = before.unicode(); | - | ||||||||||||||||||
| 2630 | if (d->size) {
| 1248-135666 | ||||||||||||||||||
| 2631 | detach(); | - | ||||||||||||||||||
| 2632 | ushort *i = d->data(); | - | ||||||||||||||||||
| 2633 | const ushort *e = i + d->size; | - | ||||||||||||||||||
| 2634 | if (cs == Qt::CaseSensitive) {
| 22-135644 | ||||||||||||||||||
| 2635 | for (; i != e; ++i)
| 135644-1098526 | ||||||||||||||||||
| 2636 | if (*i == b)
| 9864-1088662 | ||||||||||||||||||
| 2637 | *i = a; executed 9864 times by 24 tests: *i = a;Executed by:
| 9864 | ||||||||||||||||||
| 2638 | } else { executed 135644 times by 63 tests: end of blockExecuted by:
| 135644 | ||||||||||||||||||
| 2639 | b = foldCase(b); | - | ||||||||||||||||||
| 2640 | for (; i != e; ++i)
| 22-58 | ||||||||||||||||||
| 2641 | if (foldCase(*i) == b)
| 28-30 | ||||||||||||||||||
| 2642 | *i = a; executed 30 times by 1 test: *i = a;Executed by:
| 30 | ||||||||||||||||||
| 2643 | } executed 22 times by 1 test: end of blockExecuted by:
| 22 | ||||||||||||||||||
| 2644 | } | - | ||||||||||||||||||
| 2645 | return *this; executed 136914 times by 63 tests: return *this;Executed by:
| 136914 | ||||||||||||||||||
| 2646 | } | - | ||||||||||||||||||
| 2647 | - | |||||||||||||||||||
| 2648 | /*! | - | ||||||||||||||||||
| 2649 | \since 4.5 | - | ||||||||||||||||||
| 2650 | \overload replace() | - | ||||||||||||||||||
| 2651 | - | |||||||||||||||||||
| 2652 | Replaces every occurrence of the string \a before with the string \a | - | ||||||||||||||||||
| 2653 | after and returns a reference to this string. | - | ||||||||||||||||||
| 2654 | - | |||||||||||||||||||
| 2655 | If \a cs is Qt::CaseSensitive (default), the search is case | - | ||||||||||||||||||
| 2656 | sensitive; otherwise the search is case insensitive. | - | ||||||||||||||||||
| 2657 | - | |||||||||||||||||||
| 2658 | \note The text is not rescanned after a replacement. | - | ||||||||||||||||||
| 2659 | */ | - | ||||||||||||||||||
| 2660 | QString &QString::replace(QLatin1String before, QLatin1String after, Qt::CaseSensitivity cs) | - | ||||||||||||||||||
| 2661 | { | - | ||||||||||||||||||
| 2662 | int alen = after.size(); | - | ||||||||||||||||||
| 2663 | int blen = before.size(); | - | ||||||||||||||||||
| 2664 | QVarLengthArray<ushort> a(alen); | - | ||||||||||||||||||
| 2665 | QVarLengthArray<ushort> b(blen); | - | ||||||||||||||||||
| 2666 | qt_from_latin1(a.data(), after.latin1(), alen); | - | ||||||||||||||||||
| 2667 | qt_from_latin1(b.data(), before.latin1(), blen); | - | ||||||||||||||||||
| 2668 | return replace((const QChar *)b.data(), blen, (const QChar *)a.data(), alen, cs); executed 1004 times by 42 tests: return replace((const QChar *)b.data(), blen, (const QChar *)a.data(), alen, cs);Executed by:
| 1004 | ||||||||||||||||||
| 2669 | } | - | ||||||||||||||||||
| 2670 | - | |||||||||||||||||||
| 2671 | /*! | - | ||||||||||||||||||
| 2672 | \since 4.5 | - | ||||||||||||||||||
| 2673 | \overload replace() | - | ||||||||||||||||||
| 2674 | - | |||||||||||||||||||
| 2675 | Replaces every occurrence of the string \a before with the string \a | - | ||||||||||||||||||
| 2676 | after and returns a reference to this string. | - | ||||||||||||||||||
| 2677 | - | |||||||||||||||||||
| 2678 | If \a cs is Qt::CaseSensitive (default), the search is case | - | ||||||||||||||||||
| 2679 | sensitive; otherwise the search is case insensitive. | - | ||||||||||||||||||
| 2680 | - | |||||||||||||||||||
| 2681 | \note The text is not rescanned after a replacement. | - | ||||||||||||||||||
| 2682 | */ | - | ||||||||||||||||||
| 2683 | QString &QString::replace(QLatin1String before, const QString &after, Qt::CaseSensitivity cs) | - | ||||||||||||||||||
| 2684 | { | - | ||||||||||||||||||
| 2685 | int blen = before.size(); | - | ||||||||||||||||||
| 2686 | QVarLengthArray<ushort> b(blen); | - | ||||||||||||||||||
| 2687 | qt_from_latin1(b.data(), before.latin1(), blen); | - | ||||||||||||||||||
| 2688 | return replace((const QChar *)b.data(), blen, after.constData(), after.d->size, cs); executed 201 times by 3 tests: return replace((const QChar *)b.data(), blen, after.constData(), after.d->size, cs);Executed by:
| 201 | ||||||||||||||||||
| 2689 | } | - | ||||||||||||||||||
| 2690 | - | |||||||||||||||||||
| 2691 | /*! | - | ||||||||||||||||||
| 2692 | \since 4.5 | - | ||||||||||||||||||
| 2693 | \overload replace() | - | ||||||||||||||||||
| 2694 | - | |||||||||||||||||||
| 2695 | Replaces every occurrence of the string \a before with the string \a | - | ||||||||||||||||||
| 2696 | after and returns a reference to this string. | - | ||||||||||||||||||
| 2697 | - | |||||||||||||||||||
| 2698 | If \a cs is Qt::CaseSensitive (default), the search is case | - | ||||||||||||||||||
| 2699 | sensitive; otherwise the search is case insensitive. | - | ||||||||||||||||||
| 2700 | - | |||||||||||||||||||
| 2701 | \note The text is not rescanned after a replacement. | - | ||||||||||||||||||
| 2702 | */ | - | ||||||||||||||||||
| 2703 | QString &QString::replace(const QString &before, QLatin1String after, Qt::CaseSensitivity cs) | - | ||||||||||||||||||
| 2704 | { | - | ||||||||||||||||||
| 2705 | int alen = after.size(); | - | ||||||||||||||||||
| 2706 | QVarLengthArray<ushort> a(alen); | - | ||||||||||||||||||
| 2707 | qt_from_latin1(a.data(), after.latin1(), alen); | - | ||||||||||||||||||
| 2708 | 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 | ||||||||||||||||||
| 2709 | } | - | ||||||||||||||||||
| 2710 | - | |||||||||||||||||||
| 2711 | /*! | - | ||||||||||||||||||
| 2712 | \since 4.5 | - | ||||||||||||||||||
| 2713 | \overload replace() | - | ||||||||||||||||||
| 2714 | - | |||||||||||||||||||
| 2715 | Replaces every occurrence of the character \a c with the string \a | - | ||||||||||||||||||
| 2716 | after and returns a reference to this string. | - | ||||||||||||||||||
| 2717 | - | |||||||||||||||||||
| 2718 | If \a cs is Qt::CaseSensitive (default), the search is case | - | ||||||||||||||||||
| 2719 | sensitive; otherwise the search is case insensitive. | - | ||||||||||||||||||
| 2720 | - | |||||||||||||||||||
| 2721 | \note The text is not rescanned after a replacement. | - | ||||||||||||||||||
| 2722 | */ | - | ||||||||||||||||||
| 2723 | QString &QString::replace(QChar c, QLatin1String after, Qt::CaseSensitivity cs) | - | ||||||||||||||||||
| 2724 | { | - | ||||||||||||||||||
| 2725 | int alen = after.size(); | - | ||||||||||||||||||
| 2726 | QVarLengthArray<ushort> a(alen); | - | ||||||||||||||||||
| 2727 | qt_from_latin1(a.data(), after.latin1(), alen); | - | ||||||||||||||||||
| 2728 | return replace(&c, 1, (const QChar *)a.data(), alen, cs); executed 24942 times by 71 tests: return replace(&c, 1, (const QChar *)a.data(), alen, cs);Executed by:
| 24942 | ||||||||||||||||||
| 2729 | } | - | ||||||||||||||||||
| 2730 | - | |||||||||||||||||||
| 2731 | - | |||||||||||||||||||
| 2732 | /*! | - | ||||||||||||||||||
| 2733 | \relates QString | - | ||||||||||||||||||
| 2734 | Returns \c true if string \a s1 is equal to string \a s2; otherwise | - | ||||||||||||||||||
| 2735 | returns \c false. | - | ||||||||||||||||||
| 2736 | - | |||||||||||||||||||
| 2737 | The comparison is based exclusively on the numeric Unicode values of | - | ||||||||||||||||||
| 2738 | the characters and is very fast, but is not what a human would | - | ||||||||||||||||||
| 2739 | expect. Consider sorting user-interface strings with | - | ||||||||||||||||||
| 2740 | localeAwareCompare(). | - | ||||||||||||||||||
| 2741 | */ | - | ||||||||||||||||||
| 2742 | bool operator==(const QString &s1, const QString &s2) Q_DECL_NOTHROW | - | ||||||||||||||||||
| 2743 | { | - | ||||||||||||||||||
| 2744 | if (s1.d->size != s2.d->size)
| 358990-2791400 | ||||||||||||||||||
| 2745 | return false; executed 358990 times by 302 tests: return false;Executed by:
| 358990 | ||||||||||||||||||
| 2746 | - | |||||||||||||||||||
| 2747 | return qMemEquals(s1.d->data(), s2.d->data(), s1.d->size); executed 2791400 times by 526 tests: return qMemEquals(s1.d->data(), s2.d->data(), s1.d->size);Executed by:
| 2791400 | ||||||||||||||||||
| 2748 | } | - | ||||||||||||||||||
| 2749 | - | |||||||||||||||||||
| 2750 | /*! | - | ||||||||||||||||||
| 2751 | \overload operator==() | - | ||||||||||||||||||
| 2752 | Returns \c true if this string is equal to \a other; otherwise | - | ||||||||||||||||||
| 2753 | returns \c false. | - | ||||||||||||||||||
| 2754 | */ | - | ||||||||||||||||||
| 2755 | bool QString::operator==(QLatin1String other) const Q_DECL_NOTHROW | - | ||||||||||||||||||
| 2756 | { | - | ||||||||||||||||||
| 2757 | if (d->size != other.size())
| 195896-1117851 | ||||||||||||||||||
| 2758 | return false; executed 1117851 times by 341 tests: return false;Executed by:
| 1117851 | ||||||||||||||||||
| 2759 | - | |||||||||||||||||||
| 2760 | if (!other.size())
| 4-195892 | ||||||||||||||||||
| 2761 | return isEmpty(); executed 4 times by 1 test: return isEmpty();Executed by:
| 4 | ||||||||||||||||||
| 2762 | - | |||||||||||||||||||
| 2763 | return compare_helper(data(), size(), other, Qt::CaseSensitive) == 0; executed 195892 times by 444 tests: return compare_helper(data(), size(), other, Qt::CaseSensitive) == 0;Executed by:
| 195892 | ||||||||||||||||||
| 2764 | } | - | ||||||||||||||||||
| 2765 | - | |||||||||||||||||||
| 2766 | /*! \fn bool QString::operator==(const QByteArray &other) const | - | ||||||||||||||||||
| 2767 | - | |||||||||||||||||||
| 2768 | \overload operator==() | - | ||||||||||||||||||
| 2769 | - | |||||||||||||||||||
| 2770 | The \a other byte array is converted to a QString using the | - | ||||||||||||||||||
| 2771 | fromUtf8() function. This function stops conversion at the | - | ||||||||||||||||||
| 2772 | first NUL character found, or the end of the byte array. | - | ||||||||||||||||||
| 2773 | - | |||||||||||||||||||
| 2774 | You can disable this operator by defining \c | - | ||||||||||||||||||
| 2775 | QT_NO_CAST_FROM_ASCII when you compile your applications. This | - | ||||||||||||||||||
| 2776 | can be useful if you want to ensure that all user-visible strings | - | ||||||||||||||||||
| 2777 | go through QObject::tr(), for example. | - | ||||||||||||||||||
| 2778 | - | |||||||||||||||||||
| 2779 | Returns \c true if this string is lexically equal to the parameter | - | ||||||||||||||||||
| 2780 | string \a other. Otherwise returns \c false. | - | ||||||||||||||||||
| 2781 | */ | - | ||||||||||||||||||
| 2782 | - | |||||||||||||||||||
| 2783 | /*! \fn bool QString::operator==(const char *other) const | - | ||||||||||||||||||
| 2784 | - | |||||||||||||||||||
| 2785 | \overload operator==() | - | ||||||||||||||||||
| 2786 | - | |||||||||||||||||||
| 2787 | The \a other const char pointer is converted to a QString using | - | ||||||||||||||||||
| 2788 | the fromUtf8() function. | - | ||||||||||||||||||
| 2789 | - | |||||||||||||||||||
| 2790 | You can disable this operator by defining \c | - | ||||||||||||||||||
| 2791 | QT_NO_CAST_FROM_ASCII when you compile your applications. This | - | ||||||||||||||||||
| 2792 | can be useful if you want to ensure that all user-visible strings | - | ||||||||||||||||||
| 2793 | go through QObject::tr(), for example. | - | ||||||||||||||||||
| 2794 | */ | - | ||||||||||||||||||
| 2795 | - | |||||||||||||||||||
| 2796 | /*! | - | ||||||||||||||||||
| 2797 | \relates QString | - | ||||||||||||||||||
| 2798 | Returns \c true if string \a s1 is lexically less than string | - | ||||||||||||||||||
| 2799 | \a s2; otherwise returns \c false. | - | ||||||||||||||||||
| 2800 | - | |||||||||||||||||||
| 2801 | The comparison is based exclusively on the numeric Unicode values | - | ||||||||||||||||||
| 2802 | of the characters and is very fast, but is not what a human would | - | ||||||||||||||||||
| 2803 | expect. Consider sorting user-interface strings using the | - | ||||||||||||||||||
| 2804 | QString::localeAwareCompare() function. | - | ||||||||||||||||||
| 2805 | */ | - | ||||||||||||||||||
| 2806 | bool operator<(const QString &s1, const QString &s2) Q_DECL_NOTHROW | - | ||||||||||||||||||
| 2807 | { | - | ||||||||||||||||||
| 2808 | return ucstrcmp(s1.constData(), s1.length(), s2.constData(), s2.length()) < 0; executed 1719191 times by 420 tests: return ucstrcmp(s1.constData(), s1.length(), s2.constData(), s2.length()) < 0;Executed by:
| 1719191 | ||||||||||||||||||
| 2809 | } | - | ||||||||||||||||||
| 2810 | /*! | - | ||||||||||||||||||
| 2811 | \overload operator<() | - | ||||||||||||||||||
| 2812 | - | |||||||||||||||||||
| 2813 | Returns \c true if this string is lexically less than the parameter | - | ||||||||||||||||||
| 2814 | string called \a other; otherwise returns \c false. | - | ||||||||||||||||||
| 2815 | */ | - | ||||||||||||||||||
| 2816 | bool QString::operator<(QLatin1String other) const Q_DECL_NOTHROW | - | ||||||||||||||||||
| 2817 | { | - | ||||||||||||||||||
| 2818 | const uchar *c = (const uchar *) other.latin1(); | - | ||||||||||||||||||
| 2819 | if (!c || *c == 0)
| 5-2354 | ||||||||||||||||||
| 2820 | return false; executed 12 times by 1 test: return false;Executed by:
| 12 | ||||||||||||||||||
| 2821 | - | |||||||||||||||||||
| 2822 | return compare_helper(data(), size(), other, Qt::CaseSensitive) < 0; executed 2347 times by 19 tests: return compare_helper(data(), size(), other, Qt::CaseSensitive) < 0;Executed by:
| 2347 | ||||||||||||||||||
| 2823 | } | - | ||||||||||||||||||
| 2824 | - | |||||||||||||||||||
| 2825 | /*! \fn bool QString::operator<(const QByteArray &other) const | - | ||||||||||||||||||
| 2826 | - | |||||||||||||||||||
| 2827 | \overload operator<() | - | ||||||||||||||||||
| 2828 | - | |||||||||||||||||||
| 2829 | The \a other byte array is converted to a QString using the | - | ||||||||||||||||||
| 2830 | fromUtf8() function. If any NUL characters ('\\0') are embedded | - | ||||||||||||||||||
| 2831 | in the byte array, they will be included in the transformation. | - | ||||||||||||||||||
| 2832 | - | |||||||||||||||||||
| 2833 | You can disable this operator by defining \c | - | ||||||||||||||||||
| 2834 | QT_NO_CAST_FROM_ASCII when you compile your applications. This | - | ||||||||||||||||||
| 2835 | can be useful if you want to ensure that all user-visible strings | - | ||||||||||||||||||
| 2836 | go through QObject::tr(), for example. | - | ||||||||||||||||||
| 2837 | */ | - | ||||||||||||||||||
| 2838 | - | |||||||||||||||||||
| 2839 | /*! \fn bool QString::operator<(const char *other) const | - | ||||||||||||||||||
| 2840 | - | |||||||||||||||||||
| 2841 | Returns \c true if this string is lexically less than string \a other. | - | ||||||||||||||||||
| 2842 | Otherwise returns \c false. | - | ||||||||||||||||||
| 2843 | - | |||||||||||||||||||
| 2844 | \overload operator<() | - | ||||||||||||||||||
| 2845 | - | |||||||||||||||||||
| 2846 | The \a other const char pointer is converted to a QString using | - | ||||||||||||||||||
| 2847 | the fromUtf8() function. | - | ||||||||||||||||||
| 2848 | - | |||||||||||||||||||
| 2849 | You can disable this operator by defining \c | - | ||||||||||||||||||
| 2850 | QT_NO_CAST_FROM_ASCII when you compile your applications. This | - | ||||||||||||||||||
| 2851 | can be useful if you want to ensure that all user-visible strings | - | ||||||||||||||||||
| 2852 | go through QObject::tr(), for example. | - | ||||||||||||||||||
| 2853 | */ | - | ||||||||||||||||||
| 2854 | - | |||||||||||||||||||
| 2855 | /*! \fn bool operator<=(const QString &s1, const QString &s2) | - | ||||||||||||||||||
| 2856 | - | |||||||||||||||||||
| 2857 | \relates QString | - | ||||||||||||||||||
| 2858 | - | |||||||||||||||||||
| 2859 | Returns \c true if string \a s1 is lexically less than or equal to | - | ||||||||||||||||||
| 2860 | string \a s2; otherwise returns \c false. | - | ||||||||||||||||||
| 2861 | - | |||||||||||||||||||
| 2862 | The comparison is based exclusively on the numeric Unicode values | - | ||||||||||||||||||
| 2863 | of the characters and is very fast, but is not what a human would | - | ||||||||||||||||||
| 2864 | expect. Consider sorting user-interface strings with | - | ||||||||||||||||||
| 2865 | localeAwareCompare(). | - | ||||||||||||||||||
| 2866 | */ | - | ||||||||||||||||||
| 2867 | - | |||||||||||||||||||
| 2868 | /*! \fn bool QString::operator<=(QLatin1String other) const | - | ||||||||||||||||||
| 2869 | - | |||||||||||||||||||
| 2870 | Returns \c true if this string is lexically less than or equal to | - | ||||||||||||||||||
| 2871 | parameter string \a other. Otherwise returns \c false. | - | ||||||||||||||||||
| 2872 | - | |||||||||||||||||||
| 2873 | \overload operator<=() | - | ||||||||||||||||||
| 2874 | */ | - | ||||||||||||||||||
| 2875 | - | |||||||||||||||||||
| 2876 | /*! \fn bool QString::operator<=(const QByteArray &other) const | - | ||||||||||||||||||
| 2877 | - | |||||||||||||||||||
| 2878 | \overload operator<=() | - | ||||||||||||||||||
| 2879 | - | |||||||||||||||||||
| 2880 | The \a other byte array is converted to a QString using the | - | ||||||||||||||||||
| 2881 | fromUtf8() function. If any NUL characters ('\\0') are embedded | - | ||||||||||||||||||
| 2882 | in the byte array, they will be included in the transformation. | - | ||||||||||||||||||
| 2883 | - | |||||||||||||||||||
| 2884 | You can disable this operator by defining \c | - | ||||||||||||||||||
| 2885 | QT_NO_CAST_FROM_ASCII when you compile your applications. This | - | ||||||||||||||||||
| 2886 | can be useful if you want to ensure that all user-visible strings | - | ||||||||||||||||||
| 2887 | go through QObject::tr(), for example. | - | ||||||||||||||||||
| 2888 | */ | - | ||||||||||||||||||
| 2889 | - | |||||||||||||||||||
| 2890 | /*! \fn bool QString::operator<=(const char *other) const | - | ||||||||||||||||||
| 2891 | - | |||||||||||||||||||
| 2892 | \overload operator<=() | - | ||||||||||||||||||
| 2893 | - | |||||||||||||||||||
| 2894 | The \a other const char pointer is converted to a QString using | - | ||||||||||||||||||
| 2895 | the fromUtf8() function. | - | ||||||||||||||||||
| 2896 | - | |||||||||||||||||||
| 2897 | You can disable this operator by defining \c | - | ||||||||||||||||||
| 2898 | QT_NO_CAST_FROM_ASCII when you compile your applications. This | - | ||||||||||||||||||
| 2899 | can be useful if you want to ensure that all user-visible strings | - | ||||||||||||||||||
| 2900 | go through QObject::tr(), for example. | - | ||||||||||||||||||
| 2901 | */ | - | ||||||||||||||||||
| 2902 | - | |||||||||||||||||||
| 2903 | /*! \fn bool operator>(const QString &s1, const QString &s2) | - | ||||||||||||||||||
| 2904 | \relates QString | - | ||||||||||||||||||
| 2905 | - | |||||||||||||||||||
| 2906 | Returns \c true if string \a s1 is lexically greater than string \a s2; | - | ||||||||||||||||||
| 2907 | otherwise returns \c false. | - | ||||||||||||||||||
| 2908 | - | |||||||||||||||||||
| 2909 | The comparison is based exclusively on the numeric Unicode values | - | ||||||||||||||||||
| 2910 | of the characters and is very fast, but is not what a human would | - | ||||||||||||||||||
| 2911 | expect. Consider sorting user-interface strings with | - | ||||||||||||||||||
| 2912 | localeAwareCompare(). | - | ||||||||||||||||||
| 2913 | */ | - | ||||||||||||||||||
| 2914 | - | |||||||||||||||||||
| 2915 | /*! | - | ||||||||||||||||||
| 2916 | \overload operator>() | - | ||||||||||||||||||
| 2917 | - | |||||||||||||||||||
| 2918 | Returns \c true if this string is lexically greater than the parameter | - | ||||||||||||||||||
| 2919 | string \a other; otherwise returns \c false. | - | ||||||||||||||||||
| 2920 | */ | - | ||||||||||||||||||
| 2921 | bool QString::operator>(QLatin1String other) const Q_DECL_NOTHROW | - | ||||||||||||||||||
| 2922 | { | - | ||||||||||||||||||
| 2923 | const uchar *c = (const uchar *) other.latin1(); | - | ||||||||||||||||||
| 2924 | if (!c || *c == '\0')
| 5-17569 | ||||||||||||||||||
| 2925 | return !isEmpty(); executed 12 times by 1 test: return !isEmpty();Executed by:
| 12 | ||||||||||||||||||
| 2926 | - | |||||||||||||||||||
| 2927 | return compare_helper(data(), size(), other, Qt::CaseSensitive) > 0; executed 17562 times by 27 tests: return compare_helper(data(), size(), other, Qt::CaseSensitive) > 0;Executed by:
| 17562 | ||||||||||||||||||
| 2928 | } | - | ||||||||||||||||||
| 2929 | - | |||||||||||||||||||
| 2930 | /*! \fn bool QString::operator>(const QByteArray &other) const | - | ||||||||||||||||||
| 2931 | - | |||||||||||||||||||
| 2932 | \overload operator>() | - | ||||||||||||||||||
| 2933 | - | |||||||||||||||||||
| 2934 | The \a other byte array is converted to a QString using the | - | ||||||||||||||||||
| 2935 | fromUtf8() function. If any NUL characters ('\\0') are embedded | - | ||||||||||||||||||
| 2936 | in the byte array, they will be included in the transformation. | - | ||||||||||||||||||
| 2937 | - | |||||||||||||||||||
| 2938 | You can disable this operator by defining \c | - | ||||||||||||||||||
| 2939 | QT_NO_CAST_FROM_ASCII when you compile your applications. This | - | ||||||||||||||||||
| 2940 | can be useful if you want to ensure that all user-visible strings | - | ||||||||||||||||||
| 2941 | go through QObject::tr(), for example. | - | ||||||||||||||||||
| 2942 | */ | - | ||||||||||||||||||
| 2943 | - | |||||||||||||||||||
| 2944 | /*! \fn bool QString::operator>(const char *other) const | - | ||||||||||||||||||
| 2945 | - | |||||||||||||||||||
| 2946 | \overload operator>() | - | ||||||||||||||||||
| 2947 | - | |||||||||||||||||||
| 2948 | The \a other const char pointer is converted to a QString using | - | ||||||||||||||||||
| 2949 | the fromUtf8() function. | - | ||||||||||||||||||
| 2950 | - | |||||||||||||||||||
| 2951 | You can disable this operator by defining \c QT_NO_CAST_FROM_ASCII | - | ||||||||||||||||||
| 2952 | when you compile your applications. This can be useful if you want | - | ||||||||||||||||||
| 2953 | to ensure that all user-visible strings go through QObject::tr(), | - | ||||||||||||||||||
| 2954 | for example. | - | ||||||||||||||||||
| 2955 | */ | - | ||||||||||||||||||
| 2956 | - | |||||||||||||||||||
| 2957 | /*! \fn bool operator>=(const QString &s1, const QString &s2) | - | ||||||||||||||||||
| 2958 | \relates QString | - | ||||||||||||||||||
| 2959 | - | |||||||||||||||||||
| 2960 | Returns \c true if string \a s1 is lexically greater than or equal to | - | ||||||||||||||||||
| 2961 | string \a s2; otherwise returns \c false. | - | ||||||||||||||||||
| 2962 | - | |||||||||||||||||||
| 2963 | The comparison is based exclusively on the numeric Unicode values | - | ||||||||||||||||||
| 2964 | of the characters and is very fast, but is not what a human would | - | ||||||||||||||||||
| 2965 | expect. Consider sorting user-interface strings with | - | ||||||||||||||||||
| 2966 | localeAwareCompare(). | - | ||||||||||||||||||
| 2967 | */ | - | ||||||||||||||||||
| 2968 | - | |||||||||||||||||||
| 2969 | /*! \fn bool QString::operator>=(QLatin1String other) const | - | ||||||||||||||||||
| 2970 | - | |||||||||||||||||||
| 2971 | Returns \c true if this string is lexically greater than or equal to parameter | - | ||||||||||||||||||
| 2972 | string \a other. Otherwise returns \c false. | - | ||||||||||||||||||
| 2973 | - | |||||||||||||||||||
| 2974 | \overload operator>=() | - | ||||||||||||||||||
| 2975 | */ | - | ||||||||||||||||||
| 2976 | - | |||||||||||||||||||
| 2977 | /*! \fn bool QString::operator>=(const QByteArray &other) const | - | ||||||||||||||||||
| 2978 | - | |||||||||||||||||||
| 2979 | \overload operator>=() | - | ||||||||||||||||||
| 2980 | - | |||||||||||||||||||
| 2981 | The \a other byte array is converted to a QString using the | - | ||||||||||||||||||
| 2982 | fromUtf8() function. If any NUL characters ('\\0') are embedded in | - | ||||||||||||||||||
| 2983 | the byte array, they will be included in the transformation. | - | ||||||||||||||||||
| 2984 | - | |||||||||||||||||||
| 2985 | You can disable this operator by defining \c QT_NO_CAST_FROM_ASCII | - | ||||||||||||||||||
| 2986 | when you compile your applications. This can be useful if you want | - | ||||||||||||||||||
| 2987 | to ensure that all user-visible strings go through QObject::tr(), | - | ||||||||||||||||||
| 2988 | for example. | - | ||||||||||||||||||
| 2989 | */ | - | ||||||||||||||||||
| 2990 | - | |||||||||||||||||||
| 2991 | /*! \fn bool QString::operator>=(const char *other) const | - | ||||||||||||||||||
| 2992 | - | |||||||||||||||||||
| 2993 | \overload operator>=() | - | ||||||||||||||||||
| 2994 | - | |||||||||||||||||||
| 2995 | The \a other const char pointer is converted to a QString using | - | ||||||||||||||||||
| 2996 | the fromUtf8() function. | - | ||||||||||||||||||
| 2997 | - | |||||||||||||||||||
| 2998 | You can disable this operator by defining \c QT_NO_CAST_FROM_ASCII | - | ||||||||||||||||||
| 2999 | when you compile your applications. This can be useful if you want | - | ||||||||||||||||||
| 3000 | to ensure that all user-visible strings go through QObject::tr(), | - | ||||||||||||||||||
| 3001 | for example. | - | ||||||||||||||||||
| 3002 | */ | - | ||||||||||||||||||
| 3003 | - | |||||||||||||||||||
| 3004 | /*! \fn bool operator!=(const QString &s1, const QString &s2) | - | ||||||||||||||||||
| 3005 | \relates QString | - | ||||||||||||||||||
| 3006 | - | |||||||||||||||||||
| 3007 | Returns \c true if string \a s1 is not equal to string \a s2; | - | ||||||||||||||||||
| 3008 | otherwise returns \c false. | - | ||||||||||||||||||
| 3009 | - | |||||||||||||||||||
| 3010 | The comparison is based exclusively on the numeric Unicode values | - | ||||||||||||||||||
| 3011 | of the characters and is very fast, but is not what a human would | - | ||||||||||||||||||
| 3012 | expect. Consider sorting user-interface strings with | - | ||||||||||||||||||
| 3013 | localeAwareCompare(). | - | ||||||||||||||||||
| 3014 | */ | - | ||||||||||||||||||
| 3015 | - | |||||||||||||||||||
| 3016 | /*! \fn bool QString::operator!=(QLatin1String other) const | - | ||||||||||||||||||
| 3017 | - | |||||||||||||||||||
| 3018 | Returns \c true if this string is not equal to parameter string \a other. | - | ||||||||||||||||||
| 3019 | Otherwise returns \c false. | - | ||||||||||||||||||
| 3020 | - | |||||||||||||||||||
| 3021 | \overload operator!=() | - | ||||||||||||||||||
| 3022 | */ | - | ||||||||||||||||||
| 3023 | - | |||||||||||||||||||
| 3024 | /*! \fn bool QString::operator!=(const QByteArray &other) const | - | ||||||||||||||||||
| 3025 | - | |||||||||||||||||||
| 3026 | \overload operator!=() | - | ||||||||||||||||||
| 3027 | - | |||||||||||||||||||
| 3028 | The \a other byte array is converted to a QString using the | - | ||||||||||||||||||
| 3029 | fromUtf8() function. If any NUL characters ('\\0') are embedded | - | ||||||||||||||||||
| 3030 | in the byte array, they will be included in the transformation. | - | ||||||||||||||||||
| 3031 | - | |||||||||||||||||||
| 3032 | You can disable this operator by defining \c QT_NO_CAST_FROM_ASCII | - | ||||||||||||||||||
| 3033 | when you compile your applications. This can be useful if you want | - | ||||||||||||||||||
| 3034 | to ensure that all user-visible strings go through QObject::tr(), | - | ||||||||||||||||||
| 3035 | for example. | - | ||||||||||||||||||
| 3036 | */ | - | ||||||||||||||||||
| 3037 | - | |||||||||||||||||||
| 3038 | /*! \fn bool QString::operator!=(const char *other) const | - | ||||||||||||||||||
| 3039 | - | |||||||||||||||||||
| 3040 | \overload operator!=() | - | ||||||||||||||||||
| 3041 | - | |||||||||||||||||||
| 3042 | The \a other const char pointer is converted to a QString using | - | ||||||||||||||||||
| 3043 | the fromUtf8() function. | - | ||||||||||||||||||
| 3044 | - | |||||||||||||||||||
| 3045 | You can disable this operator by defining \c | - | ||||||||||||||||||
| 3046 | QT_NO_CAST_FROM_ASCII when you compile your applications. This | - | ||||||||||||||||||
| 3047 | can be useful if you want to ensure that all user-visible strings | - | ||||||||||||||||||
| 3048 | go through QObject::tr(), for example. | - | ||||||||||||||||||
| 3049 | */ | - | ||||||||||||||||||
| 3050 | - | |||||||||||||||||||
| 3051 | /*! | - | ||||||||||||||||||
| 3052 | Returns the index position of the first occurrence of the string \a | - | ||||||||||||||||||
| 3053 | str in this string, searching forward from index position \a | - | ||||||||||||||||||
| 3054 | from. Returns -1 if \a str is not found. | - | ||||||||||||||||||
| 3055 | - | |||||||||||||||||||
| 3056 | If \a cs is Qt::CaseSensitive (default), the search is case | - | ||||||||||||||||||
| 3057 | sensitive; otherwise the search is case insensitive. | - | ||||||||||||||||||
| 3058 | - | |||||||||||||||||||
| 3059 | Example: | - | ||||||||||||||||||
| 3060 | - | |||||||||||||||||||
| 3061 | \snippet qstring/main.cpp 24 | - | ||||||||||||||||||
| 3062 | - | |||||||||||||||||||
| 3063 | If \a from is -1, the search starts at the last character; if it is | - | ||||||||||||||||||
| 3064 | -2, at the next to last character and so on. | - | ||||||||||||||||||
| 3065 | - | |||||||||||||||||||
| 3066 | \sa lastIndexOf(), contains(), count() | - | ||||||||||||||||||
| 3067 | */ | - | ||||||||||||||||||
| 3068 | int QString::indexOf(const QString &str, int from, Qt::CaseSensitivity cs) const | - | ||||||||||||||||||
| 3069 | { | - | ||||||||||||||||||
| 3070 | return qFindString(unicode(), length(), from, str.unicode(), str.length(), cs); executed 899908 times by 83 tests: return qFindString(unicode(), length(), from, str.unicode(), str.length(), cs);Executed by:
| 899908 | ||||||||||||||||||
| 3071 | } | - | ||||||||||||||||||
| 3072 | - | |||||||||||||||||||
| 3073 | /*! | - | ||||||||||||||||||
| 3074 | \since 4.5 | - | ||||||||||||||||||
| 3075 | Returns the index position of the first occurrence of the string \a | - | ||||||||||||||||||
| 3076 | str in this string, searching forward from index position \a | - | ||||||||||||||||||
| 3077 | from. Returns -1 if \a str is not found. | - | ||||||||||||||||||
| 3078 | - | |||||||||||||||||||
| 3079 | If \a cs is Qt::CaseSensitive (default), the search is case | - | ||||||||||||||||||
| 3080 | sensitive; otherwise the search is case insensitive. | - | ||||||||||||||||||
| 3081 | - | |||||||||||||||||||
| 3082 | Example: | - | ||||||||||||||||||
| 3083 | - | |||||||||||||||||||
| 3084 | \snippet qstring/main.cpp 24 | - | ||||||||||||||||||
| 3085 | - | |||||||||||||||||||
| 3086 | If \a from is -1, the search starts at the last character; if it is | - | ||||||||||||||||||
| 3087 | -2, at the next to last character and so on. | - | ||||||||||||||||||
| 3088 | - | |||||||||||||||||||
| 3089 | \sa lastIndexOf(), contains(), count() | - | ||||||||||||||||||
| 3090 | */ | - | ||||||||||||||||||
| 3091 | - | |||||||||||||||||||
| 3092 | int QString::indexOf(QLatin1String str, int from, Qt::CaseSensitivity cs) const | - | ||||||||||||||||||
| 3093 | { | - | ||||||||||||||||||
| 3094 | return qt_find_latin1_string(unicode(), size(), str, from, cs); executed 10519 times by 181 tests: return qt_find_latin1_string(unicode(), size(), str, from, cs);Executed by:
| 10519 | ||||||||||||||||||
| 3095 | } | - | ||||||||||||||||||
| 3096 | - | |||||||||||||||||||
| 3097 | int qFindString( | - | ||||||||||||||||||
| 3098 | const QChar *haystack0, int haystackLen, int from, | - | ||||||||||||||||||
| 3099 | const QChar *needle0, int needleLen, Qt::CaseSensitivity cs) | - | ||||||||||||||||||
| 3100 | { | - | ||||||||||||||||||
| 3101 | const int l = haystackLen; | - | ||||||||||||||||||
| 3102 | const int sl = needleLen; | - | ||||||||||||||||||
| 3103 | if (from < 0)
| 0-1477224 | ||||||||||||||||||
| 3104 | from += l; never executed: from += l; | 0 | ||||||||||||||||||
| 3105 | if (uint(sl + from) > (uint)l)
| 47418-1429806 | ||||||||||||||||||
| 3106 | return -1; executed 47418 times by 88 tests: return -1;Executed by:
| 47418 | ||||||||||||||||||
| 3107 | if (!sl)
| 392-1429414 | ||||||||||||||||||
| 3108 | return from; executed 392 times by 12 tests: return from;Executed by:
| 392 | ||||||||||||||||||
| 3109 | if (!l)
| 0-1429414 | ||||||||||||||||||
| 3110 | return -1; never executed: return -1; | 0 | ||||||||||||||||||
| 3111 | - | |||||||||||||||||||
| 3112 | if (sl == 1)
| 523575-905839 | ||||||||||||||||||
| 3113 | return findChar(haystack0, haystackLen, needle0[0], from, cs); executed 523575 times by 271 tests: return findChar(haystack0, haystackLen, needle0[0], from, cs);Executed by:
| 523575 | ||||||||||||||||||
| 3114 | - | |||||||||||||||||||
| 3115 | /* | - | ||||||||||||||||||
| 3116 | We use the Boyer-Moore algorithm in cases where the overhead | - | ||||||||||||||||||
| 3117 | for the skip table should pay off, otherwise we use a simple | - | ||||||||||||||||||
| 3118 | hash function. | - | ||||||||||||||||||
| 3119 | */ | - | ||||||||||||||||||
| 3120 | if (l > 500 && sl > 5)
| 19-905644 | ||||||||||||||||||
| 3121 | return qFindStringBoyerMoore(haystack0, haystackLen, from, executed 176 times by 12 tests: return qFindStringBoyerMoore(haystack0, haystackLen, from, needle0, needleLen, cs);Executed by:
| 176 | ||||||||||||||||||
| 3122 | needle0, needleLen, cs); executed 176 times by 12 tests: return qFindStringBoyerMoore(haystack0, haystackLen, from, needle0, needleLen, cs);Executed by:
| 176 | ||||||||||||||||||
| 3123 | - | |||||||||||||||||||
| 3124 | /* | - | ||||||||||||||||||
| 3125 | We use some hashing for efficiency's sake. Instead of | - | ||||||||||||||||||
| 3126 | comparing strings, we compare the hash value of str with that | - | ||||||||||||||||||
| 3127 | of a part of this QString. Only if that matches, we call | - | ||||||||||||||||||
| 3128 | ucstrncmp() or ucstrnicmp(). | - | ||||||||||||||||||
| 3129 | */ | - | ||||||||||||||||||
| 3130 | const ushort *needle = (const ushort *)needle0; | - | ||||||||||||||||||
| 3131 | const ushort *haystack = (const ushort *)haystack0 + from; | - | ||||||||||||||||||
| 3132 | const ushort *end = (const ushort *)haystack0 + (l-sl); | - | ||||||||||||||||||
| 3133 | const uint sl_minus_1 = sl - 1; | - | ||||||||||||||||||
| 3134 | uint hashNeedle = 0, hashHaystack = 0; | - | ||||||||||||||||||
| 3135 | int idx; | - | ||||||||||||||||||
| 3136 | - | |||||||||||||||||||
| 3137 | if (cs == Qt::CaseSensitive) {
| 1318-904345 | ||||||||||||||||||
| 3138 | for (idx = 0; idx < sl; ++idx) {
| 904345-4502412 | ||||||||||||||||||
| 3139 | hashNeedle = ((hashNeedle<<1) + needle[idx]); | - | ||||||||||||||||||
| 3140 | hashHaystack = ((hashHaystack<<1) + haystack[idx]); | - | ||||||||||||||||||
| 3141 | } executed 4502412 times by 206 tests: end of blockExecuted by:
| 4502412 | ||||||||||||||||||
| 3142 | hashHaystack -= haystack[sl_minus_1]; | - | ||||||||||||||||||
| 3143 | - | |||||||||||||||||||
| 3144 | while (haystack <= end) {
| 612933-5114794 | ||||||||||||||||||
| 3145 | hashHaystack += haystack[sl_minus_1]; | - | ||||||||||||||||||
| 3146 | if (hashHaystack == hashNeedle
| 291572-4823222 | ||||||||||||||||||
| 3147 | && ucstrncmp((const QChar *)needle, (const QChar *)haystack, sl) == 0)
| 160-291412 | ||||||||||||||||||
| 3148 | return haystack - (const ushort *)haystack0; executed 291412 times by 67 tests: return haystack - (const ushort *)haystack0;Executed by:
| 291412 | ||||||||||||||||||
| 3149 | - | |||||||||||||||||||
| 3150 | REHASH(*haystack); executed 4821888 times by 205 tests: hashHaystack -= uint(*haystack) << sl_minus_1;Executed by:
| 1494-4821888 | ||||||||||||||||||
| 3151 | ++haystack; | - | ||||||||||||||||||
| 3152 | } executed 4823382 times by 205 tests: end of blockExecuted by:
| 4823382 | ||||||||||||||||||
| 3153 | } else { executed 612933 times by 193 tests: end of blockExecuted by:
| 612933 | ||||||||||||||||||
| 3154 | const ushort *haystack_start = (const ushort *)haystack0; | - | ||||||||||||||||||
| 3155 | for (idx = 0; idx < sl; ++idx) {
| 1318-4376 | ||||||||||||||||||
| 3156 | hashNeedle = (hashNeedle<<1) + foldCase(needle + idx, needle); | - | ||||||||||||||||||
| 3157 | hashHaystack = (hashHaystack<<1) + foldCase(haystack + idx, haystack_start); | - | ||||||||||||||||||
| 3158 | } executed 4376 times by 18 tests: end of blockExecuted by:
| 4376 | ||||||||||||||||||
| 3159 | hashHaystack -= foldCase(haystack + sl_minus_1, haystack_start); | - | ||||||||||||||||||
| 3160 | - | |||||||||||||||||||
| 3161 | while (haystack <= end) {
| 219-3265 | ||||||||||||||||||
| 3162 | hashHaystack += foldCase(haystack + sl_minus_1, haystack_start); | - | ||||||||||||||||||
| 3163 | if (hashHaystack == hashNeedle && ucstrnicmp(needle, haystack, sl) == 0)
| 3-2163 | ||||||||||||||||||
| 3164 | return haystack - (const ushort *)haystack0; executed 1099 times by 13 tests: return haystack - (const ushort *)haystack0;Executed by:
| 1099 | ||||||||||||||||||
| 3165 | - | |||||||||||||||||||
| 3166 | REHASH(foldCase(haystack, haystack_start)); executed 1981 times by 17 tests: hashHaystack -= uint(foldCase(haystack, haystack_start)) << sl_minus_1;Executed by:
| 185-1981 | ||||||||||||||||||
| 3167 | ++haystack; | - | ||||||||||||||||||
| 3168 | } executed 2166 times by 17 tests: end of blockExecuted by:
| 2166 | ||||||||||||||||||
| 3169 | } executed 219 times by 17 tests: end of blockExecuted by:
| 219 | ||||||||||||||||||
| 3170 | return -1; executed 613152 times by 198 tests: return -1;Executed by:
| 613152 | ||||||||||||||||||
| 3171 | } | - | ||||||||||||||||||
| 3172 | - | |||||||||||||||||||
| 3173 | /*! | - | ||||||||||||||||||
| 3174 | \overload indexOf() | - | ||||||||||||||||||
| 3175 | - | |||||||||||||||||||
| 3176 | Returns the index position of the first occurrence of the | - | ||||||||||||||||||
| 3177 | character \a ch in the string, searching forward from index | - | ||||||||||||||||||
| 3178 | position \a from. Returns -1 if \a ch could not be found. | - | ||||||||||||||||||
| 3179 | */ | - | ||||||||||||||||||
| 3180 | int QString::indexOf(QChar ch, int from, Qt::CaseSensitivity cs) const | - | ||||||||||||||||||
| 3181 | { | - | ||||||||||||||||||
| 3182 | return findChar(unicode(), length(), ch, from, cs); executed 907496 times by 285 tests: return findChar(unicode(), length(), ch, from, cs);Executed by:
| 907496 | ||||||||||||||||||
| 3183 | } | - | ||||||||||||||||||
| 3184 | - | |||||||||||||||||||
| 3185 | /*! | - | ||||||||||||||||||
| 3186 | \since 4.8 | - | ||||||||||||||||||
| 3187 | - | |||||||||||||||||||
| 3188 | \overload indexOf() | - | ||||||||||||||||||
| 3189 | - | |||||||||||||||||||
| 3190 | Returns the index position of the first occurrence of the string | - | ||||||||||||||||||
| 3191 | reference \a str in this string, searching forward from index | - | ||||||||||||||||||
| 3192 | position \a from. Returns -1 if \a str is not found. | - | ||||||||||||||||||
| 3193 | - | |||||||||||||||||||
| 3194 | If \a cs is Qt::CaseSensitive (default), the search is case | - | ||||||||||||||||||
| 3195 | sensitive; otherwise the search is case insensitive. | - | ||||||||||||||||||
| 3196 | */ | - | ||||||||||||||||||
| 3197 | int QString::indexOf(const QStringRef &str, int from, Qt::CaseSensitivity cs) const | - | ||||||||||||||||||
| 3198 | { | - | ||||||||||||||||||
| 3199 | 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 | ||||||||||||||||||
| 3200 | } | - | ||||||||||||||||||
| 3201 | - | |||||||||||||||||||
| 3202 | static int lastIndexOfHelper(const ushort *haystack, int from, const ushort *needle, int sl, Qt::CaseSensitivity cs) | - | ||||||||||||||||||
| 3203 | { | - | ||||||||||||||||||
| 3204 | /* | - | ||||||||||||||||||
| 3205 | See indexOf() for explanations. | - | ||||||||||||||||||
| 3206 | */ | - | ||||||||||||||||||
| 3207 | - | |||||||||||||||||||
| 3208 | const ushort *end = haystack; | - | ||||||||||||||||||
| 3209 | haystack += from; | - | ||||||||||||||||||
| 3210 | const uint sl_minus_1 = sl - 1; | - | ||||||||||||||||||
| 3211 | const ushort *n = needle+sl_minus_1; | - | ||||||||||||||||||
| 3212 | const ushort *h = haystack+sl_minus_1; | - | ||||||||||||||||||
| 3213 | uint hashNeedle = 0, hashHaystack = 0; | - | ||||||||||||||||||
| 3214 | int idx; | - | ||||||||||||||||||
| 3215 | - | |||||||||||||||||||
| 3216 | if (cs == Qt::CaseSensitive) {
| 85-103 | ||||||||||||||||||
| 3217 | for (idx = 0; idx < sl; ++idx) {
| 85-1125 | ||||||||||||||||||
| 3218 | hashNeedle = ((hashNeedle<<1) + *(n-idx)); | - | ||||||||||||||||||
| 3219 | hashHaystack = ((hashHaystack<<1) + *(h-idx)); | - | ||||||||||||||||||
| 3220 | } executed 1125 times by 8 tests: end of blockExecuted by:
| 1125 | ||||||||||||||||||
| 3221 | hashHaystack -= *haystack; | - | ||||||||||||||||||
| 3222 | - | |||||||||||||||||||
| 3223 | while (haystack >= end) {
| 18-668 | ||||||||||||||||||
| 3224 | hashHaystack += *haystack; | - | ||||||||||||||||||
| 3225 | if (hashHaystack == hashNeedle
| 71-597 | ||||||||||||||||||
| 3226 | && ucstrncmp((const QChar *)needle, (const QChar *)haystack, sl) == 0)
| 4-67 | ||||||||||||||||||
| 3227 | return haystack - end; executed 67 times by 8 tests: return haystack - end;Executed by:
| 67 | ||||||||||||||||||
| 3228 | --haystack; | - | ||||||||||||||||||
| 3229 | REHASH(haystack[sl]); executed 465 times by 5 tests: hashHaystack -= uint(haystack[sl]) << sl_minus_1;Executed by:
| 136-465 | ||||||||||||||||||
| 3230 | } executed 601 times by 5 tests: end of blockExecuted by:
| 601 | ||||||||||||||||||
| 3231 | } else { executed 18 times by 4 tests: end of blockExecuted by:
| 18 | ||||||||||||||||||
| 3232 | for (idx = 0; idx < sl; ++idx) {
| 103-1106 | ||||||||||||||||||
| 3233 | hashNeedle = ((hashNeedle<<1) + foldCase(n-idx, needle)); | - | ||||||||||||||||||
| 3234 | hashHaystack = ((hashHaystack<<1) + foldCase(h-idx, end)); | - | ||||||||||||||||||
| 3235 | } executed 1106 times by 3 tests: end of blockExecuted by:
| 1106 | ||||||||||||||||||
| 3236 | hashHaystack -= foldCase(haystack, end); | - | ||||||||||||||||||
| 3237 | - | |||||||||||||||||||
| 3238 | while (haystack >= end) {
| 38-675 | ||||||||||||||||||
| 3239 | hashHaystack += foldCase(haystack, end); | - | ||||||||||||||||||
| 3240 | if (hashHaystack == hashNeedle && ucstrnicmp(needle, haystack, sl) == 0)
| 4-606 | ||||||||||||||||||
| 3241 | return haystack - end; executed 65 times by 3 tests: return haystack - end;Executed by:
| 65 | ||||||||||||||||||
| 3242 | --haystack; | - | ||||||||||||||||||
| 3243 | REHASH(foldCase(haystack + sl, end)); executed 474 times by 3 tests: hashHaystack -= uint(foldCase(haystack + sl, end)) << sl_minus_1;Executed by:
| 136-474 | ||||||||||||||||||
| 3244 | } executed 610 times by 3 tests: end of blockExecuted by:
| 610 | ||||||||||||||||||
| 3245 | } executed 38 times by 3 tests: end of blockExecuted by:
| 38 | ||||||||||||||||||
| 3246 | return -1; executed 56 times by 4 tests: return -1;Executed by:
| 56 | ||||||||||||||||||
| 3247 | } | - | ||||||||||||||||||
| 3248 | - | |||||||||||||||||||
| 3249 | /*! | - | ||||||||||||||||||
| 3250 | Returns the index position of the last occurrence of the string \a | - | ||||||||||||||||||
| 3251 | str in this string, searching backward from index position \a | - | ||||||||||||||||||
| 3252 | from. If \a from is -1 (default), the search starts at the last | - | ||||||||||||||||||
| 3253 | character; if \a from is -2, at the next to last character and so | - | ||||||||||||||||||
| 3254 | on. Returns -1 if \a str is not found. | - | ||||||||||||||||||
| 3255 | - | |||||||||||||||||||
| 3256 | If \a cs is Qt::CaseSensitive (default), the search is case | - | ||||||||||||||||||
| 3257 | sensitive; otherwise the search is case insensitive. | - | ||||||||||||||||||
| 3258 | - | |||||||||||||||||||
| 3259 | Example: | - | ||||||||||||||||||
| 3260 | - | |||||||||||||||||||
| 3261 | \snippet qstring/main.cpp 29 | - | ||||||||||||||||||
| 3262 | - | |||||||||||||||||||
| 3263 | \sa indexOf(), contains(), count() | - | ||||||||||||||||||
| 3264 | */ | - | ||||||||||||||||||
| 3265 | int QString::lastIndexOf(const QString &str, int from, Qt::CaseSensitivity cs) const | - | ||||||||||||||||||
| 3266 | { | - | ||||||||||||||||||
| 3267 | const int sl = str.d->size; | - | ||||||||||||||||||
| 3268 | if (sl == 1)
| 95-119 | ||||||||||||||||||
| 3269 | return lastIndexOf(QChar(str.d->data()[0]), from, cs); executed 119 times by 1 test: return lastIndexOf(QChar(str.d->data()[0]), from, cs);Executed by:
| 119 | ||||||||||||||||||
| 3270 | - | |||||||||||||||||||
| 3271 | const int l = d->size; | - | ||||||||||||||||||
| 3272 | if (from < 0)
| 31-64 | ||||||||||||||||||
| 3273 | from += l; executed 64 times by 5 tests: from += l;Executed by:
| 64 | ||||||||||||||||||
| 3274 | int delta = l-sl; | - | ||||||||||||||||||
| 3275 | if (from == l && sl == 0)
| 3-89 | ||||||||||||||||||
| 3276 | return from; executed 3 times by 1 test: return from;Executed by:
| 3 | ||||||||||||||||||
| 3277 | if (uint(from) >= uint(l) || delta < 0)
| 9-76 | ||||||||||||||||||
| 3278 | return -1; executed 25 times by 1 test: return -1;Executed by:
| 25 | ||||||||||||||||||
| 3279 | if (from > delta)
| 19-48 | ||||||||||||||||||
| 3280 | from = delta; executed 48 times by 5 tests: from = delta;Executed by:
| 48 | ||||||||||||||||||
| 3281 | - | |||||||||||||||||||
| 3282 | 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 | ||||||||||||||||||
| 3283 | } | - | ||||||||||||||||||
| 3284 | - | |||||||||||||||||||
| 3285 | /*! | - | ||||||||||||||||||
| 3286 | \since 4.5 | - | ||||||||||||||||||
| 3287 | \overload lastIndexOf() | - | ||||||||||||||||||
| 3288 | - | |||||||||||||||||||
| 3289 | Returns the index position of the last occurrence of the string \a | - | ||||||||||||||||||
| 3290 | str in this string, searching backward from index position \a | - | ||||||||||||||||||
| 3291 | from. If \a from is -1 (default), the search starts at the last | - | ||||||||||||||||||
| 3292 | character; if \a from is -2, at the next to last character and so | - | ||||||||||||||||||
| 3293 | on. Returns -1 if \a str is not found. | - | ||||||||||||||||||
| 3294 | - | |||||||||||||||||||
| 3295 | If \a cs is Qt::CaseSensitive (default), the search is case | - | ||||||||||||||||||
| 3296 | sensitive; otherwise the search is case insensitive. | - | ||||||||||||||||||
| 3297 | - | |||||||||||||||||||
| 3298 | Example: | - | ||||||||||||||||||
| 3299 | - | |||||||||||||||||||
| 3300 | \snippet qstring/main.cpp 29 | - | ||||||||||||||||||
| 3301 | - | |||||||||||||||||||
| 3302 | \sa indexOf(), contains(), count() | - | ||||||||||||||||||
| 3303 | */ | - | ||||||||||||||||||
| 3304 | int QString::lastIndexOf(QLatin1String str, int from, Qt::CaseSensitivity cs) const | - | ||||||||||||||||||
| 3305 | { | - | ||||||||||||||||||
| 3306 | const int sl = str.size(); | - | ||||||||||||||||||
| 3307 | if (sl == 1)
| 0-13 | ||||||||||||||||||
| 3308 | return lastIndexOf(QLatin1Char(str.latin1()[0]), from, cs); never executed: return lastIndexOf(QLatin1Char(str.latin1()[0]), from, cs); | 0 | ||||||||||||||||||
| 3309 | - | |||||||||||||||||||
| 3310 | const int l = d->size; | - | ||||||||||||||||||
| 3311 | if (from < 0)
| 0-13 | ||||||||||||||||||
| 3312 | from += l; never executed: from += l; | 0 | ||||||||||||||||||
| 3313 | int delta = l-sl; | - | ||||||||||||||||||
| 3314 | if (from == l && sl == 0)
| 0-13 | ||||||||||||||||||
| 3315 | return from; never executed: return from; | 0 | ||||||||||||||||||
| 3316 | if (uint(from) >= uint(l) || delta < 0)
| 0-13 | ||||||||||||||||||
| 3317 | return -1; never executed: return -1; | 0 | ||||||||||||||||||
| 3318 | if (from > delta)
| 0-13 | ||||||||||||||||||
| 3319 | from = delta; executed 13 times by 2 tests: from = delta;Executed by:
| 13 | ||||||||||||||||||
| 3320 | - | |||||||||||||||||||
| 3321 | QVarLengthArray<ushort> s(sl); | - | ||||||||||||||||||
| 3322 | qt_from_latin1(s.data(), str.latin1(), sl); | - | ||||||||||||||||||
| 3323 | - | |||||||||||||||||||
| 3324 | 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 | ||||||||||||||||||
| 3325 | } | - | ||||||||||||||||||
| 3326 | - | |||||||||||||||||||
| 3327 | /*! | - | ||||||||||||||||||
| 3328 | \overload lastIndexOf() | - | ||||||||||||||||||
| 3329 | - | |||||||||||||||||||
| 3330 | Returns the index position of the last occurrence of the character | - | ||||||||||||||||||
| 3331 | \a ch, searching backward from position \a from. | - | ||||||||||||||||||
| 3332 | */ | - | ||||||||||||||||||
| 3333 | int QString::lastIndexOf(QChar ch, int from, Qt::CaseSensitivity cs) const | - | ||||||||||||||||||
| 3334 | { | - | ||||||||||||||||||
| 3335 | return qt_last_index_of(unicode(), size(), ch, from, cs); executed 263733 times by 303 tests: return qt_last_index_of(unicode(), size(), ch, from, cs);Executed by:
| 263733 | ||||||||||||||||||
| 3336 | } | - | ||||||||||||||||||
| 3337 | - | |||||||||||||||||||
| 3338 | /*! | - | ||||||||||||||||||
| 3339 | \since 4.8 | - | ||||||||||||||||||
| 3340 | \overload lastIndexOf() | - | ||||||||||||||||||
| 3341 | - | |||||||||||||||||||
| 3342 | Returns the index position of the last occurrence of the string | - | ||||||||||||||||||
| 3343 | reference \a str in this string, searching backward from index | - | ||||||||||||||||||
| 3344 | position \a from. If \a from is -1 (default), the search starts at | - | ||||||||||||||||||
| 3345 | the last character; if \a from is -2, at the next to last character | - | ||||||||||||||||||
| 3346 | and so on. Returns -1 if \a str is not found. | - | ||||||||||||||||||
| 3347 | - | |||||||||||||||||||
| 3348 | If \a cs is Qt::CaseSensitive (default), the search is case | - | ||||||||||||||||||
| 3349 | sensitive; otherwise the search is case insensitive. | - | ||||||||||||||||||
| 3350 | - | |||||||||||||||||||
| 3351 | \sa indexOf(), contains(), count() | - | ||||||||||||||||||
| 3352 | */ | - | ||||||||||||||||||
| 3353 | int QString::lastIndexOf(const QStringRef &str, int from, Qt::CaseSensitivity cs) const | - | ||||||||||||||||||
| 3354 | { | - | ||||||||||||||||||
| 3355 | const int sl = str.size(); | - | ||||||||||||||||||
| 3356 | if (sl == 1)
| 62-86 | ||||||||||||||||||
| 3357 | return lastIndexOf(str.at(0), from, cs); executed 86 times by 2 tests: return lastIndexOf(str.at(0), from, cs);Executed by:
| 86 | ||||||||||||||||||
| 3358 | - | |||||||||||||||||||
| 3359 | const int l = d->size; | - | ||||||||||||||||||
| 3360 | if (from < 0)
| 14-48 | ||||||||||||||||||
| 3361 | from += l; executed 48 times by 2 tests: from += l;Executed by:
| 48 | ||||||||||||||||||
| 3362 | int delta = l - sl; | - | ||||||||||||||||||
| 3363 | if (from == l && sl == 0)
| 2-58 | ||||||||||||||||||
| 3364 | return from; executed 2 times by 2 tests: return from;Executed by:
| 2 | ||||||||||||||||||
| 3365 | if (uint(from) >= uint(l) || delta < 0)
| 8-48 | ||||||||||||||||||
| 3366 | return -1; executed 20 times by 2 tests: return -1;Executed by:
| 20 | ||||||||||||||||||
| 3367 | if (from > delta)
| 10-30 | ||||||||||||||||||
| 3368 | from = delta; executed 30 times by 2 tests: from = delta;Executed by:
| 30 | ||||||||||||||||||
| 3369 | - | |||||||||||||||||||
| 3370 | 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 | ||||||||||||||||||
| 3371 | 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 | ||||||||||||||||||
| 3372 | } | - | ||||||||||||||||||
| 3373 | - | |||||||||||||||||||
| 3374 | - | |||||||||||||||||||
| 3375 | #if !(defined(QT_NO_REGEXP) && defined(QT_NO_REGULAREXPRESSION)) | - | ||||||||||||||||||
| 3376 | struct QStringCapture | - | ||||||||||||||||||
| 3377 | { | - | ||||||||||||||||||
| 3378 | int pos; | - | ||||||||||||||||||
| 3379 | int len; | - | ||||||||||||||||||
| 3380 | int no; | - | ||||||||||||||||||
| 3381 | }; | - | ||||||||||||||||||
| 3382 | Q_DECLARE_TYPEINFO(QStringCapture, Q_PRIMITIVE_TYPE); | - | ||||||||||||||||||
| 3383 | #endif | - | ||||||||||||||||||
| 3384 | - | |||||||||||||||||||
| 3385 | #ifndef QT_NO_REGEXP | - | ||||||||||||||||||
| 3386 | - | |||||||||||||||||||
| 3387 | /*! | - | ||||||||||||||||||
| 3388 | \overload replace() | - | ||||||||||||||||||
| 3389 | - | |||||||||||||||||||
| 3390 | Replaces every occurrence of the regular expression \a rx in the | - | ||||||||||||||||||
| 3391 | string with \a after. Returns a reference to the string. For | - | ||||||||||||||||||
| 3392 | example: | - | ||||||||||||||||||
| 3393 | - | |||||||||||||||||||
| 3394 | \snippet qstring/main.cpp 42 | - | ||||||||||||||||||
| 3395 | - | |||||||||||||||||||
| 3396 | For regular expressions containing \l{capturing parentheses}, | - | ||||||||||||||||||
| 3397 | occurrences of \b{\\1}, \b{\\2}, ..., in \a after are replaced | - | ||||||||||||||||||
| 3398 | with \a{rx}.cap(1), cap(2), ... | - | ||||||||||||||||||
| 3399 | - | |||||||||||||||||||
| 3400 | \snippet qstring/main.cpp 43 | - | ||||||||||||||||||
| 3401 | - | |||||||||||||||||||
| 3402 | \sa indexOf(), lastIndexOf(), remove(), QRegExp::cap() | - | ||||||||||||||||||
| 3403 | */ | - | ||||||||||||||||||
| 3404 | QString& QString::replace(const QRegExp &rx, const QString &after) | - | ||||||||||||||||||
| 3405 | { | - | ||||||||||||||||||
| 3406 | QRegExp rx2(rx); | - | ||||||||||||||||||
| 3407 | - | |||||||||||||||||||
| 3408 | if (isEmpty() && rx2.indexIn(*this) == -1)
| 18-90688 | ||||||||||||||||||
| 3409 | return *this; executed 51961 times by 2 tests: return *this;Executed by:
| 51961 | ||||||||||||||||||
| 3410 | - | |||||||||||||||||||
| 3411 | reallocData(uint(d->size) + 1u); | - | ||||||||||||||||||
| 3412 | - | |||||||||||||||||||
| 3413 | int index = 0; | - | ||||||||||||||||||
| 3414 | int numCaptures = rx2.captureCount(); | - | ||||||||||||||||||
| 3415 | int al = after.length(); | - | ||||||||||||||||||
| 3416 | QRegExp::CaretMode caretMode = QRegExp::CaretAtZero; | - | ||||||||||||||||||
| 3417 | - | |||||||||||||||||||
| 3418 | if (numCaptures > 0) {
| 27-90679 | ||||||||||||||||||
| 3419 | const QChar *uc = after.unicode(); | - | ||||||||||||||||||
| 3420 | int numBackRefs = 0; | - | ||||||||||||||||||
| 3421 | - | |||||||||||||||||||
| 3422 | for (int i = 0; i < al - 1; i++) {
| 27-173 | ||||||||||||||||||
| 3423 | if (uc[i] == QLatin1Char('\\')) {
| 76-97 | ||||||||||||||||||
| 3424 | int no = uc[i + 1].digitValue(); | - | ||||||||||||||||||
| 3425 | if (no > 0 && no <= numCaptures)
| 2-68 | ||||||||||||||||||
| 3426 | numBackRefs++; executed 66 times by 3 tests: numBackRefs++;Executed by:
| 66 | ||||||||||||||||||
| 3427 | } executed 76 times by 3 tests: end of blockExecuted by:
| 76 | ||||||||||||||||||
| 3428 | } executed 173 times by 3 tests: end of blockExecuted by:
| 173 | ||||||||||||||||||
| 3429 | - | |||||||||||||||||||
| 3430 | /* | - | ||||||||||||||||||
| 3431 | This is the harder case where we have back-references. | - | ||||||||||||||||||
| 3432 | */ | - | ||||||||||||||||||
| 3433 | if (numBackRefs > 0) {
| 6-21 | ||||||||||||||||||
| 3434 | QVarLengthArray<QStringCapture, 16> captures(numBackRefs); | - | ||||||||||||||||||
| 3435 | int j = 0; | - | ||||||||||||||||||
| 3436 | - | |||||||||||||||||||
| 3437 | for (int i = 0; i < al - 1; i++) {
| 21-164 | ||||||||||||||||||
| 3438 | if (uc[i] == QLatin1Char('\\')) {
| 72-92 | ||||||||||||||||||
| 3439 | int no = uc[i + 1].digitValue(); | - | ||||||||||||||||||
| 3440 | if (no > 0 && no <= numCaptures) {
| 1-67 | ||||||||||||||||||
| 3441 | QStringCapture capture; | - | ||||||||||||||||||
| 3442 | capture.pos = i; | - | ||||||||||||||||||
| 3443 | capture.len = 2; | - | ||||||||||||||||||
| 3444 | - | |||||||||||||||||||
| 3445 | if (i < al - 2) {
| 10-56 | ||||||||||||||||||
| 3446 | int secondDigit = uc[i + 2].digitValue(); | - | ||||||||||||||||||
| 3447 | if (secondDigit != -1 && ((no * 10) + secondDigit) <= numCaptures) {
| 6-28 | ||||||||||||||||||
| 3448 | no = (no * 10) + secondDigit; | - | ||||||||||||||||||
| 3449 | ++capture.len; | - | ||||||||||||||||||
| 3450 | } executed 6 times by 1 test: end of blockExecuted by:
| 6 | ||||||||||||||||||
| 3451 | } executed 56 times by 3 tests: end of blockExecuted by:
| 56 | ||||||||||||||||||
| 3452 | - | |||||||||||||||||||
| 3453 | capture.no = no; | - | ||||||||||||||||||
| 3454 | captures[j++] = capture; | - | ||||||||||||||||||
| 3455 | } executed 66 times by 3 tests: end of blockExecuted by:
| 66 | ||||||||||||||||||
| 3456 | } executed 72 times by 3 tests: end of blockExecuted by:
| 72 | ||||||||||||||||||
| 3457 | } executed 164 times by 3 tests: end of blockExecuted by:
| 164 | ||||||||||||||||||
| 3458 | - | |||||||||||||||||||
| 3459 | while (index <= length()) {
| 0-46 | ||||||||||||||||||
| 3460 | index = rx2.indexIn(*this, index, caretMode); | - | ||||||||||||||||||
| 3461 | if (index == -1)
| 21-25 | ||||||||||||||||||
| 3462 | break; executed 21 times by 3 tests: break;Executed by:
| 21 | ||||||||||||||||||
| 3463 | - | |||||||||||||||||||
| 3464 | QString after2(after); | - | ||||||||||||||||||
| 3465 | for (j = numBackRefs - 1; j >= 0; j--) {
| 25-64 | ||||||||||||||||||
| 3466 | const QStringCapture &capture = captures[j]; | - | ||||||||||||||||||
| 3467 | after2.replace(capture.pos, capture.len, rx2.cap(capture.no)); | - | ||||||||||||||||||
| 3468 | } executed 64 times by 3 tests: end of blockExecuted by:
| 64 | ||||||||||||||||||
| 3469 | - | |||||||||||||||||||
| 3470 | replace(index, rx2.matchedLength(), after2); | - | ||||||||||||||||||
| 3471 | index += after2.length(); | - | ||||||||||||||||||
| 3472 | - | |||||||||||||||||||
| 3473 | // avoid infinite loop on 0-length matches (e.g., QRegExp("[a-z]*")) | - | ||||||||||||||||||
| 3474 | if (rx2.matchedLength() == 0)
| 0-25 | ||||||||||||||||||
| 3475 | ++index; never executed: ++index; | 0 | ||||||||||||||||||
| 3476 | - | |||||||||||||||||||
| 3477 | caretMode = QRegExp::CaretWontMatch; | - | ||||||||||||||||||
| 3478 | } executed 25 times by 3 tests: end of blockExecuted by:
| 25 | ||||||||||||||||||
| 3479 | return *this; executed 21 times by 3 tests: return *this;Executed by:
| 21 | ||||||||||||||||||
| 3480 | } | - | ||||||||||||||||||
| 3481 | } executed 6 times by 2 tests: end of blockExecuted by:
| 6 | ||||||||||||||||||
| 3482 | - | |||||||||||||||||||
| 3483 | /* | - | ||||||||||||||||||
| 3484 | This is the simple and optimized case where we don't have | - | ||||||||||||||||||
| 3485 | back-references. | - | ||||||||||||||||||
| 3486 | */ | - | ||||||||||||||||||
| 3487 | while (index != -1) {
| 3645-90685 | ||||||||||||||||||
| 3488 | struct { | - | ||||||||||||||||||
| 3489 | int pos; | - | ||||||||||||||||||
| 3490 | int length; | - | ||||||||||||||||||
| 3491 | } replacements[2048]; | - | ||||||||||||||||||
| 3492 | - | |||||||||||||||||||
| 3493 | int pos = 0; | - | ||||||||||||||||||
| 3494 | int adjust = 0; | - | ||||||||||||||||||
| 3495 | while (pos < 2047) {
| 0-99686 | ||||||||||||||||||
| 3496 | index = rx2.indexIn(*this, index, caretMode); | - | ||||||||||||||||||
| 3497 | if (index == -1)
| 9001-90685 | ||||||||||||||||||
| 3498 | break; executed 90685 times by 17 tests: break;Executed by:
| 90685 | ||||||||||||||||||
| 3499 | int ml = rx2.matchedLength(); | - | ||||||||||||||||||
| 3500 | replacements[pos].pos = index; | - | ||||||||||||||||||
| 3501 | replacements[pos++].length = ml; | - | ||||||||||||||||||
| 3502 | index += ml; | - | ||||||||||||||||||
| 3503 | adjust += al - ml; | - | ||||||||||||||||||
| 3504 | // avoid infinite loop | - | ||||||||||||||||||
| 3505 | if (!ml)
| 46-8955 | ||||||||||||||||||
| 3506 | index++; executed 46 times by 3 tests: index++;Executed by:
| 46 | ||||||||||||||||||
| 3507 | } executed 9001 times by 12 tests: end of blockExecuted by:
| 9001 | ||||||||||||||||||
| 3508 | if (!pos)
| 3645-87040 | ||||||||||||||||||
| 3509 | break; executed 87040 times by 13 tests: break;Executed by:
| 87040 | ||||||||||||||||||
| 3510 | replacements[pos].pos = d->size; | - | ||||||||||||||||||
| 3511 | int newlen = d->size + adjust; | - | ||||||||||||||||||
| 3512 | - | |||||||||||||||||||
| 3513 | // to continue searching at the right position after we did | - | ||||||||||||||||||
| 3514 | // the first round of replacements | - | ||||||||||||||||||
| 3515 | if (index != -1)
| 0-3645 | ||||||||||||||||||
| 3516 | index += adjust; never executed: index += adjust; | 0 | ||||||||||||||||||
| 3517 | QString newstring; | - | ||||||||||||||||||
| 3518 | newstring.reserve(newlen + 1); | - | ||||||||||||||||||
| 3519 | QChar *newuc = newstring.data(); | - | ||||||||||||||||||
| 3520 | QChar *uc = newuc; | - | ||||||||||||||||||
| 3521 | int copystart = 0; | - | ||||||||||||||||||
| 3522 | int i = 0; | - | ||||||||||||||||||
| 3523 | while (i < pos) {
| 3645-9001 | ||||||||||||||||||
| 3524 | int copyend = replacements[i].pos; | - | ||||||||||||||||||
| 3525 | int size = copyend - copystart; | - | ||||||||||||||||||
| 3526 | memcpy(uc, d->data() + copystart, size * sizeof(QChar)); | - | ||||||||||||||||||
| 3527 | uc += size; | - | ||||||||||||||||||
| 3528 | memcpy(uc, after.d->data(), al * sizeof(QChar)); | - | ||||||||||||||||||
| 3529 | uc += al; | - | ||||||||||||||||||
| 3530 | copystart = copyend + replacements[i].length; | - | ||||||||||||||||||
| 3531 | i++; | - | ||||||||||||||||||
| 3532 | } executed 9001 times by 12 tests: end of blockExecuted by:
| 9001 | ||||||||||||||||||
| 3533 | memcpy(uc, d->data() + copystart, (d->size - copystart) * sizeof(QChar)); | - | ||||||||||||||||||
| 3534 | newstring.resize(newlen); | - | ||||||||||||||||||
| 3535 | *this = newstring; | - | ||||||||||||||||||
| 3536 | caretMode = QRegExp::CaretWontMatch; | - | ||||||||||||||||||
| 3537 | } executed 3645 times by 12 tests: end of blockExecuted by:
| 3645 | ||||||||||||||||||
| 3538 | return *this; executed 90685 times by 17 tests: return *this;Executed by:
| 90685 | ||||||||||||||||||
| 3539 | } | - | ||||||||||||||||||
| 3540 | #endif | - | ||||||||||||||||||
| 3541 | - | |||||||||||||||||||
| 3542 | #ifndef QT_NO_REGULAREXPRESSION | - | ||||||||||||||||||
| 3543 | #ifndef QT_BOOTSTRAPPED | - | ||||||||||||||||||
| 3544 | /*! | - | ||||||||||||||||||
| 3545 | \overload replace() | - | ||||||||||||||||||
| 3546 | \since 5.0 | - | ||||||||||||||||||
| 3547 | - | |||||||||||||||||||
| 3548 | Replaces every occurrence of the regular expression \a re in the | - | ||||||||||||||||||
| 3549 | string with \a after. Returns a reference to the string. For | - | ||||||||||||||||||
| 3550 | example: | - | ||||||||||||||||||
| 3551 | - | |||||||||||||||||||
| 3552 | \snippet qstring/main.cpp 87 | - | ||||||||||||||||||
| 3553 | - | |||||||||||||||||||
| 3554 | For regular expressions containing capturing groups, | - | ||||||||||||||||||
| 3555 | occurrences of \b{\\1}, \b{\\2}, ..., in \a after are replaced | - | ||||||||||||||||||
| 3556 | with the string captured by the corresponding capturing group. | - | ||||||||||||||||||
| 3557 | - | |||||||||||||||||||
| 3558 | \snippet qstring/main.cpp 88 | - | ||||||||||||||||||
| 3559 | - | |||||||||||||||||||
| 3560 | \sa indexOf(), lastIndexOf(), remove(), QRegularExpression, QRegularExpressionMatch | - | ||||||||||||||||||
| 3561 | */ | - | ||||||||||||||||||
| 3562 | QString &QString::replace(const QRegularExpression &re, const QString &after) | - | ||||||||||||||||||
| 3563 | { | - | ||||||||||||||||||
| 3564 | if (!re.isValid()) {
| 2-7185 | ||||||||||||||||||
| 3565 | qWarning("QString::replace: invalid QRegularExpression object"); | - | ||||||||||||||||||
| 3566 | return *this; executed 2 times by 1 test: return *this;Executed by:
| 2 | ||||||||||||||||||
| 3567 | } | - | ||||||||||||||||||
| 3568 | - | |||||||||||||||||||
| 3569 | const QString copy(*this); | - | ||||||||||||||||||
| 3570 | QRegularExpressionMatchIterator iterator = re.globalMatch(copy); | - | ||||||||||||||||||
| 3571 | if (!iterator.hasNext()) // no matches at all
| 1501-5684 | ||||||||||||||||||
| 3572 | return *this; executed 5684 times by 3 tests: return *this;Executed by:
| 5684 | ||||||||||||||||||
| 3573 | - | |||||||||||||||||||
| 3574 | reallocData(uint(d->size) + 1u); | - | ||||||||||||||||||
| 3575 | - | |||||||||||||||||||
| 3576 | int numCaptures = re.captureCount(); | - | ||||||||||||||||||
| 3577 | - | |||||||||||||||||||
| 3578 | // 1. build the backreferences vector, holding where the backreferences | - | ||||||||||||||||||
| 3579 | // are in the replacement string | - | ||||||||||||||||||
| 3580 | QVector<QStringCapture> backReferences; | - | ||||||||||||||||||
| 3581 | const int al = after.length(); | - | ||||||||||||||||||
| 3582 | const QChar *ac = after.unicode(); | - | ||||||||||||||||||
| 3583 | - | |||||||||||||||||||
| 3584 | for (int i = 0; i < al - 1; i++) {
| 1501-30058 | ||||||||||||||||||
| 3585 | if (ac[i] == QLatin1Char('\\')) {
| 55-30003 | ||||||||||||||||||
| 3586 | int no = ac[i + 1].digitValue(); | - | ||||||||||||||||||
| 3587 | if (no > 0 && no <= numCaptures) {
| 3-51 | ||||||||||||||||||
| 3588 | QStringCapture backReference; | - | ||||||||||||||||||
| 3589 | backReference.pos = i; | - | ||||||||||||||||||
| 3590 | backReference.len = 2; | - | ||||||||||||||||||
| 3591 | - | |||||||||||||||||||
| 3592 | if (i < al - 2) {
| 5-43 | ||||||||||||||||||
| 3593 | int secondDigit = ac[i + 2].digitValue(); | - | ||||||||||||||||||
| 3594 | if (secondDigit != -1 && ((no * 10) + secondDigit) <= numCaptures) {
| 6-28 | ||||||||||||||||||
| 3595 | no = (no * 10) + secondDigit; | - | ||||||||||||||||||
| 3596 | ++backReference.len; | - | ||||||||||||||||||
| 3597 | } executed 6 times by 1 test: end of blockExecuted by:
| 6 | ||||||||||||||||||
| 3598 | } executed 43 times by 2 tests: end of blockExecuted by:
| 43 | ||||||||||||||||||
| 3599 | - | |||||||||||||||||||
| 3600 | backReference.no = no; | - | ||||||||||||||||||
| 3601 | backReferences.append(backReference); | - | ||||||||||||||||||
| 3602 | } executed 48 times by 2 tests: end of blockExecuted by:
| 48 | ||||||||||||||||||
| 3603 | } executed 55 times by 2 tests: end of blockExecuted by:
| 55 | ||||||||||||||||||
| 3604 | } executed 30058 times by 3 tests: end of blockExecuted by:
| 30058 | ||||||||||||||||||
| 3605 | - | |||||||||||||||||||
| 3606 | // 2. iterate on the matches. For every match, copy in chunks | - | ||||||||||||||||||
| 3607 | // - the part before the match | - | ||||||||||||||||||
| 3608 | // - the after string, with the proper replacements for the backreferences | - | ||||||||||||||||||
| 3609 | - | |||||||||||||||||||
| 3610 | int newLength = 0; // length of the new string, with all the replacements | - | ||||||||||||||||||
| 3611 | int lastEnd = 0; | - | ||||||||||||||||||
| 3612 | QVector<QStringRef> chunks; | - | ||||||||||||||||||
| 3613 | while (iterator.hasNext()) {
| 1501-1518 | ||||||||||||||||||
| 3614 | QRegularExpressionMatch match = iterator.next(); | - | ||||||||||||||||||
| 3615 | int len; | - | ||||||||||||||||||
| 3616 | // add the part before the match | - | ||||||||||||||||||
| 3617 | len = match.capturedStart() - lastEnd; | - | ||||||||||||||||||
| 3618 | if (len > 0) {
| 154-1364 | ||||||||||||||||||
| 3619 | chunks << copy.midRef(lastEnd, len); | - | ||||||||||||||||||
| 3620 | newLength += len; | - | ||||||||||||||||||
| 3621 | } executed 1364 times by 2 tests: end of blockExecuted by:
| 1364 | ||||||||||||||||||
| 3622 | - | |||||||||||||||||||
| 3623 | lastEnd = 0; | - | ||||||||||||||||||
| 3624 | // add the after string, with replacements for the backreferences | - | ||||||||||||||||||
| 3625 | for (const QStringCapture &backReference : qAsConst(backReferences)) { | - | ||||||||||||||||||
| 3626 | // part of "after" before the backreference | - | ||||||||||||||||||
| 3627 | len = backReference.pos - lastEnd; | - | ||||||||||||||||||
| 3628 | if (len > 0) {
| 28-30 | ||||||||||||||||||
| 3629 | chunks << after.midRef(lastEnd, len); | - | ||||||||||||||||||
| 3630 | newLength += len; | - | ||||||||||||||||||
| 3631 | } executed 28 times by 2 tests: end of blockExecuted by:
| 28 | ||||||||||||||||||
| 3632 | - | |||||||||||||||||||
| 3633 | // backreference itself | - | ||||||||||||||||||
| 3634 | len = match.capturedLength(backReference.no); | - | ||||||||||||||||||
| 3635 | if (len > 0) {
| 1-57 | ||||||||||||||||||
| 3636 | chunks << copy.midRef(match.capturedStart(backReference.no), len); | - | ||||||||||||||||||
| 3637 | newLength += len; | - | ||||||||||||||||||
| 3638 | } executed 57 times by 2 tests: end of blockExecuted by:
| 57 | ||||||||||||||||||
| 3639 | - | |||||||||||||||||||
| 3640 | lastEnd = backReference.pos + backReference.len; | - | ||||||||||||||||||
| 3641 | } executed 58 times by 2 tests: end of blockExecuted by:
| 58 | ||||||||||||||||||
| 3642 | - | |||||||||||||||||||
| 3643 | // add the last part of the after string | - | ||||||||||||||||||
| 3644 | len = after.length() - lastEnd; | - | ||||||||||||||||||
| 3645 | if (len > 0) {
| 131-1387 | ||||||||||||||||||
| 3646 | chunks << after.midRef(lastEnd, len); | - | ||||||||||||||||||
| 3647 | newLength += len; | - | ||||||||||||||||||
| 3648 | } executed 1387 times by 3 tests: end of blockExecuted by:
| 1387 | ||||||||||||||||||
| 3649 | - | |||||||||||||||||||
| 3650 | lastEnd = match.capturedEnd(); | - | ||||||||||||||||||
| 3651 | } executed 1518 times by 4 tests: end of blockExecuted by:
| 1518 | ||||||||||||||||||
| 3652 | - | |||||||||||||||||||
| 3653 | // 3. trailing string after the last match | - | ||||||||||||||||||
| 3654 | if (copy.length() > lastEnd) {
| 14-1487 | ||||||||||||||||||
| 3655 | chunks << copy.midRef(lastEnd); | - | ||||||||||||||||||
| 3656 | newLength += copy.length() - lastEnd; | - | ||||||||||||||||||
| 3657 | } executed 1487 times by 4 tests: end of blockExecuted by:
| 1487 | ||||||||||||||||||
| 3658 | - | |||||||||||||||||||
| 3659 | // 4. assemble the chunks together | - | ||||||||||||||||||
| 3660 | resize(newLength); | - | ||||||||||||||||||
| 3661 | int i = 0; | - | ||||||||||||||||||
| 3662 | QChar *uc = data(); | - | ||||||||||||||||||
| 3663 | for (const QStringRef &chunk : qAsConst(chunks)) { | - | ||||||||||||||||||
| 3664 | int len = chunk.length(); | - | ||||||||||||||||||
| 3665 | memcpy(uc + i, chunk.unicode(), len * sizeof(QChar)); | - | ||||||||||||||||||
| 3666 | i += len; | - | ||||||||||||||||||
| 3667 | } executed 4323 times by 4 tests: end of blockExecuted by:
| 4323 | ||||||||||||||||||
| 3668 | - | |||||||||||||||||||
| 3669 | return *this; executed 1501 times by 4 tests: return *this;Executed by:
| 1501 | ||||||||||||||||||
| 3670 | } | - | ||||||||||||||||||
| 3671 | #endif // QT_BOOTSTRAPPED | - | ||||||||||||||||||
| 3672 | #endif // QT_NO_REGULAREXPRESSION | - | ||||||||||||||||||
| 3673 | - | |||||||||||||||||||
| 3674 | /*! | - | ||||||||||||||||||
| 3675 | Returns the number of (potentially overlapping) occurrences of | - | ||||||||||||||||||
| 3676 | the string \a str in this string. | - | ||||||||||||||||||
| 3677 | - | |||||||||||||||||||
| 3678 | If \a cs is Qt::CaseSensitive (default), the search is | - | ||||||||||||||||||
| 3679 | case sensitive; otherwise the search is case insensitive. | - | ||||||||||||||||||
| 3680 | - | |||||||||||||||||||
| 3681 | \sa contains(), indexOf() | - | ||||||||||||||||||
| 3682 | */ | - | ||||||||||||||||||
| 3683 | - | |||||||||||||||||||
| 3684 | int QString::count(const QString &str, Qt::CaseSensitivity cs) const | - | ||||||||||||||||||
| 3685 | { | - | ||||||||||||||||||
| 3686 | 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 | ||||||||||||||||||
| 3687 | } | - | ||||||||||||||||||
| 3688 | - | |||||||||||||||||||
| 3689 | /*! | - | ||||||||||||||||||
| 3690 | \overload count() | - | ||||||||||||||||||
| 3691 | - | |||||||||||||||||||
| 3692 | Returns the number of occurrences of character \a ch in the string. | - | ||||||||||||||||||
| 3693 | - | |||||||||||||||||||
| 3694 | If \a cs is Qt::CaseSensitive (default), the search is | - | ||||||||||||||||||
| 3695 | case sensitive; otherwise the search is case insensitive. | - | ||||||||||||||||||
| 3696 | - | |||||||||||||||||||
| 3697 | \sa contains(), indexOf() | - | ||||||||||||||||||
| 3698 | */ | - | ||||||||||||||||||
| 3699 | - | |||||||||||||||||||
| 3700 | int QString::count(QChar ch, Qt::CaseSensitivity cs) const | - | ||||||||||||||||||
| 3701 | { | - | ||||||||||||||||||
| 3702 | return qt_string_count(unicode(), size(), ch, cs); executed 54672 times by 29 tests: return qt_string_count(unicode(), size(), ch, cs);Executed by:
| 54672 | ||||||||||||||||||
| 3703 | } | - | ||||||||||||||||||
| 3704 | - | |||||||||||||||||||
| 3705 | /*! | - | ||||||||||||||||||
| 3706 | \since 4.8 | - | ||||||||||||||||||
| 3707 | \overload count() | - | ||||||||||||||||||
| 3708 | Returns the number of (potentially overlapping) occurrences of the | - | ||||||||||||||||||
| 3709 | string reference \a str in this string. | - | ||||||||||||||||||
| 3710 | - | |||||||||||||||||||
| 3711 | If \a cs is Qt::CaseSensitive (default), the search is | - | ||||||||||||||||||
| 3712 | case sensitive; otherwise the search is case insensitive. | - | ||||||||||||||||||
| 3713 | - | |||||||||||||||||||
| 3714 | \sa contains(), indexOf() | - | ||||||||||||||||||
| 3715 | */ | - | ||||||||||||||||||
| 3716 | int QString::count(const QStringRef &str, Qt::CaseSensitivity cs) const | - | ||||||||||||||||||
| 3717 | { | - | ||||||||||||||||||
| 3718 | 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 | ||||||||||||||||||
| 3719 | } | - | ||||||||||||||||||
| 3720 | - | |||||||||||||||||||
| 3721 | - | |||||||||||||||||||
| 3722 | /*! \fn bool QString::contains(const QString &str, Qt::CaseSensitivity cs = Qt::CaseSensitive) const | - | ||||||||||||||||||
| 3723 | - | |||||||||||||||||||
| 3724 | Returns \c true if this string contains an occurrence of the string | - | ||||||||||||||||||
| 3725 | \a str; otherwise returns \c false. | - | ||||||||||||||||||
| 3726 | - | |||||||||||||||||||
| 3727 | If \a cs is Qt::CaseSensitive (default), the search is | - | ||||||||||||||||||
| 3728 | case sensitive; otherwise the search is case insensitive. | - | ||||||||||||||||||
| 3729 | - | |||||||||||||||||||
| 3730 | Example: | - | ||||||||||||||||||
| 3731 | \snippet qstring/main.cpp 17 | - | ||||||||||||||||||
| 3732 | - | |||||||||||||||||||
| 3733 | \sa indexOf(), count() | - | ||||||||||||||||||
| 3734 | */ | - | ||||||||||||||||||
| 3735 | - | |||||||||||||||||||
| 3736 | /*! \fn bool QString::contains(QLatin1String str, Qt::CaseSensitivity cs = Qt::CaseSensitive) const | - | ||||||||||||||||||
| 3737 | \since 5.3 | - | ||||||||||||||||||
| 3738 | - | |||||||||||||||||||
| 3739 | \overload contains() | - | ||||||||||||||||||
| 3740 | - | |||||||||||||||||||
| 3741 | Returns \c true if this string contains an occurrence of the latin-1 string | - | ||||||||||||||||||
| 3742 | \a str; otherwise returns \c false. | - | ||||||||||||||||||
| 3743 | */ | - | ||||||||||||||||||
| 3744 | - | |||||||||||||||||||
| 3745 | /*! \fn bool QString::contains(QChar ch, Qt::CaseSensitivity cs = Qt::CaseSensitive) const | - | ||||||||||||||||||
| 3746 | - | |||||||||||||||||||
| 3747 | \overload contains() | - | ||||||||||||||||||
| 3748 | - | |||||||||||||||||||
| 3749 | Returns \c true if this string contains an occurrence of the | - | ||||||||||||||||||
| 3750 | character \a ch; otherwise returns \c false. | - | ||||||||||||||||||
| 3751 | */ | - | ||||||||||||||||||
| 3752 | - | |||||||||||||||||||
| 3753 | /*! \fn bool QString::contains(const QStringRef &str, Qt::CaseSensitivity cs = Qt::CaseSensitive) const | - | ||||||||||||||||||
| 3754 | \since 4.8 | - | ||||||||||||||||||
| 3755 | - | |||||||||||||||||||
| 3756 | Returns \c true if this string contains an occurrence of the string | - | ||||||||||||||||||
| 3757 | reference \a str; otherwise returns \c false. | - | ||||||||||||||||||
| 3758 | - | |||||||||||||||||||
| 3759 | If \a cs is Qt::CaseSensitive (default), the search is | - | ||||||||||||||||||
| 3760 | case sensitive; otherwise the search is case insensitive. | - | ||||||||||||||||||
| 3761 | - | |||||||||||||||||||
| 3762 | \sa indexOf(), count() | - | ||||||||||||||||||
| 3763 | */ | - | ||||||||||||||||||
| 3764 | - | |||||||||||||||||||
| 3765 | /*! \fn bool QString::contains(const QRegExp &rx) const | - | ||||||||||||||||||
| 3766 | - | |||||||||||||||||||
| 3767 | \overload contains() | - | ||||||||||||||||||
| 3768 | - | |||||||||||||||||||
| 3769 | Returns \c true if the regular expression \a rx matches somewhere in | - | ||||||||||||||||||
| 3770 | this string; otherwise returns \c false. | - | ||||||||||||||||||
| 3771 | */ | - | ||||||||||||||||||
| 3772 | - | |||||||||||||||||||
| 3773 | /*! \fn bool QString::contains(QRegExp &rx) const | - | ||||||||||||||||||
| 3774 | \overload contains() | - | ||||||||||||||||||
| 3775 | \since 4.5 | - | ||||||||||||||||||
| 3776 | - | |||||||||||||||||||
| 3777 | Returns \c true if the regular expression \a rx matches somewhere in | - | ||||||||||||||||||
| 3778 | this string; otherwise returns \c false. | - | ||||||||||||||||||
| 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 | - | |||||||||||||||||||
| 3784 | #ifndef QT_NO_REGEXP | - | ||||||||||||||||||
| 3785 | /*! | - | ||||||||||||||||||
| 3786 | \overload indexOf() | - | ||||||||||||||||||
| 3787 | - | |||||||||||||||||||
| 3788 | Returns the index position of the first match of the regular | - | ||||||||||||||||||
| 3789 | expression \a rx in the string, searching forward from index | - | ||||||||||||||||||
| 3790 | position \a from. Returns -1 if \a rx didn't match anywhere. | - | ||||||||||||||||||
| 3791 | - | |||||||||||||||||||
| 3792 | Example: | - | ||||||||||||||||||
| 3793 | - | |||||||||||||||||||
| 3794 | \snippet qstring/main.cpp 25 | - | ||||||||||||||||||
| 3795 | */ | - | ||||||||||||||||||
| 3796 | int QString::indexOf(const QRegExp& rx, int from) const | - | ||||||||||||||||||
| 3797 | { | - | ||||||||||||||||||
| 3798 | QRegExp rx2(rx); | - | ||||||||||||||||||
| 3799 | return rx2.indexIn(*this, from); executed 20349 times by 11 tests: return rx2.indexIn(*this, from);Executed by:
| 20349 | ||||||||||||||||||
| 3800 | } | - | ||||||||||||||||||
| 3801 | - | |||||||||||||||||||
| 3802 | /*! | - | ||||||||||||||||||
| 3803 | \overload indexOf() | - | ||||||||||||||||||
| 3804 | \since 4.5 | - | ||||||||||||||||||
| 3805 | - | |||||||||||||||||||
| 3806 | Returns the index position of the first match of the regular | - | ||||||||||||||||||
| 3807 | expression \a rx in the string, searching forward from index | - | ||||||||||||||||||
| 3808 | position \a from. Returns -1 if \a rx didn't match anywhere. | - | ||||||||||||||||||
| 3809 | - | |||||||||||||||||||
| 3810 | If there is a match, the \a rx regular expression will contain the | - | ||||||||||||||||||
| 3811 | matched captures (see QRegExp::matchedLength, QRegExp::cap). | - | ||||||||||||||||||
| 3812 | - | |||||||||||||||||||
| 3813 | Example: | - | ||||||||||||||||||
| 3814 | - | |||||||||||||||||||
| 3815 | \snippet qstring/main.cpp 25 | - | ||||||||||||||||||
| 3816 | */ | - | ||||||||||||||||||
| 3817 | int QString::indexOf(QRegExp& rx, int from) const | - | ||||||||||||||||||
| 3818 | { | - | ||||||||||||||||||
| 3819 | return rx.indexIn(*this, from); executed 327 times by 5 tests: return rx.indexIn(*this, from);Executed by:
| 327 | ||||||||||||||||||
| 3820 | } | - | ||||||||||||||||||
| 3821 | - | |||||||||||||||||||
| 3822 | /*! | - | ||||||||||||||||||
| 3823 | \overload lastIndexOf() | - | ||||||||||||||||||
| 3824 | - | |||||||||||||||||||
| 3825 | Returns the index position of the last match of the regular | - | ||||||||||||||||||
| 3826 | expression \a rx in the string, searching backward from index | - | ||||||||||||||||||
| 3827 | position \a from. Returns -1 if \a rx didn't match anywhere. | - | ||||||||||||||||||
| 3828 | - | |||||||||||||||||||
| 3829 | Example: | - | ||||||||||||||||||
| 3830 | - | |||||||||||||||||||
| 3831 | \snippet qstring/main.cpp 30 | - | ||||||||||||||||||
| 3832 | */ | - | ||||||||||||||||||
| 3833 | int QString::lastIndexOf(const QRegExp& rx, int from) const | - | ||||||||||||||||||
| 3834 | { | - | ||||||||||||||||||
| 3835 | QRegExp rx2(rx); | - | ||||||||||||||||||
| 3836 | return rx2.lastIndexIn(*this, from); executed 36 times by 1 test: return rx2.lastIndexIn(*this, from);Executed by:
| 36 | ||||||||||||||||||
| 3837 | } | - | ||||||||||||||||||
| 3838 | - | |||||||||||||||||||
| 3839 | /*! | - | ||||||||||||||||||
| 3840 | \overload lastIndexOf() | - | ||||||||||||||||||
| 3841 | \since 4.5 | - | ||||||||||||||||||
| 3842 | - | |||||||||||||||||||
| 3843 | Returns the index position of the last match of the regular | - | ||||||||||||||||||
| 3844 | expression \a rx in the string, searching backward from index | - | ||||||||||||||||||
| 3845 | position \a from. Returns -1 if \a rx didn't match anywhere. | - | ||||||||||||||||||
| 3846 | - | |||||||||||||||||||
| 3847 | If there is a match, the \a rx regular expression will contain the | - | ||||||||||||||||||
| 3848 | matched captures (see QRegExp::matchedLength, QRegExp::cap). | - | ||||||||||||||||||
| 3849 | - | |||||||||||||||||||
| 3850 | Example: | - | ||||||||||||||||||
| 3851 | - | |||||||||||||||||||
| 3852 | \snippet qstring/main.cpp 30 | - | ||||||||||||||||||
| 3853 | */ | - | ||||||||||||||||||
| 3854 | int QString::lastIndexOf(QRegExp& rx, int from) const | - | ||||||||||||||||||
| 3855 | { | - | ||||||||||||||||||
| 3856 | return rx.lastIndexIn(*this, from); executed 36 times by 1 test: return rx.lastIndexIn(*this, from);Executed by:
| 36 | ||||||||||||||||||
| 3857 | } | - | ||||||||||||||||||
| 3858 | - | |||||||||||||||||||
| 3859 | /*! | - | ||||||||||||||||||
| 3860 | \overload count() | - | ||||||||||||||||||
| 3861 | - | |||||||||||||||||||
| 3862 | Returns the number of times the regular expression \a rx matches | - | ||||||||||||||||||
| 3863 | in the string. | - | ||||||||||||||||||
| 3864 | - | |||||||||||||||||||
| 3865 | This function counts overlapping matches, so in the example | - | ||||||||||||||||||
| 3866 | below, there are four instances of "ana" or "ama": | - | ||||||||||||||||||
| 3867 | - | |||||||||||||||||||
| 3868 | \snippet qstring/main.cpp 18 | - | ||||||||||||||||||
| 3869 | - | |||||||||||||||||||
| 3870 | */ | - | ||||||||||||||||||
| 3871 | int QString::count(const QRegExp& rx) const | - | ||||||||||||||||||
| 3872 | { | - | ||||||||||||||||||
| 3873 | QRegExp rx2(rx); | - | ||||||||||||||||||
| 3874 | int count = 0; | - | ||||||||||||||||||
| 3875 | int index = -1; | - | ||||||||||||||||||
| 3876 | int len = length(); | - | ||||||||||||||||||
| 3877 | while (index < len - 1) { // count overlapping matches
| 0-5 | ||||||||||||||||||
| 3878 | index = rx2.indexIn(*this, index + 1); | - | ||||||||||||||||||
| 3879 | if (index == -1)
| 2-3 | ||||||||||||||||||
| 3880 | break; executed 2 times by 1 test: break;Executed by:
| 2 | ||||||||||||||||||
| 3881 | count++; | - | ||||||||||||||||||
| 3882 | } executed 3 times by 1 test: end of blockExecuted by:
| 3 | ||||||||||||||||||
| 3883 | return count; executed 2 times by 1 test: return count;Executed by:
| 2 | ||||||||||||||||||
| 3884 | } | - | ||||||||||||||||||
| 3885 | #endif // QT_NO_REGEXP | - | ||||||||||||||||||
| 3886 | - | |||||||||||||||||||
| 3887 | #ifndef QT_NO_REGULAREXPRESSION | - | ||||||||||||||||||
| 3888 | #ifndef QT_BOOTSTRAPPED | - | ||||||||||||||||||
| 3889 | /*! | - | ||||||||||||||||||
| 3890 | \overload indexOf() | - | ||||||||||||||||||
| 3891 | \since 5.0 | - | ||||||||||||||||||
| 3892 | - | |||||||||||||||||||
| 3893 | Returns the index position of the first match of the regular | - | ||||||||||||||||||
| 3894 | expression \a re in the string, searching forward from index | - | ||||||||||||||||||
| 3895 | position \a from. Returns -1 if \a re didn't match anywhere. | - | ||||||||||||||||||
| 3896 | - | |||||||||||||||||||
| 3897 | Example: | - | ||||||||||||||||||
| 3898 | - | |||||||||||||||||||
| 3899 | \snippet qstring/main.cpp 93 | - | ||||||||||||||||||
| 3900 | */ | - | ||||||||||||||||||
| 3901 | int QString::indexOf(const QRegularExpression& re, int from) const | - | ||||||||||||||||||
| 3902 | { | - | ||||||||||||||||||
| 3903 | return indexOf(re, from, Q_NULLPTR); executed 65 times by 1 test: return indexOf(re, from, nullptr);Executed by:
| 65 | ||||||||||||||||||
| 3904 | } | - | ||||||||||||||||||
| 3905 | - | |||||||||||||||||||
| 3906 | /*! | - | ||||||||||||||||||
| 3907 | \overload | - | ||||||||||||||||||
| 3908 | \since 5.5 | - | ||||||||||||||||||
| 3909 | - | |||||||||||||||||||
| 3910 | Returns the index position of the first match of the regular | - | ||||||||||||||||||
| 3911 | expression \a re in the string, searching forward from index | - | ||||||||||||||||||
| 3912 | position \a from. Returns -1 if \a re didn't match anywhere. | - | ||||||||||||||||||
| 3913 | - | |||||||||||||||||||
| 3914 | If the match is successful and \a rmatch is not a null pointer, it also | - | ||||||||||||||||||
| 3915 | writes the results of the match into the QRegularExpressionMatch object | - | ||||||||||||||||||
| 3916 | pointed to by \a rmatch. | - | ||||||||||||||||||
| 3917 | - | |||||||||||||||||||
| 3918 | Example: | - | ||||||||||||||||||
| 3919 | - | |||||||||||||||||||
| 3920 | \snippet qstring/main.cpp 99 | - | ||||||||||||||||||
| 3921 | */ | - | ||||||||||||||||||
| 3922 | int QString::indexOf(const QRegularExpression &re, int from, QRegularExpressionMatch *rmatch) const | - | ||||||||||||||||||
| 3923 | { | - | ||||||||||||||||||
| 3924 | if (!re.isValid()) {
| 3-196 | ||||||||||||||||||
| 3925 | qWarning("QString::indexOf: invalid QRegularExpression object"); | - | ||||||||||||||||||
| 3926 | return -1; executed 3 times by 1 test: return -1;Executed by:
| 3 | ||||||||||||||||||
| 3927 | } | - | ||||||||||||||||||
| 3928 | - | |||||||||||||||||||
| 3929 | QRegularExpressionMatch match = re.match(*this, from); | - | ||||||||||||||||||
| 3930 | if (match.hasMatch()) {
| 87-109 | ||||||||||||||||||
| 3931 | const int ret = match.capturedStart(); | - | ||||||||||||||||||
| 3932 | if (rmatch)
| 39-70 | ||||||||||||||||||
| 3933 | *rmatch = qMove(match); executed 39 times by 2 tests: *rmatch = std::move(match);Executed by:
| 39 | ||||||||||||||||||
| 3934 | return ret; executed 109 times by 2 tests: return ret;Executed by:
| 109 | ||||||||||||||||||
| 3935 | } | - | ||||||||||||||||||
| 3936 | - | |||||||||||||||||||
| 3937 | return -1; executed 87 times by 1 test: return -1;Executed by:
| 87 | ||||||||||||||||||
| 3938 | } | - | ||||||||||||||||||
| 3939 | - | |||||||||||||||||||
| 3940 | /*! | - | ||||||||||||||||||
| 3941 | \overload lastIndexOf() | - | ||||||||||||||||||
| 3942 | \since 5.0 | - | ||||||||||||||||||
| 3943 | - | |||||||||||||||||||
| 3944 | Returns the index position of the last match of the regular | - | ||||||||||||||||||
| 3945 | expression \a re in the string, which starts before the index | - | ||||||||||||||||||
| 3946 | position \a from. Returns -1 if \a re didn't match anywhere. | - | ||||||||||||||||||
| 3947 | - | |||||||||||||||||||
| 3948 | Example: | - | ||||||||||||||||||
| 3949 | - | |||||||||||||||||||
| 3950 | \snippet qstring/main.cpp 94 | - | ||||||||||||||||||
| 3951 | */ | - | ||||||||||||||||||
| 3952 | int QString::lastIndexOf(const QRegularExpression &re, int from) const | - | ||||||||||||||||||
| 3953 | { | - | ||||||||||||||||||
| 3954 | return lastIndexOf(re, from, Q_NULLPTR); executed 19 times by 1 test: return lastIndexOf(re, from, nullptr);Executed by:
| 19 | ||||||||||||||||||
| 3955 | } | - | ||||||||||||||||||
| 3956 | - | |||||||||||||||||||
| 3957 | /*! | - | ||||||||||||||||||
| 3958 | \overload | - | ||||||||||||||||||
| 3959 | \since 5.5 | - | ||||||||||||||||||
| 3960 | - | |||||||||||||||||||
| 3961 | Returns the index position of the last match of the regular | - | ||||||||||||||||||
| 3962 | expression \a re in the string, which starts before the index | - | ||||||||||||||||||
| 3963 | position \a from. Returns -1 if \a re didn't match anywhere. | - | ||||||||||||||||||
| 3964 | - | |||||||||||||||||||
| 3965 | If the match is successful and \a rmatch is not a null pointer, it also | - | ||||||||||||||||||
| 3966 | writes the results of the match into the QRegularExpressionMatch object | - | ||||||||||||||||||
| 3967 | pointed to by \a rmatch. | - | ||||||||||||||||||
| 3968 | - | |||||||||||||||||||
| 3969 | Example: | - | ||||||||||||||||||
| 3970 | - | |||||||||||||||||||
| 3971 | \snippet qstring/main.cpp 100 | - | ||||||||||||||||||
| 3972 | */ | - | ||||||||||||||||||
| 3973 | int QString::lastIndexOf(const QRegularExpression &re, int from, QRegularExpressionMatch *rmatch) const | - | ||||||||||||||||||
| 3974 | { | - | ||||||||||||||||||
| 3975 | if (!re.isValid()) {
| 3-57 | ||||||||||||||||||
| 3976 | qWarning("QString::lastIndexOf: invalid QRegularExpression object"); | - | ||||||||||||||||||
| 3977 | return -1; executed 3 times by 1 test: return -1;Executed by:
| 3 | ||||||||||||||||||
| 3978 | } | - | ||||||||||||||||||
| 3979 | - | |||||||||||||||||||
| 3980 | int endpos = (from < 0) ? (size() + from + 1) : (from + 1);
| 18-39 | ||||||||||||||||||
| 3981 | QRegularExpressionMatchIterator iterator = re.globalMatch(*this); | - | ||||||||||||||||||
| 3982 | int lastIndex = -1; | - | ||||||||||||||||||
| 3983 | while (iterator.hasNext()) {
| 40-109 | ||||||||||||||||||
| 3984 | QRegularExpressionMatch match = iterator.next(); | - | ||||||||||||||||||
| 3985 | int start = match.capturedStart(); | - | ||||||||||||||||||
| 3986 | if (start < endpos) {
| 17-92 | ||||||||||||||||||
| 3987 | lastIndex = start; | - | ||||||||||||||||||
| 3988 | if (rmatch)
| 34-58 | ||||||||||||||||||
| 3989 | *rmatch = qMove(match); executed 34 times by 2 tests: *rmatch = std::move(match);Executed by:
| 34 | ||||||||||||||||||
| 3990 | } else { executed 92 times by 2 tests: end of blockExecuted by:
| 92 | ||||||||||||||||||
| 3991 | break; executed 17 times by 2 tests: break;Executed by:
| 17 | ||||||||||||||||||
| 3992 | } | - | ||||||||||||||||||
| 3993 | } | - | ||||||||||||||||||
| 3994 | - | |||||||||||||||||||
| 3995 | return lastIndex; executed 57 times by 2 tests: return lastIndex;Executed by:
| 57 | ||||||||||||||||||
| 3996 | } | - | ||||||||||||||||||
| 3997 | - | |||||||||||||||||||
| 3998 | /*! \overload contains() | - | ||||||||||||||||||
| 3999 | \since 5.0 | - | ||||||||||||||||||
| 4000 | - | |||||||||||||||||||
| 4001 | Returns \c true if the regular expression \a re matches somewhere in | - | ||||||||||||||||||
| 4002 | this string; otherwise returns \c false. | - | ||||||||||||||||||
| 4003 | */ | - | ||||||||||||||||||
| 4004 | bool QString::contains(const QRegularExpression &re) const | - | ||||||||||||||||||
| 4005 | { | - | ||||||||||||||||||
| 4006 | return contains(re, Q_NULLPTR); executed 6 times by 2 tests: return contains(re, nullptr);Executed by:
| 6 | ||||||||||||||||||
| 4007 | } | - | ||||||||||||||||||
| 4008 | - | |||||||||||||||||||
| 4009 | /*! | - | ||||||||||||||||||
| 4010 | \overload contains() | - | ||||||||||||||||||
| 4011 | \since 5.1 | - | ||||||||||||||||||
| 4012 | - | |||||||||||||||||||
| 4013 | Returns \c true if the regular expression \a re matches somewhere in this | - | ||||||||||||||||||
| 4014 | string; otherwise returns \c false. | - | ||||||||||||||||||
| 4015 | - | |||||||||||||||||||
| 4016 | If the match is successful and \a match is not a null pointer, it also | - | ||||||||||||||||||
| 4017 | writes the results of the match into the QRegularExpressionMatch object | - | ||||||||||||||||||
| 4018 | pointed to by \a match. | - | ||||||||||||||||||
| 4019 | - | |||||||||||||||||||
| 4020 | \sa QRegularExpression::match() | - | ||||||||||||||||||
| 4021 | */ | - | ||||||||||||||||||
| 4022 | - | |||||||||||||||||||
| 4023 | bool QString::contains(const QRegularExpression &re, QRegularExpressionMatch *match) const | - | ||||||||||||||||||
| 4024 | { | - | ||||||||||||||||||
| 4025 | if (!re.isValid()) {
| 1-12 | ||||||||||||||||||
| 4026 | qWarning("QString::contains: invalid QRegularExpression object"); | - | ||||||||||||||||||
| 4027 | return false; executed 1 time by 1 test: return false;Executed by:
| 1 | ||||||||||||||||||
| 4028 | } | - | ||||||||||||||||||
| 4029 | QRegularExpressionMatch m = re.match(*this); | - | ||||||||||||||||||
| 4030 | bool hasMatch = m.hasMatch(); | - | ||||||||||||||||||
| 4031 | if (hasMatch && match)
| 3-9 | ||||||||||||||||||
| 4032 | *match = qMove(m); executed 4 times by 1 test: *match = std::move(m);Executed by:
| 4 | ||||||||||||||||||
| 4033 | return hasMatch; executed 12 times by 2 tests: return hasMatch;Executed by:
| 12 | ||||||||||||||||||
| 4034 | } | - | ||||||||||||||||||
| 4035 | - | |||||||||||||||||||
| 4036 | /*! | - | ||||||||||||||||||
| 4037 | \overload count() | - | ||||||||||||||||||
| 4038 | \since 5.0 | - | ||||||||||||||||||
| 4039 | - | |||||||||||||||||||
| 4040 | Returns the number of times the regular expression \a re matches | - | ||||||||||||||||||
| 4041 | in the string. | - | ||||||||||||||||||
| 4042 | - | |||||||||||||||||||
| 4043 | This function counts overlapping matches, so in the example | - | ||||||||||||||||||
| 4044 | below, there are four instances of "ana" or "ama": | - | ||||||||||||||||||
| 4045 | - | |||||||||||||||||||
| 4046 | \snippet qstring/main.cpp 95 | - | ||||||||||||||||||
| 4047 | */ | - | ||||||||||||||||||
| 4048 | int QString::count(const QRegularExpression &re) const | - | ||||||||||||||||||
| 4049 | { | - | ||||||||||||||||||
| 4050 | if (!re.isValid()) {
| 1-122 | ||||||||||||||||||
| 4051 | qWarning("QString::count: invalid QRegularExpression object"); | - | ||||||||||||||||||
| 4052 | return 0; executed 1 time by 1 test: return 0;Executed by:
| 1 | ||||||||||||||||||
| 4053 | } | - | ||||||||||||||||||
| 4054 | int count = 0; | - | ||||||||||||||||||
| 4055 | int index = -1; | - | ||||||||||||||||||
| 4056 | int len = length(); | - | ||||||||||||||||||
| 4057 | while (index < len - 1) {
| 0-245 | ||||||||||||||||||
| 4058 | QRegularExpressionMatch match = re.match(*this, index + 1); | - | ||||||||||||||||||
| 4059 | if (!match.hasMatch())
| 122-123 | ||||||||||||||||||
| 4060 | break; executed 122 times by 2 tests: break;Executed by:
| 122 | ||||||||||||||||||
| 4061 | index = match.capturedStart(); | - | ||||||||||||||||||
| 4062 | count++; | - | ||||||||||||||||||
| 4063 | } executed 123 times by 2 tests: end of blockExecuted by:
| 123 | ||||||||||||||||||
| 4064 | return count; executed 122 times by 2 tests: return count;Executed by:
| 122 | ||||||||||||||||||
| 4065 | } | - | ||||||||||||||||||
| 4066 | #endif // QT_BOOTSTRAPPED | - | ||||||||||||||||||
| 4067 | #endif // QT_NO_REGULAREXPRESSION | - | ||||||||||||||||||
| 4068 | - | |||||||||||||||||||
| 4069 | /*! \fn int QString::count() const | - | ||||||||||||||||||
| 4070 | - | |||||||||||||||||||
| 4071 | \overload count() | - | ||||||||||||||||||
| 4072 | - | |||||||||||||||||||
| 4073 | Same as size(). | - | ||||||||||||||||||
| 4074 | */ | - | ||||||||||||||||||
| 4075 | - | |||||||||||||||||||
| 4076 | - | |||||||||||||||||||
| 4077 | /*! | - | ||||||||||||||||||
| 4078 | \enum QString::SectionFlag | - | ||||||||||||||||||
| 4079 | - | |||||||||||||||||||
| 4080 | This enum specifies flags that can be used to affect various | - | ||||||||||||||||||
| 4081 | aspects of the section() function's behavior with respect to | - | ||||||||||||||||||
| 4082 | separators and empty fields. | - | ||||||||||||||||||
| 4083 | - | |||||||||||||||||||
| 4084 | \value SectionDefault Empty fields are counted, leading and | - | ||||||||||||||||||
| 4085 | trailing separators are not included, and the separator is | - | ||||||||||||||||||
| 4086 | compared case sensitively. | - | ||||||||||||||||||
| 4087 | - | |||||||||||||||||||
| 4088 | \value SectionSkipEmpty Treat empty fields as if they don't exist, | - | ||||||||||||||||||
| 4089 | i.e. they are not considered as far as \e start and \e end are | - | ||||||||||||||||||
| 4090 | concerned. | - | ||||||||||||||||||
| 4091 | - | |||||||||||||||||||
| 4092 | \value SectionIncludeLeadingSep Include the leading separator (if | - | ||||||||||||||||||
| 4093 | any) in the result string. | - | ||||||||||||||||||
| 4094 | - | |||||||||||||||||||
| 4095 | \value SectionIncludeTrailingSep Include the trailing separator | - | ||||||||||||||||||
| 4096 | (if any) in the result string. | - | ||||||||||||||||||
| 4097 | - | |||||||||||||||||||
| 4098 | \value SectionCaseInsensitiveSeps Compare the separator | - | ||||||||||||||||||
| 4099 | case-insensitively. | - | ||||||||||||||||||
| 4100 | - | |||||||||||||||||||
| 4101 | \sa section() | - | ||||||||||||||||||
| 4102 | */ | - | ||||||||||||||||||
| 4103 | - | |||||||||||||||||||
| 4104 | /*! | - | ||||||||||||||||||
| 4105 | \fn QString QString::section(QChar sep, int start, int end = -1, SectionFlags flags) const | - | ||||||||||||||||||
| 4106 | - | |||||||||||||||||||
| 4107 | This function returns a section of the string. | - | ||||||||||||||||||
| 4108 | - | |||||||||||||||||||
| 4109 | This string is treated as a sequence of fields separated by the | - | ||||||||||||||||||
| 4110 | character, \a sep. The returned string consists of the fields from | - | ||||||||||||||||||
| 4111 | position \a start to position \a end inclusive. If \a end is not | - | ||||||||||||||||||
| 4112 | specified, all fields from position \a start to the end of the | - | ||||||||||||||||||
| 4113 | string are included. Fields are numbered 0, 1, 2, etc., counting | - | ||||||||||||||||||
| 4114 | from the left, and -1, -2, etc., counting from right to left. | - | ||||||||||||||||||
| 4115 | - | |||||||||||||||||||
| 4116 | The \a flags argument can be used to affect some aspects of the | - | ||||||||||||||||||
| 4117 | function's behavior, e.g. whether to be case sensitive, whether | - | ||||||||||||||||||
| 4118 | to skip empty fields and how to deal with leading and trailing | - | ||||||||||||||||||
| 4119 | separators; see \l{SectionFlags}. | - | ||||||||||||||||||
| 4120 | - | |||||||||||||||||||
| 4121 | \snippet qstring/main.cpp 52 | - | ||||||||||||||||||
| 4122 | - | |||||||||||||||||||
| 4123 | If \a start or \a end is negative, we count fields from the right | - | ||||||||||||||||||
| 4124 | of the string, the right-most field being -1, the one from | - | ||||||||||||||||||
| 4125 | right-most field being -2, and so on. | - | ||||||||||||||||||
| 4126 | - | |||||||||||||||||||
| 4127 | \snippet qstring/main.cpp 53 | - | ||||||||||||||||||
| 4128 | - | |||||||||||||||||||
| 4129 | \sa split() | - | ||||||||||||||||||
| 4130 | */ | - | ||||||||||||||||||
| 4131 | - | |||||||||||||||||||
| 4132 | /*! | - | ||||||||||||||||||
| 4133 | \overload section() | - | ||||||||||||||||||
| 4134 | - | |||||||||||||||||||
| 4135 | \snippet qstring/main.cpp 51 | - | ||||||||||||||||||
| 4136 | \snippet qstring/main.cpp 54 | - | ||||||||||||||||||
| 4137 | - | |||||||||||||||||||
| 4138 | \sa split() | - | ||||||||||||||||||
| 4139 | */ | - | ||||||||||||||||||
| 4140 | - | |||||||||||||||||||
| 4141 | QString QString::section(const QString &sep, int start, int end, SectionFlags flags) const | - | ||||||||||||||||||
| 4142 | { | - | ||||||||||||||||||
| 4143 | const QVector<QStringRef> sections = splitRef(sep, KeepEmptyParts, | - | ||||||||||||||||||
| 4144 | (flags & SectionCaseInsensitiveSeps) ? Qt::CaseInsensitive : Qt::CaseSensitive); | - | ||||||||||||||||||
| 4145 | const int sectionsSize = sections.size(); | - | ||||||||||||||||||
| 4146 | if (!(flags & SectionSkipEmpty)) {
| 230-1992 | ||||||||||||||||||
| 4147 | if (start < 0)
| 64-166 | ||||||||||||||||||
| 4148 | start += sectionsSize; executed 166 times by 8 tests: start += sectionsSize;Executed by:
| 166 | ||||||||||||||||||
| 4149 | if (end < 0)
| 59-171 | ||||||||||||||||||
| 4150 | end += sectionsSize; executed 171 times by 9 tests: end += sectionsSize;Executed by:
| 171 | ||||||||||||||||||
| 4151 | } else { executed 230 times by 11 tests: end of blockExecuted by:
| 230 | ||||||||||||||||||
| 4152 | int skip = 0; | - | ||||||||||||||||||
| 4153 | for (int k = 0; k < sectionsSize; ++k) {
| 1992-15024 | ||||||||||||||||||
| 4154 | if (sections.at(k).isEmpty())
| 2048-12976 | ||||||||||||||||||
| 4155 | skip++; executed 2048 times by 2 tests: skip++;Executed by:
| 2048 | ||||||||||||||||||
| 4156 | } executed 15024 times by 3 tests: end of blockExecuted by:
| 15024 | ||||||||||||||||||
| 4157 | if (start < 0)
| 4-1988 | ||||||||||||||||||
| 4158 | start += sectionsSize - skip; executed 4 times by 1 test: start += sectionsSize - skip;Executed by:
| 4 | ||||||||||||||||||
| 4159 | if (end < 0)
| 198-1794 | ||||||||||||||||||
| 4160 | end += sectionsSize - skip; executed 1794 times by 2 tests: end += sectionsSize - skip;Executed by:
| 1794 | ||||||||||||||||||
| 4161 | } executed 1992 times by 3 tests: end of blockExecuted by:
| 1992 | ||||||||||||||||||
| 4162 | if (start >= sectionsSize || end < 0 || start > end)
| 2-2220 | ||||||||||||||||||
| 4163 | return QString(); executed 6 times by 1 test: return QString();Executed by:
| 6 | ||||||||||||||||||
| 4164 | - | |||||||||||||||||||
| 4165 | QString ret; | - | ||||||||||||||||||
| 4166 | int first_i = start, last_i = end; | - | ||||||||||||||||||
| 4167 | for (int x = 0, i = 0; x <= end && i < sectionsSize; ++i) {
| 0-13295 | ||||||||||||||||||
| 4168 | const QStringRef §ion = sections.at(i); | - | ||||||||||||||||||
| 4169 | const bool empty = section.isEmpty(); | - | ||||||||||||||||||
| 4170 | if (x >= start) {
| 2307-10988 | ||||||||||||||||||
| 4171 | if(x == start)
| 45-2262 | ||||||||||||||||||
| 4172 | first_i = i; executed 2262 times by 13 tests: first_i = i;Executed by:
| 2262 | ||||||||||||||||||
| 4173 | if(x == end)
| 43-2264 | ||||||||||||||||||
| 4174 | last_i = i; executed 2264 times by 13 tests: last_i = i;Executed by:
| 2264 | ||||||||||||||||||
| 4175 | if (x > start && i > 0)
| 2-2262 | ||||||||||||||||||
| 4176 | ret += sep; executed 43 times by 2 tests: ret += sep;Executed by:
| 43 | ||||||||||||||||||
| 4177 | ret += section; | - | ||||||||||||||||||
| 4178 | } executed 2307 times by 13 tests: end of blockExecuted by:
| 2307 | ||||||||||||||||||
| 4179 | if (!empty || !(flags & SectionSkipEmpty))
| 24-13139 | ||||||||||||||||||
| 4180 | x++; executed 13163 times by 13 tests: x++;Executed by:
| 13163 | ||||||||||||||||||
| 4181 | } executed 13295 times by 13 tests: end of blockExecuted by:
| 13295 | ||||||||||||||||||
| 4182 | if ((flags & SectionIncludeLeadingSep) && first_i > 0)
| 10-16 | ||||||||||||||||||
| 4183 | ret.prepend(sep); executed 16 times by 1 test: ret.prepend(sep);Executed by:
| 16 | ||||||||||||||||||
| 4184 | if ((flags & SectionIncludeTrailingSep) && last_i < sectionsSize - 1)
| 4-16 | ||||||||||||||||||
| 4185 | ret += sep; executed 16 times by 1 test: ret += sep;Executed by:
| 16 | ||||||||||||||||||
| 4186 | return ret; executed 2216 times by 13 tests: return ret;Executed by:
| 2216 | ||||||||||||||||||
| 4187 | } | - | ||||||||||||||||||
| 4188 | - | |||||||||||||||||||
| 4189 | #if !(defined(QT_NO_REGEXP) && defined(QT_NO_REGULAREXPRESSION)) | - | ||||||||||||||||||
| 4190 | class qt_section_chunk { | - | ||||||||||||||||||
| 4191 | public: | - | ||||||||||||||||||
| 4192 | qt_section_chunk() {} | - | ||||||||||||||||||
| 4193 | qt_section_chunk(int l, QStringRef s) : length(l), string(qMove(s)) {} executed 638 times by 2 tests: end of blockExecuted by:
| 638 | ||||||||||||||||||
| 4194 | int length; | - | ||||||||||||||||||
| 4195 | QStringRef string; | - | ||||||||||||||||||
| 4196 | }; | - | ||||||||||||||||||
| 4197 | Q_DECLARE_TYPEINFO(qt_section_chunk, Q_MOVABLE_TYPE); | - | ||||||||||||||||||
| 4198 | - | |||||||||||||||||||
| 4199 | static QString extractSections(const QVector<qt_section_chunk> §ions, | - | ||||||||||||||||||
| 4200 | int start, | - | ||||||||||||||||||
| 4201 | int end, | - | ||||||||||||||||||
| 4202 | QString::SectionFlags flags) | - | ||||||||||||||||||
| 4203 | { | - | ||||||||||||||||||
| 4204 | const int sectionsSize = sections.size(); | - | ||||||||||||||||||
| 4205 | - | |||||||||||||||||||
| 4206 | if (!(flags & QString::SectionSkipEmpty)) {
| 18-72 | ||||||||||||||||||
| 4207 | if (start < 0)
| 9-63 | ||||||||||||||||||
| 4208 | start += sectionsSize; executed 9 times by 2 tests: start += sectionsSize;Executed by:
| 9 | ||||||||||||||||||
| 4209 | if (end < 0)
| 18-54 | ||||||||||||||||||
| 4210 | end += sectionsSize; executed 18 times by 2 tests: end += sectionsSize;Executed by:
| 18 | ||||||||||||||||||
| 4211 | } else { executed 72 times by 2 tests: end of blockExecuted by:
| 72 | ||||||||||||||||||
| 4212 | int skip = 0; | - | ||||||||||||||||||
| 4213 | for (int k = 0; k < sectionsSize; ++k) {
| 18-324 | ||||||||||||||||||
| 4214 | const qt_section_chunk §ion = sections.at(k); | - | ||||||||||||||||||
| 4215 | if (section.length == section.string.length())
| 68-256 | ||||||||||||||||||
| 4216 | skip++; executed 256 times by 1 test: skip++;Executed by:
| 256 | ||||||||||||||||||
| 4217 | } executed 324 times by 1 test: end of blockExecuted by:
| 324 | ||||||||||||||||||
| 4218 | if (start < 0)
| 4-14 | ||||||||||||||||||
| 4219 | start += sectionsSize - skip; executed 4 times by 1 test: start += sectionsSize - skip;Executed by:
| 4 | ||||||||||||||||||
| 4220 | if (end < 0)
| 2-16 | ||||||||||||||||||
| 4221 | end += sectionsSize - skip; executed 2 times by 1 test: end += sectionsSize - skip;Executed by:
| 2 | ||||||||||||||||||
| 4222 | } executed 18 times by 1 test: end of blockExecuted by:
| 18 | ||||||||||||||||||
| 4223 | if (start >= sectionsSize || end < 0 || start > end)
| 2-86 | ||||||||||||||||||
| 4224 | return QString(); executed 9 times by 2 tests: return QString();Executed by:
| 9 | ||||||||||||||||||
| 4225 | - | |||||||||||||||||||
| 4226 | QString ret; | - | ||||||||||||||||||
| 4227 | int x = 0; | - | ||||||||||||||||||
| 4228 | int first_i = start, last_i = end; | - | ||||||||||||||||||
| 4229 | for (int i = 0; x <= end && i < sectionsSize; ++i) {
| 0-365 | ||||||||||||||||||
| 4230 | const qt_section_chunk §ion = sections.at(i); | - | ||||||||||||||||||
| 4231 | const bool empty = (section.length == section.string.length()); | - | ||||||||||||||||||
| 4232 | if (x >= start) {
| 173-192 | ||||||||||||||||||
| 4233 | if (x == start)
| 65-127 | ||||||||||||||||||
| 4234 | first_i = i; executed 127 times by 2 tests: first_i = i;Executed by:
| 127 | ||||||||||||||||||
| 4235 | if (x == end)
| 63-129 | ||||||||||||||||||
| 4236 | last_i = i; executed 129 times by 2 tests: last_i = i;Executed by:
| 129 | ||||||||||||||||||
| 4237 | if (x != start)
| 65-127 | ||||||||||||||||||
| 4238 | ret += section.string; executed 65 times by 2 tests: ret += section.string;Executed by:
| 65 | ||||||||||||||||||
| 4239 | else | - | ||||||||||||||||||
| 4240 | ret += section.string.mid(section.length); executed 127 times by 2 tests: ret += section.string.mid(section.length);Executed by:
| 127 | ||||||||||||||||||
| 4241 | } | - | ||||||||||||||||||
| 4242 | if (!empty || !(flags & QString::SectionSkipEmpty))
| 50-183 | ||||||||||||||||||
| 4243 | x++; executed 233 times by 2 tests: x++;Executed by:
| 233 | ||||||||||||||||||
| 4244 | } executed 365 times by 2 tests: end of blockExecuted by:
| 365 | ||||||||||||||||||
| 4245 | - | |||||||||||||||||||
| 4246 | if ((flags & QString::SectionIncludeLeadingSep) && first_i >= 0) {
| 2-44 | ||||||||||||||||||
| 4247 | const qt_section_chunk §ion = sections.at(first_i); | - | ||||||||||||||||||
| 4248 | ret.prepend(section.string.left(section.length)); | - | ||||||||||||||||||
| 4249 | } executed 44 times by 1 test: end of blockExecuted by:
| 44 | ||||||||||||||||||
| 4250 | - | |||||||||||||||||||
| 4251 | if ((flags & QString::SectionIncludeTrailingSep) | - | ||||||||||||||||||
| 4252 | && last_i < sectionsSize - 1) {
| 6-28 | ||||||||||||||||||
| 4253 | const qt_section_chunk §ion = sections.at(last_i+1); | - | ||||||||||||||||||
| 4254 | ret += section.string.left(section.length); | - | ||||||||||||||||||
| 4255 | } executed 28 times by 1 test: end of blockExecuted by:
| 28 | ||||||||||||||||||
| 4256 | - | |||||||||||||||||||
| 4257 | return ret; executed 81 times by 2 tests: return ret;Executed by:
| 81 | ||||||||||||||||||
| 4258 | } | - | ||||||||||||||||||
| 4259 | #endif | - | ||||||||||||||||||
| 4260 | - | |||||||||||||||||||
| 4261 | #ifndef QT_NO_REGEXP | - | ||||||||||||||||||
| 4262 | /*! | - | ||||||||||||||||||
| 4263 | \overload section() | - | ||||||||||||||||||
| 4264 | - | |||||||||||||||||||
| 4265 | This string is treated as a sequence of fields separated by the | - | ||||||||||||||||||
| 4266 | regular expression, \a reg. | - | ||||||||||||||||||
| 4267 | - | |||||||||||||||||||
| 4268 | \snippet qstring/main.cpp 55 | - | ||||||||||||||||||
| 4269 | - | |||||||||||||||||||
| 4270 | \warning Using this QRegExp version is much more expensive than | - | ||||||||||||||||||
| 4271 | the overloaded string and character versions. | - | ||||||||||||||||||
| 4272 | - | |||||||||||||||||||
| 4273 | \sa split(), simplified() | - | ||||||||||||||||||
| 4274 | */ | - | ||||||||||||||||||
| 4275 | QString QString::section(const QRegExp ®, int start, int end, SectionFlags flags) const | - | ||||||||||||||||||
| 4276 | { | - | ||||||||||||||||||
| 4277 | const QChar *uc = unicode(); | - | ||||||||||||||||||
| 4278 | if(!uc)
| 0-48 | ||||||||||||||||||
| 4279 | return QString(); never executed: return QString(); | 0 | ||||||||||||||||||
| 4280 | - | |||||||||||||||||||
| 4281 | QRegExp sep(reg); | - | ||||||||||||||||||
| 4282 | sep.setCaseSensitivity((flags & SectionCaseInsensitiveSeps) ? Qt::CaseInsensitive | - | ||||||||||||||||||
| 4283 | : Qt::CaseSensitive); | - | ||||||||||||||||||
| 4284 | - | |||||||||||||||||||
| 4285 | QVector<qt_section_chunk> sections; | - | ||||||||||||||||||
| 4286 | int n = length(), m = 0, last_m = 0, last_len = 0; | - | ||||||||||||||||||
| 4287 | while ((m = sep.indexIn(*this, m)) != -1) {
| 48-277 | ||||||||||||||||||
| 4288 | sections.append(qt_section_chunk(last_len, QStringRef(this, last_m, m - last_m))); | - | ||||||||||||||||||
| 4289 | last_m = m; | - | ||||||||||||||||||
| 4290 | last_len = sep.matchedLength(); | - | ||||||||||||||||||
| 4291 | m += qMax(sep.matchedLength(), 1); | - | ||||||||||||||||||
| 4292 | } executed 277 times by 2 tests: end of blockExecuted by:
| 277 | ||||||||||||||||||
| 4293 | sections.append(qt_section_chunk(last_len, QStringRef(this, last_m, n - last_m))); | - | ||||||||||||||||||
| 4294 | - | |||||||||||||||||||
| 4295 | return extractSections(sections, start, end, flags); executed 48 times by 2 tests: return extractSections(sections, start, end, flags);Executed by:
| 48 | ||||||||||||||||||
| 4296 | } | - | ||||||||||||||||||
| 4297 | #endif | - | ||||||||||||||||||
| 4298 | - | |||||||||||||||||||
| 4299 | #ifndef QT_NO_REGULAREXPRESSION | - | ||||||||||||||||||
| 4300 | #ifndef QT_BOOTSTRAPPED | - | ||||||||||||||||||
| 4301 | /*! | - | ||||||||||||||||||
| 4302 | \overload section() | - | ||||||||||||||||||
| 4303 | \since 5.0 | - | ||||||||||||||||||
| 4304 | - | |||||||||||||||||||
| 4305 | This string is treated as a sequence of fields separated by the | - | ||||||||||||||||||
| 4306 | regular expression, \a re. | - | ||||||||||||||||||
| 4307 | - | |||||||||||||||||||
| 4308 | \snippet qstring/main.cpp 89 | - | ||||||||||||||||||
| 4309 | - | |||||||||||||||||||
| 4310 | \warning Using this QRegularExpression version is much more expensive than | - | ||||||||||||||||||
| 4311 | the overloaded string and character versions. | - | ||||||||||||||||||
| 4312 | - | |||||||||||||||||||
| 4313 | \sa split(), simplified() | - | ||||||||||||||||||
| 4314 | */ | - | ||||||||||||||||||
| 4315 | QString QString::section(const QRegularExpression &re, int start, int end, SectionFlags flags) const | - | ||||||||||||||||||
| 4316 | { | - | ||||||||||||||||||
| 4317 | if (!re.isValid()) {
| 0-42 | ||||||||||||||||||
| 4318 | qWarning("QString::section: invalid QRegularExpression object"); | - | ||||||||||||||||||
| 4319 | return QString(); never executed: return QString(); | 0 | ||||||||||||||||||
| 4320 | } | - | ||||||||||||||||||
| 4321 | - | |||||||||||||||||||
| 4322 | const QChar *uc = unicode(); | - | ||||||||||||||||||
| 4323 | if (!uc)
| 0-42 | ||||||||||||||||||
| 4324 | return QString(); never executed: return QString(); | 0 | ||||||||||||||||||
| 4325 | - | |||||||||||||||||||
| 4326 | QRegularExpression sep(re); | - | ||||||||||||||||||
| 4327 | if (flags & SectionCaseInsensitiveSeps)
| 1-41 | ||||||||||||||||||
| 4328 | sep.setPatternOptions(sep.patternOptions() | QRegularExpression::CaseInsensitiveOption); executed 1 time by 1 test: sep.setPatternOptions(sep.patternOptions() | QRegularExpression::CaseInsensitiveOption);Executed by:
| 1 | ||||||||||||||||||
| 4329 | - | |||||||||||||||||||
| 4330 | QVector<qt_section_chunk> sections; | - | ||||||||||||||||||
| 4331 | int n = length(), m = 0, last_m = 0, last_len = 0; | - | ||||||||||||||||||
| 4332 | QRegularExpressionMatchIterator iterator = sep.globalMatch(*this); | - | ||||||||||||||||||
| 4333 | while (iterator.hasNext()) {
| 42-271 | ||||||||||||||||||
| 4334 | QRegularExpressionMatch match = iterator.next(); | - | ||||||||||||||||||
| 4335 | m = match.capturedStart(); | - | ||||||||||||||||||
| 4336 | sections.append(qt_section_chunk(last_len, QStringRef(this, last_m, m - last_m))); | - | ||||||||||||||||||
| 4337 | last_m = m; | - | ||||||||||||||||||
| 4338 | last_len = match.capturedLength(); | - | ||||||||||||||||||
| 4339 | } executed 271 times by 1 test: end of blockExecuted by:
| 271 | ||||||||||||||||||
| 4340 | sections.append(qt_section_chunk(last_len, QStringRef(this, last_m, n - last_m))); | - | ||||||||||||||||||
| 4341 | - | |||||||||||||||||||
| 4342 | return extractSections(sections, start, end, flags); executed 42 times by 1 test: return extractSections(sections, start, end, flags);Executed by:
| 42 | ||||||||||||||||||
| 4343 | } | - | ||||||||||||||||||
| 4344 | #endif // QT_BOOTSTRAPPED | - | ||||||||||||||||||
| 4345 | #endif // QT_NO_REGULAREXPRESSION | - | ||||||||||||||||||
| 4346 | - | |||||||||||||||||||
| 4347 | /*! | - | ||||||||||||||||||
| 4348 | Returns a substring that contains the \a n leftmost characters | - | ||||||||||||||||||
| 4349 | of the string. | - | ||||||||||||||||||
| 4350 | - | |||||||||||||||||||
| 4351 | The entire string is returned if \a n is greater than or equal | - | ||||||||||||||||||
| 4352 | to size(), or less than zero. | - | ||||||||||||||||||
| 4353 | - | |||||||||||||||||||
| 4354 | \snippet qstring/main.cpp 31 | - | ||||||||||||||||||
| 4355 | - | |||||||||||||||||||
| 4356 | \sa right(), mid(), startsWith() | - | ||||||||||||||||||
| 4357 | */ | - | ||||||||||||||||||
| 4358 | QString QString::left(int n) const | - | ||||||||||||||||||
| 4359 | { | - | ||||||||||||||||||
| 4360 | if (uint(n) >= uint(d->size))
| 33846-79580 | ||||||||||||||||||
| 4361 | return *this; executed 33846 times by 81 tests: return *this;Executed by:
| 33846 | ||||||||||||||||||
| 4362 | return QString((const QChar*) d->data(), n); executed 79580 times by 197 tests: return QString((const QChar*) d->data(), n);Executed by:
| 79580 | ||||||||||||||||||
| 4363 | } | - | ||||||||||||||||||
| 4364 | - | |||||||||||||||||||
| 4365 | /*! | - | ||||||||||||||||||
| 4366 | Returns a substring that contains the \a n rightmost characters | - | ||||||||||||||||||
| 4367 | of the string. | - | ||||||||||||||||||
| 4368 | - | |||||||||||||||||||
| 4369 | The entire string is returned if \a n is greater than or equal | - | ||||||||||||||||||
| 4370 | to size(), or less than zero. | - | ||||||||||||||||||
| 4371 | - | |||||||||||||||||||
| 4372 | \snippet qstring/main.cpp 48 | - | ||||||||||||||||||
| 4373 | - | |||||||||||||||||||
| 4374 | \sa left(), mid(), endsWith() | - | ||||||||||||||||||
| 4375 | */ | - | ||||||||||||||||||
| 4376 | QString QString::right(int n) const | - | ||||||||||||||||||
| 4377 | { | - | ||||||||||||||||||
| 4378 | if (uint(n) >= uint(d->size))
| 62-4751 | ||||||||||||||||||
| 4379 | return *this; executed 62 times by 3 tests: return *this;Executed by:
| 62 | ||||||||||||||||||
| 4380 | return QString((const QChar*) d->data() + d->size - n, n); executed 4751 times by 32 tests: return QString((const QChar*) d->data() + d->size - n, n);Executed by:
| 4751 | ||||||||||||||||||
| 4381 | } | - | ||||||||||||||||||
| 4382 | - | |||||||||||||||||||
| 4383 | /*! | - | ||||||||||||||||||
| 4384 | Returns a string that contains \a n characters of this string, | - | ||||||||||||||||||
| 4385 | starting at the specified \a position index. | - | ||||||||||||||||||
| 4386 | - | |||||||||||||||||||
| 4387 | Returns a null string if the \a position index exceeds the | - | ||||||||||||||||||
| 4388 | length of the string. If there are less than \a n characters | - | ||||||||||||||||||
| 4389 | available in the string starting at the given \a position, or if | - | ||||||||||||||||||
| 4390 | \a n is -1 (default), the function returns all characters that | - | ||||||||||||||||||
| 4391 | are available from the specified \a position. | - | ||||||||||||||||||
| 4392 | - | |||||||||||||||||||
| 4393 | Example: | - | ||||||||||||||||||
| 4394 | - | |||||||||||||||||||
| 4395 | \snippet qstring/main.cpp 34 | - | ||||||||||||||||||
| 4396 | - | |||||||||||||||||||
| 4397 | \sa left(), right() | - | ||||||||||||||||||
| 4398 | */ | - | ||||||||||||||||||
| 4399 | - | |||||||||||||||||||
| 4400 | QString QString::mid(int position, int n) const | - | ||||||||||||||||||
| 4401 | { | - | ||||||||||||||||||
| 4402 | using namespace QtPrivate; | - | ||||||||||||||||||
| 4403 | switch (QContainerImplHelper::mid(d->size, &position, &n)) { | - | ||||||||||||||||||
| 4404 | case QContainerImplHelper::Null: executed 12348 times by 7 tests: case QContainerImplHelper::Null:Executed by:
| 12348 | ||||||||||||||||||
| 4405 | return QString(); executed 12348 times by 7 tests: return QString();Executed by:
| 12348 | ||||||||||||||||||
| 4406 | case QContainerImplHelper::Empty: executed 6166 times by 43 tests: case QContainerImplHelper::Empty:Executed by:
| 6166 | ||||||||||||||||||
| 4407 | { | - | ||||||||||||||||||
| 4408 | QStringDataPtr empty = { Data::allocate(0) }; | - | ||||||||||||||||||
| 4409 | return QString(empty); executed 6166 times by 43 tests: return QString(empty);Executed by:
| 6166 | ||||||||||||||||||
| 4410 | } | - | ||||||||||||||||||
| 4411 | case QContainerImplHelper::Full: executed 77627 times by 200 tests: case QContainerImplHelper::Full:Executed by:
| 77627 | ||||||||||||||||||
| 4412 | return *this; executed 77627 times by 200 tests: return *this;Executed by:
| 77627 | ||||||||||||||||||
| 4413 | case QContainerImplHelper::Subset: executed 893675 times by 268 tests: case QContainerImplHelper::Subset:Executed by:
| 893675 | ||||||||||||||||||
| 4414 | return QString((const QChar*)d->data() + position, n); executed 893675 times by 268 tests: return QString((const QChar*)d->data() + position, n);Executed by:
| 893675 | ||||||||||||||||||
| 4415 | } | - | ||||||||||||||||||
| 4416 | Q_UNREACHABLE(); | - | ||||||||||||||||||
| 4417 | return QString(); never executed: return QString(); | 0 | ||||||||||||||||||
| 4418 | } | - | ||||||||||||||||||
| 4419 | - | |||||||||||||||||||
| 4420 | /*! | - | ||||||||||||||||||
| 4421 | Returns \c true if the string starts with \a s; otherwise returns | - | ||||||||||||||||||
| 4422 | \c false. | - | ||||||||||||||||||
| 4423 | - | |||||||||||||||||||
| 4424 | If \a cs is Qt::CaseSensitive (default), the search is | - | ||||||||||||||||||
| 4425 | case sensitive; otherwise the search is case insensitive. | - | ||||||||||||||||||
| 4426 | - | |||||||||||||||||||
| 4427 | \snippet qstring/main.cpp 65 | - | ||||||||||||||||||
| 4428 | - | |||||||||||||||||||
| 4429 | \sa endsWith() | - | ||||||||||||||||||
| 4430 | */ | - | ||||||||||||||||||
| 4431 | bool QString::startsWith(const QString& s, Qt::CaseSensitivity cs) const | - | ||||||||||||||||||
| 4432 | { | - | ||||||||||||||||||
| 4433 | return qt_starts_with(isNull() ? 0 : unicode(), size(), executed 432530 times by 119 tests: return qt_starts_with(isNull() ? 0 : unicode(), size(), s.isNull() ? 0 : s.unicode(), s.size(), cs);Executed by:
| 432530 | ||||||||||||||||||
| 4434 | s.isNull() ? 0 : s.unicode(), s.size(), cs); executed 432530 times by 119 tests: return qt_starts_with(isNull() ? 0 : unicode(), size(), s.isNull() ? 0 : s.unicode(), s.size(), cs);Executed by:
| 432530 | ||||||||||||||||||
| 4435 | } | - | ||||||||||||||||||
| 4436 | - | |||||||||||||||||||
| 4437 | /*! | - | ||||||||||||||||||
| 4438 | \overload startsWith() | - | ||||||||||||||||||
| 4439 | */ | - | ||||||||||||||||||
| 4440 | bool QString::startsWith(QLatin1String s, Qt::CaseSensitivity cs) const | - | ||||||||||||||||||
| 4441 | { | - | ||||||||||||||||||
| 4442 | return qt_starts_with(isNull() ? 0 : unicode(), size(), s, cs); executed 252355 times by 235 tests: return qt_starts_with(isNull() ? 0 : unicode(), size(), s, cs);Executed by:
| 252355 | ||||||||||||||||||
| 4443 | } | - | ||||||||||||||||||
| 4444 | - | |||||||||||||||||||
| 4445 | /*! | - | ||||||||||||||||||
| 4446 | \overload startsWith() | - | ||||||||||||||||||
| 4447 | - | |||||||||||||||||||
| 4448 | Returns \c true if the string starts with \a c; otherwise returns | - | ||||||||||||||||||
| 4449 | \c false. | - | ||||||||||||||||||
| 4450 | */ | - | ||||||||||||||||||
| 4451 | bool QString::startsWith(QChar c, Qt::CaseSensitivity cs) const | - | ||||||||||||||||||
| 4452 | { | - | ||||||||||||||||||
| 4453 | return d->size executed 349268 times by 257 tests: return d->size && (cs == Qt::CaseSensitive ? d->data()[0] == c : foldCase(d->data()[0]) == foldCase(c.unicode()));Executed by:
| 349268 | ||||||||||||||||||
| 4454 | && (cs == Qt::CaseSensitive executed 349268 times by 257 tests: return d->size && (cs == Qt::CaseSensitive ? d->data()[0] == c : foldCase(d->data()[0]) == foldCase(c.unicode()));Executed by:
| 349268 | ||||||||||||||||||
| 4455 | ? d->data()[0] == c executed 349268 times by 257 tests: return d->size && (cs == Qt::CaseSensitive ? d->data()[0] == c : foldCase(d->data()[0]) == foldCase(c.unicode()));Executed by:
| 349268 | ||||||||||||||||||
| 4456 | : foldCase(d->data()[0]) == foldCase(c.unicode())); executed 349268 times by 257 tests: return d->size && (cs == Qt::CaseSensitive ? d->data()[0] == c : foldCase(d->data()[0]) == foldCase(c.unicode()));Executed by:
| 349268 | ||||||||||||||||||
| 4457 | } | - | ||||||||||||||||||
| 4458 | - | |||||||||||||||||||
| 4459 | /*! | - | ||||||||||||||||||
| 4460 | \since 4.8 | - | ||||||||||||||||||
| 4461 | \overload | - | ||||||||||||||||||
| 4462 | Returns \c true if the string starts with the string reference \a s; | - | ||||||||||||||||||
| 4463 | otherwise returns \c false. | - | ||||||||||||||||||
| 4464 | - | |||||||||||||||||||
| 4465 | If \a cs is Qt::CaseSensitive (default), the search is case | - | ||||||||||||||||||
| 4466 | sensitive; otherwise the search is case insensitive. | - | ||||||||||||||||||
| 4467 | - | |||||||||||||||||||
| 4468 | \sa endsWith() | - | ||||||||||||||||||
| 4469 | */ | - | ||||||||||||||||||
| 4470 | bool QString::startsWith(const QStringRef &s, Qt::CaseSensitivity cs) const | - | ||||||||||||||||||
| 4471 | { | - | ||||||||||||||||||
| 4472 | 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 | ||||||||||||||||||
| 4473 | 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 | ||||||||||||||||||
| 4474 | } | - | ||||||||||||||||||
| 4475 | - | |||||||||||||||||||
| 4476 | /*! | - | ||||||||||||||||||
| 4477 | Returns \c true if the string ends with \a s; otherwise returns | - | ||||||||||||||||||
| 4478 | \c false. | - | ||||||||||||||||||
| 4479 | - | |||||||||||||||||||
| 4480 | If \a cs is Qt::CaseSensitive (default), the search is case | - | ||||||||||||||||||
| 4481 | sensitive; otherwise the search is case insensitive. | - | ||||||||||||||||||
| 4482 | - | |||||||||||||||||||
| 4483 | \snippet qstring/main.cpp 20 | - | ||||||||||||||||||
| 4484 | - | |||||||||||||||||||
| 4485 | \sa startsWith() | - | ||||||||||||||||||
| 4486 | */ | - | ||||||||||||||||||
| 4487 | bool QString::endsWith(const QString& s, Qt::CaseSensitivity cs) const | - | ||||||||||||||||||
| 4488 | { | - | ||||||||||||||||||
| 4489 | return qt_ends_with(isNull() ? 0 : unicode(), size(), executed 4492 times by 62 tests: return qt_ends_with(isNull() ? 0 : unicode(), size(), s.isNull() ? 0 : s.unicode(), s.size(), cs);Executed by:
| 4492 | ||||||||||||||||||
| 4490 | s.isNull() ? 0 : s.unicode(), s.size(), cs); executed 4492 times by 62 tests: return qt_ends_with(isNull() ? 0 : unicode(), size(), s.isNull() ? 0 : s.unicode(), s.size(), cs);Executed by:
| 4492 | ||||||||||||||||||
| 4491 | } | - | ||||||||||||||||||
| 4492 | - | |||||||||||||||||||
| 4493 | /*! | - | ||||||||||||||||||
| 4494 | \since 4.8 | - | ||||||||||||||||||
| 4495 | \overload endsWith() | - | ||||||||||||||||||
| 4496 | Returns \c true if the string ends with the string reference \a s; | - | ||||||||||||||||||
| 4497 | otherwise returns \c false. | - | ||||||||||||||||||
| 4498 | - | |||||||||||||||||||
| 4499 | If \a cs is Qt::CaseSensitive (default), the search is case | - | ||||||||||||||||||
| 4500 | sensitive; otherwise the search is case insensitive. | - | ||||||||||||||||||
| 4501 | - | |||||||||||||||||||
| 4502 | \sa startsWith() | - | ||||||||||||||||||
| 4503 | */ | - | ||||||||||||||||||
| 4504 | bool QString::endsWith(const QStringRef &s, Qt::CaseSensitivity cs) const | - | ||||||||||||||||||
| 4505 | { | - | ||||||||||||||||||
| 4506 | 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 | ||||||||||||||||||
| 4507 | 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 | ||||||||||||||||||
| 4508 | } | - | ||||||||||||||||||
| 4509 | - | |||||||||||||||||||
| 4510 | - | |||||||||||||||||||
| 4511 | /*! | - | ||||||||||||||||||
| 4512 | \overload endsWith() | - | ||||||||||||||||||
| 4513 | */ | - | ||||||||||||||||||
| 4514 | bool QString::endsWith(QLatin1String s, Qt::CaseSensitivity cs) const | - | ||||||||||||||||||
| 4515 | { | - | ||||||||||||||||||
| 4516 | return qt_ends_with(isNull() ? 0 : unicode(), size(), s, cs); executed 49972 times by 122 tests: return qt_ends_with(isNull() ? 0 : unicode(), size(), s, cs);Executed by:
| 49972 | ||||||||||||||||||
| 4517 | } | - | ||||||||||||||||||
| 4518 | - | |||||||||||||||||||
| 4519 | /*! | - | ||||||||||||||||||
| 4520 | Returns \c true if the string ends with \a c; otherwise returns | - | ||||||||||||||||||
| 4521 | \c false. | - | ||||||||||||||||||
| 4522 | - | |||||||||||||||||||
| 4523 | \overload endsWith() | - | ||||||||||||||||||
| 4524 | */ | - | ||||||||||||||||||
| 4525 | bool QString::endsWith(QChar c, Qt::CaseSensitivity cs) const | - | ||||||||||||||||||
| 4526 | { | - | ||||||||||||||||||
| 4527 | return d->size executed 156240 times by 334 tests: return d->size && (cs == Qt::CaseSensitive ? d->data()[d->size - 1] == c : foldCase(d->data()[d->size - 1]) == foldCase(c.unicode()));Executed by:
| 156240 | ||||||||||||||||||
| 4528 | && (cs == Qt::CaseSensitive executed 156240 times by 334 tests: return d->size && (cs == Qt::CaseSensitive ? d->data()[d->size - 1] == c : foldCase(d->data()[d->size - 1]) == foldCase(c.unicode()));Executed by:
| 156240 | ||||||||||||||||||
| 4529 | ? d->data()[d->size - 1] == c executed 156240 times by 334 tests: return d->size && (cs == Qt::CaseSensitive ? d->data()[d->size - 1] == c : foldCase(d->data()[d->size - 1]) == foldCase(c.unicode()));Executed by:
| 156240 | ||||||||||||||||||
| 4530 | : foldCase(d->data()[d->size - 1]) == foldCase(c.unicode())); executed 156240 times by 334 tests: return d->size && (cs == Qt::CaseSensitive ? d->data()[d->size - 1] == c : foldCase(d->data()[d->size - 1]) == foldCase(c.unicode()));Executed by:
| 156240 | ||||||||||||||||||
| 4531 | } | - | ||||||||||||||||||
| 4532 | - | |||||||||||||||||||
| 4533 | QByteArray QString::toLatin1_helper(const QString &string) | - | ||||||||||||||||||
| 4534 | { | - | ||||||||||||||||||
| 4535 | if (Q_UNLIKELY(string.isNull()))
| 2239-232661 | ||||||||||||||||||
| 4536 | return QByteArray(); executed 2239 times by 165 tests: return QByteArray();Executed by:
| 2239 | ||||||||||||||||||
| 4537 | - | |||||||||||||||||||
| 4538 | return toLatin1_helper(string.constData(), string.length()); executed 232661 times by 433 tests: return toLatin1_helper(string.constData(), string.length());Executed by:
| 232661 | ||||||||||||||||||
| 4539 | } | - | ||||||||||||||||||
| 4540 | - | |||||||||||||||||||
| 4541 | QByteArray QString::toLatin1_helper(const QChar *data, int length) | - | ||||||||||||||||||
| 4542 | { | - | ||||||||||||||||||
| 4543 | QByteArray ba(length, Qt::Uninitialized); | - | ||||||||||||||||||
| 4544 | - | |||||||||||||||||||
| 4545 | // since we own the only copy, we're going to const_cast the constData; | - | ||||||||||||||||||
| 4546 | // that avoids an unnecessary call to detach() and expansion code that will never get used | - | ||||||||||||||||||
| 4547 | qt_to_latin1(reinterpret_cast<uchar *>(const_cast<char *>(ba.constData())), | - | ||||||||||||||||||
| 4548 | reinterpret_cast<const ushort *>(data), length); | - | ||||||||||||||||||
| 4549 | return ba; executed 237008 times by 434 tests: return ba;Executed by:
| 237008 | ||||||||||||||||||
| 4550 | } | - | ||||||||||||||||||
| 4551 | - | |||||||||||||||||||
| 4552 | QByteArray QString::toLatin1_helper_inplace(QString &s) | - | ||||||||||||||||||
| 4553 | { | - | ||||||||||||||||||
| 4554 | if (!s.isDetached())
| 30267-46795 | ||||||||||||||||||
| 4555 | return s.toLatin1(); executed 30267 times by 156 tests: return s.toLatin1();Executed by:
| 30267 | ||||||||||||||||||
| 4556 | - | |||||||||||||||||||
| 4557 | // We can return our own buffer to the caller. | - | ||||||||||||||||||
| 4558 | // Conversion to Latin-1 always shrinks the buffer by half. | - | ||||||||||||||||||
| 4559 | const ushort *data = reinterpret_cast<const ushort *>(s.constData()); | - | ||||||||||||||||||
| 4560 | uint length = s.size(); | - | ||||||||||||||||||
| 4561 | - | |||||||||||||||||||
| 4562 | // Swap the d pointers. | - | ||||||||||||||||||
| 4563 | // Kids, avert your eyes. Don't try this at home. | - | ||||||||||||||||||
| 4564 | QArrayData *ba_d = s.d; | - | ||||||||||||||||||
| 4565 | - | |||||||||||||||||||
| 4566 | // multiply the allocated capacity by sizeof(ushort) | - | ||||||||||||||||||
| 4567 | ba_d->alloc *= sizeof(ushort); | - | ||||||||||||||||||
| 4568 | - | |||||||||||||||||||
| 4569 | // reset ourselves to QString() | - | ||||||||||||||||||
| 4570 | s.d = QString().d; | - | ||||||||||||||||||
| 4571 | - | |||||||||||||||||||
| 4572 | // do the in-place conversion | - | ||||||||||||||||||
| 4573 | uchar *dst = reinterpret_cast<uchar *>(ba_d->data()); | - | ||||||||||||||||||
| 4574 | qt_to_latin1(dst, data, length); | - | ||||||||||||||||||
| 4575 | dst[length] = '\0'; | - | ||||||||||||||||||
| 4576 | - | |||||||||||||||||||
| 4577 | QByteArrayDataPtr badptr = { ba_d }; | - | ||||||||||||||||||
| 4578 | return QByteArray(badptr); executed 46795 times by 131 tests: return QByteArray(badptr);Executed by:
| 46795 | ||||||||||||||||||
| 4579 | } | - | ||||||||||||||||||
| 4580 | - | |||||||||||||||||||
| 4581 | - | |||||||||||||||||||
| 4582 | /*! | - | ||||||||||||||||||
| 4583 | \fn QByteArray QString::toLatin1() const | - | ||||||||||||||||||
| 4584 | - | |||||||||||||||||||
| 4585 | Returns a Latin-1 representation of the string as a QByteArray. | - | ||||||||||||||||||
| 4586 | - | |||||||||||||||||||
| 4587 | The returned byte array is undefined if the string contains non-Latin1 | - | ||||||||||||||||||
| 4588 | characters. Those characters may be suppressed or replaced with a | - | ||||||||||||||||||
| 4589 | question mark. | - | ||||||||||||||||||
| 4590 | - | |||||||||||||||||||
| 4591 | \sa fromLatin1(), toUtf8(), toLocal8Bit(), QTextCodec | - | ||||||||||||||||||
| 4592 | */ | - | ||||||||||||||||||
| 4593 | - | |||||||||||||||||||
| 4594 | /*! | - | ||||||||||||||||||
| 4595 | \fn QByteArray QString::toAscii() const | - | ||||||||||||||||||
| 4596 | \deprecated | - | ||||||||||||||||||
| 4597 | Returns an 8-bit representation of the string as a QByteArray. | - | ||||||||||||||||||
| 4598 | - | |||||||||||||||||||
| 4599 | This function does the same as toLatin1(). | - | ||||||||||||||||||
| 4600 | - | |||||||||||||||||||
| 4601 | Note that, despite the name, this function does not necessarily return an US-ASCII | - | ||||||||||||||||||
| 4602 | (ANSI X3.4-1986) string and its result may not be US-ASCII compatible. | - | ||||||||||||||||||
| 4603 | - | |||||||||||||||||||
| 4604 | \sa fromAscii(), toLatin1(), toUtf8(), toLocal8Bit(), QTextCodec | - | ||||||||||||||||||
| 4605 | */ | - | ||||||||||||||||||
| 4606 | - | |||||||||||||||||||
| 4607 | /*! | - | ||||||||||||||||||
| 4608 | \fn QByteArray QString::toLocal8Bit() const | - | ||||||||||||||||||
| 4609 | - | |||||||||||||||||||
| 4610 | Returns the local 8-bit representation of the string as a | - | ||||||||||||||||||
| 4611 | QByteArray. The returned byte array is undefined if the string | - | ||||||||||||||||||
| 4612 | contains characters not supported by the local 8-bit encoding. | - | ||||||||||||||||||
| 4613 | - | |||||||||||||||||||
| 4614 | QTextCodec::codecForLocale() is used to perform the conversion from | - | ||||||||||||||||||
| 4615 | Unicode. If the locale encoding could not be determined, this function | - | ||||||||||||||||||
| 4616 | does the same as toLatin1(). | - | ||||||||||||||||||
| 4617 | - | |||||||||||||||||||
| 4618 | If this string contains any characters that cannot be encoded in the | - | ||||||||||||||||||
| 4619 | locale, the returned byte array is undefined. Those characters may be | - | ||||||||||||||||||
| 4620 | suppressed or replaced by another. | - | ||||||||||||||||||
| 4621 | - | |||||||||||||||||||
| 4622 | \sa fromLocal8Bit(), toLatin1(), toUtf8(), QTextCodec | - | ||||||||||||||||||
| 4623 | */ | - | ||||||||||||||||||
| 4624 | - | |||||||||||||||||||
| 4625 | QByteArray QString::toLocal8Bit_helper(const QChar *data, int size) | - | ||||||||||||||||||
| 4626 | { | - | ||||||||||||||||||
| 4627 | #ifndef QT_NO_TEXTCODEC | - | ||||||||||||||||||
| 4628 | QTextCodec *localeCodec = QTextCodec::codecForLocale(); | - | ||||||||||||||||||
| 4629 | if (localeCodec)
| 3-482680 | ||||||||||||||||||
| 4630 | return localeCodec->fromUnicode(data, size); executed 482680 times by 411 tests: return localeCodec->fromUnicode(data, size);Executed by:
| 482680 | ||||||||||||||||||
| 4631 | #endif // QT_NO_TEXTCODEC | - | ||||||||||||||||||
| 4632 | return toLatin1_helper(data, size); executed 3 times by 1 test: return toLatin1_helper(data, size);Executed by:
| 3 | ||||||||||||||||||
| 4633 | } | - | ||||||||||||||||||
| 4634 | - | |||||||||||||||||||
| 4635 | - | |||||||||||||||||||
| 4636 | /*! | - | ||||||||||||||||||
| 4637 | \fn QByteArray QString::toUtf8() const | - | ||||||||||||||||||
| 4638 | - | |||||||||||||||||||
| 4639 | Returns a UTF-8 representation of the string as a QByteArray. | - | ||||||||||||||||||
| 4640 | - | |||||||||||||||||||
| 4641 | UTF-8 is a Unicode codec and can represent all characters in a Unicode | - | ||||||||||||||||||
| 4642 | string like QString. | - | ||||||||||||||||||
| 4643 | - | |||||||||||||||||||
| 4644 | \sa fromUtf8(), toLatin1(), toLocal8Bit(), QTextCodec | - | ||||||||||||||||||
| 4645 | */ | - | ||||||||||||||||||
| 4646 | - | |||||||||||||||||||
| 4647 | QByteArray QString::toUtf8_helper(const QString &str) | - | ||||||||||||||||||
| 4648 | { | - | ||||||||||||||||||
| 4649 | if (str.isNull())
| 5705-100635 | ||||||||||||||||||
| 4650 | return QByteArray(); executed 5705 times by 155 tests: return QByteArray();Executed by:
| 5705 | ||||||||||||||||||
| 4651 | - | |||||||||||||||||||
| 4652 | return QUtf8::convertFromUnicode(str.constData(), str.length()); executed 100635 times by 245 tests: return QUtf8::convertFromUnicode(str.constData(), str.length());Executed by:
| 100635 | ||||||||||||||||||
| 4653 | } | - | ||||||||||||||||||
| 4654 | - | |||||||||||||||||||
| 4655 | /*! | - | ||||||||||||||||||
| 4656 | \since 4.2 | - | ||||||||||||||||||
| 4657 | - | |||||||||||||||||||
| 4658 | Returns a UCS-4/UTF-32 representation of the string as a QVector<uint>. | - | ||||||||||||||||||
| 4659 | - | |||||||||||||||||||
| 4660 | UCS-4 is a Unicode codec and therefore it is lossless. All characters from | - | ||||||||||||||||||
| 4661 | this string will be encoded in UCS-4. Any invalid sequence of code units in | - | ||||||||||||||||||
| 4662 | this string is replaced by the Unicode's replacement character | - | ||||||||||||||||||
| 4663 | (QChar::ReplacementCharacter, which corresponds to \c{U+FFFD}). | - | ||||||||||||||||||
| 4664 | - | |||||||||||||||||||
| 4665 | The returned vector is not NUL terminated. | - | ||||||||||||||||||
| 4666 | - | |||||||||||||||||||
| 4667 | \sa fromUtf8(), toUtf8(), toLatin1(), toLocal8Bit(), QTextCodec, fromUcs4(), toWCharArray() | - | ||||||||||||||||||
| 4668 | */ | - | ||||||||||||||||||
| 4669 | QVector<uint> QString::toUcs4() const | - | ||||||||||||||||||
| 4670 | { | - | ||||||||||||||||||
| 4671 | QVector<uint> v(length()); | - | ||||||||||||||||||
| 4672 | uint *a = v.data(); | - | ||||||||||||||||||
| 4673 | int len = toUcs4_helper(d->data(), length(), a); | - | ||||||||||||||||||
| 4674 | v.resize(len); | - | ||||||||||||||||||
| 4675 | return v; executed 10 times by 1 test: return v;Executed by:
| 10 | ||||||||||||||||||
| 4676 | } | - | ||||||||||||||||||
| 4677 | - | |||||||||||||||||||
| 4678 | QString::Data *QString::fromLatin1_helper(const char *str, int size) | - | ||||||||||||||||||
| 4679 | { | - | ||||||||||||||||||
| 4680 | Data *d; | - | ||||||||||||||||||
| 4681 | if (!str) {
| 72-1941418 | ||||||||||||||||||
| 4682 | d = Data::sharedNull(); | - | ||||||||||||||||||
| 4683 | } else if (size == 0 || (!*str && size < 0)) { executed 72 times by 5 tests: end of blockExecuted by:
| 0-1917229 | ||||||||||||||||||
| 4684 | d = Data::allocate(0); | - | ||||||||||||||||||
| 4685 | } else { executed 24189 times by 442 tests: end of blockExecuted by:
| 24189 | ||||||||||||||||||
| 4686 | if (size < 0)
| 0-1917229 | ||||||||||||||||||
| 4687 | size = qstrlen(str); never executed: size = qstrlen(str); | 0 | ||||||||||||||||||
| 4688 | d = Data::allocate(size + 1); | - | ||||||||||||||||||
| 4689 | Q_CHECK_PTR(d); never executed: qBadAlloc();
| 0-1917229 | ||||||||||||||||||
| 4690 | d->size = size; | - | ||||||||||||||||||
| 4691 | d->data()[size] = '\0'; | - | ||||||||||||||||||
| 4692 | ushort *dst = d->data(); | - | ||||||||||||||||||
| 4693 | - | |||||||||||||||||||
| 4694 | qt_from_latin1(dst, str, uint(size)); | - | ||||||||||||||||||
| 4695 | } executed 1917229 times by 644 tests: end of blockExecuted by:
| 1917229 | ||||||||||||||||||
| 4696 | return d; executed 1941490 times by 686 tests: return d;Executed by:
| 1941490 | ||||||||||||||||||
| 4697 | } | - | ||||||||||||||||||
| 4698 | - | |||||||||||||||||||
| 4699 | QString::Data *QString::fromAscii_helper(const char *str, int size) | - | ||||||||||||||||||
| 4700 | { | - | ||||||||||||||||||
| 4701 | QString s = fromUtf8(str, size); | - | ||||||||||||||||||
| 4702 | s.d->ref.ref(); | - | ||||||||||||||||||
| 4703 | return s.d; executed 1402114 times by 340 tests: return s.d;Executed by:
| 1402114 | ||||||||||||||||||
| 4704 | } | - | ||||||||||||||||||
| 4705 | - | |||||||||||||||||||
| 4706 | /*! \fn QString QString::fromLatin1(const char *str, int size) | - | ||||||||||||||||||
| 4707 | Returns a QString initialized with the first \a size characters | - | ||||||||||||||||||
| 4708 | of the Latin-1 string \a str. | - | ||||||||||||||||||
| 4709 | - | |||||||||||||||||||
| 4710 | If \a size is -1 (default), it is taken to be strlen(\a | - | ||||||||||||||||||
| 4711 | str). | - | ||||||||||||||||||
| 4712 | - | |||||||||||||||||||
| 4713 | \sa toLatin1(), fromUtf8(), fromLocal8Bit() | - | ||||||||||||||||||
| 4714 | */ | - | ||||||||||||||||||
| 4715 | - | |||||||||||||||||||
| 4716 | /*! | - | ||||||||||||||||||
| 4717 | \fn QString QString::fromLatin1(const QByteArray &str) | - | ||||||||||||||||||
| 4718 | \overload | - | ||||||||||||||||||
| 4719 | \since 5.0 | - | ||||||||||||||||||
| 4720 | - | |||||||||||||||||||
| 4721 | Returns a QString initialized with the Latin-1 string \a str. | - | ||||||||||||||||||
| 4722 | */ | - | ||||||||||||||||||
| 4723 | - | |||||||||||||||||||
| 4724 | /*! \fn QString QString::fromLocal8Bit(const char *str, int size) | - | ||||||||||||||||||
| 4725 | Returns a QString initialized with the first \a size characters | - | ||||||||||||||||||
| 4726 | of the 8-bit string \a str. | - | ||||||||||||||||||
| 4727 | - | |||||||||||||||||||
| 4728 | If \a size is -1 (default), it is taken to be strlen(\a | - | ||||||||||||||||||
| 4729 | str). | - | ||||||||||||||||||
| 4730 | - | |||||||||||||||||||
| 4731 | QTextCodec::codecForLocale() is used to perform the conversion. | - | ||||||||||||||||||
| 4732 | - | |||||||||||||||||||
| 4733 | \sa toLocal8Bit(), fromLatin1(), fromUtf8() | - | ||||||||||||||||||
| 4734 | */ | - | ||||||||||||||||||
| 4735 | - | |||||||||||||||||||
| 4736 | /*! | - | ||||||||||||||||||
| 4737 | \fn QString QString::fromLocal8Bit(const QByteArray &str) | - | ||||||||||||||||||
| 4738 | \overload | - | ||||||||||||||||||
| 4739 | \since 5.0 | - | ||||||||||||||||||
| 4740 | - | |||||||||||||||||||
| 4741 | Returns a QString initialized with the 8-bit string \a str. | - | ||||||||||||||||||
| 4742 | */ | - | ||||||||||||||||||
| 4743 | QString QString::fromLocal8Bit_helper(const char *str, int size) | - | ||||||||||||||||||
| 4744 | { | - | ||||||||||||||||||
| 4745 | if (!str)
| 1-294005 | ||||||||||||||||||
| 4746 | return QString(); executed 1 time by 1 test: return QString();Executed by:
| 1 | ||||||||||||||||||
| 4747 | if (size == 0 || (!*str && size < 0)) {
| 0-292991 | ||||||||||||||||||
| 4748 | QStringDataPtr empty = { Data::allocate(0) }; | - | ||||||||||||||||||
| 4749 | return QString(empty); executed 1014 times by 12 tests: return QString(empty);Executed by:
| 1014 | ||||||||||||||||||
| 4750 | } | - | ||||||||||||||||||
| 4751 | #if !defined(QT_NO_TEXTCODEC) | - | ||||||||||||||||||
| 4752 | if (size < 0)
| 0-292991 | ||||||||||||||||||
| 4753 | size = qstrlen(str); never executed: size = qstrlen(str); | 0 | ||||||||||||||||||
| 4754 | QTextCodec *codec = QTextCodec::codecForLocale(); | - | ||||||||||||||||||
| 4755 | if (codec)
| 2-292989 | ||||||||||||||||||
| 4756 | return codec->toUnicode(str, size); executed 292989 times by 340 tests: return codec->toUnicode(str, size);Executed by:
| 292989 | ||||||||||||||||||
| 4757 | #endif // !QT_NO_TEXTCODEC | - | ||||||||||||||||||
| 4758 | return fromLatin1(str, size); executed 2 times by 1 test: return fromLatin1(str, size);Executed by:
| 2 | ||||||||||||||||||
| 4759 | } | - | ||||||||||||||||||
| 4760 | - | |||||||||||||||||||
| 4761 | /*! \fn QString QString::fromAscii(const char *, int size); | - | ||||||||||||||||||
| 4762 | \deprecated | - | ||||||||||||||||||
| 4763 | - | |||||||||||||||||||
| 4764 | Returns a QString initialized with the first \a size characters | - | ||||||||||||||||||
| 4765 | from the string \a str. | - | ||||||||||||||||||
| 4766 | - | |||||||||||||||||||
| 4767 | If \a size is -1 (default), it is taken to be strlen(\a | - | ||||||||||||||||||
| 4768 | str). | - | ||||||||||||||||||
| 4769 | - | |||||||||||||||||||
| 4770 | This function does the same as fromLatin1(). | - | ||||||||||||||||||
| 4771 | - | |||||||||||||||||||
| 4772 | \sa toAscii(), fromLatin1(), fromUtf8(), fromLocal8Bit() | - | ||||||||||||||||||
| 4773 | */ | - | ||||||||||||||||||
| 4774 | - | |||||||||||||||||||
| 4775 | /*! | - | ||||||||||||||||||
| 4776 | \fn QString QString::fromAscii(const QByteArray &str) | - | ||||||||||||||||||
| 4777 | \deprecated | - | ||||||||||||||||||
| 4778 | \overload | - | ||||||||||||||||||
| 4779 | \since 5.0 | - | ||||||||||||||||||
| 4780 | - | |||||||||||||||||||
| 4781 | Returns a QString initialized with the string \a str. | - | ||||||||||||||||||
| 4782 | */ | - | ||||||||||||||||||
| 4783 | - | |||||||||||||||||||
| 4784 | /*! \fn QString QString::fromUtf8(const char *str, int size) | - | ||||||||||||||||||
| 4785 | Returns a QString initialized with the first \a size bytes | - | ||||||||||||||||||
| 4786 | of the UTF-8 string \a str. | - | ||||||||||||||||||
| 4787 | - | |||||||||||||||||||
| 4788 | If \a size is -1 (default), it is taken to be strlen(\a | - | ||||||||||||||||||
| 4789 | str). | - | ||||||||||||||||||
| 4790 | - | |||||||||||||||||||
| 4791 | UTF-8 is a Unicode codec and can represent all characters in a Unicode | - | ||||||||||||||||||
| 4792 | string like QString. However, invalid sequences are possible with UTF-8 | - | ||||||||||||||||||
| 4793 | and, if any such are found, they will be replaced with one or more | - | ||||||||||||||||||
| 4794 | "replacement characters", or suppressed. These include non-Unicode | - | ||||||||||||||||||
| 4795 | sequences, non-characters, overlong sequences or surrogate codepoints | - | ||||||||||||||||||
| 4796 | encoded into UTF-8. | - | ||||||||||||||||||
| 4797 | - | |||||||||||||||||||
| 4798 | This function can be used to process incoming data incrementally as long as | - | ||||||||||||||||||
| 4799 | all UTF-8 characters are terminated within the incoming data. Any | - | ||||||||||||||||||
| 4800 | unterminated characters at the end of the string will be replaced or | - | ||||||||||||||||||
| 4801 | suppressed. In order to do stateful decoding, please use \l QTextDecoder. | - | ||||||||||||||||||
| 4802 | - | |||||||||||||||||||
| 4803 | \sa toUtf8(), fromLatin1(), fromLocal8Bit() | - | ||||||||||||||||||
| 4804 | */ | - | ||||||||||||||||||
| 4805 | - | |||||||||||||||||||
| 4806 | /*! | - | ||||||||||||||||||
| 4807 | \fn QString QString::fromUtf8(const QByteArray &str) | - | ||||||||||||||||||
| 4808 | \overload | - | ||||||||||||||||||
| 4809 | \since 5.0 | - | ||||||||||||||||||
| 4810 | - | |||||||||||||||||||
| 4811 | Returns a QString initialized with the UTF-8 string \a str. | - | ||||||||||||||||||
| 4812 | */ | - | ||||||||||||||||||
| 4813 | QString QString::fromUtf8_helper(const char *str, int size) | - | ||||||||||||||||||
| 4814 | { | - | ||||||||||||||||||
| 4815 | if (!str)
| 7640-3930821 | ||||||||||||||||||
| 4816 | return QString(); executed 7640 times by 297 tests: return QString();Executed by:
| 7640 | ||||||||||||||||||
| 4817 | - | |||||||||||||||||||
| 4818 | Q_ASSERT(size != -1); | - | ||||||||||||||||||
| 4819 | return QUtf8::convertToUnicode(str, size); executed 3930821 times by 532 tests: return QUtf8::convertToUnicode(str, size);Executed by:
| 3930821 | ||||||||||||||||||
| 4820 | } | - | ||||||||||||||||||
| 4821 | - | |||||||||||||||||||
| 4822 | /*! | - | ||||||||||||||||||
| 4823 | Returns a QString initialized with the first \a size characters | - | ||||||||||||||||||
| 4824 | of the Unicode string \a unicode (ISO-10646-UTF-16 encoded). | - | ||||||||||||||||||
| 4825 | - | |||||||||||||||||||
| 4826 | If \a size is -1 (default), \a unicode must be terminated | - | ||||||||||||||||||
| 4827 | with a 0. | - | ||||||||||||||||||
| 4828 | - | |||||||||||||||||||
| 4829 | This function checks for a Byte Order Mark (BOM). If it is missing, | - | ||||||||||||||||||
| 4830 | host byte order is assumed. | - | ||||||||||||||||||
| 4831 | - | |||||||||||||||||||
| 4832 | This function is slow compared to the other Unicode conversions. | - | ||||||||||||||||||
| 4833 | Use QString(const QChar *, int) or QString(const QChar *) if possible. | - | ||||||||||||||||||
| 4834 | - | |||||||||||||||||||
| 4835 | QString makes a deep copy of the Unicode data. | - | ||||||||||||||||||
| 4836 | - | |||||||||||||||||||
| 4837 | \sa utf16(), setUtf16(), fromStdU16String() | - | ||||||||||||||||||
| 4838 | */ | - | ||||||||||||||||||
| 4839 | QString QString::fromUtf16(const ushort *unicode, int size) | - | ||||||||||||||||||
| 4840 | { | - | ||||||||||||||||||
| 4841 | if (!unicode)
| 0-233831 | ||||||||||||||||||
| 4842 | return QString(); never executed: return QString(); | 0 | ||||||||||||||||||
| 4843 | if (size < 0) {
| 164-233667 | ||||||||||||||||||
| 4844 | size = 0; | - | ||||||||||||||||||
| 4845 | while (unicode[size] != 0)
| 164-689 | ||||||||||||||||||
| 4846 | ++size; executed 689 times by 9 tests: ++size;Executed by:
| 689 | ||||||||||||||||||
| 4847 | } executed 164 times by 9 tests: end of blockExecuted by:
| 164 | ||||||||||||||||||
| 4848 | return QUtf16::convertToUnicode((const char *)unicode, size*2, 0); executed 233831 times by 18 tests: return QUtf16::convertToUnicode((const char *)unicode, size*2, 0);Executed by:
| 233831 | ||||||||||||||||||
| 4849 | } | - | ||||||||||||||||||
| 4850 | - | |||||||||||||||||||
| 4851 | /*! | - | ||||||||||||||||||
| 4852 | \fn QString QString::fromUtf16(const char16_t *str, int size) | - | ||||||||||||||||||
| 4853 | \since 5.3 | - | ||||||||||||||||||
| 4854 | - | |||||||||||||||||||
| 4855 | Returns a QString initialized with the first \a size characters | - | ||||||||||||||||||
| 4856 | of the Unicode string \a str (ISO-10646-UTF-16 encoded). | - | ||||||||||||||||||
| 4857 | - | |||||||||||||||||||
| 4858 | If \a size is -1 (default), \a str must be terminated | - | ||||||||||||||||||
| 4859 | with a 0. | - | ||||||||||||||||||
| 4860 | - | |||||||||||||||||||
| 4861 | This function checks for a Byte Order Mark (BOM). If it is missing, | - | ||||||||||||||||||
| 4862 | host byte order is assumed. | - | ||||||||||||||||||
| 4863 | - | |||||||||||||||||||
| 4864 | This function is slow compared to the other Unicode conversions. | - | ||||||||||||||||||
| 4865 | Use QString(const QChar *, int) or QString(const QChar *) if possible. | - | ||||||||||||||||||
| 4866 | - | |||||||||||||||||||
| 4867 | QString makes a deep copy of the Unicode data. | - | ||||||||||||||||||
| 4868 | - | |||||||||||||||||||
| 4869 | \sa utf16(), setUtf16(), fromStdU16String() | - | ||||||||||||||||||
| 4870 | */ | - | ||||||||||||||||||
| 4871 | - | |||||||||||||||||||
| 4872 | /*! | - | ||||||||||||||||||
| 4873 | \fn QString QString::fromUcs4(const char32_t *str, int size) | - | ||||||||||||||||||
| 4874 | \since 5.3 | - | ||||||||||||||||||
| 4875 | - | |||||||||||||||||||
| 4876 | Returns a QString initialized with the first \a size characters | - | ||||||||||||||||||
| 4877 | of the Unicode string \a str (ISO-10646-UCS-4 encoded). | - | ||||||||||||||||||
| 4878 | - | |||||||||||||||||||
| 4879 | If \a size is -1 (default), \a str must be terminated | - | ||||||||||||||||||
| 4880 | with a 0. | - | ||||||||||||||||||
| 4881 | - | |||||||||||||||||||
| 4882 | \sa toUcs4(), fromUtf16(), utf16(), setUtf16(), fromWCharArray(), fromStdU32String() | - | ||||||||||||||||||
| 4883 | */ | - | ||||||||||||||||||
| 4884 | - | |||||||||||||||||||
| 4885 | /*! | - | ||||||||||||||||||
| 4886 | \since 4.2 | - | ||||||||||||||||||
| 4887 | - | |||||||||||||||||||
| 4888 | Returns a QString initialized with the first \a size characters | - | ||||||||||||||||||
| 4889 | of the Unicode string \a unicode (ISO-10646-UCS-4 encoded). | - | ||||||||||||||||||
| 4890 | - | |||||||||||||||||||
| 4891 | If \a size is -1 (default), \a unicode must be terminated | - | ||||||||||||||||||
| 4892 | with a 0. | - | ||||||||||||||||||
| 4893 | - | |||||||||||||||||||
| 4894 | \sa toUcs4(), fromUtf16(), utf16(), setUtf16(), fromWCharArray(), fromStdU32String() | - | ||||||||||||||||||
| 4895 | */ | - | ||||||||||||||||||
| 4896 | QString QString::fromUcs4(const uint *unicode, int size) | - | ||||||||||||||||||
| 4897 | { | - | ||||||||||||||||||
| 4898 | if (!unicode)
| 3-410515 | ||||||||||||||||||
| 4899 | return QString(); executed 3 times by 1 test: return QString();Executed by:
| 3 | ||||||||||||||||||
| 4900 | if (size < 0) {
| 315-410200 | ||||||||||||||||||
| 4901 | size = 0; | - | ||||||||||||||||||
| 4902 | while (unicode[size] != 0)
| 315-1163 | ||||||||||||||||||
| 4903 | ++size; executed 1163 times by 3 tests: ++size;Executed by:
| 1163 | ||||||||||||||||||
| 4904 | } executed 315 times by 3 tests: end of blockExecuted by:
| 315 | ||||||||||||||||||
| 4905 | 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 | ||||||||||||||||||
| 4906 | } | - | ||||||||||||||||||
| 4907 | - | |||||||||||||||||||
| 4908 | /*! | - | ||||||||||||||||||
| 4909 | Resizes the string to \a size characters and copies \a unicode | - | ||||||||||||||||||
| 4910 | into the string. | - | ||||||||||||||||||
| 4911 | - | |||||||||||||||||||
| 4912 | If \a unicode is 0, nothing is copied, but the string is still | - | ||||||||||||||||||
| 4913 | resized to \a size. | - | ||||||||||||||||||
| 4914 | - | |||||||||||||||||||
| 4915 | \sa unicode(), setUtf16() | - | ||||||||||||||||||
| 4916 | */ | - | ||||||||||||||||||
| 4917 | QString& QString::setUnicode(const QChar *unicode, int size) | - | ||||||||||||||||||
| 4918 | { | - | ||||||||||||||||||
| 4919 | resize(size); | - | ||||||||||||||||||
| 4920 | if (unicode && size)
| 0-184425 | ||||||||||||||||||
| 4921 | memcpy(d->data(), unicode, size * sizeof(QChar)); executed 97555 times by 19 tests: memcpy(d->data(), unicode, size * sizeof(QChar));Executed by:
| 97555 | ||||||||||||||||||
| 4922 | return *this; executed 184425 times by 20 tests: return *this;Executed by:
| 184425 | ||||||||||||||||||
| 4923 | } | - | ||||||||||||||||||
| 4924 | - | |||||||||||||||||||
| 4925 | /*! | - | ||||||||||||||||||
| 4926 | \fn QString &QString::setUtf16(const ushort *unicode, int size) | - | ||||||||||||||||||
| 4927 | - | |||||||||||||||||||
| 4928 | Resizes the string to \a size characters and copies \a unicode | - | ||||||||||||||||||
| 4929 | into the string. | - | ||||||||||||||||||
| 4930 | - | |||||||||||||||||||
| 4931 | If \a unicode is 0, nothing is copied, but the string is still | - | ||||||||||||||||||
| 4932 | resized to \a size. | - | ||||||||||||||||||
| 4933 | - | |||||||||||||||||||
| 4934 | Note that unlike fromUtf16(), this function does not consider BOMs and | - | ||||||||||||||||||
| 4935 | possibly differing byte ordering. | - | ||||||||||||||||||
| 4936 | - | |||||||||||||||||||
| 4937 | \sa utf16(), setUnicode() | - | ||||||||||||||||||
| 4938 | */ | - | ||||||||||||||||||
| 4939 | - | |||||||||||||||||||
| 4940 | /*! | - | ||||||||||||||||||
| 4941 | \fn QString QString::simplified() const | - | ||||||||||||||||||
| 4942 | - | |||||||||||||||||||
| 4943 | Returns a string that has whitespace removed from the start | - | ||||||||||||||||||
| 4944 | and the end, and that has each sequence of internal whitespace | - | ||||||||||||||||||
| 4945 | replaced with a single space. | - | ||||||||||||||||||
| 4946 | - | |||||||||||||||||||
| 4947 | Whitespace means any character for which QChar::isSpace() returns | - | ||||||||||||||||||
| 4948 | \c true. This includes the ASCII characters '\\t', '\\n', '\\v', | - | ||||||||||||||||||
| 4949 | '\\f', '\\r', and ' '. | - | ||||||||||||||||||
| 4950 | - | |||||||||||||||||||
| 4951 | Example: | - | ||||||||||||||||||
| 4952 | - | |||||||||||||||||||
| 4953 | \snippet qstring/main.cpp 57 | - | ||||||||||||||||||
| 4954 | - | |||||||||||||||||||
| 4955 | \sa trimmed() | - | ||||||||||||||||||
| 4956 | */ | - | ||||||||||||||||||
| 4957 | QString QString::simplified_helper(const QString &str) | - | ||||||||||||||||||
| 4958 | { | - | ||||||||||||||||||
| 4959 | return QStringAlgorithms<const QString>::simplified_helper(str); executed 68112 times by 109 tests: return QStringAlgorithms<const QString>::simplified_helper(str);Executed by:
| 68112 | ||||||||||||||||||
| 4960 | } | - | ||||||||||||||||||
| 4961 | - | |||||||||||||||||||
| 4962 | QString QString::simplified_helper(QString &str) | - | ||||||||||||||||||
| 4963 | { | - | ||||||||||||||||||
| 4964 | return QStringAlgorithms<QString>::simplified_helper(str); executed 23141 times by 6 tests: return QStringAlgorithms<QString>::simplified_helper(str);Executed by:
| 23141 | ||||||||||||||||||
| 4965 | } | - | ||||||||||||||||||
| 4966 | - | |||||||||||||||||||
| 4967 | /*! | - | ||||||||||||||||||
| 4968 | \fn QString QString::trimmed() const | - | ||||||||||||||||||
| 4969 | - | |||||||||||||||||||
| 4970 | Returns a string that has whitespace removed from the start and | - | ||||||||||||||||||
| 4971 | the end. | - | ||||||||||||||||||
| 4972 | - | |||||||||||||||||||
| 4973 | Whitespace means any character for which QChar::isSpace() returns | - | ||||||||||||||||||
| 4974 | \c true. This includes the ASCII characters '\\t', '\\n', '\\v', | - | ||||||||||||||||||
| 4975 | '\\f', '\\r', and ' '. | - | ||||||||||||||||||
| 4976 | - | |||||||||||||||||||
| 4977 | Example: | - | ||||||||||||||||||
| 4978 | - | |||||||||||||||||||
| 4979 | \snippet qstring/main.cpp 82 | - | ||||||||||||||||||
| 4980 | - | |||||||||||||||||||
| 4981 | Unlike simplified(), trimmed() leaves internal whitespace alone. | - | ||||||||||||||||||
| 4982 | - | |||||||||||||||||||
| 4983 | \sa simplified() | - | ||||||||||||||||||
| 4984 | */ | - | ||||||||||||||||||
| 4985 | QString QString::trimmed_helper(const QString &str) | - | ||||||||||||||||||
| 4986 | { | - | ||||||||||||||||||
| 4987 | return QStringAlgorithms<const QString>::trimmed_helper(str); executed 8462 times by 104 tests: return QStringAlgorithms<const QString>::trimmed_helper(str);Executed by:
| 8462 | ||||||||||||||||||
| 4988 | } | - | ||||||||||||||||||
| 4989 | - | |||||||||||||||||||
| 4990 | QString QString::trimmed_helper(QString &str) | - | ||||||||||||||||||
| 4991 | { | - | ||||||||||||||||||
| 4992 | return QStringAlgorithms<QString>::trimmed_helper(str); executed 6550 times by 31 tests: return QStringAlgorithms<QString>::trimmed_helper(str);Executed by:
| 6550 | ||||||||||||||||||
| 4993 | } | - | ||||||||||||||||||
| 4994 | - | |||||||||||||||||||
| 4995 | /*! \fn const QChar QString::at(int position) const | - | ||||||||||||||||||
| 4996 | - | |||||||||||||||||||
| 4997 | Returns the character at the given index \a position in the | - | ||||||||||||||||||
| 4998 | string. | - | ||||||||||||||||||
| 4999 | - | |||||||||||||||||||
| 5000 | The \a position must be a valid index position in the string | - | ||||||||||||||||||
| 5001 | (i.e., 0 <= \a position < size()). | - | ||||||||||||||||||
| 5002 | - | |||||||||||||||||||
| 5003 | \sa operator[]() | - | ||||||||||||||||||
| 5004 | */ | - | ||||||||||||||||||
| 5005 | - | |||||||||||||||||||
| 5006 | /*! | - | ||||||||||||||||||
| 5007 | \fn QCharRef QString::operator[](int position) | - | ||||||||||||||||||
| 5008 | - | |||||||||||||||||||
| 5009 | Returns the character at the specified \a position in the string as a | - | ||||||||||||||||||
| 5010 | modifiable reference. | - | ||||||||||||||||||
| 5011 | - | |||||||||||||||||||
| 5012 | Example: | - | ||||||||||||||||||
| 5013 | - | |||||||||||||||||||
| 5014 | \snippet qstring/main.cpp 85 | - | ||||||||||||||||||
| 5015 | - | |||||||||||||||||||
| 5016 | The return value is of type QCharRef, a helper class for QString. | - | ||||||||||||||||||
| 5017 | When you get an object of type QCharRef, you can use it as if it | - | ||||||||||||||||||
| 5018 | were a QChar &. If you assign to it, the assignment will apply to | - | ||||||||||||||||||
| 5019 | the character in the QString from which you got the reference. | - | ||||||||||||||||||
| 5020 | - | |||||||||||||||||||
| 5021 | \sa at() | - | ||||||||||||||||||
| 5022 | */ | - | ||||||||||||||||||
| 5023 | - | |||||||||||||||||||
| 5024 | /*! | - | ||||||||||||||||||
| 5025 | \fn const QChar QString::operator[](int position) const | - | ||||||||||||||||||
| 5026 | - | |||||||||||||||||||
| 5027 | \overload operator[]() | - | ||||||||||||||||||
| 5028 | */ | - | ||||||||||||||||||
| 5029 | - | |||||||||||||||||||
| 5030 | /*! \fn QCharRef QString::operator[](uint position) | - | ||||||||||||||||||
| 5031 | - | |||||||||||||||||||
| 5032 | \overload operator[]() | - | ||||||||||||||||||
| 5033 | - | |||||||||||||||||||
| 5034 | Returns the character at the specified \a position in the string as a | - | ||||||||||||||||||
| 5035 | modifiable reference. | - | ||||||||||||||||||
| 5036 | */ | - | ||||||||||||||||||
| 5037 | - | |||||||||||||||||||
| 5038 | /*! \fn const QChar QString::operator[](uint position) const | - | ||||||||||||||||||
| 5039 | Equivalent to \c at(position). | - | ||||||||||||||||||
| 5040 | \overload operator[]() | - | ||||||||||||||||||
| 5041 | */ | - | ||||||||||||||||||
| 5042 | - | |||||||||||||||||||
| 5043 | /*! | - | ||||||||||||||||||
| 5044 | \fn void QString::truncate(int position) | - | ||||||||||||||||||
| 5045 | - | |||||||||||||||||||
| 5046 | Truncates the string at the given \a position index. | - | ||||||||||||||||||
| 5047 | - | |||||||||||||||||||
| 5048 | If the specified \a position index is beyond the end of the | - | ||||||||||||||||||
| 5049 | string, nothing happens. | - | ||||||||||||||||||
| 5050 | - | |||||||||||||||||||
| 5051 | Example: | - | ||||||||||||||||||
| 5052 | - | |||||||||||||||||||
| 5053 | \snippet qstring/main.cpp 83 | - | ||||||||||||||||||
| 5054 | - | |||||||||||||||||||
| 5055 | If \a position is negative, it is equivalent to passing zero. | - | ||||||||||||||||||
| 5056 | - | |||||||||||||||||||
| 5057 | \sa chop(), resize(), left(), QStringRef::truncate() | - | ||||||||||||||||||
| 5058 | */ | - | ||||||||||||||||||
| 5059 | - | |||||||||||||||||||
| 5060 | void QString::truncate(int pos) | - | ||||||||||||||||||
| 5061 | { | - | ||||||||||||||||||
| 5062 | if (pos < d->size)
| 3920098-42105615 | ||||||||||||||||||
| 5063 | resize(pos); executed 42105615 times by 367 tests: resize(pos);Executed by:
| 42105615 | ||||||||||||||||||
| 5064 | } executed 46025168 times by 564 tests: end of blockExecuted by:
| 46025168 | ||||||||||||||||||
| 5065 | - | |||||||||||||||||||
| 5066 | - | |||||||||||||||||||
| 5067 | /*! | - | ||||||||||||||||||
| 5068 | Removes \a n characters from the end of the string. | - | ||||||||||||||||||
| 5069 | - | |||||||||||||||||||
| 5070 | If \a n is greater than or equal to size(), the result is an | - | ||||||||||||||||||
| 5071 | empty string; if \a n is negative, it is equivalent to passing zero. | - | ||||||||||||||||||
| 5072 | - | |||||||||||||||||||
| 5073 | Example: | - | ||||||||||||||||||
| 5074 | \snippet qstring/main.cpp 15 | - | ||||||||||||||||||
| 5075 | - | |||||||||||||||||||
| 5076 | If you want to remove characters from the \e beginning of the | - | ||||||||||||||||||
| 5077 | string, use remove() instead. | - | ||||||||||||||||||
| 5078 | - | |||||||||||||||||||
| 5079 | \sa truncate(), resize(), remove() | - | ||||||||||||||||||
| 5080 | */ | - | ||||||||||||||||||
| 5081 | void QString::chop(int n) | - | ||||||||||||||||||
| 5082 | { | - | ||||||||||||||||||
| 5083 | if (n > 0)
| 140-68667 | ||||||||||||||||||
| 5084 | resize(d->size - n); executed 68667 times by 364 tests: resize(d->size - n);Executed by:
| 68667 | ||||||||||||||||||
| 5085 | } executed 68807 times by 364 tests: end of blockExecuted by:
| 68807 | ||||||||||||||||||
| 5086 | - | |||||||||||||||||||
| 5087 | /*! | - | ||||||||||||||||||
| 5088 | Sets every character in the string to character \a ch. If \a size | - | ||||||||||||||||||
| 5089 | is different from -1 (default), the string is resized to \a | - | ||||||||||||||||||
| 5090 | size beforehand. | - | ||||||||||||||||||
| 5091 | - | |||||||||||||||||||
| 5092 | Example: | - | ||||||||||||||||||
| 5093 | - | |||||||||||||||||||
| 5094 | \snippet qstring/main.cpp 21 | - | ||||||||||||||||||
| 5095 | - | |||||||||||||||||||
| 5096 | \sa resize() | - | ||||||||||||||||||
| 5097 | */ | - | ||||||||||||||||||
| 5098 | - | |||||||||||||||||||
| 5099 | QString& QString::fill(QChar ch, int size) | - | ||||||||||||||||||
| 5100 | { | - | ||||||||||||||||||
| 5101 | resize(size < 0 ? d->size : size); | - | ||||||||||||||||||
| 5102 | if (d->size) {
| 5425-11557 | ||||||||||||||||||
| 5103 | QChar *i = (QChar*)d->data() + d->size; | - | ||||||||||||||||||
| 5104 | QChar *b = (QChar*)d->data(); | - | ||||||||||||||||||
| 5105 | while (i != b)
| 11557-2697569 | ||||||||||||||||||
| 5106 | *--i = ch; executed 2697569 times by 10 tests: *--i = ch;Executed by:
| 2697569 | ||||||||||||||||||
| 5107 | } executed 11557 times by 10 tests: end of blockExecuted by:
| 11557 | ||||||||||||||||||
| 5108 | return *this; executed 16982 times by 12 tests: return *this;Executed by:
| 16982 | ||||||||||||||||||
| 5109 | } | - | ||||||||||||||||||
| 5110 | - | |||||||||||||||||||
| 5111 | /*! | - | ||||||||||||||||||
| 5112 | \fn int QString::length() const | - | ||||||||||||||||||
| 5113 | - | |||||||||||||||||||
| 5114 | Returns the number of characters in this string. Equivalent to | - | ||||||||||||||||||
| 5115 | size(). | - | ||||||||||||||||||
| 5116 | - | |||||||||||||||||||
| 5117 | \sa resize() | - | ||||||||||||||||||
| 5118 | */ | - | ||||||||||||||||||
| 5119 | - | |||||||||||||||||||
| 5120 | /*! | - | ||||||||||||||||||
| 5121 | \fn int QString::size() const | - | ||||||||||||||||||
| 5122 | - | |||||||||||||||||||
| 5123 | Returns the number of characters in this string. | - | ||||||||||||||||||
| 5124 | - | |||||||||||||||||||
| 5125 | The last character in the string is at position size() - 1. In | - | ||||||||||||||||||
| 5126 | addition, QString ensures that the character at position size() | - | ||||||||||||||||||
| 5127 | is always '\\0', so that you can use the return value of data() | - | ||||||||||||||||||
| 5128 | and constData() as arguments to functions that expect | - | ||||||||||||||||||
| 5129 | '\\0'-terminated strings. | - | ||||||||||||||||||
| 5130 | - | |||||||||||||||||||
| 5131 | Example: | - | ||||||||||||||||||
| 5132 | - | |||||||||||||||||||
| 5133 | \snippet qstring/main.cpp 58 | - | ||||||||||||||||||
| 5134 | - | |||||||||||||||||||
| 5135 | \sa isEmpty(), resize() | - | ||||||||||||||||||
| 5136 | */ | - | ||||||||||||||||||
| 5137 | - | |||||||||||||||||||
| 5138 | /*! \fn bool QString::isNull() const | - | ||||||||||||||||||
| 5139 | - | |||||||||||||||||||
| 5140 | Returns \c true if this string is null; otherwise returns \c false. | - | ||||||||||||||||||
| 5141 | - | |||||||||||||||||||
| 5142 | Example: | - | ||||||||||||||||||
| 5143 | - | |||||||||||||||||||
| 5144 | \snippet qstring/main.cpp 28 | - | ||||||||||||||||||
| 5145 | - | |||||||||||||||||||
| 5146 | Qt makes a distinction between null strings and empty strings for | - | ||||||||||||||||||
| 5147 | historical reasons. For most applications, what matters is | - | ||||||||||||||||||
| 5148 | whether or not a string contains any data, and this can be | - | ||||||||||||||||||
| 5149 | determined using the isEmpty() function. | - | ||||||||||||||||||
| 5150 | - | |||||||||||||||||||
| 5151 | \sa isEmpty() | - | ||||||||||||||||||
| 5152 | */ | - | ||||||||||||||||||
| 5153 | - | |||||||||||||||||||
| 5154 | /*! \fn bool QString::isEmpty() const | - | ||||||||||||||||||
| 5155 | - | |||||||||||||||||||
| 5156 | Returns \c true if the string has no characters; otherwise returns | - | ||||||||||||||||||
| 5157 | \c false. | - | ||||||||||||||||||
| 5158 | - | |||||||||||||||||||
| 5159 | Example: | - | ||||||||||||||||||
| 5160 | - | |||||||||||||||||||
| 5161 | \snippet qstring/main.cpp 27 | - | ||||||||||||||||||
| 5162 | - | |||||||||||||||||||
| 5163 | \sa size() | - | ||||||||||||||||||
| 5164 | */ | - | ||||||||||||||||||
| 5165 | - | |||||||||||||||||||
| 5166 | /*! \fn QString &QString::operator+=(const QString &other) | - | ||||||||||||||||||
| 5167 | - | |||||||||||||||||||
| 5168 | Appends the string \a other onto the end of this string and | - | ||||||||||||||||||
| 5169 | returns a reference to this string. | - | ||||||||||||||||||
| 5170 | - | |||||||||||||||||||
| 5171 | Example: | - | ||||||||||||||||||
| 5172 | - | |||||||||||||||||||
| 5173 | \snippet qstring/main.cpp 84 | - | ||||||||||||||||||
| 5174 | - | |||||||||||||||||||
| 5175 | This operation is typically very fast (\l{constant time}), | - | ||||||||||||||||||
| 5176 | because QString preallocates extra space at the end of the string | - | ||||||||||||||||||
| 5177 | data so it can grow without reallocating the entire string each | - | ||||||||||||||||||
| 5178 | time. | - | ||||||||||||||||||
| 5179 | - | |||||||||||||||||||
| 5180 | \sa append(), prepend() | - | ||||||||||||||||||
| 5181 | */ | - | ||||||||||||||||||
| 5182 | - | |||||||||||||||||||
| 5183 | /*! \fn QString &QString::operator+=(QLatin1String str) | - | ||||||||||||||||||
| 5184 | - | |||||||||||||||||||
| 5185 | \overload operator+=() | - | ||||||||||||||||||
| 5186 | - | |||||||||||||||||||
| 5187 | Appends the Latin-1 string \a str to this string. | - | ||||||||||||||||||
| 5188 | */ | - | ||||||||||||||||||
| 5189 | - | |||||||||||||||||||
| 5190 | /*! \fn QString &QString::operator+=(const QByteArray &ba) | - | ||||||||||||||||||
| 5191 | - | |||||||||||||||||||
| 5192 | \overload operator+=() | - | ||||||||||||||||||
| 5193 | - | |||||||||||||||||||
| 5194 | Appends the byte array \a ba to this string. The byte array is converted | - | ||||||||||||||||||
| 5195 | to Unicode using the fromUtf8() function. If any NUL characters ('\\0') | - | ||||||||||||||||||
| 5196 | are embedded in the \a ba byte array, they will be included in the | - | ||||||||||||||||||
| 5197 | transformation. | - | ||||||||||||||||||
| 5198 | - | |||||||||||||||||||
| 5199 | You can disable this function by defining \c | - | ||||||||||||||||||
| 5200 | QT_NO_CAST_FROM_ASCII when you compile your applications. This | - | ||||||||||||||||||
| 5201 | can be useful if you want to ensure that all user-visible strings | - | ||||||||||||||||||
| 5202 | go through QObject::tr(), for example. | - | ||||||||||||||||||
| 5203 | */ | - | ||||||||||||||||||
| 5204 | - | |||||||||||||||||||
| 5205 | /*! \fn QString &QString::operator+=(const char *str) | - | ||||||||||||||||||
| 5206 | - | |||||||||||||||||||
| 5207 | \overload operator+=() | - | ||||||||||||||||||
| 5208 | - | |||||||||||||||||||
| 5209 | Appends the string \a str to this string. The const char pointer | - | ||||||||||||||||||
| 5210 | is converted to Unicode using the fromUtf8() function. | - | ||||||||||||||||||
| 5211 | - | |||||||||||||||||||
| 5212 | You can disable this function by defining \c QT_NO_CAST_FROM_ASCII | - | ||||||||||||||||||
| 5213 | when you compile your applications. This can be useful if you want | - | ||||||||||||||||||
| 5214 | to ensure that all user-visible strings go through QObject::tr(), | - | ||||||||||||||||||
| 5215 | for example. | - | ||||||||||||||||||
| 5216 | */ | - | ||||||||||||||||||
| 5217 | - | |||||||||||||||||||
| 5218 | /*! \fn QString &QString::operator+=(const QStringRef &str) | - | ||||||||||||||||||
| 5219 | - | |||||||||||||||||||
| 5220 | \overload operator+=() | - | ||||||||||||||||||
| 5221 | - | |||||||||||||||||||
| 5222 | Appends the string section referenced by \a str to this string. | - | ||||||||||||||||||
| 5223 | */ | - | ||||||||||||||||||
| 5224 | - | |||||||||||||||||||
| 5225 | /*! \fn QString &QString::operator+=(char ch) | - | ||||||||||||||||||
| 5226 | - | |||||||||||||||||||
| 5227 | \overload operator+=() | - | ||||||||||||||||||
| 5228 | - | |||||||||||||||||||
| 5229 | Appends the character \a ch to this string. Note that the character is | - | ||||||||||||||||||
| 5230 | converted to Unicode using the fromLatin1() function, unlike other 8-bit | - | ||||||||||||||||||
| 5231 | functions that operate on UTF-8 data. | - | ||||||||||||||||||
| 5232 | - | |||||||||||||||||||
| 5233 | You can disable this function by defining \c QT_NO_CAST_FROM_ASCII | - | ||||||||||||||||||
| 5234 | when you compile your applications. This can be useful if you want | - | ||||||||||||||||||
| 5235 | to ensure that all user-visible strings go through QObject::tr(), | - | ||||||||||||||||||
| 5236 | for example. | - | ||||||||||||||||||
| 5237 | */ | - | ||||||||||||||||||
| 5238 | - | |||||||||||||||||||
| 5239 | /*! \fn QString &QString::operator+=(QChar ch) | - | ||||||||||||||||||
| 5240 | - | |||||||||||||||||||
| 5241 | \overload operator+=() | - | ||||||||||||||||||
| 5242 | - | |||||||||||||||||||
| 5243 | Appends the character \a ch to the string. | - | ||||||||||||||||||
| 5244 | */ | - | ||||||||||||||||||
| 5245 | - | |||||||||||||||||||
| 5246 | /*! \fn QString &QString::operator+=(QChar::SpecialCharacter c) | - | ||||||||||||||||||
| 5247 | - | |||||||||||||||||||
| 5248 | \overload operator+=() | - | ||||||||||||||||||
| 5249 | - | |||||||||||||||||||
| 5250 | \internal | - | ||||||||||||||||||
| 5251 | */ | - | ||||||||||||||||||
| 5252 | - | |||||||||||||||||||
| 5253 | /*! | - | ||||||||||||||||||
| 5254 | \fn bool operator==(const char *s1, const QString &s2) | - | ||||||||||||||||||
| 5255 | - | |||||||||||||||||||
| 5256 | \overload operator==() | - | ||||||||||||||||||
| 5257 | \relates QString | - | ||||||||||||||||||
| 5258 | - | |||||||||||||||||||
| 5259 | Returns \c true if \a s1 is equal to \a s2; otherwise returns \c false. | - | ||||||||||||||||||
| 5260 | Note that no string is equal to \a s1 being 0. | - | ||||||||||||||||||
| 5261 | - | |||||||||||||||||||
| 5262 | Equivalent to \c {s1 != 0 && compare(s1, s2) == 0}. | - | ||||||||||||||||||
| 5263 | - | |||||||||||||||||||
| 5264 | \sa QString::compare() | - | ||||||||||||||||||
| 5265 | */ | - | ||||||||||||||||||
| 5266 | - | |||||||||||||||||||
| 5267 | /*! | - | ||||||||||||||||||
| 5268 | \fn bool operator!=(const char *s1, const QString &s2) | - | ||||||||||||||||||
| 5269 | \relates QString | - | ||||||||||||||||||
| 5270 | - | |||||||||||||||||||
| 5271 | Returns \c true if \a s1 is not equal to \a s2; otherwise returns | - | ||||||||||||||||||
| 5272 | \c false. | - | ||||||||||||||||||
| 5273 | - | |||||||||||||||||||
| 5274 | For \a s1 != 0, this is equivalent to \c {compare(} \a s1, \a s2 | - | ||||||||||||||||||
| 5275 | \c {) != 0}. Note that no string is equal to \a s1 being 0. | - | ||||||||||||||||||
| 5276 | - | |||||||||||||||||||
| 5277 | \sa QString::compare() | - | ||||||||||||||||||
| 5278 | */ | - | ||||||||||||||||||
| 5279 | - | |||||||||||||||||||
| 5280 | /*! | - | ||||||||||||||||||
| 5281 | \fn bool operator<(const char *s1, const QString &s2) | - | ||||||||||||||||||
| 5282 | \relates QString | - | ||||||||||||||||||
| 5283 | - | |||||||||||||||||||
| 5284 | Returns \c true if \a s1 is lexically less than \a s2; otherwise | - | ||||||||||||||||||
| 5285 | returns \c false. For \a s1 != 0, this is equivalent to \c | - | ||||||||||||||||||
| 5286 | {compare(s1, s2) < 0}. | - | ||||||||||||||||||
| 5287 | - | |||||||||||||||||||
| 5288 | The comparison is based exclusively on the numeric Unicode values | - | ||||||||||||||||||
| 5289 | of the characters and is very fast, but is not what a human would | - | ||||||||||||||||||
| 5290 | expect. Consider sorting user-interface strings using the | - | ||||||||||||||||||
| 5291 | QString::localeAwareCompare() function. | - | ||||||||||||||||||
| 5292 | - | |||||||||||||||||||
| 5293 | \sa QString::compare() | - | ||||||||||||||||||
| 5294 | */ | - | ||||||||||||||||||
| 5295 | - | |||||||||||||||||||
| 5296 | /*! | - | ||||||||||||||||||
| 5297 | \fn bool operator<=(const char *s1, const QString &s2) | - | ||||||||||||||||||
| 5298 | \relates QString | - | ||||||||||||||||||
| 5299 | - | |||||||||||||||||||
| 5300 | Returns \c true if \a s1 is lexically less than or equal to \a s2; | - | ||||||||||||||||||
| 5301 | otherwise returns \c false. For \a s1 != 0, this is equivalent to \c | - | ||||||||||||||||||
| 5302 | {compare(s1, s2) <= 0}. | - | ||||||||||||||||||
| 5303 | - | |||||||||||||||||||
| 5304 | The comparison is based exclusively on the numeric Unicode values | - | ||||||||||||||||||
| 5305 | of the characters and is very fast, but is not what a human would | - | ||||||||||||||||||
| 5306 | expect. Consider sorting user-interface strings with | - | ||||||||||||||||||
| 5307 | QString::localeAwareCompare(). | - | ||||||||||||||||||
| 5308 | - | |||||||||||||||||||
| 5309 | \sa QString::compare() | - | ||||||||||||||||||
| 5310 | */ | - | ||||||||||||||||||
| 5311 | - | |||||||||||||||||||
| 5312 | /*! | - | ||||||||||||||||||
| 5313 | \fn bool operator>(const char *s1, const QString &s2) | - | ||||||||||||||||||
| 5314 | \relates QString | - | ||||||||||||||||||
| 5315 | - | |||||||||||||||||||
| 5316 | Returns \c true if \a s1 is lexically greater than \a s2; otherwise | - | ||||||||||||||||||
| 5317 | returns \c false. Equivalent to \c {compare(s1, s2) > 0}. | - | ||||||||||||||||||
| 5318 | - | |||||||||||||||||||
| 5319 | The comparison is based exclusively on the numeric Unicode values | - | ||||||||||||||||||
| 5320 | of the characters and is very fast, but is not what a human would | - | ||||||||||||||||||
| 5321 | expect. Consider sorting user-interface strings using the | - | ||||||||||||||||||
| 5322 | QString::localeAwareCompare() function. | - | ||||||||||||||||||
| 5323 | - | |||||||||||||||||||
| 5324 | \sa QString::compare() | - | ||||||||||||||||||
| 5325 | */ | - | ||||||||||||||||||
| 5326 | - | |||||||||||||||||||
| 5327 | /*! | - | ||||||||||||||||||
| 5328 | \fn bool operator>=(const char *s1, const QString &s2) | - | ||||||||||||||||||
| 5329 | \relates QString | - | ||||||||||||||||||
| 5330 | - | |||||||||||||||||||
| 5331 | Returns \c true if \a s1 is lexically greater than or equal to \a s2; | - | ||||||||||||||||||
| 5332 | otherwise returns \c false. For \a s1 != 0, this is equivalent to \c | - | ||||||||||||||||||
| 5333 | {compare(s1, s2) >= 0}. | - | ||||||||||||||||||
| 5334 | - | |||||||||||||||||||
| 5335 | The comparison is based exclusively on the numeric Unicode values | - | ||||||||||||||||||
| 5336 | of the characters and is very fast, but is not what a human would | - | ||||||||||||||||||
| 5337 | expect. Consider sorting user-interface strings using the | - | ||||||||||||||||||
| 5338 | QString::localeAwareCompare() function. | - | ||||||||||||||||||
| 5339 | */ | - | ||||||||||||||||||
| 5340 | - | |||||||||||||||||||
| 5341 | /*! | - | ||||||||||||||||||
| 5342 | \fn const QString operator+(const QString &s1, const QString &s2) | - | ||||||||||||||||||
| 5343 | \relates QString | - | ||||||||||||||||||
| 5344 | - | |||||||||||||||||||
| 5345 | Returns a string which is the result of concatenating \a s1 and \a | - | ||||||||||||||||||
| 5346 | s2. | - | ||||||||||||||||||
| 5347 | */ | - | ||||||||||||||||||
| 5348 | - | |||||||||||||||||||
| 5349 | /*! | - | ||||||||||||||||||
| 5350 | \fn const QString operator+(const QString &s1, const char *s2) | - | ||||||||||||||||||
| 5351 | \relates QString | - | ||||||||||||||||||
| 5352 | - | |||||||||||||||||||
| 5353 | Returns a string which is the result of concatenating \a s1 and \a | - | ||||||||||||||||||
| 5354 | s2 (\a s2 is converted to Unicode using the QString::fromUtf8() | - | ||||||||||||||||||
| 5355 | function). | - | ||||||||||||||||||
| 5356 | - | |||||||||||||||||||
| 5357 | \sa QString::fromUtf8() | - | ||||||||||||||||||
| 5358 | */ | - | ||||||||||||||||||
| 5359 | - | |||||||||||||||||||
| 5360 | /*! | - | ||||||||||||||||||
| 5361 | \fn const QString operator+(const char *s1, const QString &s2) | - | ||||||||||||||||||
| 5362 | \relates QString | - | ||||||||||||||||||
| 5363 | - | |||||||||||||||||||
| 5364 | Returns a string which is the result of concatenating \a s1 and \a | - | ||||||||||||||||||
| 5365 | s2 (\a s1 is converted to Unicode using the QString::fromUtf8() | - | ||||||||||||||||||
| 5366 | function). | - | ||||||||||||||||||
| 5367 | - | |||||||||||||||||||
| 5368 | \sa QString::fromUtf8() | - | ||||||||||||||||||
| 5369 | */ | - | ||||||||||||||||||
| 5370 | - | |||||||||||||||||||
| 5371 | /*! | - | ||||||||||||||||||
| 5372 | \fn const QString operator+(const QString &s, char ch) | - | ||||||||||||||||||
| 5373 | \relates QString | - | ||||||||||||||||||
| 5374 | - | |||||||||||||||||||
| 5375 | Returns a string which is the result of concatenating the string | - | ||||||||||||||||||
| 5376 | \a s and the character \a ch. | - | ||||||||||||||||||
| 5377 | */ | - | ||||||||||||||||||
| 5378 | - | |||||||||||||||||||
| 5379 | /*! | - | ||||||||||||||||||
| 5380 | \fn const QString operator+(char ch, const QString &s) | - | ||||||||||||||||||
| 5381 | \relates QString | - | ||||||||||||||||||
| 5382 | - | |||||||||||||||||||
| 5383 | Returns a string which is the result of concatenating the | - | ||||||||||||||||||
| 5384 | character \a ch and the string \a s. | - | ||||||||||||||||||
| 5385 | */ | - | ||||||||||||||||||
| 5386 | - | |||||||||||||||||||
| 5387 | /*! | - | ||||||||||||||||||
| 5388 | \fn int QString::compare(const QString &s1, const QString &s2, Qt::CaseSensitivity cs) | - | ||||||||||||||||||
| 5389 | \since 4.2 | - | ||||||||||||||||||
| 5390 | - | |||||||||||||||||||
| 5391 | Compares \a s1 with \a s2 and returns an integer less than, equal | - | ||||||||||||||||||
| 5392 | to, or greater than zero if \a s1 is less than, equal to, or | - | ||||||||||||||||||
| 5393 | greater than \a s2. | - | ||||||||||||||||||
| 5394 | - | |||||||||||||||||||
| 5395 | If \a cs is Qt::CaseSensitive, the comparison is case sensitive; | - | ||||||||||||||||||
| 5396 | otherwise the comparison is case insensitive. | - | ||||||||||||||||||
| 5397 | - | |||||||||||||||||||
| 5398 | Case sensitive comparison is based exclusively on the numeric | - | ||||||||||||||||||
| 5399 | Unicode values of the characters and is very fast, but is not what | - | ||||||||||||||||||
| 5400 | a human would expect. Consider sorting user-visible strings with | - | ||||||||||||||||||
| 5401 | localeAwareCompare(). | - | ||||||||||||||||||
| 5402 | - | |||||||||||||||||||
| 5403 | \snippet qstring/main.cpp 16 | - | ||||||||||||||||||
| 5404 | - | |||||||||||||||||||
| 5405 | \sa operator==(), operator<(), operator>() | - | ||||||||||||||||||
| 5406 | */ | - | ||||||||||||||||||
| 5407 | - | |||||||||||||||||||
| 5408 | /*! | - | ||||||||||||||||||
| 5409 | \fn int QString::compare(const QString &s1, QLatin1String s2, Qt::CaseSensitivity cs) | - | ||||||||||||||||||
| 5410 | \since 4.2 | - | ||||||||||||||||||
| 5411 | \overload compare() | - | ||||||||||||||||||
| 5412 | - | |||||||||||||||||||
| 5413 | Performs a comparison of \a s1 and \a s2, using the case | - | ||||||||||||||||||
| 5414 | sensitivity setting \a cs. | - | ||||||||||||||||||
| 5415 | */ | - | ||||||||||||||||||
| 5416 | - | |||||||||||||||||||
| 5417 | /*! | - | ||||||||||||||||||
| 5418 | \fn int QString::compare(QLatin1String s1, const QString &s2, Qt::CaseSensitivity cs = Qt::CaseSensitive) | - | ||||||||||||||||||
| 5419 | - | |||||||||||||||||||
| 5420 | \since 4.2 | - | ||||||||||||||||||
| 5421 | \overload compare() | - | ||||||||||||||||||
| 5422 | - | |||||||||||||||||||
| 5423 | Performs a comparison of \a s1 and \a s2, using the case | - | ||||||||||||||||||
| 5424 | sensitivity setting \a cs. | - | ||||||||||||||||||
| 5425 | */ | - | ||||||||||||||||||
| 5426 | - | |||||||||||||||||||
| 5427 | - | |||||||||||||||||||
| 5428 | /*! | - | ||||||||||||||||||
| 5429 | \overload compare() | - | ||||||||||||||||||
| 5430 | \since 4.2 | - | ||||||||||||||||||
| 5431 | - | |||||||||||||||||||
| 5432 | Lexically compares this string with the \a other string and | - | ||||||||||||||||||
| 5433 | returns an integer less than, equal to, or greater than zero if | - | ||||||||||||||||||
| 5434 | this string is less than, equal to, or greater than the other | - | ||||||||||||||||||
| 5435 | string. | - | ||||||||||||||||||
| 5436 | - | |||||||||||||||||||
| 5437 | Same as compare(*this, \a other, \a cs). | - | ||||||||||||||||||
| 5438 | */ | - | ||||||||||||||||||
| 5439 | int QString::compare(const QString &other, Qt::CaseSensitivity cs) const Q_DECL_NOTHROW | - | ||||||||||||||||||
| 5440 | { | - | ||||||||||||||||||
| 5441 | if (cs == Qt::CaseSensitive)
| 240051-513982 | ||||||||||||||||||
| 5442 | return ucstrcmp(constData(), length(), other.constData(), other.length()); executed 240051 times by 215 tests: return ucstrcmp(constData(), length(), other.constData(), other.length());Executed by:
| 240051 | ||||||||||||||||||
| 5443 | return ucstricmp(d->data(), d->data() + d->size, other.d->data(), other.d->data() + other.d->size); executed 513982 times by 161 tests: return ucstricmp(d->data(), d->data() + d->size, other.d->data(), other.d->data() + other.d->size);Executed by:
| 513982 | ||||||||||||||||||
| 5444 | } | - | ||||||||||||||||||
| 5445 | - | |||||||||||||||||||
| 5446 | /*! | - | ||||||||||||||||||
| 5447 | \internal | - | ||||||||||||||||||
| 5448 | \since 4.5 | - | ||||||||||||||||||
| 5449 | */ | - | ||||||||||||||||||
| 5450 | int QString::compare_helper(const QChar *data1, int length1, const QChar *data2, int length2, | - | ||||||||||||||||||
| 5451 | Qt::CaseSensitivity cs) Q_DECL_NOTHROW | - | ||||||||||||||||||
| 5452 | { | - | ||||||||||||||||||
| 5453 | if (cs == Qt::CaseSensitive)
| 2594-552902 | ||||||||||||||||||
| 5454 | return ucstrcmp(data1, length1, data2, length2); executed 552902 times by 47 tests: return ucstrcmp(data1, length1, data2, length2);Executed by:
| 552902 | ||||||||||||||||||
| 5455 | const ushort *s1 = reinterpret_cast<const ushort *>(data1); | - | ||||||||||||||||||
| 5456 | const ushort *s2 = reinterpret_cast<const ushort *>(data2); | - | ||||||||||||||||||
| 5457 | return ucstricmp(s1, s1 + length1, s2, s2 + length2); executed 2594 times by 25 tests: return ucstricmp(s1, s1 + length1, s2, s2 + length2);Executed by:
| 2594 | ||||||||||||||||||
| 5458 | } | - | ||||||||||||||||||
| 5459 | - | |||||||||||||||||||
| 5460 | /*! | - | ||||||||||||||||||
| 5461 | \overload compare() | - | ||||||||||||||||||
| 5462 | \since 4.2 | - | ||||||||||||||||||
| 5463 | - | |||||||||||||||||||
| 5464 | Same as compare(*this, \a other, \a cs). | - | ||||||||||||||||||
| 5465 | */ | - | ||||||||||||||||||
| 5466 | int QString::compare(QLatin1String other, Qt::CaseSensitivity cs) const Q_DECL_NOTHROW | - | ||||||||||||||||||
| 5467 | { | - | ||||||||||||||||||
| 5468 | return compare_helper(unicode(), length(), other, cs); executed 19282 times by 66 tests: return compare_helper(unicode(), length(), other, cs);Executed by:
| 19282 | ||||||||||||||||||
| 5469 | } | - | ||||||||||||||||||
| 5470 | - | |||||||||||||||||||
| 5471 | /*! | - | ||||||||||||||||||
| 5472 | \fn int QString::compare(const QStringRef &ref, Qt::CaseSensitivity cs = Qt::CaseSensitive) const | - | ||||||||||||||||||
| 5473 | \overload compare() | - | ||||||||||||||||||
| 5474 | - | |||||||||||||||||||
| 5475 | Compares the string reference, \a ref, with the string and returns | - | ||||||||||||||||||
| 5476 | an integer less than, equal to, or greater than zero if the string | - | ||||||||||||||||||
| 5477 | is less than, equal to, or greater than \a ref. | - | ||||||||||||||||||
| 5478 | */ | - | ||||||||||||||||||
| 5479 | - | |||||||||||||||||||
| 5480 | /*! | - | ||||||||||||||||||
| 5481 | \internal | - | ||||||||||||||||||
| 5482 | \since 5.0 | - | ||||||||||||||||||
| 5483 | */ | - | ||||||||||||||||||
| 5484 | int QString::compare_helper(const QChar *data1, int length1, const char *data2, int length2, | - | ||||||||||||||||||
| 5485 | Qt::CaseSensitivity cs) | - | ||||||||||||||||||
| 5486 | { | - | ||||||||||||||||||
| 5487 | // ### optimize me | - | ||||||||||||||||||
| 5488 | const QString s2 = QString::fromUtf8(data2, length2 == -1 ? (data2 ? int(strlen(data2)) : -1) : length2); | - | ||||||||||||||||||
| 5489 | return compare_helper(data1, length1, s2.constData(), s2.size(), cs); executed 552553 times by 46 tests: return compare_helper(data1, length1, s2.constData(), s2.size(), cs);Executed by:
| 552553 | ||||||||||||||||||
| 5490 | } | - | ||||||||||||||||||
| 5491 | - | |||||||||||||||||||
| 5492 | /*! | - | ||||||||||||||||||
| 5493 | \fn int QString::compare(const QString &s1, const QStringRef &s2, Qt::CaseSensitivity cs = Qt::CaseSensitive) | - | ||||||||||||||||||
| 5494 | \overload compare() | - | ||||||||||||||||||
| 5495 | */ | - | ||||||||||||||||||
| 5496 | - | |||||||||||||||||||
| 5497 | /*! | - | ||||||||||||||||||
| 5498 | \internal | - | ||||||||||||||||||
| 5499 | \since 4.5 | - | ||||||||||||||||||
| 5500 | */ | - | ||||||||||||||||||
| 5501 | int QString::compare_helper(const QChar *data1, int length1, QLatin1String s2, | - | ||||||||||||||||||
| 5502 | Qt::CaseSensitivity cs) Q_DECL_NOTHROW | - | ||||||||||||||||||
| 5503 | { | - | ||||||||||||||||||
| 5504 | const ushort *uc = reinterpret_cast<const ushort *>(data1); | - | ||||||||||||||||||
| 5505 | const ushort *uce = uc + length1; | - | ||||||||||||||||||
| 5506 | const uchar *c = (const uchar *)s2.latin1(); | - | ||||||||||||||||||
| 5507 | - | |||||||||||||||||||
| 5508 | if (!c)
| 0-235224 | ||||||||||||||||||
| 5509 | return length1; never executed: return length1; | 0 | ||||||||||||||||||
| 5510 | - | |||||||||||||||||||
| 5511 | if (cs == Qt::CaseSensitive) {
| 17633-217591 | ||||||||||||||||||
| 5512 | return ucstrcmp(data1, length1, c, s2.size()); executed 217591 times by 445 tests: return ucstrcmp(data1, length1, c, s2.size());Executed by:
| 217591 | ||||||||||||||||||
| 5513 | } else { | - | ||||||||||||||||||
| 5514 | return ucstricmp(uc, uce, c, c + s2.size()); executed 17633 times by 48 tests: return ucstricmp(uc, uce, c, c + s2.size());Executed by:
| 17633 | ||||||||||||||||||
| 5515 | } | - | ||||||||||||||||||
| 5516 | } | - | ||||||||||||||||||
| 5517 | - | |||||||||||||||||||
| 5518 | /*! | - | ||||||||||||||||||
| 5519 | \fn int QString::localeAwareCompare(const QString & s1, const QString & s2) | - | ||||||||||||||||||
| 5520 | - | |||||||||||||||||||
| 5521 | Compares \a s1 with \a s2 and returns an integer less than, equal | - | ||||||||||||||||||
| 5522 | to, or greater than zero if \a s1 is less than, equal to, or | - | ||||||||||||||||||
| 5523 | greater than \a s2. | - | ||||||||||||||||||
| 5524 | - | |||||||||||||||||||
| 5525 | The comparison is performed in a locale- and also | - | ||||||||||||||||||
| 5526 | platform-dependent manner. Use this function to present sorted | - | ||||||||||||||||||
| 5527 | lists of strings to the user. | - | ||||||||||||||||||
| 5528 | - | |||||||||||||||||||
| 5529 | On \macos and iOS this function compares according the | - | ||||||||||||||||||
| 5530 | "Order for sorted lists" setting in the International preferences panel. | - | ||||||||||||||||||
| 5531 | - | |||||||||||||||||||
| 5532 | \sa compare(), QLocale | - | ||||||||||||||||||
| 5533 | */ | - | ||||||||||||||||||
| 5534 | - | |||||||||||||||||||
| 5535 | /*! | - | ||||||||||||||||||
| 5536 | \fn int QString::localeAwareCompare(const QStringRef &other) const | - | ||||||||||||||||||
| 5537 | \since 4.5 | - | ||||||||||||||||||
| 5538 | \overload localeAwareCompare() | - | ||||||||||||||||||
| 5539 | - | |||||||||||||||||||
| 5540 | Compares this string with the \a other string and returns an | - | ||||||||||||||||||
| 5541 | integer less than, equal to, or greater than zero if this string | - | ||||||||||||||||||
| 5542 | is less than, equal to, or greater than the \a other string. | - | ||||||||||||||||||
| 5543 | - | |||||||||||||||||||
| 5544 | The comparison is performed in a locale- and also | - | ||||||||||||||||||
| 5545 | platform-dependent manner. Use this function to present sorted | - | ||||||||||||||||||
| 5546 | lists of strings to the user. | - | ||||||||||||||||||
| 5547 | - | |||||||||||||||||||
| 5548 | Same as \c {localeAwareCompare(*this, other)}. | - | ||||||||||||||||||
| 5549 | */ | - | ||||||||||||||||||
| 5550 | - | |||||||||||||||||||
| 5551 | /*! | - | ||||||||||||||||||
| 5552 | \fn int QString::localeAwareCompare(const QString &s1, const QStringRef &s2) | - | ||||||||||||||||||
| 5553 | \since 4.5 | - | ||||||||||||||||||
| 5554 | \overload localeAwareCompare() | - | ||||||||||||||||||
| 5555 | - | |||||||||||||||||||
| 5556 | Compares \a s1 with \a s2 and returns an integer less than, equal | - | ||||||||||||||||||
| 5557 | to, or greater than zero if \a s1 is less than, equal to, or | - | ||||||||||||||||||
| 5558 | greater than \a s2. | - | ||||||||||||||||||
| 5559 | - | |||||||||||||||||||
| 5560 | The comparison is performed in a locale- and also | - | ||||||||||||||||||
| 5561 | platform-dependent manner. Use this function to present sorted | - | ||||||||||||||||||
| 5562 | lists of strings to the user. | - | ||||||||||||||||||
| 5563 | */ | - | ||||||||||||||||||
| 5564 | - | |||||||||||||||||||
| 5565 | - | |||||||||||||||||||
| 5566 | #if !defined(CSTR_LESS_THAN) | - | ||||||||||||||||||
| 5567 | #define CSTR_LESS_THAN 1 | - | ||||||||||||||||||
| 5568 | #define CSTR_EQUAL 2 | - | ||||||||||||||||||
| 5569 | #define CSTR_GREATER_THAN 3 | - | ||||||||||||||||||
| 5570 | #endif | - | ||||||||||||||||||
| 5571 | - | |||||||||||||||||||
| 5572 | /*! | - | ||||||||||||||||||
| 5573 | \overload localeAwareCompare() | - | ||||||||||||||||||
| 5574 | - | |||||||||||||||||||
| 5575 | Compares this string with the \a other string and returns an | - | ||||||||||||||||||
| 5576 | integer less than, equal to, or greater than zero if this string | - | ||||||||||||||||||
| 5577 | is less than, equal to, or greater than the \a other string. | - | ||||||||||||||||||
| 5578 | - | |||||||||||||||||||
| 5579 | The comparison is performed in a locale- and also | - | ||||||||||||||||||
| 5580 | platform-dependent manner. Use this function to present sorted | - | ||||||||||||||||||
| 5581 | lists of strings to the user. | - | ||||||||||||||||||
| 5582 | - | |||||||||||||||||||
| 5583 | Same as \c {localeAwareCompare(*this, other)}. | - | ||||||||||||||||||
| 5584 | */ | - | ||||||||||||||||||
| 5585 | int QString::localeAwareCompare(const QString &other) const | - | ||||||||||||||||||
| 5586 | { | - | ||||||||||||||||||
| 5587 | 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 | ||||||||||||||||||
| 5588 | } | - | ||||||||||||||||||
| 5589 | - | |||||||||||||||||||
| 5590 | #if defined(QT_USE_ICU) && !defined(Q_OS_WIN32) && !defined(Q_OS_WINCE) && !defined (Q_OS_MAC) | - | ||||||||||||||||||
| 5591 | 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 | ||||||||||||||||||
| 5592 | #endif | - | ||||||||||||||||||
| 5593 | - | |||||||||||||||||||
| 5594 | /*! | - | ||||||||||||||||||
| 5595 | \internal | - | ||||||||||||||||||
| 5596 | \since 4.5 | - | ||||||||||||||||||
| 5597 | */ | - | ||||||||||||||||||
| 5598 | int QString::localeAwareCompare_helper(const QChar *data1, int length1, | - | ||||||||||||||||||
| 5599 | const QChar *data2, int length2) | - | ||||||||||||||||||
| 5600 | { | - | ||||||||||||||||||
| 5601 | // do the right thing for null and empty | - | ||||||||||||||||||
| 5602 | if (length1 == 0 || length2 == 0)
| 0-11395 | ||||||||||||||||||
| 5603 | return ucstrcmp(data1, length1, data2, length2); executed 7 times by 1 test: return ucstrcmp(data1, length1, data2, length2);Executed by:
| 7 | ||||||||||||||||||
| 5604 | - | |||||||||||||||||||
| 5605 | #if defined(Q_OS_WIN32) || defined(Q_OS_WINCE) | - | ||||||||||||||||||
| 5606 | #ifndef Q_OS_WINRT | - | ||||||||||||||||||
| 5607 | int res = CompareString(GetUserDefaultLCID(), 0, (wchar_t*)data1, length1, (wchar_t*)data2, length2); | - | ||||||||||||||||||
| 5608 | #else | - | ||||||||||||||||||
| 5609 | int res = CompareStringEx(LOCALE_NAME_USER_DEFAULT, 0, (LPCWSTR)data1, length1, (LPCWSTR)data2, length2, NULL, NULL, 0); | - | ||||||||||||||||||
| 5610 | #endif | - | ||||||||||||||||||
| 5611 | - | |||||||||||||||||||
| 5612 | switch (res) { | - | ||||||||||||||||||
| 5613 | case CSTR_LESS_THAN: | - | ||||||||||||||||||
| 5614 | return -1; | - | ||||||||||||||||||
| 5615 | case CSTR_GREATER_THAN: | - | ||||||||||||||||||
| 5616 | return 1; | - | ||||||||||||||||||
| 5617 | default: | - | ||||||||||||||||||
| 5618 | return 0; | - | ||||||||||||||||||
| 5619 | } | - | ||||||||||||||||||
| 5620 | #elif defined (Q_OS_MAC) | - | ||||||||||||||||||
| 5621 | // Use CFStringCompare for comparing strings on Mac. This makes Qt order | - | ||||||||||||||||||
| 5622 | // strings the same way as native applications do, and also respects | - | ||||||||||||||||||
| 5623 | // the "Order for sorted lists" setting in the International preferences | - | ||||||||||||||||||
| 5624 | // panel. | - | ||||||||||||||||||
| 5625 | const CFStringRef thisString = | - | ||||||||||||||||||
| 5626 | CFStringCreateWithCharactersNoCopy(kCFAllocatorDefault, | - | ||||||||||||||||||
| 5627 | reinterpret_cast<const UniChar *>(data1), length1, kCFAllocatorNull); | - | ||||||||||||||||||
| 5628 | const CFStringRef otherString = | - | ||||||||||||||||||
| 5629 | CFStringCreateWithCharactersNoCopy(kCFAllocatorDefault, | - | ||||||||||||||||||
| 5630 | reinterpret_cast<const UniChar *>(data2), length2, kCFAllocatorNull); | - | ||||||||||||||||||
| 5631 | - | |||||||||||||||||||
| 5632 | const int result = CFStringCompare(thisString, otherString, kCFCompareLocalized); | - | ||||||||||||||||||
| 5633 | CFRelease(thisString); | - | ||||||||||||||||||
| 5634 | CFRelease(otherString); | - | ||||||||||||||||||
| 5635 | return result; | - | ||||||||||||||||||
| 5636 | #elif defined(QT_USE_ICU) | - | ||||||||||||||||||
| 5637 | if (!defaultCollator()->hasLocalData())
| 6-11389 | ||||||||||||||||||
| 5638 | defaultCollator()->setLocalData(QCollator()); executed 6 times by 6 tests: defaultCollator()->setLocalData(QCollator());Executed by:
| 6 | ||||||||||||||||||
| 5639 | 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 | ||||||||||||||||||
| 5640 | #elif defined(Q_OS_UNIX) | - | ||||||||||||||||||
| 5641 | // declared in <string.h> | - | ||||||||||||||||||
| 5642 | int delta = strcoll(toLocal8Bit_helper(data1, length1).constData(), toLocal8Bit_helper(data2, length2).constData()); | - | ||||||||||||||||||
| 5643 | if (delta == 0) | - | ||||||||||||||||||
| 5644 | delta = ucstrcmp(data1, length1, data2, length2); | - | ||||||||||||||||||
| 5645 | return delta; | - | ||||||||||||||||||
| 5646 | #else | - | ||||||||||||||||||
| 5647 | return ucstrcmp(data1, length1, data2, length2); | - | ||||||||||||||||||
| 5648 | #endif | - | ||||||||||||||||||
| 5649 | } | - | ||||||||||||||||||
| 5650 | - | |||||||||||||||||||
| 5651 | - | |||||||||||||||||||
| 5652 | /*! | - | ||||||||||||||||||
| 5653 | \fn const QChar *QString::unicode() const | - | ||||||||||||||||||
| 5654 | - | |||||||||||||||||||
| 5655 | Returns a '\\0'-terminated Unicode representation of the string. | - | ||||||||||||||||||
| 5656 | The result remains valid until the string is modified. | - | ||||||||||||||||||
| 5657 | - | |||||||||||||||||||
| 5658 | \sa utf16() | - | ||||||||||||||||||
| 5659 | */ | - | ||||||||||||||||||
| 5660 | - | |||||||||||||||||||
| 5661 | /*! | - | ||||||||||||||||||
| 5662 | \fn const ushort *QString::utf16() const | - | ||||||||||||||||||
| 5663 | - | |||||||||||||||||||
| 5664 | Returns the QString as a '\\0\'-terminated array of unsigned | - | ||||||||||||||||||
| 5665 | shorts. The result remains valid until the string is modified. | - | ||||||||||||||||||
| 5666 | - | |||||||||||||||||||
| 5667 | The returned string is in host byte order. | - | ||||||||||||||||||
| 5668 | - | |||||||||||||||||||
| 5669 | \sa unicode() | - | ||||||||||||||||||
| 5670 | */ | - | ||||||||||||||||||
| 5671 | - | |||||||||||||||||||
| 5672 | const ushort *QString::utf16() const | - | ||||||||||||||||||
| 5673 | { | - | ||||||||||||||||||
| 5674 | if (IS_RAW_DATA(d)) {
| 0-139250 | ||||||||||||||||||
| 5675 | // ensure '\0'-termination for ::fromRawData strings | - | ||||||||||||||||||
| 5676 | const_cast<QString*>(this)->reallocData(uint(d->size) + 1u); | - | ||||||||||||||||||
| 5677 | } never executed: end of block | 0 | ||||||||||||||||||
| 5678 | return d->data(); executed 139250 times by 55 tests: return d->data();Executed by:
| 139250 | ||||||||||||||||||
| 5679 | } | - | ||||||||||||||||||
| 5680 | - | |||||||||||||||||||
| 5681 | /*! | - | ||||||||||||||||||
| 5682 | Returns a string of size \a width that contains this string | - | ||||||||||||||||||
| 5683 | padded by the \a fill character. | - | ||||||||||||||||||
| 5684 | - | |||||||||||||||||||
| 5685 | If \a truncate is \c false and the size() of the string is more than | - | ||||||||||||||||||
| 5686 | \a width, then the returned string is a copy of the string. | - | ||||||||||||||||||
| 5687 | - | |||||||||||||||||||
| 5688 | \snippet qstring/main.cpp 32 | - | ||||||||||||||||||
| 5689 | - | |||||||||||||||||||
| 5690 | If \a truncate is \c true and the size() of the string is more than | - | ||||||||||||||||||
| 5691 | \a width, then any characters in a copy of the string after | - | ||||||||||||||||||
| 5692 | position \a width are removed, and the copy is returned. | - | ||||||||||||||||||
| 5693 | - | |||||||||||||||||||
| 5694 | \snippet qstring/main.cpp 33 | - | ||||||||||||||||||
| 5695 | - | |||||||||||||||||||
| 5696 | \sa rightJustified() | - | ||||||||||||||||||
| 5697 | */ | - | ||||||||||||||||||
| 5698 | - | |||||||||||||||||||
| 5699 | QString QString::leftJustified(int width, QChar fill, bool truncate) const | - | ||||||||||||||||||
| 5700 | { | - | ||||||||||||||||||
| 5701 | QString result; | - | ||||||||||||||||||
| 5702 | int len = length(); | - | ||||||||||||||||||
| 5703 | int padlen = width - len; | - | ||||||||||||||||||
| 5704 | if (padlen > 0) {
| 806-4210 | ||||||||||||||||||
| 5705 | result.resize(len+padlen); | - | ||||||||||||||||||
| 5706 | if (len)
| 1-805 | ||||||||||||||||||
| 5707 | memcpy(result.d->data(), d->data(), sizeof(QChar)*len); executed 805 times by 3 tests: memcpy(result.d->data(), d->data(), sizeof(QChar)*len);Executed by:
| 805 | ||||||||||||||||||
| 5708 | QChar *uc = (QChar*)result.d->data() + len; | - | ||||||||||||||||||
| 5709 | while (padlen--)
| 806-32193 | ||||||||||||||||||
| 5710 | * uc++ = fill; executed 32193 times by 3 tests: * uc++ = fill;Executed by:
| 32193 | ||||||||||||||||||
| 5711 | } else { executed 806 times by 3 tests: end of blockExecuted by:
| 806 | ||||||||||||||||||
| 5712 | if (truncate)
| 4-4206 | ||||||||||||||||||
| 5713 | result = left(width); executed 4 times by 1 test: result = left(width);Executed by:
| 4 | ||||||||||||||||||
| 5714 | else | - | ||||||||||||||||||
| 5715 | result = *this; executed 4206 times by 1 test: result = *this;Executed by:
| 4206 | ||||||||||||||||||
| 5716 | } | - | ||||||||||||||||||
| 5717 | return result; executed 5016 times by 3 tests: return result;Executed by:
| 5016 | ||||||||||||||||||
| 5718 | } | - | ||||||||||||||||||
| 5719 | - | |||||||||||||||||||
| 5720 | /*! | - | ||||||||||||||||||
| 5721 | Returns a string of size() \a width that contains the \a fill | - | ||||||||||||||||||
| 5722 | character followed by the string. For example: | - | ||||||||||||||||||
| 5723 | - | |||||||||||||||||||
| 5724 | \snippet qstring/main.cpp 49 | - | ||||||||||||||||||
| 5725 | - | |||||||||||||||||||
| 5726 | If \a truncate is \c false and the size() of the string is more than | - | ||||||||||||||||||
| 5727 | \a width, then the returned string is a copy of the string. | - | ||||||||||||||||||
| 5728 | - | |||||||||||||||||||
| 5729 | If \a truncate is true and the size() of the string is more than | - | ||||||||||||||||||
| 5730 | \a width, then the resulting string is truncated at position \a | - | ||||||||||||||||||
| 5731 | width. | - | ||||||||||||||||||
| 5732 | - | |||||||||||||||||||
| 5733 | \snippet qstring/main.cpp 50 | - | ||||||||||||||||||
| 5734 | - | |||||||||||||||||||
| 5735 | \sa leftJustified() | - | ||||||||||||||||||
| 5736 | */ | - | ||||||||||||||||||
| 5737 | - | |||||||||||||||||||
| 5738 | QString QString::rightJustified(int width, QChar fill, bool truncate) const | - | ||||||||||||||||||
| 5739 | { | - | ||||||||||||||||||
| 5740 | QString result; | - | ||||||||||||||||||
| 5741 | int len = length(); | - | ||||||||||||||||||
| 5742 | int padlen = width - len; | - | ||||||||||||||||||
| 5743 | if (padlen > 0) {
| 802-389151 | ||||||||||||||||||
| 5744 | result.resize(len+padlen); | - | ||||||||||||||||||
| 5745 | QChar *uc = (QChar*)result.d->data(); | - | ||||||||||||||||||
| 5746 | while (padlen--)
| 802-30764 | ||||||||||||||||||
| 5747 | * uc++ = fill; executed 30764 times by 4 tests: * uc++ = fill;Executed by:
| 30764 | ||||||||||||||||||
| 5748 | if (len)
| 1-801 | ||||||||||||||||||
| 5749 | memcpy(uc, d->data(), sizeof(QChar)*len); executed 801 times by 4 tests: memcpy(uc, d->data(), sizeof(QChar)*len);Executed by:
| 801 | ||||||||||||||||||
| 5750 | } else { executed 802 times by 4 tests: end of blockExecuted by:
| 802 | ||||||||||||||||||
| 5751 | if (truncate)
| 4-389147 | ||||||||||||||||||
| 5752 | result = left(width); executed 4 times by 1 test: result = left(width);Executed by:
| 4 | ||||||||||||||||||
| 5753 | else | - | ||||||||||||||||||
| 5754 | result = *this; executed 389147 times by 110 tests: result = *this;Executed by:
| 389147 | ||||||||||||||||||
| 5755 | } | - | ||||||||||||||||||
| 5756 | return result; executed 389953 times by 110 tests: return result;Executed by:
| 389953 | ||||||||||||||||||
| 5757 | } | - | ||||||||||||||||||
| 5758 | - | |||||||||||||||||||
| 5759 | /*! | - | ||||||||||||||||||
| 5760 | \fn QString QString::toLower() const | - | ||||||||||||||||||
| 5761 | - | |||||||||||||||||||
| 5762 | Returns a lowercase copy of the string. | - | ||||||||||||||||||
| 5763 | - | |||||||||||||||||||
| 5764 | \snippet qstring/main.cpp 75 | - | ||||||||||||||||||
| 5765 | - | |||||||||||||||||||
| 5766 | The case conversion will always happen in the 'C' locale. For locale dependent | - | ||||||||||||||||||
| 5767 | case folding use QLocale::toLower() | - | ||||||||||||||||||
| 5768 | - | |||||||||||||||||||
| 5769 | \sa toUpper(), QLocale::toLower() | - | ||||||||||||||||||
| 5770 | */ | - | ||||||||||||||||||
| 5771 | - | |||||||||||||||||||
| 5772 | namespace QUnicodeTables { | - | ||||||||||||||||||
| 5773 | /* | - | ||||||||||||||||||
| 5774 | \internal | - | ||||||||||||||||||
| 5775 | Converts the \a str string starting from the position pointed to by the \a | - | ||||||||||||||||||
| 5776 | it iterator, using the Unicode case traits \c Traits, and returns the | - | ||||||||||||||||||
| 5777 | result. The input string must not be empty (the convertCase function below | - | ||||||||||||||||||
| 5778 | guarantees that). | - | ||||||||||||||||||
| 5779 | - | |||||||||||||||||||
| 5780 | The string type \c{T} is also a template and is either \c{const QString} or | - | ||||||||||||||||||
| 5781 | \c{QString}. This function can do both copy-conversion and in-place | - | ||||||||||||||||||
| 5782 | conversion depending on the state of the \a str parameter: | - | ||||||||||||||||||
| 5783 | \list | - | ||||||||||||||||||
| 5784 | \li \c{T} is \c{const QString}: copy-convert | - | ||||||||||||||||||
| 5785 | \li \c{T} is \c{QString} and its refcount != 1: copy-convert | - | ||||||||||||||||||
| 5786 | \li \c{T} is \c{QString} and its refcount == 1: in-place convert | - | ||||||||||||||||||
| 5787 | \endlist | - | ||||||||||||||||||
| 5788 | - | |||||||||||||||||||
| 5789 | In copy-convert mode, the local variable \c{s} is detached from the input | - | ||||||||||||||||||
| 5790 | \a str. In the in-place convert mode, \a str is in moved-from state (which | - | ||||||||||||||||||
| 5791 | this function requires to be a valid, empty string) and \c{s} contains the | - | ||||||||||||||||||
| 5792 | only copy of the string, without reallocation (thus, \a it is still valid). | - | ||||||||||||||||||
| 5793 | - | |||||||||||||||||||
| 5794 | There's one pathological case left: when the in-place conversion needs to | - | ||||||||||||||||||
| 5795 | reallocate memory to grow the buffer. In that case, we need to adjust the \a | - | ||||||||||||||||||
| 5796 | it pointer. | - | ||||||||||||||||||
| 5797 | */ | - | ||||||||||||||||||
| 5798 | template <typename Traits, typename T> | - | ||||||||||||||||||
| 5799 | Q_NEVER_INLINE | - | ||||||||||||||||||
| 5800 | static QString detachAndConvertCase(T &str, QStringIterator it) | - | ||||||||||||||||||
| 5801 | { | - | ||||||||||||||||||
| 5802 | Q_ASSERT(!str.isEmpty()); | - | ||||||||||||||||||
| 5803 | QString s = qMove(str); // will copy if T is const QString | - | ||||||||||||||||||
| 5804 | QChar *pp = s.begin() + it.index(); // will detach if necessary | - | ||||||||||||||||||
| 5805 | - | |||||||||||||||||||
| 5806 | do { | - | ||||||||||||||||||
| 5807 | uint uc = it.nextUnchecked(); | - | ||||||||||||||||||
| 5808 | - | |||||||||||||||||||
| 5809 | const QUnicodeTables::Properties *prop = qGetProp(uc); | - | ||||||||||||||||||
| 5810 | signed short caseDiff = Traits::caseDiff(prop); | - | ||||||||||||||||||
| 5811 | - | |||||||||||||||||||
| 5812 | if (Q_UNLIKELY(Traits::caseSpecial(prop))) {
| 212-2309443 | ||||||||||||||||||
| 5813 | const ushort *specialCase = specialCaseMap + caseDiff; | - | ||||||||||||||||||
| 5814 | ushort length = *specialCase++; | - | ||||||||||||||||||
| 5815 | - | |||||||||||||||||||
| 5816 | if (Q_LIKELY(length == 1)) {
| 8-204 | ||||||||||||||||||
| 5817 | *pp++ = QChar(*specialCase); | - | ||||||||||||||||||
| 5818 | } else { executed 204 times by 1 test: end of blockExecuted by:
| 204 | ||||||||||||||||||
| 5819 | // slow path: the string is growing | - | ||||||||||||||||||
| 5820 | int inpos = it.index() - 1; | - | ||||||||||||||||||
| 5821 | int outpos = pp - s.constBegin(); | - | ||||||||||||||||||
| 5822 | - | |||||||||||||||||||
| 5823 | s.replace(outpos, 1, reinterpret_cast<const QChar *>(specialCase), length); | - | ||||||||||||||||||
| 5824 | pp = const_cast<QChar *>(s.constBegin()) + outpos + length; | - | ||||||||||||||||||
| 5825 | - | |||||||||||||||||||
| 5826 | // do we need to adjust the input iterator too? | - | ||||||||||||||||||
| 5827 | // if it is pointing to s's data, str is empty | - | ||||||||||||||||||
| 5828 | if (str.isEmpty())
| 2-6 | ||||||||||||||||||
| 5829 | 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 | ||||||||||||||||||
| 5830 | } executed 8 times by 1 test: end of blockExecuted by:
| 8 | ||||||||||||||||||
| 5831 | } else if (Q_UNLIKELY(QChar::requiresSurrogates(uc))) {
| 23-2309420 | ||||||||||||||||||
| 5832 | // so far, case convertion never changes planes (guaranteed by the qunicodetables generator) | - | ||||||||||||||||||
| 5833 | pp++; | - | ||||||||||||||||||
| 5834 | *pp++ = QChar::lowSurrogate(uc + caseDiff); | - | ||||||||||||||||||
| 5835 | } else { executed 23 times by 2 tests: end of blockExecuted by:
| 23 | ||||||||||||||||||
| 5836 | *pp++ = QChar(uc + caseDiff); | - | ||||||||||||||||||
| 5837 | } executed 2309420 times by 188 tests: end of blockExecuted by:
| 2309420 | ||||||||||||||||||
| 5838 | } while (it.hasNext());
| 266185-2043470 | ||||||||||||||||||
| 5839 | - | |||||||||||||||||||
| 5840 | return s; executed 266185 times by 188 tests: return s;Executed by:
| 266185 | ||||||||||||||||||
| 5841 | } | - | ||||||||||||||||||
| 5842 | - | |||||||||||||||||||
| 5843 | template <typename Traits, typename T> | - | ||||||||||||||||||
| 5844 | static QString convertCase(T &str) | - | ||||||||||||||||||
| 5845 | { | - | ||||||||||||||||||
| 5846 | const QChar *p = str.constBegin(); | - | ||||||||||||||||||
| 5847 | const QChar *e = p + str.size(); | - | ||||||||||||||||||
| 5848 | - | |||||||||||||||||||
| 5849 | // this avoids out of bounds check in the loop | - | ||||||||||||||||||
| 5850 | while (e != p && e[-1].isHighSurrogate())
| 2054-545568 | ||||||||||||||||||
| 5851 | --e; executed 2054 times by 1 test: --e;Executed by:
| 2054 | ||||||||||||||||||
| 5852 | - | |||||||||||||||||||
| 5853 | QStringIterator it(p, e); | - | ||||||||||||||||||
| 5854 | while (it.hasNext()) {
| 281379-1808666 | ||||||||||||||||||
| 5855 | uint uc = it.nextUnchecked(); | - | ||||||||||||||||||
| 5856 | if (Traits::caseDiff(qGetProp(uc))) {
| 266185-1542481 | ||||||||||||||||||
| 5857 | it.recedeUnchecked(); | - | ||||||||||||||||||
| 5858 | return detachAndConvertCase<Traits>(str, it); executed 266185 times by 188 tests: return detachAndConvertCase<Traits>(str, it);Executed by:
| 266185 | ||||||||||||||||||
| 5859 | } | - | ||||||||||||||||||
| 5860 | } executed 1542481 times by 184 tests: end of blockExecuted by:
| 1542481 | ||||||||||||||||||
| 5861 | return qMove(str); executed 281379 times by 181 tests: return std::move(str);Executed by:
| 281379 | ||||||||||||||||||
| 5862 | } | - | ||||||||||||||||||
| 5863 | } // namespace QUnicodeTables | - | ||||||||||||||||||
| 5864 | - | |||||||||||||||||||
| 5865 | QString QString::toLower_helper(const QString &str) | - | ||||||||||||||||||
| 5866 | { | - | ||||||||||||||||||
| 5867 | return QUnicodeTables::convertCase<QUnicodeTables::LowercaseTraits>(str); executed 315713 times by 199 tests: return QUnicodeTables::convertCase<QUnicodeTables::LowercaseTraits>(str);Executed by:
| 315713 | ||||||||||||||||||
| 5868 | } | - | ||||||||||||||||||
| 5869 | - | |||||||||||||||||||
| 5870 | QString QString::toLower_helper(QString &str) | - | ||||||||||||||||||
| 5871 | { | - | ||||||||||||||||||
| 5872 | return QUnicodeTables::convertCase<QUnicodeTables::LowercaseTraits>(str); executed 45255 times by 174 tests: return QUnicodeTables::convertCase<QUnicodeTables::LowercaseTraits>(str);Executed by:
| 45255 | ||||||||||||||||||
| 5873 | } | - | ||||||||||||||||||
| 5874 | - | |||||||||||||||||||
| 5875 | /*! | - | ||||||||||||||||||
| 5876 | \fn QString QString::toCaseFolded() const | - | ||||||||||||||||||
| 5877 | - | |||||||||||||||||||
| 5878 | Returns the case folded equivalent of the string. For most Unicode | - | ||||||||||||||||||
| 5879 | characters this is the same as toLower(). | - | ||||||||||||||||||
| 5880 | */ | - | ||||||||||||||||||
| 5881 | - | |||||||||||||||||||
| 5882 | QString QString::toCaseFolded_helper(const QString &str) | - | ||||||||||||||||||
| 5883 | { | - | ||||||||||||||||||
| 5884 | return QUnicodeTables::convertCase<QUnicodeTables::CasefoldTraits>(str); executed 175937 times by 125 tests: return QUnicodeTables::convertCase<QUnicodeTables::CasefoldTraits>(str);Executed by:
| 175937 | ||||||||||||||||||
| 5885 | } | - | ||||||||||||||||||
| 5886 | - | |||||||||||||||||||
| 5887 | QString QString::toCaseFolded_helper(QString &str) | - | ||||||||||||||||||
| 5888 | { | - | ||||||||||||||||||
| 5889 | return QUnicodeTables::convertCase<QUnicodeTables::CasefoldTraits>(str); executed 18 times by 1 test: return QUnicodeTables::convertCase<QUnicodeTables::CasefoldTraits>(str);Executed by:
| 18 | ||||||||||||||||||
| 5890 | } | - | ||||||||||||||||||
| 5891 | - | |||||||||||||||||||
| 5892 | /*! | - | ||||||||||||||||||
| 5893 | \fn QString QString::toUpper() const | - | ||||||||||||||||||
| 5894 | - | |||||||||||||||||||
| 5895 | Returns an uppercase copy of the string. | - | ||||||||||||||||||
| 5896 | - | |||||||||||||||||||
| 5897 | \snippet qstring/main.cpp 81 | - | ||||||||||||||||||
| 5898 | - | |||||||||||||||||||
| 5899 | The case conversion will always happen in the 'C' locale. For locale dependent | - | ||||||||||||||||||
| 5900 | case folding use QLocale::toUpper() | - | ||||||||||||||||||
| 5901 | - | |||||||||||||||||||
| 5902 | \sa toLower(), QLocale::toLower() | - | ||||||||||||||||||
| 5903 | */ | - | ||||||||||||||||||
| 5904 | - | |||||||||||||||||||
| 5905 | QString QString::toUpper_helper(const QString &str) | - | ||||||||||||||||||
| 5906 | { | - | ||||||||||||||||||
| 5907 | return QUnicodeTables::convertCase<QUnicodeTables::UppercaseTraits>(str); executed 6040 times by 15 tests: return QUnicodeTables::convertCase<QUnicodeTables::UppercaseTraits>(str);Executed by:
| 6040 | ||||||||||||||||||
| 5908 | } | - | ||||||||||||||||||
| 5909 | - | |||||||||||||||||||
| 5910 | QString QString::toUpper_helper(QString &str) | - | ||||||||||||||||||
| 5911 | { | - | ||||||||||||||||||
| 5912 | return QUnicodeTables::convertCase<QUnicodeTables::UppercaseTraits>(str); executed 4601 times by 23 tests: return QUnicodeTables::convertCase<QUnicodeTables::UppercaseTraits>(str);Executed by:
| 4601 | ||||||||||||||||||
| 5913 | } | - | ||||||||||||||||||
| 5914 | - | |||||||||||||||||||
| 5915 | /*! | - | ||||||||||||||||||
| 5916 | \obsolete | - | ||||||||||||||||||
| 5917 | - | |||||||||||||||||||
| 5918 | Use asprintf(), arg() or QTextStream instead. | - | ||||||||||||||||||
| 5919 | */ | - | ||||||||||||||||||
| 5920 | QString &QString::sprintf(const char *cformat, ...) | - | ||||||||||||||||||
| 5921 | { | - | ||||||||||||||||||
| 5922 | va_list ap; | - | ||||||||||||||||||
| 5923 | va_start(ap, cformat); | - | ||||||||||||||||||
| 5924 | *this = vasprintf(cformat, ap); | - | ||||||||||||||||||
| 5925 | va_end(ap); | - | ||||||||||||||||||
| 5926 | return *this; executed 10040 times by 3 tests: return *this;Executed by:
| 10040 | ||||||||||||||||||
| 5927 | } | - | ||||||||||||||||||
| 5928 | - | |||||||||||||||||||
| 5929 | // ### Qt 6: Consider whether this function shouldn't be removed See task 202871. | - | ||||||||||||||||||
| 5930 | /*! | - | ||||||||||||||||||
| 5931 | \since 5.5 | - | ||||||||||||||||||
| 5932 | - | |||||||||||||||||||
| 5933 | Safely builds a formatted string from the format string \a cformat | - | ||||||||||||||||||
| 5934 | and an arbitrary list of arguments. | - | ||||||||||||||||||
| 5935 | - | |||||||||||||||||||
| 5936 | The format string supports the conversion specifiers, length modifiers, | - | ||||||||||||||||||
| 5937 | and flags provided by printf() in the standard C++ library. The \a cformat | - | ||||||||||||||||||
| 5938 | string and \c{%s} arguments must be UTF-8 encoded. | - | ||||||||||||||||||
| 5939 | - | |||||||||||||||||||
| 5940 | \note The \c{%lc} escape sequence expects a unicode character of type | - | ||||||||||||||||||
| 5941 | \c char16_t, or \c ushort (as returned by QChar::unicode()). | - | ||||||||||||||||||
| 5942 | The \c{%ls} escape sequence expects a pointer to a zero-terminated array | - | ||||||||||||||||||
| 5943 | of unicode characters of type \c char16_t, or ushort (as returned by | - | ||||||||||||||||||
| 5944 | QString::utf16()). This is at odds with the printf() in the standard C++ | - | ||||||||||||||||||
| 5945 | library, which defines \c {%lc} to print a wchar_t and \c{%ls} to print | - | ||||||||||||||||||
| 5946 | a \c{wchar_t*}, and might also produce compiler warnings on platforms | - | ||||||||||||||||||
| 5947 | where the size of \c {wchar_t} is not 16 bits. | - | ||||||||||||||||||
| 5948 | - | |||||||||||||||||||
| 5949 | \warning We do not recommend using QString::asprintf() in new Qt | - | ||||||||||||||||||
| 5950 | code. Instead, consider using QTextStream or arg(), both of | - | ||||||||||||||||||
| 5951 | which support Unicode strings seamlessly and are type-safe. | - | ||||||||||||||||||
| 5952 | Here's an example that uses QTextStream: | - | ||||||||||||||||||
| 5953 | - | |||||||||||||||||||
| 5954 | \snippet qstring/main.cpp 64 | - | ||||||||||||||||||
| 5955 | - | |||||||||||||||||||
| 5956 | For \l {QObject::tr()}{translations}, especially if the strings | - | ||||||||||||||||||
| 5957 | contains more than one escape sequence, you should consider using | - | ||||||||||||||||||
| 5958 | the arg() function instead. This allows the order of the | - | ||||||||||||||||||
| 5959 | replacements to be controlled by the translator. | - | ||||||||||||||||||
| 5960 | - | |||||||||||||||||||
| 5961 | \sa arg() | - | ||||||||||||||||||
| 5962 | */ | - | ||||||||||||||||||
| 5963 | - | |||||||||||||||||||
| 5964 | QString QString::asprintf(const char *cformat, ...) | - | ||||||||||||||||||
| 5965 | { | - | ||||||||||||||||||
| 5966 | va_list ap; | - | ||||||||||||||||||
| 5967 | va_start(ap, cformat); | - | ||||||||||||||||||
| 5968 | const QString s = vasprintf(cformat, ap); | - | ||||||||||||||||||
| 5969 | va_end(ap); | - | ||||||||||||||||||
| 5970 | return s; executed 25965 times by 48 tests: return s;Executed by:
| 25965 | ||||||||||||||||||
| 5971 | } | - | ||||||||||||||||||
| 5972 | - | |||||||||||||||||||
| 5973 | /*! | - | ||||||||||||||||||
| 5974 | \obsolete | - | ||||||||||||||||||
| 5975 | - | |||||||||||||||||||
| 5976 | Use vasprintf(), arg() or QTextStream instead. | - | ||||||||||||||||||
| 5977 | */ | - | ||||||||||||||||||
| 5978 | QString &QString::vsprintf(const char *cformat, va_list ap) | - | ||||||||||||||||||
| 5979 | { | - | ||||||||||||||||||
| 5980 | return *this = vasprintf(cformat, ap); never executed: return *this = vasprintf(cformat, ap); | 0 | ||||||||||||||||||
| 5981 | } | - | ||||||||||||||||||
| 5982 | - | |||||||||||||||||||
| 5983 | static void append_utf8(QString &qs, const char *cs, int len) | - | ||||||||||||||||||
| 5984 | { | - | ||||||||||||||||||
| 5985 | const int oldSize = qs.size(); | - | ||||||||||||||||||
| 5986 | qs.resize(oldSize + len); | - | ||||||||||||||||||
| 5987 | const QChar *newEnd = QUtf8::convertToUnicode(qs.data() + oldSize, cs, len); | - | ||||||||||||||||||
| 5988 | qs.resize(newEnd - qs.constData()); | - | ||||||||||||||||||
| 5989 | } executed 683187 times by 161 tests: end of blockExecuted by:
| 683187 | ||||||||||||||||||
| 5990 | - | |||||||||||||||||||
| 5991 | static uint parse_flag_characters(const char * &c) Q_DECL_NOTHROW | - | ||||||||||||||||||
| 5992 | { | - | ||||||||||||||||||
| 5993 | uint flags = QLocaleData::ZeroPadExponent; | - | ||||||||||||||||||
| 5994 | while (true) { | - | ||||||||||||||||||
| 5995 | switch (*c) { | - | ||||||||||||||||||
| 5996 | case '#': flags |= QLocaleData::Alternate; break; executed 4992 times by 1 test: break;Executed by:
executed 4992 times by 1 test: case '#':Executed by:
| 4992 | ||||||||||||||||||
| 5997 | case '0': flags |= QLocaleData::ZeroPadded; break; executed 12678 times by 15 tests: break;Executed by:
executed 12678 times by 15 tests: case '0':Executed by:
| 12678 | ||||||||||||||||||
| 5998 | case '-': flags |= QLocaleData::LeftAdjusted; break; executed 5000 times by 1 test: break;Executed by:
executed 5000 times by 1 test: case '-':Executed by:
| 5000 | ||||||||||||||||||
| 5999 | case ' ': flags |= QLocaleData::BlankBeforePositive; break; executed 4992 times by 1 test: break;Executed by:
executed 4992 times by 1 test: case ' ':Executed by:
| 4992 | ||||||||||||||||||
| 6000 | case '+': flags |= QLocaleData::AlwaysShowSign; break; executed 4992 times by 1 test: break;Executed by:
executed 4992 times by 1 test: case '+':Executed by:
| 4992 | ||||||||||||||||||
| 6001 | case '\'': flags |= QLocaleData::ThousandsGroup; break; executed 9984 times by 1 test: break;Executed by:
executed 9984 times by 1 test: case '\'':Executed by:
| 9984 | ||||||||||||||||||
| 6002 | default: return flags; executed 394937 times by 110 tests: return flags;Executed by:
executed 394937 times by 110 tests: default:Executed by:
| 394937 | ||||||||||||||||||
| 6003 | } | - | ||||||||||||||||||
| 6004 | ++c; | - | ||||||||||||||||||
| 6005 | } executed 42638 times by 15 tests: end of blockExecuted by:
| 42638 | ||||||||||||||||||
| 6006 | } never executed: end of block | 0 | ||||||||||||||||||
| 6007 | - | |||||||||||||||||||
| 6008 | static int parse_field_width(const char * &c) | - | ||||||||||||||||||
| 6009 | { | - | ||||||||||||||||||
| 6010 | Q_ASSERT(qIsDigit(*c)); | - | ||||||||||||||||||
| 6011 | - | |||||||||||||||||||
| 6012 | // can't be negative - started with a digit | - | ||||||||||||||||||
| 6013 | // contains at least one digit | - | ||||||||||||||||||
| 6014 | const char *endp; | - | ||||||||||||||||||
| 6015 | bool ok; | - | ||||||||||||||||||
| 6016 | const qulonglong result = qstrtoull(c, &endp, 10, &ok); | - | ||||||||||||||||||
| 6017 | c = endp; | - | ||||||||||||||||||
| 6018 | while (qIsDigit(*c)) // preserve Qt 5.5 behavior of consuming all digits, no matter how many
| 0-24569 | ||||||||||||||||||
| 6019 | ++c; never executed: ++c; | 0 | ||||||||||||||||||
| 6020 | return ok && result < qulonglong(std::numeric_limits<int>::max()) ? int(result) : 0; executed 24569 times by 22 tests: return ok && result < qulonglong(std::numeric_limits<int>::max()) ? int(result) : 0;Executed by:
| 24569 | ||||||||||||||||||
| 6021 | } | - | ||||||||||||||||||
| 6022 | - | |||||||||||||||||||
| 6023 | enum LengthMod { lm_none, lm_hh, lm_h, lm_l, lm_ll, lm_L, lm_j, lm_z, lm_t }; | - | ||||||||||||||||||
| 6024 | - | |||||||||||||||||||
| 6025 | static inline bool can_consume(const char * &c, char ch) Q_DECL_NOTHROW | - | ||||||||||||||||||
| 6026 | { | - | ||||||||||||||||||
| 6027 | if (*c == ch) {
| 42-2022 | ||||||||||||||||||
| 6028 | ++c; | - | ||||||||||||||||||
| 6029 | return true; executed 2022 times by 3 tests: return true;Executed by:
| 2022 | ||||||||||||||||||
| 6030 | } | - | ||||||||||||||||||
| 6031 | return false; executed 42 times by 7 tests: return false;Executed by:
| 42 | ||||||||||||||||||
| 6032 | } | - | ||||||||||||||||||
| 6033 | - | |||||||||||||||||||
| 6034 | static LengthMod parse_length_modifier(const char * &c) Q_DECL_NOTHROW | - | ||||||||||||||||||
| 6035 | { | - | ||||||||||||||||||
| 6036 | switch (*c++) { | - | ||||||||||||||||||
| 6037 | case 'h': return can_consume(c, 'h') ? lm_hh : lm_h; never executed: return can_consume(c, 'h') ? lm_hh : lm_h;never executed: case 'h': | 0 | ||||||||||||||||||
| 6038 | case 'l': return can_consume(c, 'l') ? lm_ll : lm_l; executed 2064 times by 9 tests: return can_consume(c, 'l') ? lm_ll : lm_l;Executed by:
executed 2064 times by 9 tests: case 'l':Executed by:
| 2064 | ||||||||||||||||||
| 6039 | case 'L': return lm_L; never executed: return lm_L;never executed: case 'L': | 0 | ||||||||||||||||||
| 6040 | case 'j': return lm_j; never executed: return lm_j;never executed: case 'j': | 0 | ||||||||||||||||||
| 6041 | case 'z': executed 3 times by 1 test: case 'z':Executed by:
| 3 | ||||||||||||||||||
| 6042 | case 'Z': return lm_z; executed 3 times by 1 test: return lm_z;Executed by:
never executed: case 'Z': | 0-3 | ||||||||||||||||||
| 6043 | case 't': return lm_t; never executed: return lm_t;never executed: case 't': | 0 | ||||||||||||||||||
| 6044 | } | - | ||||||||||||||||||
| 6045 | --c; // don't consume *c - it wasn't a flag | - | ||||||||||||||||||
| 6046 | return lm_none; executed 392870 times by 110 tests: return lm_none;Executed by:
| 392870 | ||||||||||||||||||
| 6047 | } | - | ||||||||||||||||||
| 6048 | - | |||||||||||||||||||
| 6049 | /*! | - | ||||||||||||||||||
| 6050 | \fn QString::vasprintf(const char *cformat, va_list ap) | - | ||||||||||||||||||
| 6051 | \since 5.5 | - | ||||||||||||||||||
| 6052 | - | |||||||||||||||||||
| 6053 | Equivalent method to asprintf(), but takes a va_list \a ap | - | ||||||||||||||||||
| 6054 | instead a list of variable arguments. See the asprintf() | - | ||||||||||||||||||
| 6055 | documentation for an explanation of \a cformat. | - | ||||||||||||||||||
| 6056 | - | |||||||||||||||||||
| 6057 | This method does not call the va_end macro, the caller | - | ||||||||||||||||||
| 6058 | is responsible to call va_end on \a ap. | - | ||||||||||||||||||
| 6059 | - | |||||||||||||||||||
| 6060 | \sa asprintf() | - | ||||||||||||||||||
| 6061 | */ | - | ||||||||||||||||||
| 6062 | - | |||||||||||||||||||
| 6063 | QString QString::vasprintf(const char *cformat, va_list ap) | - | ||||||||||||||||||
| 6064 | { | - | ||||||||||||||||||
| 6065 | if (!cformat || !*cformat) {
| 0-288236 | ||||||||||||||||||
| 6066 | // Qt 1.x compat | - | ||||||||||||||||||
| 6067 | return fromLatin1(""); executed 1 time by 1 test: return fromLatin1("");Executed by:
| 1 | ||||||||||||||||||
| 6068 | } | - | ||||||||||||||||||
| 6069 | - | |||||||||||||||||||
| 6070 | // Parse cformat | - | ||||||||||||||||||
| 6071 | - | |||||||||||||||||||
| 6072 | QString result; | - | ||||||||||||||||||
| 6073 | const char *c = cformat; | - | ||||||||||||||||||
| 6074 | for (;;) { | - | ||||||||||||||||||
| 6075 | // Copy non-escape chars to result | - | ||||||||||||||||||
| 6076 | const char *cb = c; | - | ||||||||||||||||||
| 6077 | while (*c != '\0' && *c != '%')
| 214564-609515 | ||||||||||||||||||
| 6078 | c++; executed 214564 times by 161 tests: c++;Executed by:
| 214564 | ||||||||||||||||||
| 6079 | append_utf8(result, cb, int(c - cb)); | - | ||||||||||||||||||
| 6080 | - | |||||||||||||||||||
| 6081 | if (*c == '\0')
| 288236-394951 | ||||||||||||||||||
| 6082 | break; executed 288236 times by 161 tests: break;Executed by:
| 288236 | ||||||||||||||||||
| 6083 | - | |||||||||||||||||||
| 6084 | // Found '%' | - | ||||||||||||||||||
| 6085 | const char *escape_start = c; | - | ||||||||||||||||||
| 6086 | ++c; | - | ||||||||||||||||||
| 6087 | - | |||||||||||||||||||
| 6088 | if (*c == '\0') {
| 0-394951 | ||||||||||||||||||
| 6089 | result.append(QLatin1Char('%')); // a % at the end of the string - treat as non-escape text | - | ||||||||||||||||||
| 6090 | break; never executed: break; | 0 | ||||||||||||||||||
| 6091 | } | - | ||||||||||||||||||
| 6092 | if (*c == '%') {
| 14-394937 | ||||||||||||||||||
| 6093 | result.append(QLatin1Char('%')); // %% | - | ||||||||||||||||||
| 6094 | ++c; | - | ||||||||||||||||||
| 6095 | continue; executed 14 times by 2 tests: continue;Executed by:
| 14 | ||||||||||||||||||
| 6096 | } | - | ||||||||||||||||||
| 6097 | - | |||||||||||||||||||
| 6098 | uint flags = parse_flag_characters(c); | - | ||||||||||||||||||
| 6099 | - | |||||||||||||||||||
| 6100 | if (*c == '\0') {
| 0-394937 | ||||||||||||||||||
| 6101 | result.append(QLatin1String(escape_start)); // incomplete escape, treat as non-escape text | - | ||||||||||||||||||
| 6102 | break; never executed: break; | 0 | ||||||||||||||||||
| 6103 | } | - | ||||||||||||||||||
| 6104 | - | |||||||||||||||||||
| 6105 | // Parse field width | - | ||||||||||||||||||
| 6106 | int width = -1; // -1 means unspecified | - | ||||||||||||||||||
| 6107 | if (qIsDigit(*c)) {
| 15195-379742 | ||||||||||||||||||
| 6108 | width = parse_field_width(c); | - | ||||||||||||||||||
| 6109 | } else if (*c == '*') { // can't parse this in another function, not portably, at least executed 15195 times by 15 tests: end of blockExecuted by:
| 1-379741 | ||||||||||||||||||
| 6110 | width = va_arg(ap, int); | - | ||||||||||||||||||
| 6111 | if (width < 0)
| 0-1 | ||||||||||||||||||
| 6112 | width = -1; // treat all negative numbers as unspecified never executed: width = -1; | 0 | ||||||||||||||||||
| 6113 | ++c; | - | ||||||||||||||||||
| 6114 | } executed 1 time by 1 test: end of blockExecuted by:
| 1 | ||||||||||||||||||
| 6115 | - | |||||||||||||||||||
| 6116 | if (*c == '\0') {
| 0-394937 | ||||||||||||||||||
| 6117 | result.append(QLatin1String(escape_start)); // incomplete escape, treat as non-escape text | - | ||||||||||||||||||
| 6118 | break; never executed: break; | 0 | ||||||||||||||||||
| 6119 | } | - | ||||||||||||||||||
| 6120 | - | |||||||||||||||||||
| 6121 | // Parse precision | - | ||||||||||||||||||
| 6122 | int precision = -1; // -1 means unspecified | - | ||||||||||||||||||
| 6123 | if (*c == '.') {
| 9375-385562 | ||||||||||||||||||
| 6124 | ++c; | - | ||||||||||||||||||
| 6125 | if (qIsDigit(*c)) {
| 1-9374 | ||||||||||||||||||
| 6126 | precision = parse_field_width(c); | - | ||||||||||||||||||
| 6127 | } else if (*c == '*') { // can't parse this in another function, not portably, at least executed 9374 times by 8 tests: end of blockExecuted by:
| 0-9374 | ||||||||||||||||||
| 6128 | precision = va_arg(ap, int); | - | ||||||||||||||||||
| 6129 | if (precision < 0)
| 0-1 | ||||||||||||||||||
| 6130 | precision = -1; // treat all negative numbers as unspecified never executed: precision = -1; | 0 | ||||||||||||||||||
| 6131 | ++c; | - | ||||||||||||||||||
| 6132 | } executed 1 time by 1 test: end of blockExecuted by:
| 1 | ||||||||||||||||||
| 6133 | } executed 9375 times by 9 tests: end of blockExecuted by:
| 9375 | ||||||||||||||||||
| 6134 | - | |||||||||||||||||||
| 6135 | if (*c == '\0') {
| 0-394937 | ||||||||||||||||||
| 6136 | result.append(QLatin1String(escape_start)); // incomplete escape, treat as non-escape text | - | ||||||||||||||||||
| 6137 | break; never executed: break; | 0 | ||||||||||||||||||
| 6138 | } | - | ||||||||||||||||||
| 6139 | - | |||||||||||||||||||
| 6140 | const LengthMod length_mod = parse_length_modifier(c); | - | ||||||||||||||||||
| 6141 | - | |||||||||||||||||||
| 6142 | if (*c == '\0') {
| 0-394937 | ||||||||||||||||||
| 6143 | result.append(QLatin1String(escape_start)); // incomplete escape, treat as non-escape text | - | ||||||||||||||||||
| 6144 | break; never executed: break; | 0 | ||||||||||||||||||
| 6145 | } | - | ||||||||||||||||||
| 6146 | - | |||||||||||||||||||
| 6147 | // Parse the conversion specifier and do the conversion | - | ||||||||||||||||||
| 6148 | QString subst; | - | ||||||||||||||||||
| 6149 | switch (*c) { | - | ||||||||||||||||||
| 6150 | case 'd': executed 288080 times by 46 tests: case 'd':Executed by:
| 288080 | ||||||||||||||||||
| 6151 | case 'i': { executed 750 times by 7 tests: case 'i':Executed by:
| 750 | ||||||||||||||||||
| 6152 | qint64 i; | - | ||||||||||||||||||
| 6153 | switch (length_mod) { | - | ||||||||||||||||||
| 6154 | case lm_none: i = va_arg(ap, int); break; executed 288827 times by 50 tests: break;Executed by:
executed 288827 times by 50 tests: case lm_none:Executed by:
| 288827 | ||||||||||||||||||
| 6155 | case lm_hh: i = va_arg(ap, int); break; never executed: break;never executed: case lm_hh: | 0 | ||||||||||||||||||
| 6156 | case lm_h: i = va_arg(ap, int); break; never executed: break;never executed: case lm_h: | 0 | ||||||||||||||||||
| 6157 | 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 | ||||||||||||||||||
| 6158 | 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 | ||||||||||||||||||
| 6159 | case lm_j: i = va_arg(ap, long int); break; never executed: break;never executed: case lm_j: | 0 | ||||||||||||||||||
| 6160 | case lm_z: i = va_arg(ap, size_t); break; never executed: break;never executed: case lm_z: | 0 | ||||||||||||||||||
| 6161 | case lm_t: i = va_arg(ap, int); break; never executed: break;never executed: case lm_t: | 0 | ||||||||||||||||||
| 6162 | default: i = 0; break; never executed: break;never executed: default: | 0 | ||||||||||||||||||
| 6163 | } | - | ||||||||||||||||||
| 6164 | subst = QLocaleData::c()->longLongToString(i, precision, 10, width, flags); | - | ||||||||||||||||||
| 6165 | ++c; | - | ||||||||||||||||||
| 6166 | break; executed 288830 times by 50 tests: break;Executed by:
| 288830 | ||||||||||||||||||
| 6167 | } | - | ||||||||||||||||||
| 6168 | case 'o': never executed: case 'o': | 0 | ||||||||||||||||||
| 6169 | case 'u': executed 6 times by 2 tests: case 'u':Executed by:
| 6 | ||||||||||||||||||
| 6170 | case 'x': executed 6044 times by 5 tests: case 'x':Executed by:
| 6044 | ||||||||||||||||||
| 6171 | case 'X': { never executed: case 'X': | 0 | ||||||||||||||||||
| 6172 | quint64 u; | - | ||||||||||||||||||
| 6173 | switch (length_mod) { | - | ||||||||||||||||||
| 6174 | 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 | ||||||||||||||||||
| 6175 | case lm_hh: u = va_arg(ap, uint); break; never executed: break;never executed: case lm_hh: | 0 | ||||||||||||||||||
| 6176 | case lm_h: u = va_arg(ap, uint); break; never executed: break;never executed: case lm_h: | 0 | ||||||||||||||||||
| 6177 | case lm_l: u = va_arg(ap, ulong); break; never executed: break;never executed: case lm_l: | 0 | ||||||||||||||||||
| 6178 | 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 | ||||||||||||||||||
| 6179 | 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 | ||||||||||||||||||
| 6180 | default: u = 0; break; never executed: break;never executed: default: | 0 | ||||||||||||||||||
| 6181 | } | - | ||||||||||||||||||
| 6182 | - | |||||||||||||||||||
| 6183 | if (qIsUpper(*c))
| 0-6050 | ||||||||||||||||||
| 6184 | flags |= QLocaleData::CapitalEorX; never executed: flags |= QLocaleData::CapitalEorX; | 0 | ||||||||||||||||||
| 6185 | - | |||||||||||||||||||
| 6186 | int base = 10; | - | ||||||||||||||||||
| 6187 | switch (qToLower(*c)) { | - | ||||||||||||||||||
| 6188 | case 'o': never executed: case 'o': | 0 | ||||||||||||||||||
| 6189 | base = 8; break; never executed: break; | 0 | ||||||||||||||||||
| 6190 | case 'u': executed 6 times by 2 tests: case 'u':Executed by:
| 6 | ||||||||||||||||||
| 6191 | base = 10; break; executed 6 times by 2 tests: break;Executed by:
| 6 | ||||||||||||||||||
| 6192 | case 'x': executed 6044 times by 5 tests: case 'x':Executed by:
| 6044 | ||||||||||||||||||
| 6193 | base = 16; break; executed 6044 times by 5 tests: break;Executed by:
| 6044 | ||||||||||||||||||
| 6194 | default: break; never executed: break;never executed: default: | 0 | ||||||||||||||||||
| 6195 | } | - | ||||||||||||||||||
| 6196 | subst = QLocaleData::c()->unsLongLongToString(u, precision, base, width, flags); | - | ||||||||||||||||||
| 6197 | ++c; | - | ||||||||||||||||||
| 6198 | break; executed 6050 times by 7 tests: break;Executed by:
| 6050 | ||||||||||||||||||
| 6199 | } | - | ||||||||||||||||||
| 6200 | case 'E': never executed: case 'E': | 0 | ||||||||||||||||||
| 6201 | case 'e': never executed: case 'e': | 0 | ||||||||||||||||||
| 6202 | case 'F': never executed: case 'F': | 0 | ||||||||||||||||||
| 6203 | case 'f': executed 55 times by 8 tests: case 'f':Executed by:
| 55 | ||||||||||||||||||
| 6204 | case 'G': executed 4992 times by 1 test: case 'G':Executed by:
| 4992 | ||||||||||||||||||
| 6205 | case 'g': executed 5001 times by 3 tests: case 'g':Executed by:
| 5001 | ||||||||||||||||||
| 6206 | case 'A': never executed: case 'A': | 0 | ||||||||||||||||||
| 6207 | case 'a': { never executed: case 'a': | 0 | ||||||||||||||||||
| 6208 | double d; | - | ||||||||||||||||||
| 6209 | if (length_mod == lm_L)
| 0-10048 | ||||||||||||||||||
| 6210 | d = va_arg(ap, long double); // not supported - converted to a double never executed: d = __builtin_va_arg(ap,long double); | 0 | ||||||||||||||||||
| 6211 | else | - | ||||||||||||||||||
| 6212 | d = va_arg(ap, double); executed 10048 times by 10 tests: d = __builtin_va_arg(ap,double);Executed by:
| 10048 | ||||||||||||||||||
| 6213 | - | |||||||||||||||||||
| 6214 | if (qIsUpper(*c))
| 4992-5056 | ||||||||||||||||||
| 6215 | flags |= QLocaleData::CapitalEorX; executed 4992 times by 1 test: flags |= QLocaleData::CapitalEorX;Executed by:
| 4992 | ||||||||||||||||||
| 6216 | - | |||||||||||||||||||
| 6217 | QLocaleData::DoubleForm form = QLocaleData::DFDecimal; | - | ||||||||||||||||||
| 6218 | switch (qToLower(*c)) { | - | ||||||||||||||||||
| 6219 | case 'e': form = QLocaleData::DFExponent; break; never executed: break;never executed: case 'e': | 0 | ||||||||||||||||||
| 6220 | case 'a': // not supported - decimal form used instead never executed: case 'a': | 0 | ||||||||||||||||||
| 6221 | 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 | ||||||||||||||||||
| 6222 | 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 | ||||||||||||||||||
| 6223 | default: break; never executed: break;never executed: default: | 0 | ||||||||||||||||||
| 6224 | } | - | ||||||||||||||||||
| 6225 | subst = QLocaleData::c()->doubleToString(d, precision, form, width, flags); | - | ||||||||||||||||||
| 6226 | ++c; | - | ||||||||||||||||||
| 6227 | break; executed 10048 times by 10 tests: break;Executed by:
| 10048 | ||||||||||||||||||
| 6228 | } | - | ||||||||||||||||||
| 6229 | case 'c': { executed 218 times by 3 tests: case 'c':Executed by:
| 218 | ||||||||||||||||||
| 6230 | if (length_mod == lm_l)
| 0-218 | ||||||||||||||||||
| 6231 | subst = QChar((ushort) va_arg(ap, int)); never executed: subst = QChar((ushort) __builtin_va_arg(ap,int)); | 0 | ||||||||||||||||||
| 6232 | else | - | ||||||||||||||||||
| 6233 | subst = QLatin1Char((uchar) va_arg(ap, int)); executed 218 times by 3 tests: subst = QLatin1Char((uchar) __builtin_va_arg(ap,int));Executed by:
| 218 | ||||||||||||||||||
| 6234 | ++c; | - | ||||||||||||||||||
| 6235 | break; executed 218 times by 3 tests: break;Executed by:
| 218 | ||||||||||||||||||
| 6236 | } | - | ||||||||||||||||||
| 6237 | case 's': { executed 87840 times by 49 tests: case 's':Executed by:
| 87840 | ||||||||||||||||||
| 6238 | if (length_mod == lm_l) {
| 38-87802 | ||||||||||||||||||
| 6239 | const ushort *buff = va_arg(ap, const ushort*); | - | ||||||||||||||||||
| 6240 | const ushort *ch = buff; | - | ||||||||||||||||||
| 6241 | while (*ch != 0)
| 38-906 | ||||||||||||||||||
| 6242 | ++ch; executed 906 times by 5 tests: ++ch;Executed by:
| 906 | ||||||||||||||||||
| 6243 | subst.setUtf16(buff, ch - buff); | - | ||||||||||||||||||
| 6244 | } else executed 38 times by 6 tests: end of blockExecuted by:
| 38 | ||||||||||||||||||
| 6245 | subst = QString::fromUtf8(va_arg(ap, const char*)); executed 87802 times by 49 tests: subst = QString::fromUtf8(__builtin_va_arg(ap,const char*));Executed by:
| 87802 | ||||||||||||||||||
| 6246 | if (precision != -1)
| 14-87826 | ||||||||||||||||||
| 6247 | subst.truncate(precision); executed 14 times by 1 test: subst.truncate(precision);Executed by:
| 14 | ||||||||||||||||||
| 6248 | ++c; | - | ||||||||||||||||||
| 6249 | break; executed 87840 times by 49 tests: break;Executed by:
| 87840 | ||||||||||||||||||
| 6250 | } | - | ||||||||||||||||||
| 6251 | case 'p': { executed 1948 times by 33 tests: case 'p':Executed by:
| 1948 | ||||||||||||||||||
| 6252 | void *arg = va_arg(ap, void*); | - | ||||||||||||||||||
| 6253 | const quint64 i = reinterpret_cast<quintptr>(arg); | - | ||||||||||||||||||
| 6254 | flags |= QLocaleData::Alternate; | - | ||||||||||||||||||
| 6255 | subst = QLocaleData::c()->unsLongLongToString(i, precision, 16, width, flags); | - | ||||||||||||||||||
| 6256 | ++c; | - | ||||||||||||||||||
| 6257 | break; executed 1948 times by 33 tests: break;Executed by:
| 1948 | ||||||||||||||||||
| 6258 | } | - | ||||||||||||||||||
| 6259 | case 'n': executed 3 times by 1 test: case 'n':Executed by:
| 3 | ||||||||||||||||||
| 6260 | switch (length_mod) { | - | ||||||||||||||||||
| 6261 | case lm_hh: { never executed: case lm_hh: | 0 | ||||||||||||||||||
| 6262 | signed char *n = va_arg(ap, signed char*); | - | ||||||||||||||||||
| 6263 | *n = result.length(); | - | ||||||||||||||||||
| 6264 | break; never executed: break; | 0 | ||||||||||||||||||
| 6265 | } | - | ||||||||||||||||||
| 6266 | case lm_h: { never executed: case lm_h: | 0 | ||||||||||||||||||
| 6267 | short int *n = va_arg(ap, short int*); | - | ||||||||||||||||||
| 6268 | *n = result.length(); | - | ||||||||||||||||||
| 6269 | break; never executed: break; | 0 | ||||||||||||||||||
| 6270 | } | - | ||||||||||||||||||
| 6271 | case lm_l: { never executed: case lm_l: | 0 | ||||||||||||||||||
| 6272 | long int *n = va_arg(ap, long int*); | - | ||||||||||||||||||
| 6273 | *n = result.length(); | - | ||||||||||||||||||
| 6274 | break; never executed: break; | 0 | ||||||||||||||||||
| 6275 | } | - | ||||||||||||||||||
| 6276 | case lm_ll: { executed 1 time by 1 test: case lm_ll:Executed by:
| 1 | ||||||||||||||||||
| 6277 | qint64 *n = va_arg(ap, qint64*); | - | ||||||||||||||||||
| 6278 | *n = result.length(); | - | ||||||||||||||||||
| 6279 | break; executed 1 time by 1 test: break;Executed by:
| 1 | ||||||||||||||||||
| 6280 | } | - | ||||||||||||||||||
| 6281 | default: { executed 2 times by 1 test: default:Executed by:
| 2 | ||||||||||||||||||
| 6282 | int *n = va_arg(ap, int*); | - | ||||||||||||||||||
| 6283 | *n = result.length(); | - | ||||||||||||||||||
| 6284 | break; executed 2 times by 1 test: break;Executed by:
| 2 | ||||||||||||||||||
| 6285 | } | - | ||||||||||||||||||
| 6286 | } | - | ||||||||||||||||||
| 6287 | ++c; | - | ||||||||||||||||||
| 6288 | break; executed 3 times by 1 test: break;Executed by:
| 3 | ||||||||||||||||||
| 6289 | - | |||||||||||||||||||
| 6290 | default: // bad escape, treat as non-escape text never executed: default: | 0 | ||||||||||||||||||
| 6291 | for (const char *cc = escape_start; cc != c; ++cc)
| 0 | ||||||||||||||||||
| 6292 | result.append(QLatin1Char(*cc)); never executed: result.append(QLatin1Char(*cc)); | 0 | ||||||||||||||||||
| 6293 | continue; never executed: continue; | 0 | ||||||||||||||||||
| 6294 | } | - | ||||||||||||||||||
| 6295 | - | |||||||||||||||||||
| 6296 | if (flags & QLocaleData::LeftAdjusted)
| 5000-389937 | ||||||||||||||||||
| 6297 | result.append(subst.leftJustified(width)); executed 5000 times by 1 test: result.append(subst.leftJustified(width));Executed by:
| 5000 | ||||||||||||||||||
| 6298 | else | - | ||||||||||||||||||
| 6299 | result.append(subst.rightJustified(width)); executed 389937 times by 110 tests: result.append(subst.rightJustified(width));Executed by:
| 389937 | ||||||||||||||||||
| 6300 | } | - | ||||||||||||||||||
| 6301 | - | |||||||||||||||||||
| 6302 | return result; executed 288236 times by 161 tests: return result;Executed by:
| 288236 | ||||||||||||||||||
| 6303 | } | - | ||||||||||||||||||
| 6304 | - | |||||||||||||||||||
| 6305 | /*! | - | ||||||||||||||||||
| 6306 | Returns the string converted to a \c{long long} using base \a | - | ||||||||||||||||||
| 6307 | base, which is 10 by default and must be between 2 and 36, or 0. | - | ||||||||||||||||||
| 6308 | Returns 0 if the conversion fails. | - | ||||||||||||||||||
| 6309 | - | |||||||||||||||||||
| 6310 | If a conversion error occurs, *\a{ok} is set to \c false; otherwise | - | ||||||||||||||||||
| 6311 | *\a{ok} is set to \c true. | - | ||||||||||||||||||
| 6312 | - | |||||||||||||||||||
| 6313 | If \a base is 0, the C language convention is used: If the string | - | ||||||||||||||||||
| 6314 | begins with "0x", base 16 is used; if the string begins with "0", | - | ||||||||||||||||||
| 6315 | base 8 is used; otherwise, base 10 is used. | - | ||||||||||||||||||
| 6316 | - | |||||||||||||||||||
| 6317 | The string conversion will always happen in the 'C' locale. For locale | - | ||||||||||||||||||
| 6318 | dependent conversion use QLocale::toLongLong() | - | ||||||||||||||||||
| 6319 | - | |||||||||||||||||||
| 6320 | Example: | - | ||||||||||||||||||
| 6321 | - | |||||||||||||||||||
| 6322 | \snippet qstring/main.cpp 74 | - | ||||||||||||||||||
| 6323 | - | |||||||||||||||||||
| 6324 | \sa number(), toULongLong(), toInt(), QLocale::toLongLong() | - | ||||||||||||||||||
| 6325 | */ | - | ||||||||||||||||||
| 6326 | - | |||||||||||||||||||
| 6327 | qint64 QString::toLongLong(bool *ok, int base) const | - | ||||||||||||||||||
| 6328 | { | - | ||||||||||||||||||
| 6329 | return toIntegral_helper<qlonglong>(constData(), size(), ok, base); executed 59908 times by 41 tests: return toIntegral_helper<qlonglong>(constData(), size(), ok, base);Executed by:
| 59908 | ||||||||||||||||||
| 6330 | } | - | ||||||||||||||||||
| 6331 | - | |||||||||||||||||||
| 6332 | qlonglong QString::toIntegral_helper(const QChar *data, int len, bool *ok, int base) | - | ||||||||||||||||||
| 6333 | { | - | ||||||||||||||||||
| 6334 | #if defined(QT_CHECK_RANGE) | - | ||||||||||||||||||
| 6335 | if (base != 0 && (base < 2 || base > 36)) { | - | ||||||||||||||||||
| 6336 | qWarning("QString::toULongLong: Invalid base (%d)", base); | - | ||||||||||||||||||
| 6337 | base = 10; | - | ||||||||||||||||||
| 6338 | } | - | ||||||||||||||||||
| 6339 | #endif | - | ||||||||||||||||||
| 6340 | - | |||||||||||||||||||
| 6341 | return QLocaleData::c()->stringToLongLong(data, len, base, ok, QLocale::RejectGroupSeparator); executed 156190 times by 67 tests: return QLocaleData::c()->stringToLongLong(data, len, base, ok, QLocale::RejectGroupSeparator);Executed by:
| 156190 | ||||||||||||||||||
| 6342 | } | - | ||||||||||||||||||
| 6343 | - | |||||||||||||||||||
| 6344 | - | |||||||||||||||||||
| 6345 | /*! | - | ||||||||||||||||||
| 6346 | Returns the string converted to an \c{unsigned long long} using base \a | - | ||||||||||||||||||
| 6347 | base, which is 10 by default and must be between 2 and 36, or 0. | - | ||||||||||||||||||
| 6348 | Returns 0 if the conversion fails. | - | ||||||||||||||||||
| 6349 | - | |||||||||||||||||||
| 6350 | If a conversion error occurs, *\a{ok} is set to \c false; otherwise | - | ||||||||||||||||||
| 6351 | *\a{ok} is set to \c true. | - | ||||||||||||||||||
| 6352 | - | |||||||||||||||||||
| 6353 | If \a base is 0, the C language convention is used: If the string | - | ||||||||||||||||||
| 6354 | begins with "0x", base 16 is used; if the string begins with "0", | - | ||||||||||||||||||
| 6355 | base 8 is used; otherwise, base 10 is used. | - | ||||||||||||||||||
| 6356 | - | |||||||||||||||||||
| 6357 | The string conversion will always happen in the 'C' locale. For locale | - | ||||||||||||||||||
| 6358 | dependent conversion use QLocale::toULongLong() | - | ||||||||||||||||||
| 6359 | - | |||||||||||||||||||
| 6360 | Example: | - | ||||||||||||||||||
| 6361 | - | |||||||||||||||||||
| 6362 | \snippet qstring/main.cpp 79 | - | ||||||||||||||||||
| 6363 | - | |||||||||||||||||||
| 6364 | \sa number(), toLongLong(), QLocale::toULongLong() | - | ||||||||||||||||||
| 6365 | */ | - | ||||||||||||||||||
| 6366 | - | |||||||||||||||||||
| 6367 | quint64 QString::toULongLong(bool *ok, int base) const | - | ||||||||||||||||||
| 6368 | { | - | ||||||||||||||||||
| 6369 | 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 | ||||||||||||||||||
| 6370 | } | - | ||||||||||||||||||
| 6371 | - | |||||||||||||||||||
| 6372 | qulonglong QString::toIntegral_helper(const QChar *data, uint len, bool *ok, int base) | - | ||||||||||||||||||
| 6373 | { | - | ||||||||||||||||||
| 6374 | #if defined(QT_CHECK_RANGE) | - | ||||||||||||||||||
| 6375 | if (base != 0 && (base < 2 || base > 36)) { | - | ||||||||||||||||||
| 6376 | qWarning("QString::toULongLong: Invalid base (%d)", base); | - | ||||||||||||||||||
| 6377 | base = 10; | - | ||||||||||||||||||
| 6378 | } | - | ||||||||||||||||||
| 6379 | #endif | - | ||||||||||||||||||
| 6380 | - | |||||||||||||||||||
| 6381 | return QLocaleData::c()->stringToUnsLongLong(data, len, base, ok, executed 3900 times by 20 tests: return QLocaleData::c()->stringToUnsLongLong(data, len, base, ok, QLocale::RejectGroupSeparator);Executed by:
| 3900 | ||||||||||||||||||
| 6382 | QLocale::RejectGroupSeparator); executed 3900 times by 20 tests: return QLocaleData::c()->stringToUnsLongLong(data, len, base, ok, QLocale::RejectGroupSeparator);Executed by:
| 3900 | ||||||||||||||||||
| 6383 | } | - | ||||||||||||||||||
| 6384 | - | |||||||||||||||||||
| 6385 | /*! | - | ||||||||||||||||||
| 6386 | \fn long QString::toLong(bool *ok, int base) const | - | ||||||||||||||||||
| 6387 | - | |||||||||||||||||||
| 6388 | Returns the string converted to a \c long using base \a | - | ||||||||||||||||||
| 6389 | base, which is 10 by default and must be between 2 and 36, or 0. | - | ||||||||||||||||||
| 6390 | Returns 0 if the conversion fails. | - | ||||||||||||||||||
| 6391 | - | |||||||||||||||||||
| 6392 | If a conversion error occurs, *\a{ok} is set to \c false; otherwise | - | ||||||||||||||||||
| 6393 | *\a{ok} is set to \c true. | - | ||||||||||||||||||
| 6394 | - | |||||||||||||||||||
| 6395 | If \a base is 0, the C language convention is used: If the string | - | ||||||||||||||||||
| 6396 | begins with "0x", base 16 is used; if the string begins with "0", | - | ||||||||||||||||||
| 6397 | base 8 is used; otherwise, base 10 is used. | - | ||||||||||||||||||
| 6398 | - | |||||||||||||||||||
| 6399 | The string conversion will always happen in the 'C' locale. For locale | - | ||||||||||||||||||
| 6400 | dependent conversion use QLocale::toLongLong() | - | ||||||||||||||||||
| 6401 | - | |||||||||||||||||||
| 6402 | Example: | - | ||||||||||||||||||
| 6403 | - | |||||||||||||||||||
| 6404 | \snippet qstring/main.cpp 73 | - | ||||||||||||||||||
| 6405 | - | |||||||||||||||||||
| 6406 | \sa number(), toULong(), toInt(), QLocale::toInt() | - | ||||||||||||||||||
| 6407 | */ | - | ||||||||||||||||||
| 6408 | - | |||||||||||||||||||
| 6409 | long QString::toLong(bool *ok, int base) const | - | ||||||||||||||||||
| 6410 | { | - | ||||||||||||||||||
| 6411 | 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 | ||||||||||||||||||
| 6412 | } | - | ||||||||||||||||||
| 6413 | - | |||||||||||||||||||
| 6414 | /*! | - | ||||||||||||||||||
| 6415 | \fn ulong QString::toULong(bool *ok, int base) const | - | ||||||||||||||||||
| 6416 | - | |||||||||||||||||||
| 6417 | Returns the string converted to an \c{unsigned long} using base \a | - | ||||||||||||||||||
| 6418 | base, which is 10 by default and must be between 2 and 36, or 0. | - | ||||||||||||||||||
| 6419 | Returns 0 if the conversion fails. | - | ||||||||||||||||||
| 6420 | - | |||||||||||||||||||
| 6421 | If a conversion error occurs, *\a{ok} is set to \c false; otherwise | - | ||||||||||||||||||
| 6422 | *\a{ok} is set to \c true. | - | ||||||||||||||||||
| 6423 | - | |||||||||||||||||||
| 6424 | If \a base is 0, the C language convention is used: If the string | - | ||||||||||||||||||
| 6425 | begins with "0x", base 16 is used; if the string begins with "0", | - | ||||||||||||||||||
| 6426 | base 8 is used; otherwise, base 10 is used. | - | ||||||||||||||||||
| 6427 | - | |||||||||||||||||||
| 6428 | The string conversion will always happen in the 'C' locale. For locale | - | ||||||||||||||||||
| 6429 | dependent conversion use QLocale::toULongLong() | - | ||||||||||||||||||
| 6430 | - | |||||||||||||||||||
| 6431 | Example: | - | ||||||||||||||||||
| 6432 | - | |||||||||||||||||||
| 6433 | \snippet qstring/main.cpp 78 | - | ||||||||||||||||||
| 6434 | - | |||||||||||||||||||
| 6435 | \sa number(), QLocale::toUInt() | - | ||||||||||||||||||
| 6436 | */ | - | ||||||||||||||||||
| 6437 | - | |||||||||||||||||||
| 6438 | ulong QString::toULong(bool *ok, int base) const | - | ||||||||||||||||||
| 6439 | { | - | ||||||||||||||||||
| 6440 | 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 | ||||||||||||||||||
| 6441 | } | - | ||||||||||||||||||
| 6442 | - | |||||||||||||||||||
| 6443 | - | |||||||||||||||||||
| 6444 | /*! | - | ||||||||||||||||||
| 6445 | Returns the string converted to an \c int using base \a | - | ||||||||||||||||||
| 6446 | base, which is 10 by default and must be between 2 and 36, or 0. | - | ||||||||||||||||||
| 6447 | Returns 0 if the conversion fails. | - | ||||||||||||||||||
| 6448 | - | |||||||||||||||||||
| 6449 | If a conversion error occurs, *\a{ok} is set to \c false; otherwise | - | ||||||||||||||||||
| 6450 | *\a{ok} is set to \c true. | - | ||||||||||||||||||
| 6451 | - | |||||||||||||||||||
| 6452 | If \a base is 0, the C language convention is used: If the string | - | ||||||||||||||||||
| 6453 | begins with "0x", base 16 is used; if the string begins with "0", | - | ||||||||||||||||||
| 6454 | base 8 is used; otherwise, base 10 is used. | - | ||||||||||||||||||
| 6455 | - | |||||||||||||||||||
| 6456 | The string conversion will always happen in the 'C' locale. For locale | - | ||||||||||||||||||
| 6457 | dependent conversion use QLocale::toInt() | - | ||||||||||||||||||
| 6458 | - | |||||||||||||||||||
| 6459 | Example: | - | ||||||||||||||||||
| 6460 | - | |||||||||||||||||||
| 6461 | \snippet qstring/main.cpp 72 | - | ||||||||||||||||||
| 6462 | - | |||||||||||||||||||
| 6463 | \sa number(), toUInt(), toDouble(), QLocale::toInt() | - | ||||||||||||||||||
| 6464 | */ | - | ||||||||||||||||||
| 6465 | - | |||||||||||||||||||
| 6466 | int QString::toInt(bool *ok, int base) const | - | ||||||||||||||||||
| 6467 | { | - | ||||||||||||||||||
| 6468 | return toIntegral_helper<int>(constData(), size(), ok, base); executed 34526 times by 23 tests: return toIntegral_helper<int>(constData(), size(), ok, base);Executed by:
| 34526 | ||||||||||||||||||
| 6469 | } | - | ||||||||||||||||||
| 6470 | - | |||||||||||||||||||
| 6471 | /*! | - | ||||||||||||||||||
| 6472 | Returns the string converted to an \c{unsigned int} using base \a | - | ||||||||||||||||||
| 6473 | base, which is 10 by default and must be between 2 and 36, or 0. | - | ||||||||||||||||||
| 6474 | Returns 0 if the conversion fails. | - | ||||||||||||||||||
| 6475 | - | |||||||||||||||||||
| 6476 | If a conversion error occurs, *\a{ok} is set to \c false; otherwise | - | ||||||||||||||||||
| 6477 | *\a{ok} is set to \c true. | - | ||||||||||||||||||
| 6478 | - | |||||||||||||||||||
| 6479 | If \a base is 0, the C language convention is used: If the string | - | ||||||||||||||||||
| 6480 | begins with "0x", base 16 is used; if the string begins with "0", | - | ||||||||||||||||||
| 6481 | base 8 is used; otherwise, base 10 is used. | - | ||||||||||||||||||
| 6482 | - | |||||||||||||||||||
| 6483 | The string conversion will always happen in the 'C' locale. For locale | - | ||||||||||||||||||
| 6484 | dependent conversion use QLocale::toUInt() | - | ||||||||||||||||||
| 6485 | - | |||||||||||||||||||
| 6486 | Example: | - | ||||||||||||||||||
| 6487 | - | |||||||||||||||||||
| 6488 | \snippet qstring/main.cpp 77 | - | ||||||||||||||||||
| 6489 | - | |||||||||||||||||||
| 6490 | \sa number(), toInt(), QLocale::toUInt() | - | ||||||||||||||||||
| 6491 | */ | - | ||||||||||||||||||
| 6492 | - | |||||||||||||||||||
| 6493 | uint QString::toUInt(bool *ok, int base) const | - | ||||||||||||||||||
| 6494 | { | - | ||||||||||||||||||
| 6495 | return toIntegral_helper<uint>(constData(), size(), ok, base); executed 1853 times by 10 tests: return toIntegral_helper<uint>(constData(), size(), ok, base);Executed by:
| 1853 | ||||||||||||||||||
| 6496 | } | - | ||||||||||||||||||
| 6497 | - | |||||||||||||||||||
| 6498 | /*! | - | ||||||||||||||||||
| 6499 | Returns the string converted to a \c short using base \a | - | ||||||||||||||||||
| 6500 | base, which is 10 by default and must be between 2 and 36, or 0. | - | ||||||||||||||||||
| 6501 | Returns 0 if the conversion fails. | - | ||||||||||||||||||
| 6502 | - | |||||||||||||||||||
| 6503 | If a conversion error occurs, *\a{ok} is set to \c false; otherwise | - | ||||||||||||||||||
| 6504 | *\a{ok} is set to \c true. | - | ||||||||||||||||||
| 6505 | - | |||||||||||||||||||
| 6506 | If \a base is 0, the C language convention is used: If the string | - | ||||||||||||||||||
| 6507 | begins with "0x", base 16 is used; if the string begins with "0", | - | ||||||||||||||||||
| 6508 | base 8 is used; otherwise, base 10 is used. | - | ||||||||||||||||||
| 6509 | - | |||||||||||||||||||
| 6510 | The string conversion will always happen in the 'C' locale. For locale | - | ||||||||||||||||||
| 6511 | dependent conversion use QLocale::toShort() | - | ||||||||||||||||||
| 6512 | - | |||||||||||||||||||
| 6513 | Example: | - | ||||||||||||||||||
| 6514 | - | |||||||||||||||||||
| 6515 | \snippet qstring/main.cpp 76 | - | ||||||||||||||||||
| 6516 | - | |||||||||||||||||||
| 6517 | \sa number(), toUShort(), toInt(), QLocale::toShort() | - | ||||||||||||||||||
| 6518 | */ | - | ||||||||||||||||||
| 6519 | - | |||||||||||||||||||
| 6520 | short QString::toShort(bool *ok, int base) const | - | ||||||||||||||||||
| 6521 | { | - | ||||||||||||||||||
| 6522 | 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 | ||||||||||||||||||
| 6523 | } | - | ||||||||||||||||||
| 6524 | - | |||||||||||||||||||
| 6525 | /*! | - | ||||||||||||||||||
| 6526 | Returns the string converted to an \c{unsigned short} using base \a | - | ||||||||||||||||||
| 6527 | base, which is 10 by default and must be between 2 and 36, or 0. | - | ||||||||||||||||||
| 6528 | Returns 0 if the conversion fails. | - | ||||||||||||||||||
| 6529 | - | |||||||||||||||||||
| 6530 | If a conversion error occurs, *\a{ok} is set to \c false; otherwise | - | ||||||||||||||||||
| 6531 | *\a{ok} is set to \c true. | - | ||||||||||||||||||
| 6532 | - | |||||||||||||||||||
| 6533 | If \a base is 0, the C language convention is used: If the string | - | ||||||||||||||||||
| 6534 | begins with "0x", base 16 is used; if the string begins with "0", | - | ||||||||||||||||||
| 6535 | base 8 is used; otherwise, base 10 is used. | - | ||||||||||||||||||
| 6536 | - | |||||||||||||||||||
| 6537 | The string conversion will always happen in the 'C' locale. For locale | - | ||||||||||||||||||
| 6538 | dependent conversion use QLocale::toUShort() | - | ||||||||||||||||||
| 6539 | - | |||||||||||||||||||
| 6540 | Example: | - | ||||||||||||||||||
| 6541 | - | |||||||||||||||||||
| 6542 | \snippet qstring/main.cpp 80 | - | ||||||||||||||||||
| 6543 | - | |||||||||||||||||||
| 6544 | \sa number(), toShort(), QLocale::toUShort() | - | ||||||||||||||||||
| 6545 | */ | - | ||||||||||||||||||
| 6546 | - | |||||||||||||||||||
| 6547 | ushort QString::toUShort(bool *ok, int base) const | - | ||||||||||||||||||
| 6548 | { | - | ||||||||||||||||||
| 6549 | 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 | ||||||||||||||||||
| 6550 | } | - | ||||||||||||||||||
| 6551 | - | |||||||||||||||||||
| 6552 | - | |||||||||||||||||||
| 6553 | /*! | - | ||||||||||||||||||
| 6554 | Returns the string converted to a \c double value. | - | ||||||||||||||||||
| 6555 | - | |||||||||||||||||||
| 6556 | Returns 0.0 if the conversion fails. | - | ||||||||||||||||||
| 6557 | - | |||||||||||||||||||
| 6558 | If a conversion error occurs, \c{*}\a{ok} is set to \c false; | - | ||||||||||||||||||
| 6559 | otherwise \c{*}\a{ok} is set to \c true. | - | ||||||||||||||||||
| 6560 | - | |||||||||||||||||||
| 6561 | \snippet qstring/main.cpp 66 | - | ||||||||||||||||||
| 6562 | - | |||||||||||||||||||
| 6563 | \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. | - | ||||||||||||||||||
| 6564 | - | |||||||||||||||||||
| 6565 | \snippet qstring/main.cpp 67 | - | ||||||||||||||||||
| 6566 | - | |||||||||||||||||||
| 6567 | The string conversion will always happen in the 'C' locale. For locale | - | ||||||||||||||||||
| 6568 | dependent conversion use QLocale::toDouble() | - | ||||||||||||||||||
| 6569 | - | |||||||||||||||||||
| 6570 | \snippet qstring/main.cpp 68 | - | ||||||||||||||||||
| 6571 | - | |||||||||||||||||||
| 6572 | For historical reasons, this function does not handle | - | ||||||||||||||||||
| 6573 | thousands group separators. If you need to convert such numbers, | - | ||||||||||||||||||
| 6574 | use QLocale::toDouble(). | - | ||||||||||||||||||
| 6575 | - | |||||||||||||||||||
| 6576 | \snippet qstring/main.cpp 69 | - | ||||||||||||||||||
| 6577 | - | |||||||||||||||||||
| 6578 | \sa number(), QLocale::setDefault(), QLocale::toDouble(), trimmed() | - | ||||||||||||||||||
| 6579 | */ | - | ||||||||||||||||||
| 6580 | - | |||||||||||||||||||
| 6581 | double QString::toDouble(bool *ok) const | - | ||||||||||||||||||
| 6582 | { | - | ||||||||||||||||||
| 6583 | return QLocaleData::c()->stringToDouble(constData(), size(), ok, QLocale::RejectGroupSeparator); executed 2767 times by 24 tests: return QLocaleData::c()->stringToDouble(constData(), size(), ok, QLocale::RejectGroupSeparator);Executed by:
| 2767 | ||||||||||||||||||
| 6584 | } | - | ||||||||||||||||||
| 6585 | - | |||||||||||||||||||
| 6586 | /*! | - | ||||||||||||||||||
| 6587 | Returns the string converted to a \c float value. | - | ||||||||||||||||||
| 6588 | - | |||||||||||||||||||
| 6589 | If a conversion error occurs, *\a{ok} is set to \c false; otherwise | - | ||||||||||||||||||
| 6590 | *\a{ok} is set to \c true. Returns 0.0 if the conversion fails. | - | ||||||||||||||||||
| 6591 | - | |||||||||||||||||||
| 6592 | The string conversion will always happen in the 'C' locale. For locale | - | ||||||||||||||||||
| 6593 | dependent conversion use QLocale::toFloat() | - | ||||||||||||||||||
| 6594 | - | |||||||||||||||||||
| 6595 | Example: | - | ||||||||||||||||||
| 6596 | - | |||||||||||||||||||
| 6597 | \snippet qstring/main.cpp 71 | - | ||||||||||||||||||
| 6598 | - | |||||||||||||||||||
| 6599 | \sa number(), toDouble(), toInt(), QLocale::toFloat() | - | ||||||||||||||||||
| 6600 | */ | - | ||||||||||||||||||
| 6601 | - | |||||||||||||||||||
| 6602 | float QString::toFloat(bool *ok) const | - | ||||||||||||||||||
| 6603 | { | - | ||||||||||||||||||
| 6604 | return QLocaleData::convertDoubleToFloat(toDouble(ok), ok); executed 24 times by 3 tests: return QLocaleData::convertDoubleToFloat(toDouble(ok), ok);Executed by:
| 24 | ||||||||||||||||||
| 6605 | } | - | ||||||||||||||||||
| 6606 | - | |||||||||||||||||||
| 6607 | /*! \fn QString &QString::setNum(int n, int base) | - | ||||||||||||||||||
| 6608 | - | |||||||||||||||||||
| 6609 | Sets the string to the printed value of \a n in the specified \a | - | ||||||||||||||||||
| 6610 | base, and returns a reference to the string. | - | ||||||||||||||||||
| 6611 | - | |||||||||||||||||||
| 6612 | The base is 10 by default and must be between 2 and 36. For bases | - | ||||||||||||||||||
| 6613 | other than 10, \a n is treated as an unsigned integer. | - | ||||||||||||||||||
| 6614 | - | |||||||||||||||||||
| 6615 | \snippet qstring/main.cpp 56 | - | ||||||||||||||||||
| 6616 | - | |||||||||||||||||||
| 6617 | The formatting always uses QLocale::C, i.e., English/UnitedStates. | - | ||||||||||||||||||
| 6618 | To get a localized string representation of a number, use | - | ||||||||||||||||||
| 6619 | QLocale::toString() with the appropriate locale. | - | ||||||||||||||||||
| 6620 | */ | - | ||||||||||||||||||
| 6621 | - | |||||||||||||||||||
| 6622 | /*! \fn QString &QString::setNum(uint n, int base) | - | ||||||||||||||||||
| 6623 | - | |||||||||||||||||||
| 6624 | \overload | - | ||||||||||||||||||
| 6625 | */ | - | ||||||||||||||||||
| 6626 | - | |||||||||||||||||||
| 6627 | /*! \fn QString &QString::setNum(long n, int base) | - | ||||||||||||||||||
| 6628 | - | |||||||||||||||||||
| 6629 | \overload | - | ||||||||||||||||||
| 6630 | */ | - | ||||||||||||||||||
| 6631 | - | |||||||||||||||||||
| 6632 | /*! \fn QString &QString::setNum(ulong n, int base) | - | ||||||||||||||||||
| 6633 | - | |||||||||||||||||||
| 6634 | \overload | - | ||||||||||||||||||
| 6635 | */ | - | ||||||||||||||||||
| 6636 | - | |||||||||||||||||||
| 6637 | /*! | - | ||||||||||||||||||
| 6638 | \overload | - | ||||||||||||||||||
| 6639 | */ | - | ||||||||||||||||||
| 6640 | QString &QString::setNum(qlonglong n, int base) | - | ||||||||||||||||||
| 6641 | { | - | ||||||||||||||||||
| 6642 | return *this = number(n, base); executed 26915 times by 6 tests: return *this = number(n, base);Executed by:
| 26915 | ||||||||||||||||||
| 6643 | } | - | ||||||||||||||||||
| 6644 | - | |||||||||||||||||||
| 6645 | /*! | - | ||||||||||||||||||
| 6646 | \overload | - | ||||||||||||||||||
| 6647 | */ | - | ||||||||||||||||||
| 6648 | QString &QString::setNum(qulonglong n, int base) | - | ||||||||||||||||||
| 6649 | { | - | ||||||||||||||||||
| 6650 | return *this = number(n, base); executed 4 times by 1 test: return *this = number(n, base);Executed by:
| 4 | ||||||||||||||||||
| 6651 | } | - | ||||||||||||||||||
| 6652 | - | |||||||||||||||||||
| 6653 | /*! \fn QString &QString::setNum(short n, int base) | - | ||||||||||||||||||
| 6654 | - | |||||||||||||||||||
| 6655 | \overload | - | ||||||||||||||||||
| 6656 | */ | - | ||||||||||||||||||
| 6657 | - | |||||||||||||||||||
| 6658 | /*! \fn QString &QString::setNum(ushort n, int base) | - | ||||||||||||||||||
| 6659 | - | |||||||||||||||||||
| 6660 | \overload | - | ||||||||||||||||||
| 6661 | */ | - | ||||||||||||||||||
| 6662 | - | |||||||||||||||||||
| 6663 | /*! | - | ||||||||||||||||||
| 6664 | \fn QString &QString::setNum(double n, char format, int precision) | - | ||||||||||||||||||
| 6665 | \overload | - | ||||||||||||||||||
| 6666 | - | |||||||||||||||||||
| 6667 | Sets the string to the printed value of \a n, formatted according | - | ||||||||||||||||||
| 6668 | to the given \a format and \a precision, and returns a reference | - | ||||||||||||||||||
| 6669 | to the string. | - | ||||||||||||||||||
| 6670 | - | |||||||||||||||||||
| 6671 | The \a format can be 'e', 'E', 'f', 'g' or 'G' (see | - | ||||||||||||||||||
| 6672 | \l{Argument Formats} for an explanation of the formats). | - | ||||||||||||||||||
| 6673 | - | |||||||||||||||||||
| 6674 | The formatting always uses QLocale::C, i.e., English/UnitedStates. | - | ||||||||||||||||||
| 6675 | To get a localized string representation of a number, use | - | ||||||||||||||||||
| 6676 | QLocale::toString() with the appropriate locale. | - | ||||||||||||||||||
| 6677 | */ | - | ||||||||||||||||||
| 6678 | - | |||||||||||||||||||
| 6679 | QString &QString::setNum(double n, char f, int prec) | - | ||||||||||||||||||
| 6680 | { | - | ||||||||||||||||||
| 6681 | return *this = number(n, f, prec); executed 4 times by 2 tests: return *this = number(n, f, prec);Executed by:
| 4 | ||||||||||||||||||
| 6682 | } | - | ||||||||||||||||||
| 6683 | - | |||||||||||||||||||
| 6684 | /*! | - | ||||||||||||||||||
| 6685 | \fn QString &QString::setNum(float n, char format, int precision) | - | ||||||||||||||||||
| 6686 | \overload | - | ||||||||||||||||||
| 6687 | - | |||||||||||||||||||
| 6688 | Sets the string to the printed value of \a n, formatted according | - | ||||||||||||||||||
| 6689 | to the given \a format and \a precision, and returns a reference | - | ||||||||||||||||||
| 6690 | to the string. | - | ||||||||||||||||||
| 6691 | - | |||||||||||||||||||
| 6692 | The formatting always uses QLocale::C, i.e., English/UnitedStates. | - | ||||||||||||||||||
| 6693 | To get a localized string representation of a number, use | - | ||||||||||||||||||
| 6694 | QLocale::toString() with the appropriate locale. | - | ||||||||||||||||||
| 6695 | */ | - | ||||||||||||||||||
| 6696 | - | |||||||||||||||||||
| 6697 | - | |||||||||||||||||||
| 6698 | /*! | - | ||||||||||||||||||
| 6699 | \fn QString QString::number(long n, int base) | - | ||||||||||||||||||
| 6700 | - | |||||||||||||||||||
| 6701 | Returns a string equivalent of the number \a n according to the | - | ||||||||||||||||||
| 6702 | specified \a base. | - | ||||||||||||||||||
| 6703 | - | |||||||||||||||||||
| 6704 | The base is 10 by default and must be between 2 | - | ||||||||||||||||||
| 6705 | and 36. For bases other than 10, \a n is treated as an | - | ||||||||||||||||||
| 6706 | unsigned integer. | - | ||||||||||||||||||
| 6707 | - | |||||||||||||||||||
| 6708 | The formatting always uses QLocale::C, i.e., English/UnitedStates. | - | ||||||||||||||||||
| 6709 | To get a localized string representation of a number, use | - | ||||||||||||||||||
| 6710 | QLocale::toString() with the appropriate locale. | - | ||||||||||||||||||
| 6711 | - | |||||||||||||||||||
| 6712 | \snippet qstring/main.cpp 35 | - | ||||||||||||||||||
| 6713 | - | |||||||||||||||||||
| 6714 | \sa setNum() | - | ||||||||||||||||||
| 6715 | */ | - | ||||||||||||||||||
| 6716 | - | |||||||||||||||||||
| 6717 | QString QString::number(long n, int base) | - | ||||||||||||||||||
| 6718 | { | - | ||||||||||||||||||
| 6719 | return number(qlonglong(n), base); executed 18 times by 5 tests: return number(qlonglong(n), base);Executed by:
| 18 | ||||||||||||||||||
| 6720 | } | - | ||||||||||||||||||
| 6721 | - | |||||||||||||||||||
| 6722 | /*! | - | ||||||||||||||||||
| 6723 | \fn QString QString::number(ulong n, int base) | - | ||||||||||||||||||
| 6724 | - | |||||||||||||||||||
| 6725 | \overload | - | ||||||||||||||||||
| 6726 | */ | - | ||||||||||||||||||
| 6727 | QString QString::number(ulong n, int base) | - | ||||||||||||||||||
| 6728 | { | - | ||||||||||||||||||
| 6729 | return number(qulonglong(n), base); executed 32 times by 4 tests: return number(qulonglong(n), base);Executed by:
| 32 | ||||||||||||||||||
| 6730 | } | - | ||||||||||||||||||
| 6731 | - | |||||||||||||||||||
| 6732 | /*! | - | ||||||||||||||||||
| 6733 | \overload | - | ||||||||||||||||||
| 6734 | */ | - | ||||||||||||||||||
| 6735 | QString QString::number(int n, int base) | - | ||||||||||||||||||
| 6736 | { | - | ||||||||||||||||||
| 6737 | return number(qlonglong(n), base); executed 4190033 times by 174 tests: return number(qlonglong(n), base);Executed by:
| 4190033 | ||||||||||||||||||
| 6738 | } | - | ||||||||||||||||||
| 6739 | - | |||||||||||||||||||
| 6740 | /*! | - | ||||||||||||||||||
| 6741 | \overload | - | ||||||||||||||||||
| 6742 | */ | - | ||||||||||||||||||
| 6743 | QString QString::number(uint n, int base) | - | ||||||||||||||||||
| 6744 | { | - | ||||||||||||||||||
| 6745 | return number(qulonglong(n), base); executed 17442 times by 63 tests: return number(qulonglong(n), base);Executed by:
| 17442 | ||||||||||||||||||
| 6746 | } | - | ||||||||||||||||||
| 6747 | - | |||||||||||||||||||
| 6748 | /*! | - | ||||||||||||||||||
| 6749 | \overload | - | ||||||||||||||||||
| 6750 | */ | - | ||||||||||||||||||
| 6751 | QString QString::number(qlonglong n, int base) | - | ||||||||||||||||||
| 6752 | { | - | ||||||||||||||||||
| 6753 | #if defined(QT_CHECK_RANGE) | - | ||||||||||||||||||
| 6754 | if (base < 2 || base > 36) { | - | ||||||||||||||||||
| 6755 | qWarning("QString::setNum: Invalid base (%d)", base); | - | ||||||||||||||||||
| 6756 | base = 10; | - | ||||||||||||||||||
| 6757 | } | - | ||||||||||||||||||
| 6758 | #endif | - | ||||||||||||||||||
| 6759 | return QLocaleData::c()->longLongToString(n, -1, base); executed 4257340 times by 187 tests: return QLocaleData::c()->longLongToString(n, -1, base);Executed by:
| 4257340 | ||||||||||||||||||
| 6760 | } | - | ||||||||||||||||||
| 6761 | - | |||||||||||||||||||
| 6762 | /*! | - | ||||||||||||||||||
| 6763 | \overload | - | ||||||||||||||||||
| 6764 | */ | - | ||||||||||||||||||
| 6765 | QString QString::number(qulonglong n, int base) | - | ||||||||||||||||||
| 6766 | { | - | ||||||||||||||||||
| 6767 | #if defined(QT_CHECK_RANGE) | - | ||||||||||||||||||
| 6768 | if (base < 2 || base > 36) { | - | ||||||||||||||||||
| 6769 | qWarning("QString::setNum: Invalid base (%d)", base); | - | ||||||||||||||||||
| 6770 | base = 10; | - | ||||||||||||||||||
| 6771 | } | - | ||||||||||||||||||
| 6772 | #endif | - | ||||||||||||||||||
| 6773 | return QLocaleData::c()->unsLongLongToString(n, -1, base); executed 19380 times by 78 tests: return QLocaleData::c()->unsLongLongToString(n, -1, base);Executed by:
| 19380 | ||||||||||||||||||
| 6774 | } | - | ||||||||||||||||||
| 6775 | - | |||||||||||||||||||
| 6776 | - | |||||||||||||||||||
| 6777 | /*! | - | ||||||||||||||||||
| 6778 | \fn QString QString::number(double n, char format, int precision) | - | ||||||||||||||||||
| 6779 | - | |||||||||||||||||||
| 6780 | Returns a string equivalent of the number \a n, formatted | - | ||||||||||||||||||
| 6781 | according to the specified \a format and \a precision. See | - | ||||||||||||||||||
| 6782 | \l{Argument Formats} for details. | - | ||||||||||||||||||
| 6783 | - | |||||||||||||||||||
| 6784 | Unlike QLocale::toString(), this function does not honor the | - | ||||||||||||||||||
| 6785 | user's locale settings. | - | ||||||||||||||||||
| 6786 | - | |||||||||||||||||||
| 6787 | \sa setNum(), QLocale::toString() | - | ||||||||||||||||||
| 6788 | */ | - | ||||||||||||||||||
| 6789 | QString QString::number(double n, char f, int prec) | - | ||||||||||||||||||
| 6790 | { | - | ||||||||||||||||||
| 6791 | QLocaleData::DoubleForm form = QLocaleData::DFDecimal; | - | ||||||||||||||||||
| 6792 | uint flags = 0; | - | ||||||||||||||||||
| 6793 | - | |||||||||||||||||||
| 6794 | if (qIsUpper(f))
| 0-2943 | ||||||||||||||||||
| 6795 | flags = QLocaleData::CapitalEorX; never executed: flags = QLocaleData::CapitalEorX; | 0 | ||||||||||||||||||
| 6796 | f = qToLower(f); | - | ||||||||||||||||||
| 6797 | - | |||||||||||||||||||
| 6798 | switch (f) { | - | ||||||||||||||||||
| 6799 | case 'f': executed 983 times by 9 tests: case 'f':Executed by:
| 983 | ||||||||||||||||||
| 6800 | form = QLocaleData::DFDecimal; | - | ||||||||||||||||||
| 6801 | break; executed 983 times by 9 tests: break;Executed by:
| 983 | ||||||||||||||||||
| 6802 | case 'e': executed 12 times by 2 tests: case 'e':Executed by:
| 12 | ||||||||||||||||||
| 6803 | form = QLocaleData::DFExponent; | - | ||||||||||||||||||
| 6804 | break; executed 12 times by 2 tests: break;Executed by:
| 12 | ||||||||||||||||||
| 6805 | case 'g': executed 1948 times by 24 tests: case 'g':Executed by:
| 1948 | ||||||||||||||||||
| 6806 | form = QLocaleData::DFSignificantDigits; | - | ||||||||||||||||||
| 6807 | break; executed 1948 times by 24 tests: break;Executed by:
| 1948 | ||||||||||||||||||
| 6808 | default: never executed: default: | 0 | ||||||||||||||||||
| 6809 | #if defined(QT_CHECK_RANGE) | - | ||||||||||||||||||
| 6810 | qWarning("QString::setNum: Invalid format char '%c'", f); | - | ||||||||||||||||||
| 6811 | #endif | - | ||||||||||||||||||
| 6812 | break; never executed: break; | 0 | ||||||||||||||||||
| 6813 | } | - | ||||||||||||||||||
| 6814 | - | |||||||||||||||||||
| 6815 | return QLocaleData::c()->doubleToString(n, prec, form, -1, flags); executed 2943 times by 30 tests: return QLocaleData::c()->doubleToString(n, prec, form, -1, flags);Executed by:
| 2943 | ||||||||||||||||||
| 6816 | } | - | ||||||||||||||||||
| 6817 | - | |||||||||||||||||||
| 6818 | namespace { | - | ||||||||||||||||||
| 6819 | template<class ResultList, class StringSource> | - | ||||||||||||||||||
| 6820 | static ResultList splitString(const StringSource &source, const QChar *sep, | - | ||||||||||||||||||
| 6821 | QString::SplitBehavior behavior, Qt::CaseSensitivity cs, const int separatorSize) | - | ||||||||||||||||||
| 6822 | { | - | ||||||||||||||||||
| 6823 | ResultList list; | - | ||||||||||||||||||
| 6824 | int start = 0; | - | ||||||||||||||||||
| 6825 | int end; | - | ||||||||||||||||||
| 6826 | int extra = 0; | - | ||||||||||||||||||
| 6827 | while ((end = qFindString(source.constData(), source.size(), start + extra, sep, separatorSize, cs)) != -1) {
| 79663-348424 | ||||||||||||||||||
| 6828 | if (start != end || behavior == QString::KeepEmptyParts)
| 1144-324893 | ||||||||||||||||||
| 6829 | list.append(source.mid(start, end - start)); executed 326037 times by 239 tests: list.append(source.mid(start, end - start));Executed by:
| 326037 | ||||||||||||||||||
| 6830 | start = end + separatorSize; | - | ||||||||||||||||||
| 6831 | extra = (separatorSize == 0 ? 1 : 0);
| 48-348376 | ||||||||||||||||||
| 6832 | } executed 348424 times by 239 tests: end of blockExecuted by:
| 348424 | ||||||||||||||||||
| 6833 | if (start != source.size() || behavior == QString::KeepEmptyParts)
| 580-76216 | ||||||||||||||||||
| 6834 | list.append(source.mid(start, -1)); executed 79083 times by 274 tests: list.append(source.mid(start, -1));Executed by:
| 79083 | ||||||||||||||||||
| 6835 | return list; executed 79663 times by 275 tests: return list;Executed by:
| 79663 | ||||||||||||||||||
| 6836 | } | - | ||||||||||||||||||
| 6837 | - | |||||||||||||||||||
| 6838 | } // namespace | - | ||||||||||||||||||
| 6839 | - | |||||||||||||||||||
| 6840 | /*! | - | ||||||||||||||||||
| 6841 | Splits the string into substrings wherever \a sep occurs, and | - | ||||||||||||||||||
| 6842 | returns the list of those strings. If \a sep does not match | - | ||||||||||||||||||
| 6843 | anywhere in the string, split() returns a single-element list | - | ||||||||||||||||||
| 6844 | containing this string. | - | ||||||||||||||||||
| 6845 | - | |||||||||||||||||||
| 6846 | \a cs specifies whether \a sep should be matched case | - | ||||||||||||||||||
| 6847 | sensitively or case insensitively. | - | ||||||||||||||||||
| 6848 | - | |||||||||||||||||||
| 6849 | If \a behavior is QString::SkipEmptyParts, empty entries don't | - | ||||||||||||||||||
| 6850 | appear in the result. By default, empty entries are kept. | - | ||||||||||||||||||
| 6851 | - | |||||||||||||||||||
| 6852 | Example: | - | ||||||||||||||||||
| 6853 | - | |||||||||||||||||||
| 6854 | \snippet qstring/main.cpp 62 | - | ||||||||||||||||||
| 6855 | - | |||||||||||||||||||
| 6856 | \sa QStringList::join(), section() | - | ||||||||||||||||||
| 6857 | */ | - | ||||||||||||||||||
| 6858 | QStringList QString::split(const QString &sep, SplitBehavior behavior, Qt::CaseSensitivity cs) const | - | ||||||||||||||||||
| 6859 | { | - | ||||||||||||||||||
| 6860 | return splitString<QStringList>(*this, sep.constData(), behavior, cs, sep.size()); executed 607 times by 23 tests: return splitString<QStringList>(*this, sep.constData(), behavior, cs, sep.size());Executed by:
| 607 | ||||||||||||||||||
| 6861 | } | - | ||||||||||||||||||
| 6862 | - | |||||||||||||||||||
| 6863 | /*! | - | ||||||||||||||||||
| 6864 | Splits the string into substring references wherever \a sep occurs, and | - | ||||||||||||||||||
| 6865 | returns the list of those strings. If \a sep does not match | - | ||||||||||||||||||
| 6866 | anywhere in the string, splitRef() returns a single-element vector | - | ||||||||||||||||||
| 6867 | containing this string reference. | - | ||||||||||||||||||
| 6868 | - | |||||||||||||||||||
| 6869 | \a cs specifies whether \a sep should be matched case | - | ||||||||||||||||||
| 6870 | sensitively or case insensitively. | - | ||||||||||||||||||
| 6871 | - | |||||||||||||||||||
| 6872 | If \a behavior is QString::SkipEmptyParts, empty entries don't | - | ||||||||||||||||||
| 6873 | appear in the result. By default, empty entries are kept. | - | ||||||||||||||||||
| 6874 | - | |||||||||||||||||||
| 6875 | \note All references are valid as long this string is alive. Destroying this | - | ||||||||||||||||||
| 6876 | string will cause all references be dangling pointers. | - | ||||||||||||||||||
| 6877 | - | |||||||||||||||||||
| 6878 | \since 5.4 | - | ||||||||||||||||||
| 6879 | \sa QStringRef split() | - | ||||||||||||||||||
| 6880 | */ | - | ||||||||||||||||||
| 6881 | QVector<QStringRef> QString::splitRef(const QString &sep, SplitBehavior behavior, Qt::CaseSensitivity cs) const | - | ||||||||||||||||||
| 6882 | { | - | ||||||||||||||||||
| 6883 | 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 | ||||||||||||||||||
| 6884 | } | - | ||||||||||||||||||
| 6885 | /*! | - | ||||||||||||||||||
| 6886 | \overload | - | ||||||||||||||||||
| 6887 | */ | - | ||||||||||||||||||
| 6888 | QStringList QString::split(QChar sep, SplitBehavior behavior, Qt::CaseSensitivity cs) const | - | ||||||||||||||||||
| 6889 | { | - | ||||||||||||||||||
| 6890 | return splitString<QStringList>(*this, &sep, behavior, cs, 1); executed 29542 times by 81 tests: return splitString<QStringList>(*this, &sep, behavior, cs, 1);Executed by:
| 29542 | ||||||||||||||||||
| 6891 | } | - | ||||||||||||||||||
| 6892 | - | |||||||||||||||||||
| 6893 | /*! | - | ||||||||||||||||||
| 6894 | \overload | - | ||||||||||||||||||
| 6895 | \since 5.4 | - | ||||||||||||||||||
| 6896 | */ | - | ||||||||||||||||||
| 6897 | QVector<QStringRef> QString::splitRef(QChar sep, SplitBehavior behavior, Qt::CaseSensitivity cs) const | - | ||||||||||||||||||
| 6898 | { | - | ||||||||||||||||||
| 6899 | return splitString<QVector<QStringRef> >(QStringRef(this), &sep, behavior, cs, 1); executed 43525 times by 238 tests: return splitString<QVector<QStringRef> >(QStringRef(this), &sep, behavior, cs, 1);Executed by:
| 43525 | ||||||||||||||||||
| 6900 | } | - | ||||||||||||||||||
| 6901 | - | |||||||||||||||||||
| 6902 | /*! | - | ||||||||||||||||||
| 6903 | Splits the string into substrings references wherever \a sep occurs, and | - | ||||||||||||||||||
| 6904 | returns the list of those strings. If \a sep does not match | - | ||||||||||||||||||
| 6905 | anywhere in the string, split() returns a single-element vector | - | ||||||||||||||||||
| 6906 | containing this string reference. | - | ||||||||||||||||||
| 6907 | - | |||||||||||||||||||
| 6908 | \a cs specifies whether \a sep should be matched case | - | ||||||||||||||||||
| 6909 | sensitively or case insensitively. | - | ||||||||||||||||||
| 6910 | - | |||||||||||||||||||
| 6911 | If \a behavior is QString::SkipEmptyParts, empty entries don't | - | ||||||||||||||||||
| 6912 | appear in the result. By default, empty entries are kept. | - | ||||||||||||||||||
| 6913 | - | |||||||||||||||||||
| 6914 | \note All references are valid as long this string is alive. Destroying this | - | ||||||||||||||||||
| 6915 | string will cause all references be dangling pointers. | - | ||||||||||||||||||
| 6916 | - | |||||||||||||||||||
| 6917 | \since 5.4 | - | ||||||||||||||||||
| 6918 | */ | - | ||||||||||||||||||
| 6919 | QVector<QStringRef> QStringRef::split(const QString &sep, QString::SplitBehavior behavior, Qt::CaseSensitivity cs) const | - | ||||||||||||||||||
| 6920 | { | - | ||||||||||||||||||
| 6921 | return splitString<QVector<QStringRef> >(*this, sep.constData(), behavior, cs, sep.size()); executed 32 times by 2 tests: return splitString<QVector<QStringRef> >(*this, sep.constData(), behavior, cs, sep.size());Executed by:
| 32 | ||||||||||||||||||
| 6922 | } | - | ||||||||||||||||||
| 6923 | - | |||||||||||||||||||
| 6924 | /*! | - | ||||||||||||||||||
| 6925 | \overload | - | ||||||||||||||||||
| 6926 | \since 5.4 | - | ||||||||||||||||||
| 6927 | */ | - | ||||||||||||||||||
| 6928 | QVector<QStringRef> QStringRef::split(QChar sep, QString::SplitBehavior behavior, Qt::CaseSensitivity cs) const | - | ||||||||||||||||||
| 6929 | { | - | ||||||||||||||||||
| 6930 | return splitString<QVector<QStringRef> >(*this, &sep, behavior, cs, 1); executed 3714 times by 168 tests: return splitString<QVector<QStringRef> >(*this, &sep, behavior, cs, 1);Executed by:
| 3714 | ||||||||||||||||||
| 6931 | } | - | ||||||||||||||||||
| 6932 | - | |||||||||||||||||||
| 6933 | #ifndef QT_NO_REGEXP | - | ||||||||||||||||||
| 6934 | namespace { | - | ||||||||||||||||||
| 6935 | template<class ResultList, typename MidMethod> | - | ||||||||||||||||||
| 6936 | static ResultList splitString(const QString &source, MidMethod mid, const QRegExp &rx, QString::SplitBehavior behavior) | - | ||||||||||||||||||
| 6937 | { | - | ||||||||||||||||||
| 6938 | QRegExp rx2(rx); | - | ||||||||||||||||||
| 6939 | ResultList list; | - | ||||||||||||||||||
| 6940 | int start = 0; | - | ||||||||||||||||||
| 6941 | int extra = 0; | - | ||||||||||||||||||
| 6942 | int end; | - | ||||||||||||||||||
| 6943 | while ((end = rx2.indexIn(source, start + extra)) != -1) {
| 506-14366 | ||||||||||||||||||
| 6944 | int matchedLen = rx2.matchedLength(); | - | ||||||||||||||||||
| 6945 | if (start != end || behavior == QString::KeepEmptyParts)
| 22-13920 | ||||||||||||||||||
| 6946 | list.append((source.*mid)(start, end - start)); executed 14344 times by 6 tests: list.append((source.*mid)(start, end - start));Executed by:
| 14344 | ||||||||||||||||||
| 6947 | start = end + matchedLen; | - | ||||||||||||||||||
| 6948 | extra = (matchedLen == 0) ? 1 : 0;
| 62-14304 | ||||||||||||||||||
| 6949 | } executed 14366 times by 6 tests: end of blockExecuted by:
| 14366 | ||||||||||||||||||
| 6950 | if (start != source.size() || behavior == QString::KeepEmptyParts)
| 13-392 | ||||||||||||||||||
| 6951 | list.append((source.*mid)(start, -1)); executed 493 times by 5 tests: list.append((source.*mid)(start, -1));Executed by:
| 493 | ||||||||||||||||||
| 6952 | return list; executed 506 times by 6 tests: return list;Executed by:
| 506 | ||||||||||||||||||
| 6953 | } | - | ||||||||||||||||||
| 6954 | } // namespace | - | ||||||||||||||||||
| 6955 | - | |||||||||||||||||||
| 6956 | /*! | - | ||||||||||||||||||
| 6957 | \overload | - | ||||||||||||||||||
| 6958 | - | |||||||||||||||||||
| 6959 | Splits the string into substrings wherever the regular expression | - | ||||||||||||||||||
| 6960 | \a rx matches, and returns the list of those strings. If \a rx | - | ||||||||||||||||||
| 6961 | does not match anywhere in the string, split() returns a | - | ||||||||||||||||||
| 6962 | single-element list containing this string. | - | ||||||||||||||||||
| 6963 | - | |||||||||||||||||||
| 6964 | Here's an example where we extract the words in a sentence | - | ||||||||||||||||||
| 6965 | using one or more whitespace characters as the separator: | - | ||||||||||||||||||
| 6966 | - | |||||||||||||||||||
| 6967 | \snippet qstring/main.cpp 59 | - | ||||||||||||||||||
| 6968 | - | |||||||||||||||||||
| 6969 | Here's a similar example, but this time we use any sequence of | - | ||||||||||||||||||
| 6970 | non-word characters as the separator: | - | ||||||||||||||||||
| 6971 | - | |||||||||||||||||||
| 6972 | \snippet qstring/main.cpp 60 | - | ||||||||||||||||||
| 6973 | - | |||||||||||||||||||
| 6974 | Here's a third example where we use a zero-length assertion, | - | ||||||||||||||||||
| 6975 | \b{\\b} (word boundary), to split the string into an | - | ||||||||||||||||||
| 6976 | alternating sequence of non-word and word tokens: | - | ||||||||||||||||||
| 6977 | - | |||||||||||||||||||
| 6978 | \snippet qstring/main.cpp 61 | - | ||||||||||||||||||
| 6979 | - | |||||||||||||||||||
| 6980 | \sa QStringList::join(), section() | - | ||||||||||||||||||
| 6981 | */ | - | ||||||||||||||||||
| 6982 | QStringList QString::split(const QRegExp &rx, SplitBehavior behavior) const | - | ||||||||||||||||||
| 6983 | { | - | ||||||||||||||||||
| 6984 | return splitString<QStringList>(*this, &QString::mid, rx, behavior); executed 479 times by 6 tests: return splitString<QStringList>(*this, &QString::mid, rx, behavior);Executed by:
| 479 | ||||||||||||||||||
| 6985 | } | - | ||||||||||||||||||
| 6986 | - | |||||||||||||||||||
| 6987 | /*! | - | ||||||||||||||||||
| 6988 | \overload | - | ||||||||||||||||||
| 6989 | \since 5.4 | - | ||||||||||||||||||
| 6990 | - | |||||||||||||||||||
| 6991 | Splits the string into substring references wherever the regular expression | - | ||||||||||||||||||
| 6992 | \a rx matches, and returns the list of those strings. If \a rx | - | ||||||||||||||||||
| 6993 | does not match anywhere in the string, splitRef() returns a | - | ||||||||||||||||||
| 6994 | single-element vector containing this string reference. | - | ||||||||||||||||||
| 6995 | - | |||||||||||||||||||
| 6996 | \note All references are valid as long this string is alive. Destroying this | - | ||||||||||||||||||
| 6997 | string will cause all references be dangling pointers. | - | ||||||||||||||||||
| 6998 | - | |||||||||||||||||||
| 6999 | \sa QStringRef split() | - | ||||||||||||||||||
| 7000 | */ | - | ||||||||||||||||||
| 7001 | QVector<QStringRef> QString::splitRef(const QRegExp &rx, SplitBehavior behavior) const | - | ||||||||||||||||||
| 7002 | { | - | ||||||||||||||||||
| 7003 | 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 | ||||||||||||||||||
| 7004 | } | - | ||||||||||||||||||
| 7005 | #endif | - | ||||||||||||||||||
| 7006 | - | |||||||||||||||||||
| 7007 | #ifndef QT_NO_REGULAREXPRESSION | - | ||||||||||||||||||
| 7008 | #ifndef QT_BOOTSTRAPPED | - | ||||||||||||||||||
| 7009 | namespace { | - | ||||||||||||||||||
| 7010 | template<class ResultList, typename MidMethod> | - | ||||||||||||||||||
| 7011 | static ResultList splitString(const QString &source, MidMethod mid, const QRegularExpression &re, | - | ||||||||||||||||||
| 7012 | QString::SplitBehavior behavior) | - | ||||||||||||||||||
| 7013 | { | - | ||||||||||||||||||
| 7014 | ResultList list; | - | ||||||||||||||||||
| 7015 | if (!re.isValid()) {
| 0-54 | ||||||||||||||||||
| 7016 | qWarning("QString::split: invalid QRegularExpression object"); | - | ||||||||||||||||||
| 7017 | return list; never executed: return list; | 0 | ||||||||||||||||||
| 7018 | } | - | ||||||||||||||||||
| 7019 | - | |||||||||||||||||||
| 7020 | int start = 0; | - | ||||||||||||||||||
| 7021 | int end = 0; | - | ||||||||||||||||||
| 7022 | QRegularExpressionMatchIterator iterator = re.globalMatch(source); | - | ||||||||||||||||||
| 7023 | while (iterator.hasNext()) {
| 54-210 | ||||||||||||||||||
| 7024 | QRegularExpressionMatch match = iterator.next(); | - | ||||||||||||||||||
| 7025 | end = match.capturedStart(); | - | ||||||||||||||||||
| 7026 | if (start != end || behavior == QString::KeepEmptyParts)
| 22-146 | ||||||||||||||||||
| 7027 | list.append((source.*mid)(start, end - start)); executed 188 times by 1 test: list.append((source.*mid)(start, end - start));Executed by:
| 188 | ||||||||||||||||||
| 7028 | start = match.capturedEnd(); | - | ||||||||||||||||||
| 7029 | } executed 210 times by 1 test: end of blockExecuted by:
| 210 | ||||||||||||||||||
| 7030 | - | |||||||||||||||||||
| 7031 | if (start != source.size() || behavior == QString::KeepEmptyParts)
| 12-34 | ||||||||||||||||||
| 7032 | list.append((source.*mid)(start, -1)); executed 42 times by 1 test: list.append((source.*mid)(start, -1));Executed by:
| 42 | ||||||||||||||||||
| 7033 | - | |||||||||||||||||||
| 7034 | return list; executed 54 times by 1 test: return list;Executed by:
| 54 | ||||||||||||||||||
| 7035 | } | - | ||||||||||||||||||
| 7036 | } // namespace | - | ||||||||||||||||||
| 7037 | - | |||||||||||||||||||
| 7038 | /*! | - | ||||||||||||||||||
| 7039 | \overload | - | ||||||||||||||||||
| 7040 | \since 5.0 | - | ||||||||||||||||||
| 7041 | - | |||||||||||||||||||
| 7042 | Splits the string into substrings wherever the regular expression | - | ||||||||||||||||||
| 7043 | \a re matches, and returns the list of those strings. If \a re | - | ||||||||||||||||||
| 7044 | does not match anywhere in the string, split() returns a | - | ||||||||||||||||||
| 7045 | single-element list containing this string. | - | ||||||||||||||||||
| 7046 | - | |||||||||||||||||||
| 7047 | Here's an example where we extract the words in a sentence | - | ||||||||||||||||||
| 7048 | using one or more whitespace characters as the separator: | - | ||||||||||||||||||
| 7049 | - | |||||||||||||||||||
| 7050 | \snippet qstring/main.cpp 90 | - | ||||||||||||||||||
| 7051 | - | |||||||||||||||||||
| 7052 | Here's a similar example, but this time we use any sequence of | - | ||||||||||||||||||
| 7053 | non-word characters as the separator: | - | ||||||||||||||||||
| 7054 | - | |||||||||||||||||||
| 7055 | \snippet qstring/main.cpp 91 | - | ||||||||||||||||||
| 7056 | - | |||||||||||||||||||
| 7057 | Here's a third example where we use a zero-length assertion, | - | ||||||||||||||||||
| 7058 | \b{\\b} (word boundary), to split the string into an | - | ||||||||||||||||||
| 7059 | alternating sequence of non-word and word tokens: | - | ||||||||||||||||||
| 7060 | - | |||||||||||||||||||
| 7061 | \snippet qstring/main.cpp 92 | - | ||||||||||||||||||
| 7062 | - | |||||||||||||||||||
| 7063 | \sa QStringList::join(), section() | - | ||||||||||||||||||
| 7064 | */ | - | ||||||||||||||||||
| 7065 | QStringList QString::split(const QRegularExpression &re, SplitBehavior behavior) const | - | ||||||||||||||||||
| 7066 | { | - | ||||||||||||||||||
| 7067 | 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 | ||||||||||||||||||
| 7068 | } | - | ||||||||||||||||||
| 7069 | - | |||||||||||||||||||
| 7070 | /*! | - | ||||||||||||||||||
| 7071 | \overload | - | ||||||||||||||||||
| 7072 | \since 5.4 | - | ||||||||||||||||||
| 7073 | - | |||||||||||||||||||
| 7074 | Splits the string into substring references wherever the regular expression | - | ||||||||||||||||||
| 7075 | \a re matches, and returns the list of those strings. If \a re | - | ||||||||||||||||||
| 7076 | does not match anywhere in the string, splitRef() returns a | - | ||||||||||||||||||
| 7077 | single-element vector containing this string reference. | - | ||||||||||||||||||
| 7078 | - | |||||||||||||||||||
| 7079 | \note All references are valid as long this string is alive. Destroying this | - | ||||||||||||||||||
| 7080 | string will cause all references be dangling pointers. | - | ||||||||||||||||||
| 7081 | - | |||||||||||||||||||
| 7082 | \sa split() QStringRef | - | ||||||||||||||||||
| 7083 | */ | - | ||||||||||||||||||
| 7084 | QVector<QStringRef> QString::splitRef(const QRegularExpression &re, SplitBehavior behavior) const | - | ||||||||||||||||||
| 7085 | { | - | ||||||||||||||||||
| 7086 | 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 | ||||||||||||||||||
| 7087 | } | - | ||||||||||||||||||
| 7088 | #endif // QT_BOOTSTRAPPED | - | ||||||||||||||||||
| 7089 | #endif // QT_NO_REGULAREXPRESSION | - | ||||||||||||||||||
| 7090 | - | |||||||||||||||||||
| 7091 | /*! | - | ||||||||||||||||||
| 7092 | \enum QString::NormalizationForm | - | ||||||||||||||||||
| 7093 | - | |||||||||||||||||||
| 7094 | This enum describes the various normalized forms of Unicode text. | - | ||||||||||||||||||
| 7095 | - | |||||||||||||||||||
| 7096 | \value NormalizationForm_D Canonical Decomposition | - | ||||||||||||||||||
| 7097 | \value NormalizationForm_C Canonical Decomposition followed by Canonical Composition | - | ||||||||||||||||||
| 7098 | \value NormalizationForm_KD Compatibility Decomposition | - | ||||||||||||||||||
| 7099 | \value NormalizationForm_KC Compatibility Decomposition followed by Canonical Composition | - | ||||||||||||||||||
| 7100 | - | |||||||||||||||||||
| 7101 | \sa normalized(), | - | ||||||||||||||||||
| 7102 | {http://www.unicode.org/reports/tr15/}{Unicode Standard Annex #15} | - | ||||||||||||||||||
| 7103 | */ | - | ||||||||||||||||||
| 7104 | - | |||||||||||||||||||
| 7105 | /*! | - | ||||||||||||||||||
| 7106 | \since 4.5 | - | ||||||||||||||||||
| 7107 | - | |||||||||||||||||||
| 7108 | Returns a copy of this string repeated the specified number of \a times. | - | ||||||||||||||||||
| 7109 | - | |||||||||||||||||||
| 7110 | If \a times is less than 1, an empty string is returned. | - | ||||||||||||||||||
| 7111 | - | |||||||||||||||||||
| 7112 | Example: | - | ||||||||||||||||||
| 7113 | - | |||||||||||||||||||
| 7114 | \code | - | ||||||||||||||||||
| 7115 | QString str("ab"); | - | ||||||||||||||||||
| 7116 | str.repeated(4); // returns "abababab" | - | ||||||||||||||||||
| 7117 | \endcode | - | ||||||||||||||||||
| 7118 | */ | - | ||||||||||||||||||
| 7119 | QString QString::repeated(int times) const | - | ||||||||||||||||||
| 7120 | { | - | ||||||||||||||||||
| 7121 | if (d->size == 0)
| 5-9 | ||||||||||||||||||
| 7122 | return *this; executed 5 times by 1 test: return *this;Executed by:
| 5 | ||||||||||||||||||
| 7123 | - | |||||||||||||||||||
| 7124 | if (times <= 1) {
| 4-5 | ||||||||||||||||||
| 7125 | if (times == 1)
| 1-3 | ||||||||||||||||||
| 7126 | return *this; executed 1 time by 1 test: return *this;Executed by:
| 1 | ||||||||||||||||||
| 7127 | return QString(); executed 3 times by 1 test: return QString();Executed by:
| 3 | ||||||||||||||||||
| 7128 | } | - | ||||||||||||||||||
| 7129 | - | |||||||||||||||||||
| 7130 | const int resultSize = times * d->size; | - | ||||||||||||||||||
| 7131 | - | |||||||||||||||||||
| 7132 | QString result; | - | ||||||||||||||||||
| 7133 | result.reserve(resultSize); | - | ||||||||||||||||||
| 7134 | if (result.d->alloc != uint(resultSize) + 1u)
| 0-5 | ||||||||||||||||||
| 7135 | return QString(); // not enough memory never executed: return QString(); | 0 | ||||||||||||||||||
| 7136 | - | |||||||||||||||||||
| 7137 | memcpy(result.d->data(), d->data(), d->size * sizeof(ushort)); | - | ||||||||||||||||||
| 7138 | - | |||||||||||||||||||
| 7139 | int sizeSoFar = d->size; | - | ||||||||||||||||||
| 7140 | ushort *end = result.d->data() + sizeSoFar; | - | ||||||||||||||||||
| 7141 | - | |||||||||||||||||||
| 7142 | const int halfResultSize = resultSize >> 1; | - | ||||||||||||||||||
| 7143 | while (sizeSoFar <= halfResultSize) {
| 5-16 | ||||||||||||||||||
| 7144 | memcpy(end, result.d->data(), sizeSoFar * sizeof(ushort)); | - | ||||||||||||||||||
| 7145 | end += sizeSoFar; | - | ||||||||||||||||||
| 7146 | sizeSoFar <<= 1; | - | ||||||||||||||||||
| 7147 | } executed 16 times by 2 tests: end of blockExecuted by:
| 16 | ||||||||||||||||||
| 7148 | memcpy(end, result.d->data(), (resultSize - sizeSoFar) * sizeof(ushort)); | - | ||||||||||||||||||
| 7149 | result.d->data()[resultSize] = '\0'; | - | ||||||||||||||||||
| 7150 | result.d->size = resultSize; | - | ||||||||||||||||||
| 7151 | return result; executed 5 times by 2 tests: return result;Executed by:
| 5 | ||||||||||||||||||
| 7152 | } | - | ||||||||||||||||||
| 7153 | - | |||||||||||||||||||
| 7154 | void qt_string_normalize(QString *data, QString::NormalizationForm mode, QChar::UnicodeVersion version, int from) | - | ||||||||||||||||||
| 7155 | { | - | ||||||||||||||||||
| 7156 | bool simple = true; | - | ||||||||||||||||||
| 7157 | const QChar *p = data->constData(); | - | ||||||||||||||||||
| 7158 | int len = data->length(); | - | ||||||||||||||||||
| 7159 | for (int i = from; i < len; ++i) {
| 11145-613961 | ||||||||||||||||||
| 7160 | if (p[i].unicode() >= 0x80) {
| 47934-566027 | ||||||||||||||||||
| 7161 | simple = false; | - | ||||||||||||||||||
| 7162 | if (i > from)
| 32700-533327 | ||||||||||||||||||
| 7163 | from = i - 1; executed 32700 times by 6 tests: from = i - 1;Executed by:
| 32700 | ||||||||||||||||||
| 7164 | break; executed 566027 times by 9 tests: break;Executed by:
| 566027 | ||||||||||||||||||
| 7165 | } | - | ||||||||||||||||||
| 7166 | } executed 47934 times by 6 tests: end of blockExecuted by:
| 47934 | ||||||||||||||||||
| 7167 | if (simple)
| 11145-566027 | ||||||||||||||||||
| 7168 | return; executed 11145 times by 3 tests: return;Executed by:
| 11145 | ||||||||||||||||||
| 7169 | - | |||||||||||||||||||
| 7170 | if (version == QChar::Unicode_Unassigned) {
| 323-565704 | ||||||||||||||||||
| 7171 | version = QChar::currentUnicodeVersion(); | - | ||||||||||||||||||
| 7172 | } else if (int(version) <= NormalizationCorrectionsVersionMax) { executed 565704 times by 4 tests: end of blockExecuted by:
| 0-565704 | ||||||||||||||||||
| 7173 | const QString &s = *data; | - | ||||||||||||||||||
| 7174 | QChar *d = 0; | - | ||||||||||||||||||
| 7175 | for (int i = 0; i < NumNormalizationCorrections; ++i) {
| 323-1938 | ||||||||||||||||||
| 7176 | const NormalizationCorrection &n = uc_normalization_corrections[i]; | - | ||||||||||||||||||
| 7177 | if (n.version > version) {
| 321-1617 | ||||||||||||||||||
| 7178 | int pos = from; | - | ||||||||||||||||||
| 7179 | if (QChar::requiresSurrogates(n.ucs4)) {
| 2-1615 | ||||||||||||||||||
| 7180 | ushort ucs4High = QChar::highSurrogate(n.ucs4); | - | ||||||||||||||||||
| 7181 | ushort ucs4Low = QChar::lowSurrogate(n.ucs4); | - | ||||||||||||||||||
| 7182 | ushort oldHigh = QChar::highSurrogate(n.old_mapping); | - | ||||||||||||||||||
| 7183 | ushort oldLow = QChar::lowSurrogate(n.old_mapping); | - | ||||||||||||||||||
| 7184 | while (pos < s.length() - 1) {
| 1615-4925 | ||||||||||||||||||
| 7185 | if (s.at(pos).unicode() == ucs4High && s.at(pos + 1).unicode() == ucs4Low) {
| 0-4923 | ||||||||||||||||||
| 7186 | if (!d)
| 0-2 | ||||||||||||||||||
| 7187 | d = data->data(); executed 2 times by 1 test: d = data->data();Executed by:
| 2 | ||||||||||||||||||
| 7188 | d[pos] = QChar(oldHigh); | - | ||||||||||||||||||
| 7189 | d[++pos] = QChar(oldLow); | - | ||||||||||||||||||
| 7190 | } executed 2 times by 1 test: end of blockExecuted by:
| 2 | ||||||||||||||||||
| 7191 | ++pos; | - | ||||||||||||||||||
| 7192 | } executed 4925 times by 6 tests: end of blockExecuted by:
| 4925 | ||||||||||||||||||
| 7193 | } else { executed 1615 times by 6 tests: end of blockExecuted by:
| 1615 | ||||||||||||||||||
| 7194 | while (pos < s.length()) {
| 2-3 | ||||||||||||||||||
| 7195 | if (s.at(pos).unicode() == n.ucs4) {
| 1-2 | ||||||||||||||||||
| 7196 | if (!d)
| 0-1 | ||||||||||||||||||
| 7197 | d = data->data(); executed 1 time by 1 test: d = data->data();Executed by:
| 1 | ||||||||||||||||||
| 7198 | d[pos] = QChar(n.old_mapping); | - | ||||||||||||||||||
| 7199 | } executed 1 time by 1 test: end of blockExecuted by:
| 1 | ||||||||||||||||||
| 7200 | ++pos; | - | ||||||||||||||||||
| 7201 | } executed 3 times by 1 test: end of blockExecuted by:
| 3 | ||||||||||||||||||
| 7202 | } executed 2 times by 1 test: end of blockExecuted by:
| 2 | ||||||||||||||||||
| 7203 | } | - | ||||||||||||||||||
| 7204 | } executed 1938 times by 6 tests: end of blockExecuted by:
| 1938 | ||||||||||||||||||
| 7205 | } executed 323 times by 6 tests: end of blockExecuted by:
| 323 | ||||||||||||||||||
| 7206 | - | |||||||||||||||||||
| 7207 | if (normalizationQuickCheckHelper(data, mode, from, &from))
| 166051-399976 | ||||||||||||||||||
| 7208 | return; executed 399976 times by 9 tests: return;Executed by:
| 399976 | ||||||||||||||||||
| 7209 | - | |||||||||||||||||||
| 7210 | decomposeHelper(data, mode < QString::NormalizationForm_KD, version, from); | - | ||||||||||||||||||
| 7211 | - | |||||||||||||||||||
| 7212 | canonicalOrderHelper(data, version, from); | - | ||||||||||||||||||
| 7213 | - | |||||||||||||||||||
| 7214 | if (mode == QString::NormalizationForm_D || mode == QString::NormalizationForm_KD)
| 40333-125718 | ||||||||||||||||||
| 7215 | return; executed 91668 times by 1 test: return;Executed by:
| 91668 | ||||||||||||||||||
| 7216 | - | |||||||||||||||||||
| 7217 | composeHelper(data, version, from); | - | ||||||||||||||||||
| 7218 | } executed 74383 times by 3 tests: end of blockExecuted by:
| 74383 | ||||||||||||||||||
| 7219 | - | |||||||||||||||||||
| 7220 | /*! | - | ||||||||||||||||||
| 7221 | Returns the string in the given Unicode normalization \a mode, | - | ||||||||||||||||||
| 7222 | according to the given \a version of the Unicode standard. | - | ||||||||||||||||||
| 7223 | */ | - | ||||||||||||||||||
| 7224 | QString QString::normalized(QString::NormalizationForm mode, QChar::UnicodeVersion version) const | - | ||||||||||||||||||
| 7225 | { | - | ||||||||||||||||||
| 7226 | QString copy = *this; | - | ||||||||||||||||||
| 7227 | qt_string_normalize(©, mode, version, 0); | - | ||||||||||||||||||
| 7228 | return copy; executed 576836 times by 4 tests: return copy;Executed by:
| 576836 | ||||||||||||||||||
| 7229 | } | - | ||||||||||||||||||
| 7230 | - | |||||||||||||||||||
| 7231 | - | |||||||||||||||||||
| 7232 | struct ArgEscapeData | - | ||||||||||||||||||
| 7233 | { | - | ||||||||||||||||||
| 7234 | int min_escape; // lowest escape sequence number | - | ||||||||||||||||||
| 7235 | int occurrences; // number of occurrences of the lowest escape sequence number | - | ||||||||||||||||||
| 7236 | int locale_occurrences; // number of occurrences of the lowest escape sequence number that | - | ||||||||||||||||||
| 7237 | // contain 'L' | - | ||||||||||||||||||
| 7238 | int escape_len; // total length of escape sequences which will be replaced | - | ||||||||||||||||||
| 7239 | }; | - | ||||||||||||||||||
| 7240 | - | |||||||||||||||||||
| 7241 | static ArgEscapeData findArgEscapes(const QString &s) | - | ||||||||||||||||||
| 7242 | { | - | ||||||||||||||||||
| 7243 | const QChar *uc_begin = s.unicode(); | - | ||||||||||||||||||
| 7244 | const QChar *uc_end = uc_begin + s.length(); | - | ||||||||||||||||||
| 7245 | - | |||||||||||||||||||
| 7246 | ArgEscapeData d; | - | ||||||||||||||||||
| 7247 | - | |||||||||||||||||||
| 7248 | d.min_escape = INT_MAX; | - | ||||||||||||||||||
| 7249 | d.occurrences = 0; | - | ||||||||||||||||||
| 7250 | d.escape_len = 0; | - | ||||||||||||||||||
| 7251 | d.locale_occurrences = 0; | - | ||||||||||||||||||
| 7252 | - | |||||||||||||||||||
| 7253 | const QChar *c = uc_begin; | - | ||||||||||||||||||
| 7254 | while (c != uc_end) {
| 172334-1750288 | ||||||||||||||||||
| 7255 | while (c != uc_end && c->unicode() != '%')
| 305831-16168777 | ||||||||||||||||||
| 7256 | ++c; executed 14724320 times by 428 tests: ++c;Executed by:
| 14724320 | ||||||||||||||||||
| 7257 | - | |||||||||||||||||||
| 7258 | if (c == uc_end)
| 305831-1444457 | ||||||||||||||||||
| 7259 | break; executed 305831 times by 393 tests: break;Executed by:
| 305831 | ||||||||||||||||||
| 7260 | const QChar *escape_start = c; | - | ||||||||||||||||||
| 7261 | if (++c == uc_end)
| 14-1444443 | ||||||||||||||||||
| 7262 | break; executed 14 times by 2 tests: break;Executed by:
| 14 | ||||||||||||||||||
| 7263 | - | |||||||||||||||||||
| 7264 | bool locale_arg = false; | - | ||||||||||||||||||
| 7265 | if (c->unicode() == 'L') {
| 276-1444167 | ||||||||||||||||||
| 7266 | locale_arg = true; | - | ||||||||||||||||||
| 7267 | if (++c == uc_end)
| 16-260 | ||||||||||||||||||
| 7268 | break; executed 16 times by 1 test: break;Executed by:
| 16 | ||||||||||||||||||
| 7269 | } executed 260 times by 2 tests: end of blockExecuted by:
| 260 | ||||||||||||||||||
| 7270 | - | |||||||||||||||||||
| 7271 | int escape = c->digitValue(); | - | ||||||||||||||||||
| 7272 | if (escape == -1)
| 195-1444232 | ||||||||||||||||||
| 7273 | continue; executed 195 times by 1 test: continue;Executed by:
| 195 | ||||||||||||||||||
| 7274 | - | |||||||||||||||||||
| 7275 | ++c; | - | ||||||||||||||||||
| 7276 | - | |||||||||||||||||||
| 7277 | if (c != uc_end) {
| 172332-1271900 | ||||||||||||||||||
| 7278 | int next_escape = c->digitValue(); | - | ||||||||||||||||||
| 7279 | if (next_escape != -1) {
| 94-1271806 | ||||||||||||||||||
| 7280 | escape = (10 * escape) + next_escape; | - | ||||||||||||||||||
| 7281 | ++c; | - | ||||||||||||||||||
| 7282 | } executed 94 times by 1 test: end of blockExecuted by:
| 94 | ||||||||||||||||||
| 7283 | } executed 1271900 times by 409 tests: end of blockExecuted by:
| 1271900 | ||||||||||||||||||
| 7284 | - | |||||||||||||||||||
| 7285 | if (escape > d.min_escape)
| 478340-965892 | ||||||||||||||||||
| 7286 | continue; executed 965892 times by 357 tests: continue;Executed by:
| 965892 | ||||||||||||||||||
| 7287 | - | |||||||||||||||||||
| 7288 | if (escape < d.min_escape) {
| 118-478222 | ||||||||||||||||||
| 7289 | d.min_escape = escape; | - | ||||||||||||||||||
| 7290 | d.occurrences = 0; | - | ||||||||||||||||||
| 7291 | d.escape_len = 0; | - | ||||||||||||||||||
| 7292 | d.locale_occurrences = 0; | - | ||||||||||||||||||
| 7293 | } executed 478222 times by 429 tests: end of blockExecuted by:
| 478222 | ||||||||||||||||||
| 7294 | - | |||||||||||||||||||
| 7295 | ++d.occurrences; | - | ||||||||||||||||||
| 7296 | if (locale_arg)
| 225-478115 | ||||||||||||||||||
| 7297 | ++d.locale_occurrences; executed 225 times by 2 tests: ++d.locale_occurrences;Executed by:
| 225 | ||||||||||||||||||
| 7298 | d.escape_len += c - escape_start; | - | ||||||||||||||||||
| 7299 | } executed 478340 times by 429 tests: end of blockExecuted by:
| 478340 | ||||||||||||||||||
| 7300 | return d; executed 478195 times by 429 tests: return d;Executed by:
| 478195 | ||||||||||||||||||
| 7301 | } | - | ||||||||||||||||||
| 7302 | - | |||||||||||||||||||
| 7303 | static QString replaceArgEscapes(const QString &s, const ArgEscapeData &d, int field_width, | - | ||||||||||||||||||
| 7304 | const QString &arg, const QString &larg, QChar fillChar = QLatin1Char(' ')) | - | ||||||||||||||||||
| 7305 | { | - | ||||||||||||||||||
| 7306 | const QChar *uc_begin = s.unicode(); | - | ||||||||||||||||||
| 7307 | const QChar *uc_end = uc_begin + s.length(); | - | ||||||||||||||||||
| 7308 | - | |||||||||||||||||||
| 7309 | int abs_field_width = qAbs(field_width); | - | ||||||||||||||||||
| 7310 | int result_len = s.length() | - | ||||||||||||||||||
| 7311 | - d.escape_len | - | ||||||||||||||||||
| 7312 | + (d.occurrences - d.locale_occurrences) | - | ||||||||||||||||||
| 7313 | *qMax(abs_field_width, arg.length()) | - | ||||||||||||||||||
| 7314 | + d.locale_occurrences | - | ||||||||||||||||||
| 7315 | *qMax(abs_field_width, larg.length()); | - | ||||||||||||||||||
| 7316 | - | |||||||||||||||||||
| 7317 | QString result(result_len, Qt::Uninitialized); | - | ||||||||||||||||||
| 7318 | QChar *result_buff = (QChar*) result.unicode(); | - | ||||||||||||||||||
| 7319 | - | |||||||||||||||||||
| 7320 | QChar *rc = result_buff; | - | ||||||||||||||||||
| 7321 | const QChar *c = uc_begin; | - | ||||||||||||||||||
| 7322 | int repl_cnt = 0; | - | ||||||||||||||||||
| 7323 | while (c != uc_end) {
| 478189-478415 | ||||||||||||||||||
| 7324 | /* We don't have to check if we run off the end of the string with c, | - | ||||||||||||||||||
| 7325 | because as long as d.occurrences > 0 we KNOW there are valid escape | - | ||||||||||||||||||
| 7326 | sequences. */ | - | ||||||||||||||||||
| 7327 | - | |||||||||||||||||||
| 7328 | const QChar *text_start = c; | - | ||||||||||||||||||
| 7329 | - | |||||||||||||||||||
| 7330 | while (c->unicode() != '%')
| 478415-9449848 | ||||||||||||||||||
| 7331 | ++c; executed 9449848 times by 426 tests: ++c;Executed by:
| 9449848 | ||||||||||||||||||
| 7332 | - | |||||||||||||||||||
| 7333 | const QChar *escape_start = c++; | - | ||||||||||||||||||
| 7334 | - | |||||||||||||||||||
| 7335 | bool locale_arg = false; | - | ||||||||||||||||||
| 7336 | if (c->unicode() == 'L') {
| 225-478190 | ||||||||||||||||||
| 7337 | locale_arg = true; | - | ||||||||||||||||||
| 7338 | ++c; | - | ||||||||||||||||||
| 7339 | } executed 225 times by 2 tests: end of blockExecuted by:
| 225 | ||||||||||||||||||
| 7340 | - | |||||||||||||||||||
| 7341 | int escape = c->digitValue(); | - | ||||||||||||||||||
| 7342 | if (escape != -1) {
| 63-478352 | ||||||||||||||||||
| 7343 | if (c + 1 != uc_end && (c + 1)->digitValue() != -1) {
| 8-396050 | ||||||||||||||||||
| 7344 | escape = (10 * escape) + (c + 1)->digitValue(); | - | ||||||||||||||||||
| 7345 | ++c; | - | ||||||||||||||||||
| 7346 | } executed 8 times by 1 test: end of blockExecuted by:
| 8 | ||||||||||||||||||
| 7347 | } executed 478352 times by 429 tests: end of blockExecuted by:
| 478352 | ||||||||||||||||||
| 7348 | - | |||||||||||||||||||
| 7349 | if (escape != d.min_escape) {
| 110-478305 | ||||||||||||||||||
| 7350 | memcpy(rc, text_start, (c - text_start)*sizeof(QChar)); | - | ||||||||||||||||||
| 7351 | rc += c - text_start; | - | ||||||||||||||||||
| 7352 | } executed 110 times by 2 tests: end of blockExecuted by:
| 110 | ||||||||||||||||||
| 7353 | else { | - | ||||||||||||||||||
| 7354 | ++c; | - | ||||||||||||||||||
| 7355 | - | |||||||||||||||||||
| 7356 | memcpy(rc, text_start, (escape_start - text_start)*sizeof(QChar)); | - | ||||||||||||||||||
| 7357 | rc += escape_start - text_start; | - | ||||||||||||||||||
| 7358 | - | |||||||||||||||||||
| 7359 | uint pad_chars; | - | ||||||||||||||||||
| 7360 | if (locale_arg)
| 224-478081 | ||||||||||||||||||
| 7361 | 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 | ||||||||||||||||||
| 7362 | else | - | ||||||||||||||||||
| 7363 | pad_chars = qMax(abs_field_width, arg.length()) - arg.length(); executed 478081 times by 429 tests: pad_chars = qMax(abs_field_width, arg.length()) - arg.length();Executed by:
| 478081 | ||||||||||||||||||
| 7364 | - | |||||||||||||||||||
| 7365 | if (field_width > 0) { // left padded
| 1076-477229 | ||||||||||||||||||
| 7366 | for (uint i = 0; i < pad_chars; ++i)
| 145-1076 | ||||||||||||||||||
| 7367 | (rc++)->unicode() = fillChar.unicode(); executed 145 times by 2 tests: (rc++)->unicode() = fillChar.unicode();Executed by:
| 145 | ||||||||||||||||||
| 7368 | } executed 1076 times by 6 tests: end of blockExecuted by:
| 1076 | ||||||||||||||||||
| 7369 | - | |||||||||||||||||||
| 7370 | if (locale_arg) {
| 224-478081 | ||||||||||||||||||
| 7371 | memcpy(rc, larg.unicode(), larg.length()*sizeof(QChar)); | - | ||||||||||||||||||
| 7372 | rc += larg.length(); | - | ||||||||||||||||||
| 7373 | } executed 224 times by 2 tests: end of blockExecuted by:
| 224 | ||||||||||||||||||
| 7374 | else { | - | ||||||||||||||||||
| 7375 | memcpy(rc, arg.unicode(), arg.length()*sizeof(QChar)); | - | ||||||||||||||||||
| 7376 | rc += arg.length(); | - | ||||||||||||||||||
| 7377 | } executed 478081 times by 429 tests: end of blockExecuted by:
| 478081 | ||||||||||||||||||
| 7378 | - | |||||||||||||||||||
| 7379 | if (field_width < 0) { // right padded
| 5-478300 | ||||||||||||||||||
| 7380 | for (uint i = 0; i < pad_chars; ++i)
| 5-12 | ||||||||||||||||||
| 7381 | (rc++)->unicode() = fillChar.unicode(); executed 12 times by 1 test: (rc++)->unicode() = fillChar.unicode();Executed by:
| 12 | ||||||||||||||||||
| 7382 | } executed 5 times by 1 test: end of blockExecuted by:
| 5 | ||||||||||||||||||
| 7383 | - | |||||||||||||||||||
| 7384 | if (++repl_cnt == d.occurrences) {
| 116-478189 | ||||||||||||||||||
| 7385 | memcpy(rc, c, (uc_end - c)*sizeof(QChar)); | - | ||||||||||||||||||
| 7386 | rc += uc_end - c; | - | ||||||||||||||||||
| 7387 | Q_ASSERT(rc - result_buff == result_len); | - | ||||||||||||||||||
| 7388 | c = uc_end; | - | ||||||||||||||||||
| 7389 | } executed 478189 times by 429 tests: end of blockExecuted by:
| 478189 | ||||||||||||||||||
| 7390 | } executed 478305 times by 429 tests: end of blockExecuted by:
| 478305 | ||||||||||||||||||
| 7391 | } | - | ||||||||||||||||||
| 7392 | Q_ASSERT(rc == result_buff + result_len); | - | ||||||||||||||||||
| 7393 | - | |||||||||||||||||||
| 7394 | return result; executed 478189 times by 429 tests: return result;Executed by:
| 478189 | ||||||||||||||||||
| 7395 | } | - | ||||||||||||||||||
| 7396 | - | |||||||||||||||||||
| 7397 | /*! | - | ||||||||||||||||||
| 7398 | Returns a copy of this string with the lowest numbered place marker | - | ||||||||||||||||||
| 7399 | replaced by string \a a, i.e., \c %1, \c %2, ..., \c %99. | - | ||||||||||||||||||
| 7400 | - | |||||||||||||||||||
| 7401 | \a fieldWidth specifies the minimum amount of space that argument \a | - | ||||||||||||||||||
| 7402 | a shall occupy. If \a a requires less space than \a fieldWidth, it | - | ||||||||||||||||||
| 7403 | is padded to \a fieldWidth with character \a fillChar. A positive | - | ||||||||||||||||||
| 7404 | \a fieldWidth produces right-aligned text. A negative \a fieldWidth | - | ||||||||||||||||||
| 7405 | produces left-aligned text. | - | ||||||||||||||||||
| 7406 | - | |||||||||||||||||||
| 7407 | This example shows how we might create a \c status string for | - | ||||||||||||||||||
| 7408 | reporting progress while processing a list of files: | - | ||||||||||||||||||
| 7409 | - | |||||||||||||||||||
| 7410 | \snippet qstring/main.cpp 11 | - | ||||||||||||||||||
| 7411 | - | |||||||||||||||||||
| 7412 | First, \c arg(i) replaces \c %1. Then \c arg(total) replaces \c | - | ||||||||||||||||||
| 7413 | %2. Finally, \c arg(fileName) replaces \c %3. | - | ||||||||||||||||||
| 7414 | - | |||||||||||||||||||
| 7415 | One advantage of using arg() over asprintf() is that the order of the | - | ||||||||||||||||||
| 7416 | numbered place markers can change, if the application's strings are | - | ||||||||||||||||||
| 7417 | translated into other languages, but each arg() will still replace | - | ||||||||||||||||||
| 7418 | the lowest numbered unreplaced place marker, no matter where it | - | ||||||||||||||||||
| 7419 | appears. Also, if place marker \c %i appears more than once in the | - | ||||||||||||||||||
| 7420 | string, the arg() replaces all of them. | - | ||||||||||||||||||
| 7421 | - | |||||||||||||||||||
| 7422 | If there is no unreplaced place marker remaining, a warning message | - | ||||||||||||||||||
| 7423 | is output and the result is undefined. Place marker numbers must be | - | ||||||||||||||||||
| 7424 | in the range 1 to 99. | - | ||||||||||||||||||
| 7425 | */ | - | ||||||||||||||||||
| 7426 | QString QString::arg(const QString &a, int fieldWidth, QChar fillChar) const | - | ||||||||||||||||||
| 7427 | { | - | ||||||||||||||||||
| 7428 | ArgEscapeData d = findArgEscapes(*this); | - | ||||||||||||||||||
| 7429 | - | |||||||||||||||||||
| 7430 | if (d.occurrences == 0) {
| 0-152516 | ||||||||||||||||||
| 7431 | qWarning("QString::arg: Argument missing: %s, %s", toLocal8Bit().data(), | - | ||||||||||||||||||
| 7432 | a.toLocal8Bit().data()); | - | ||||||||||||||||||
| 7433 | return *this; never executed: return *this; | 0 | ||||||||||||||||||
| 7434 | } | - | ||||||||||||||||||
| 7435 | return replaceArgEscapes(*this, d, fieldWidth, a, a, fillChar); executed 152516 times by 404 tests: return replaceArgEscapes(*this, d, fieldWidth, a, a, fillChar);Executed by:
| 152516 | ||||||||||||||||||
| 7436 | } | - | ||||||||||||||||||
| 7437 | - | |||||||||||||||||||
| 7438 | /*! | - | ||||||||||||||||||
| 7439 | \fn QString QString::arg(const QString& a1, const QString& a2) const | - | ||||||||||||||||||
| 7440 | \overload arg() | - | ||||||||||||||||||
| 7441 | - | |||||||||||||||||||
| 7442 | This is the same as \c {str.arg(a1).arg(a2)}, except that the | - | ||||||||||||||||||
| 7443 | strings \a a1 and \a a2 are replaced in one pass. This can make a | - | ||||||||||||||||||
| 7444 | difference if \a a1 contains e.g. \c{%1}: | - | ||||||||||||||||||
| 7445 | - | |||||||||||||||||||
| 7446 | \snippet qstring/main.cpp 13 | - | ||||||||||||||||||
| 7447 | - | |||||||||||||||||||
| 7448 | A similar problem occurs when the numbered place markers are not | - | ||||||||||||||||||
| 7449 | white space separated: | - | ||||||||||||||||||
| 7450 | - | |||||||||||||||||||
| 7451 | \snippet qstring/main.cpp 12 | - | ||||||||||||||||||
| 7452 | \snippet qstring/main.cpp 97 | - | ||||||||||||||||||
| 7453 | - | |||||||||||||||||||
| 7454 | Let's look at the substitutions: | - | ||||||||||||||||||
| 7455 | \list | - | ||||||||||||||||||
| 7456 | \li First, \c Hello replaces \c {%1} so the string becomes \c {"Hello%3%2"}. | - | ||||||||||||||||||
| 7457 | \li Then, \c 20 replaces \c {%2} so the string becomes \c {"Hello%320"}. | - | ||||||||||||||||||
| 7458 | \li Since the maximum numbered place marker value is 99, \c 50 replaces \c {%32}. | - | ||||||||||||||||||
| 7459 | \endlist | - | ||||||||||||||||||
| 7460 | Thus the string finally becomes \c {"Hello500"}. | - | ||||||||||||||||||
| 7461 | - | |||||||||||||||||||
| 7462 | In such cases, the following yields the expected results: | - | ||||||||||||||||||
| 7463 | - | |||||||||||||||||||
| 7464 | \snippet qstring/main.cpp 12 | - | ||||||||||||||||||
| 7465 | \snippet qstring/main.cpp 98 | - | ||||||||||||||||||
| 7466 | */ | - | ||||||||||||||||||
| 7467 | - | |||||||||||||||||||
| 7468 | /*! | - | ||||||||||||||||||
| 7469 | \fn QString QString::arg(const QString& a1, const QString& a2, const QString& a3) const | - | ||||||||||||||||||
| 7470 | \overload arg() | - | ||||||||||||||||||
| 7471 | - | |||||||||||||||||||
| 7472 | This is the same as calling \c str.arg(a1).arg(a2).arg(a3), except | - | ||||||||||||||||||
| 7473 | that the strings \a a1, \a a2 and \a a3 are replaced in one pass. | - | ||||||||||||||||||
| 7474 | */ | - | ||||||||||||||||||
| 7475 | - | |||||||||||||||||||
| 7476 | /*! | - | ||||||||||||||||||
| 7477 | \fn QString QString::arg(const QString& a1, const QString& a2, const QString& a3, const QString& a4) const | - | ||||||||||||||||||
| 7478 | \overload arg() | - | ||||||||||||||||||
| 7479 | - | |||||||||||||||||||
| 7480 | This is the same as calling \c | - | ||||||||||||||||||
| 7481 | {str.arg(a1).arg(a2).arg(a3).arg(a4)}, except that the strings \a | - | ||||||||||||||||||
| 7482 | a1, \a a2, \a a3 and \a a4 are replaced in one pass. | - | ||||||||||||||||||
| 7483 | */ | - | ||||||||||||||||||
| 7484 | - | |||||||||||||||||||
| 7485 | /*! | - | ||||||||||||||||||
| 7486 | \fn QString QString::arg(const QString& a1, const QString& a2, const QString& a3, const QString& a4, const QString& a5) const | - | ||||||||||||||||||
| 7487 | \overload arg() | - | ||||||||||||||||||
| 7488 | - | |||||||||||||||||||
| 7489 | This is the same as calling \c | - | ||||||||||||||||||
| 7490 | {str.arg(a1).arg(a2).arg(a3).arg(a4).arg(a5)}, except that the strings | - | ||||||||||||||||||
| 7491 | \a a1, \a a2, \a a3, \a a4, and \a a5 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 | - | ||||||||||||||||||
| 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))}, except that | - | ||||||||||||||||||
| 7500 | the strings \a a1, \a a2, \a a3, \a a4, \a a5, and \a a6 are | - | ||||||||||||||||||
| 7501 | 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 | - | ||||||||||||||||||
| 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)}, | - | ||||||||||||||||||
| 7510 | except that the strings \a a1, \a a2, \a a3, \a a4, \a a5, \a a6, | - | ||||||||||||||||||
| 7511 | and \a a7 are replaced in one pass. | - | ||||||||||||||||||
| 7512 | */ | - | ||||||||||||||||||
| 7513 | - | |||||||||||||||||||
| 7514 | /*! | - | ||||||||||||||||||
| 7515 | \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 | - | ||||||||||||||||||
| 7516 | \overload arg() | - | ||||||||||||||||||
| 7517 | - | |||||||||||||||||||
| 7518 | This is the same as calling \c | - | ||||||||||||||||||
| 7519 | {str.arg(a1).arg(a2).arg(a3).arg(a4).arg(a5).arg(a6).arg(a7).arg(a8)}, | - | ||||||||||||||||||
| 7520 | except that the strings \a a1, \a a2, \a a3, \a a4, \a a5, \a a6, \a | - | ||||||||||||||||||
| 7521 | a7, and \a a8 are replaced in one pass. | - | ||||||||||||||||||
| 7522 | */ | - | ||||||||||||||||||
| 7523 | - | |||||||||||||||||||
| 7524 | /*! | - | ||||||||||||||||||
| 7525 | \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 | - | ||||||||||||||||||
| 7526 | \overload arg() | - | ||||||||||||||||||
| 7527 | - | |||||||||||||||||||
| 7528 | This is the same as calling \c | - | ||||||||||||||||||
| 7529 | {str.arg(a1).arg(a2).arg(a3).arg(a4).arg(a5).arg(a6).arg(a7).arg(a8).arg(a9)}, | - | ||||||||||||||||||
| 7530 | except that the strings \a a1, \a a2, \a a3, \a a4, \a a5, \a a6, \a | - | ||||||||||||||||||
| 7531 | a7, \a a8, and \a a9 are replaced in one pass. | - | ||||||||||||||||||
| 7532 | */ | - | ||||||||||||||||||
| 7533 | - | |||||||||||||||||||
| 7534 | /*! \fn QString QString::arg(int a, int fieldWidth, int base, QChar fillChar) const | - | ||||||||||||||||||
| 7535 | \overload arg() | - | ||||||||||||||||||
| 7536 | - | |||||||||||||||||||
| 7537 | The \a a argument is expressed in base \a base, which is 10 by | - | ||||||||||||||||||
| 7538 | default and must be between 2 and 36. For bases other than 10, \a a | - | ||||||||||||||||||
| 7539 | is treated as an unsigned integer. | - | ||||||||||||||||||
| 7540 | - | |||||||||||||||||||
| 7541 | \a fieldWidth specifies the minimum amount of space that \a a is | - | ||||||||||||||||||
| 7542 | padded to and filled with the character \a fillChar. A positive | - | ||||||||||||||||||
| 7543 | value produces right-aligned text; a negative value produces | - | ||||||||||||||||||
| 7544 | left-aligned text. | - | ||||||||||||||||||
| 7545 | - | |||||||||||||||||||
| 7546 | The '%' can be followed by an 'L', in which case the sequence is | - | ||||||||||||||||||
| 7547 | replaced with a localized representation of \a a. The conversion | - | ||||||||||||||||||
| 7548 | uses the default locale, set by QLocale::setDefault(). If no default | - | ||||||||||||||||||
| 7549 | locale was specified, the "C" locale is used. The 'L' flag is | - | ||||||||||||||||||
| 7550 | ignored if \a base is not 10. | - | ||||||||||||||||||
| 7551 | - | |||||||||||||||||||
| 7552 | \snippet qstring/main.cpp 12 | - | ||||||||||||||||||
| 7553 | \snippet qstring/main.cpp 14 | - | ||||||||||||||||||
| 7554 | - | |||||||||||||||||||
| 7555 | If \a fillChar is '0' (the number 0, ASCII 48), the locale's zero is | - | ||||||||||||||||||
| 7556 | used. For negative numbers, zero padding might appear before the | - | ||||||||||||||||||
| 7557 | minus sign. | - | ||||||||||||||||||
| 7558 | */ | - | ||||||||||||||||||
| 7559 | - | |||||||||||||||||||
| 7560 | /*! \fn QString QString::arg(uint a, int fieldWidth, int base, QChar fillChar) const | - | ||||||||||||||||||
| 7561 | \overload arg() | - | ||||||||||||||||||
| 7562 | - | |||||||||||||||||||
| 7563 | The \a base argument specifies the base to use when converting the | - | ||||||||||||||||||
| 7564 | integer \a a into a string. The base must be between 2 and 36. | - | ||||||||||||||||||
| 7565 | - | |||||||||||||||||||
| 7566 | If \a fillChar is '0' (the number 0, ASCII 48), the locale's zero is | - | ||||||||||||||||||
| 7567 | used. For negative numbers, zero padding might appear before the | - | ||||||||||||||||||
| 7568 | minus sign. | - | ||||||||||||||||||
| 7569 | */ | - | ||||||||||||||||||
| 7570 | - | |||||||||||||||||||
| 7571 | /*! \fn QString QString::arg(long a, int fieldWidth, int base, QChar fillChar) const | - | ||||||||||||||||||
| 7572 | \overload arg() | - | ||||||||||||||||||
| 7573 | - | |||||||||||||||||||
| 7574 | \a fieldWidth specifies the minimum amount of space that \a a is | - | ||||||||||||||||||
| 7575 | padded to and filled with the character \a fillChar. A positive | - | ||||||||||||||||||
| 7576 | value produces right-aligned text; a negative value produces | - | ||||||||||||||||||
| 7577 | left-aligned text. | - | ||||||||||||||||||
| 7578 | - | |||||||||||||||||||
| 7579 | The \a a argument is expressed in the given \a base, which is 10 by | - | ||||||||||||||||||
| 7580 | default and must be between 2 and 36. | - | ||||||||||||||||||
| 7581 | - | |||||||||||||||||||
| 7582 | The '%' can be followed by an 'L', in which case the sequence is | - | ||||||||||||||||||
| 7583 | replaced with a localized representation of \a a. The conversion | - | ||||||||||||||||||
| 7584 | uses the default locale. The default locale is determined from the | - | ||||||||||||||||||
| 7585 | system's locale settings at application startup. It can be changed | - | ||||||||||||||||||
| 7586 | using QLocale::setDefault(). The 'L' flag is ignored if \a base is | - | ||||||||||||||||||
| 7587 | not 10. | - | ||||||||||||||||||
| 7588 | - | |||||||||||||||||||
| 7589 | \snippet qstring/main.cpp 12 | - | ||||||||||||||||||
| 7590 | \snippet qstring/main.cpp 14 | - | ||||||||||||||||||
| 7591 | - | |||||||||||||||||||
| 7592 | If \a fillChar is '0' (the number 0, ASCII 48), the locale's zero is | - | ||||||||||||||||||
| 7593 | used. For negative numbers, zero padding might appear before the | - | ||||||||||||||||||
| 7594 | minus sign. | - | ||||||||||||||||||
| 7595 | */ | - | ||||||||||||||||||
| 7596 | - | |||||||||||||||||||
| 7597 | /*! \fn QString QString::arg(ulong a, int fieldWidth, int base, QChar fillChar) const | - | ||||||||||||||||||
| 7598 | \overload arg() | - | ||||||||||||||||||
| 7599 | - | |||||||||||||||||||
| 7600 | \a fieldWidth specifies the minimum amount of space that \a a is | - | ||||||||||||||||||
| 7601 | padded to and filled with the character \a fillChar. A positive | - | ||||||||||||||||||
| 7602 | value produces right-aligned text; a negative value produces | - | ||||||||||||||||||
| 7603 | left-aligned text. | - | ||||||||||||||||||
| 7604 | - | |||||||||||||||||||
| 7605 | The \a base argument specifies the base to use when converting the | - | ||||||||||||||||||
| 7606 | integer \a a to a string. The base must be between 2 and 36, with 8 | - | ||||||||||||||||||
| 7607 | giving octal, 10 decimal, and 16 hexadecimal numbers. | - | ||||||||||||||||||
| 7608 | - | |||||||||||||||||||
| 7609 | If \a fillChar is '0' (the number 0, ASCII 48), the locale's zero is | - | ||||||||||||||||||
| 7610 | used. For negative numbers, zero padding might appear before the | - | ||||||||||||||||||
| 7611 | minus sign. | - | ||||||||||||||||||
| 7612 | */ | - | ||||||||||||||||||
| 7613 | - | |||||||||||||||||||
| 7614 | /*! | - | ||||||||||||||||||
| 7615 | \overload arg() | - | ||||||||||||||||||
| 7616 | - | |||||||||||||||||||
| 7617 | \a fieldWidth specifies the minimum amount of space that \a a is | - | ||||||||||||||||||
| 7618 | padded to and filled with the character \a fillChar. A positive | - | ||||||||||||||||||
| 7619 | value produces right-aligned text; a negative value produces | - | ||||||||||||||||||
| 7620 | left-aligned text. | - | ||||||||||||||||||
| 7621 | - | |||||||||||||||||||
| 7622 | The \a base argument specifies the base to use when converting the | - | ||||||||||||||||||
| 7623 | integer \a a into a string. The base must be between 2 and 36, with | - | ||||||||||||||||||
| 7624 | 8 giving octal, 10 decimal, and 16 hexadecimal numbers. | - | ||||||||||||||||||
| 7625 | - | |||||||||||||||||||
| 7626 | If \a fillChar is '0' (the number 0, ASCII 48), the locale's zero is | - | ||||||||||||||||||
| 7627 | used. For negative numbers, zero padding might appear before the | - | ||||||||||||||||||
| 7628 | minus sign. | - | ||||||||||||||||||
| 7629 | */ | - | ||||||||||||||||||
| 7630 | QString QString::arg(qlonglong a, int fieldWidth, int base, QChar fillChar) const | - | ||||||||||||||||||
| 7631 | { | - | ||||||||||||||||||
| 7632 | ArgEscapeData d = findArgEscapes(*this); | - | ||||||||||||||||||
| 7633 | - | |||||||||||||||||||
| 7634 | if (d.occurrences == 0) {
| 6-228842 | ||||||||||||||||||
| 7635 | qWarning() << "QString::arg: Argument missing:" << *this << ',' << a; | - | ||||||||||||||||||
| 7636 | return *this; executed 6 times by 1 test: return *this;Executed by:
| 6 | ||||||||||||||||||
| 7637 | } | - | ||||||||||||||||||
| 7638 | - | |||||||||||||||||||
| 7639 | unsigned flags = QLocaleData::NoFlags; | - | ||||||||||||||||||
| 7640 | if (fillChar == QLatin1Char('0'))
| 39-228803 | ||||||||||||||||||
| 7641 | flags = QLocaleData::ZeroPadded; executed 39 times by 4 tests: flags = QLocaleData::ZeroPadded;Executed by:
| 39 | ||||||||||||||||||
| 7642 | - | |||||||||||||||||||
| 7643 | QString arg; | - | ||||||||||||||||||
| 7644 | if (d.occurrences > d.locale_occurrences)
| 211-228631 | ||||||||||||||||||
| 7645 | arg = QLocaleData::c()->longLongToString(a, -1, base, fieldWidth, flags); executed 228631 times by 362 tests: arg = QLocaleData::c()->longLongToString(a, -1, base, fieldWidth, flags);Executed by:
| 228631 | ||||||||||||||||||
| 7646 | - | |||||||||||||||||||
| 7647 | QString locale_arg; | - | ||||||||||||||||||
| 7648 | if (d.locale_occurrences > 0) {
| 211-228631 | ||||||||||||||||||
| 7649 | QLocale locale; | - | ||||||||||||||||||
| 7650 | if (!(locale.numberOptions() & QLocale::OmitGroupSeparator))
| 2-209 | ||||||||||||||||||
| 7651 | flags |= QLocaleData::ThousandsGroup; executed 209 times by 2 tests: flags |= QLocaleData::ThousandsGroup;Executed by:
| 209 | ||||||||||||||||||
| 7652 | locale_arg = locale.d->m_data->longLongToString(a, -1, base, fieldWidth, flags); | - | ||||||||||||||||||
| 7653 | } executed 211 times by 2 tests: end of blockExecuted by:
| 211 | ||||||||||||||||||
| 7654 | - | |||||||||||||||||||
| 7655 | return replaceArgEscapes(*this, d, fieldWidth, arg, locale_arg, fillChar); executed 228842 times by 362 tests: return replaceArgEscapes(*this, d, fieldWidth, arg, locale_arg, fillChar);Executed by:
| 228842 | ||||||||||||||||||
| 7656 | } | - | ||||||||||||||||||
| 7657 | - | |||||||||||||||||||
| 7658 | /*! | - | ||||||||||||||||||
| 7659 | \overload arg() | - | ||||||||||||||||||
| 7660 | - | |||||||||||||||||||
| 7661 | \a fieldWidth specifies the minimum amount of space that \a a is | - | ||||||||||||||||||
| 7662 | padded to and filled with the character \a fillChar. A positive | - | ||||||||||||||||||
| 7663 | value produces right-aligned text; a negative value produces | - | ||||||||||||||||||
| 7664 | left-aligned text. | - | ||||||||||||||||||
| 7665 | - | |||||||||||||||||||
| 7666 | The \a base argument specifies the base to use when converting the | - | ||||||||||||||||||
| 7667 | integer \a a into a string. \a base must be between 2 and 36, with 8 | - | ||||||||||||||||||
| 7668 | giving octal, 10 decimal, and 16 hexadecimal numbers. | - | ||||||||||||||||||
| 7669 | - | |||||||||||||||||||
| 7670 | If \a fillChar is '0' (the number 0, ASCII 48), the locale's zero is | - | ||||||||||||||||||
| 7671 | used. For negative numbers, zero padding might appear before the | - | ||||||||||||||||||
| 7672 | minus sign. | - | ||||||||||||||||||
| 7673 | */ | - | ||||||||||||||||||
| 7674 | QString QString::arg(qulonglong a, int fieldWidth, int base, QChar fillChar) const | - | ||||||||||||||||||
| 7675 | { | - | ||||||||||||||||||
| 7676 | ArgEscapeData d = findArgEscapes(*this); | - | ||||||||||||||||||
| 7677 | - | |||||||||||||||||||
| 7678 | if (d.occurrences == 0) {
| 0-1019 | ||||||||||||||||||
| 7679 | qWarning() << "QString::arg: Argument missing:" << *this << ',' << a; | - | ||||||||||||||||||
| 7680 | return *this; never executed: return *this; | 0 | ||||||||||||||||||
| 7681 | } | - | ||||||||||||||||||
| 7682 | - | |||||||||||||||||||
| 7683 | unsigned flags = QLocaleData::NoFlags; | - | ||||||||||||||||||
| 7684 | if (fillChar == QLatin1Char('0'))
| 31-988 | ||||||||||||||||||
| 7685 | flags = QLocaleData::ZeroPadded; executed 988 times by 1 test: flags = QLocaleData::ZeroPadded;Executed by:
| 988 | ||||||||||||||||||
| 7686 | - | |||||||||||||||||||
| 7687 | QString arg; | - | ||||||||||||||||||
| 7688 | if (d.occurrences > d.locale_occurrences)
| 0-1019 | ||||||||||||||||||
| 7689 | arg = QLocaleData::c()->unsLongLongToString(a, -1, base, fieldWidth, flags); executed 1019 times by 8 tests: arg = QLocaleData::c()->unsLongLongToString(a, -1, base, fieldWidth, flags);Executed by:
| 1019 | ||||||||||||||||||
| 7690 | - | |||||||||||||||||||
| 7691 | QString locale_arg; | - | ||||||||||||||||||
| 7692 | if (d.locale_occurrences > 0) {
| 0-1019 | ||||||||||||||||||
| 7693 | QLocale locale; | - | ||||||||||||||||||
| 7694 | if (!(locale.numberOptions() & QLocale::OmitGroupSeparator))
| 0 | ||||||||||||||||||
| 7695 | flags |= QLocaleData::ThousandsGroup; never executed: flags |= QLocaleData::ThousandsGroup; | 0 | ||||||||||||||||||
| 7696 | locale_arg = locale.d->m_data->unsLongLongToString(a, -1, base, fieldWidth, flags); | - | ||||||||||||||||||
| 7697 | } never executed: end of block | 0 | ||||||||||||||||||
| 7698 | - | |||||||||||||||||||
| 7699 | return replaceArgEscapes(*this, d, fieldWidth, arg, locale_arg, fillChar); executed 1019 times by 8 tests: return replaceArgEscapes(*this, d, fieldWidth, arg, locale_arg, fillChar);Executed by:
| 1019 | ||||||||||||||||||
| 7700 | } | - | ||||||||||||||||||
| 7701 | - | |||||||||||||||||||
| 7702 | /*! | - | ||||||||||||||||||
| 7703 | \overload arg() | - | ||||||||||||||||||
| 7704 | - | |||||||||||||||||||
| 7705 | \fn QString QString::arg(short a, int fieldWidth, int base, QChar fillChar) const | - | ||||||||||||||||||
| 7706 | - | |||||||||||||||||||
| 7707 | \a fieldWidth specifies the minimum amount of space that \a a is | - | ||||||||||||||||||
| 7708 | padded to and filled with the character \a fillChar. A positive | - | ||||||||||||||||||
| 7709 | value produces right-aligned text; a negative value produces | - | ||||||||||||||||||
| 7710 | left-aligned text. | - | ||||||||||||||||||
| 7711 | - | |||||||||||||||||||
| 7712 | The \a base argument specifies the base to use when converting the | - | ||||||||||||||||||
| 7713 | integer \a a into a string. The base must be between 2 and 36, with | - | ||||||||||||||||||
| 7714 | 8 giving octal, 10 decimal, and 16 hexadecimal numbers. | - | ||||||||||||||||||
| 7715 | - | |||||||||||||||||||
| 7716 | If \a fillChar is '0' (the number 0, ASCII 48), the locale's zero is | - | ||||||||||||||||||
| 7717 | used. For negative numbers, zero padding might appear before the | - | ||||||||||||||||||
| 7718 | minus sign. | - | ||||||||||||||||||
| 7719 | */ | - | ||||||||||||||||||
| 7720 | - | |||||||||||||||||||
| 7721 | /*! | - | ||||||||||||||||||
| 7722 | \fn QString QString::arg(ushort a, int fieldWidth, int base, QChar fillChar) const | - | ||||||||||||||||||
| 7723 | \overload arg() | - | ||||||||||||||||||
| 7724 | - | |||||||||||||||||||
| 7725 | \a fieldWidth specifies the minimum amount of space that \a a is | - | ||||||||||||||||||
| 7726 | padded to and filled with the character \a fillChar. A positive | - | ||||||||||||||||||
| 7727 | value produces right-aligned text; a negative value produces | - | ||||||||||||||||||
| 7728 | left-aligned text. | - | ||||||||||||||||||
| 7729 | - | |||||||||||||||||||
| 7730 | The \a base argument specifies the base to use when converting the | - | ||||||||||||||||||
| 7731 | integer \a a into a string. The base must be between 2 and 36, with | - | ||||||||||||||||||
| 7732 | 8 giving octal, 10 decimal, and 16 hexadecimal numbers. | - | ||||||||||||||||||
| 7733 | - | |||||||||||||||||||
| 7734 | If \a fillChar is '0' (the number 0, ASCII 48), the locale's zero is | - | ||||||||||||||||||
| 7735 | used. For negative numbers, zero padding might appear before the | - | ||||||||||||||||||
| 7736 | minus sign. | - | ||||||||||||||||||
| 7737 | */ | - | ||||||||||||||||||
| 7738 | - | |||||||||||||||||||
| 7739 | /*! | - | ||||||||||||||||||
| 7740 | \overload arg() | - | ||||||||||||||||||
| 7741 | */ | - | ||||||||||||||||||
| 7742 | QString QString::arg(QChar a, int fieldWidth, QChar fillChar) const | - | ||||||||||||||||||
| 7743 | { | - | ||||||||||||||||||
| 7744 | QString c; | - | ||||||||||||||||||
| 7745 | c += a; | - | ||||||||||||||||||
| 7746 | return arg(c, fieldWidth, fillChar); executed 191 times by 8 tests: return arg(c, fieldWidth, fillChar);Executed by:
| 191 | ||||||||||||||||||
| 7747 | } | - | ||||||||||||||||||
| 7748 | - | |||||||||||||||||||
| 7749 | /*! | - | ||||||||||||||||||
| 7750 | \overload arg() | - | ||||||||||||||||||
| 7751 | - | |||||||||||||||||||
| 7752 | The \a a argument is interpreted as a Latin-1 character. | - | ||||||||||||||||||
| 7753 | */ | - | ||||||||||||||||||
| 7754 | QString QString::arg(char a, int fieldWidth, QChar fillChar) const | - | ||||||||||||||||||
| 7755 | { | - | ||||||||||||||||||
| 7756 | QString c; | - | ||||||||||||||||||
| 7757 | c += QLatin1Char(a); | - | ||||||||||||||||||
| 7758 | return arg(c, fieldWidth, fillChar); executed 1 time by 1 test: return arg(c, fieldWidth, fillChar);Executed by:
| 1 | ||||||||||||||||||
| 7759 | } | - | ||||||||||||||||||
| 7760 | - | |||||||||||||||||||
| 7761 | /*! | - | ||||||||||||||||||
| 7762 | \fn QString QString::arg(double a, int fieldWidth, char format, int precision, QChar fillChar) const | - | ||||||||||||||||||
| 7763 | \overload arg() | - | ||||||||||||||||||
| 7764 | - | |||||||||||||||||||
| 7765 | Argument \a a is formatted according to the specified \a format and | - | ||||||||||||||||||
| 7766 | \a precision. See \l{Argument Formats} for details. | - | ||||||||||||||||||
| 7767 | - | |||||||||||||||||||
| 7768 | \a fieldWidth specifies the minimum amount of space that \a a is | - | ||||||||||||||||||
| 7769 | padded to and filled with the character \a fillChar. A positive | - | ||||||||||||||||||
| 7770 | value produces right-aligned text; a negative value produces | - | ||||||||||||||||||
| 7771 | left-aligned text. | - | ||||||||||||||||||
| 7772 | - | |||||||||||||||||||
| 7773 | \snippet code/src_corelib_tools_qstring.cpp 2 | - | ||||||||||||||||||
| 7774 | - | |||||||||||||||||||
| 7775 | The '%' can be followed by an 'L', in which case the sequence is | - | ||||||||||||||||||
| 7776 | replaced with a localized representation of \a a. The conversion | - | ||||||||||||||||||
| 7777 | uses the default locale, set by QLocale::setDefault(). If no | - | ||||||||||||||||||
| 7778 | default locale was specified, the "C" locale is used. | - | ||||||||||||||||||
| 7779 | - | |||||||||||||||||||
| 7780 | If \a fillChar is '0' (the number 0, ASCII 48), this function will | - | ||||||||||||||||||
| 7781 | use the locale's zero to pad. For negative numbers, the zero padding | - | ||||||||||||||||||
| 7782 | will probably appear before the minus sign. | - | ||||||||||||||||||
| 7783 | - | |||||||||||||||||||
| 7784 | \sa QLocale::toString() | - | ||||||||||||||||||
| 7785 | */ | - | ||||||||||||||||||
| 7786 | QString QString::arg(double a, int fieldWidth, char fmt, int prec, QChar fillChar) const | - | ||||||||||||||||||
| 7787 | { | - | ||||||||||||||||||
| 7788 | ArgEscapeData d = findArgEscapes(*this); | - | ||||||||||||||||||
| 7789 | - | |||||||||||||||||||
| 7790 | if (d.occurrences == 0) {
| 0-95812 | ||||||||||||||||||
| 7791 | qWarning("QString::arg: Argument missing: %s, %g", toLocal8Bit().data(), a); | - | ||||||||||||||||||
| 7792 | return *this; never executed: return *this; | 0 | ||||||||||||||||||
| 7793 | } | - | ||||||||||||||||||
| 7794 | - | |||||||||||||||||||
| 7795 | unsigned flags = QLocaleData::NoFlags; | - | ||||||||||||||||||
| 7796 | if (fillChar == QLatin1Char('0'))
| 5-95807 | ||||||||||||||||||
| 7797 | flags = QLocaleData::ZeroPadded; executed 5 times by 1 test: flags = QLocaleData::ZeroPadded;Executed by:
| 5 | ||||||||||||||||||
| 7798 | - | |||||||||||||||||||
| 7799 | if (qIsUpper(fmt))
| 0-95812 | ||||||||||||||||||
| 7800 | flags |= QLocaleData::CapitalEorX; never executed: flags |= QLocaleData::CapitalEorX; | 0 | ||||||||||||||||||
| 7801 | fmt = qToLower(fmt); | - | ||||||||||||||||||
| 7802 | - | |||||||||||||||||||
| 7803 | QLocaleData::DoubleForm form = QLocaleData::DFDecimal; | - | ||||||||||||||||||
| 7804 | switch (fmt) { | - | ||||||||||||||||||
| 7805 | case 'f': never executed: case 'f': | 0 | ||||||||||||||||||
| 7806 | form = QLocaleData::DFDecimal; | - | ||||||||||||||||||
| 7807 | break; never executed: break; | 0 | ||||||||||||||||||
| 7808 | case 'e': never executed: case 'e': | 0 | ||||||||||||||||||
| 7809 | form = QLocaleData::DFExponent; | - | ||||||||||||||||||
| 7810 | break; never executed: break; | 0 | ||||||||||||||||||
| 7811 | case 'g': executed 95812 times by 7 tests: case 'g':Executed by:
| 95812 | ||||||||||||||||||
| 7812 | form = QLocaleData::DFSignificantDigits; | - | ||||||||||||||||||
| 7813 | break; executed 95812 times by 7 tests: break;Executed by:
| 95812 | ||||||||||||||||||
| 7814 | default: never executed: default: | 0 | ||||||||||||||||||
| 7815 | #if defined(QT_CHECK_RANGE) | - | ||||||||||||||||||
| 7816 | qWarning("QString::arg: Invalid format char '%c'", fmt); | - | ||||||||||||||||||
| 7817 | #endif | - | ||||||||||||||||||
| 7818 | break; never executed: break; | 0 | ||||||||||||||||||
| 7819 | } | - | ||||||||||||||||||
| 7820 | - | |||||||||||||||||||
| 7821 | QString arg; | - | ||||||||||||||||||
| 7822 | if (d.occurrences > d.locale_occurrences)
| 9-95803 | ||||||||||||||||||
| 7823 | arg = QLocaleData::c()->doubleToString(a, prec, form, fieldWidth, flags); executed 95803 times by 7 tests: arg = QLocaleData::c()->doubleToString(a, prec, form, fieldWidth, flags);Executed by:
| 95803 | ||||||||||||||||||
| 7824 | - | |||||||||||||||||||
| 7825 | QString locale_arg; | - | ||||||||||||||||||
| 7826 | if (d.locale_occurrences > 0) {
| 9-95803 | ||||||||||||||||||
| 7827 | QLocale locale; | - | ||||||||||||||||||
| 7828 | - | |||||||||||||||||||
| 7829 | if (!(locale.numberOptions() & QLocale::OmitGroupSeparator))
| 2-7 | ||||||||||||||||||
| 7830 | flags |= QLocaleData::ThousandsGroup; executed 7 times by 1 test: flags |= QLocaleData::ThousandsGroup;Executed by:
| 7 | ||||||||||||||||||
| 7831 | if (!(locale.numberOptions() & QLocale::OmitLeadingZeroInExponent))
| 0-9 | ||||||||||||||||||
| 7832 | flags |= QLocaleData::ZeroPadExponent; executed 9 times by 1 test: flags |= QLocaleData::ZeroPadExponent;Executed by:
| 9 | ||||||||||||||||||
| 7833 | locale_arg = locale.d->m_data->doubleToString(a, prec, form, fieldWidth, flags); | - | ||||||||||||||||||
| 7834 | } executed 9 times by 1 test: end of blockExecuted by:
| 9 | ||||||||||||||||||
| 7835 | - | |||||||||||||||||||
| 7836 | return replaceArgEscapes(*this, d, fieldWidth, arg, locale_arg, fillChar); executed 95812 times by 7 tests: return replaceArgEscapes(*this, d, fieldWidth, arg, locale_arg, fillChar);Executed by:
| 95812 | ||||||||||||||||||
| 7837 | } | - | ||||||||||||||||||
| 7838 | - | |||||||||||||||||||
| 7839 | static int getEscape(const QChar *uc, int *pos, int len, int maxNumber = 999) | - | ||||||||||||||||||
| 7840 | { | - | ||||||||||||||||||
| 7841 | int i = *pos; | - | ||||||||||||||||||
| 7842 | ++i; | - | ||||||||||||||||||
| 7843 | if (i < len && uc[i] == QLatin1Char('L'))
| 0-691605 | ||||||||||||||||||
| 7844 | ++i; never executed: ++i; | 0 | ||||||||||||||||||
| 7845 | if (i < len) {
| 0-691605 | ||||||||||||||||||
| 7846 | int escape = uc[i].unicode() - '0'; | - | ||||||||||||||||||
| 7847 | if (uint(escape) >= 10U)
| 4-691601 | ||||||||||||||||||
| 7848 | return -1; executed 4 times by 1 test: return -1;Executed by:
| 4 | ||||||||||||||||||
| 7849 | ++i; | - | ||||||||||||||||||
| 7850 | while (i < len) {
| 5190-686433 | ||||||||||||||||||
| 7851 | int digit = uc[i].unicode() - '0'; | - | ||||||||||||||||||
| 7852 | if (uint(digit) >= 10U)
| 22-686411 | ||||||||||||||||||
| 7853 | break; executed 686411 times by 331 tests: break;Executed by:
| 686411 | ||||||||||||||||||
| 7854 | escape = (escape * 10) + digit; | - | ||||||||||||||||||
| 7855 | ++i; | - | ||||||||||||||||||
| 7856 | } executed 22 times by 1 test: end of blockExecuted by:
| 22 | ||||||||||||||||||
| 7857 | if (escape <= maxNumber) {
| 2-691599 | ||||||||||||||||||
| 7858 | *pos = i; | - | ||||||||||||||||||
| 7859 | return escape; executed 691599 times by 331 tests: return escape;Executed by:
| 691599 | ||||||||||||||||||
| 7860 | } | - | ||||||||||||||||||
| 7861 | } executed 2 times by 1 test: end of blockExecuted by:
| 2 | ||||||||||||||||||
| 7862 | return -1; executed 2 times by 1 test: return -1;Executed by:
| 2 | ||||||||||||||||||
| 7863 | } | - | ||||||||||||||||||
| 7864 | - | |||||||||||||||||||
| 7865 | /* | - | ||||||||||||||||||
| 7866 | Algorithm for multiArg: | - | ||||||||||||||||||
| 7867 | - | |||||||||||||||||||
| 7868 | 1. Parse the string as a sequence of verbatim text and placeholders (%L?\d{,3}). | - | ||||||||||||||||||
| 7869 | The L is parsed and accepted for compatibility with non-multi-arg, but since | - | ||||||||||||||||||
| 7870 | multiArg only accepts strings as replacements, the localization request can | - | ||||||||||||||||||
| 7871 | be safely ignored. | - | ||||||||||||||||||
| 7872 | 2. The result of step (1) is a list of (string-ref,int)-tuples. The string-ref | - | ||||||||||||||||||
| 7873 | either points at text to be copied verbatim (in which case the int is -1), | - | ||||||||||||||||||
| 7874 | or, initially, at the textual representation of the placeholder. In that case, | - | ||||||||||||||||||
| 7875 | the int contains the numerical number as parsed from the placeholder. | - | ||||||||||||||||||
| 7876 | 3. Next, collect all the non-negative ints found, sort them in ascending order and | - | ||||||||||||||||||
| 7877 | remove duplicates. | - | ||||||||||||||||||
| 7878 | 3a. If the result has more entires than multiArg() was given replacement strings, | - | ||||||||||||||||||
| 7879 | we have found placeholders we can't satisfy with replacement strings. That is | - | ||||||||||||||||||
| 7880 | fine (there could be another .arg() call coming after this one), so just | - | ||||||||||||||||||
| 7881 | truncate the result to the number of actual multiArg() replacement strings. | - | ||||||||||||||||||
| 7882 | 3b. If the result has less entries than multiArg() was given replacement strings, | - | ||||||||||||||||||
| 7883 | the string is missing placeholders. This is an error that the user should be | - | ||||||||||||||||||
| 7884 | warned about. | - | ||||||||||||||||||
| 7885 | 4. The result of step (3) is a mapping from the index of any replacement string to | - | ||||||||||||||||||
| 7886 | placeholder number. This is the wrong way around, but since placeholder | - | ||||||||||||||||||
| 7887 | numbers could get as large as 999, while we typically don't have more than 9 | - | ||||||||||||||||||
| 7888 | replacement strings, we trade 4K of sparsely-used memory for doing a reverse lookup | - | ||||||||||||||||||
| 7889 | each time we need to map a placeholder number to a replacement string index | - | ||||||||||||||||||
| 7890 | (that's a linear search; but still *much* faster than using an associative container). | - | ||||||||||||||||||
| 7891 | 5. Next, for each of the tuples found in step (1), do the following: | - | ||||||||||||||||||
| 7892 | 5a. If the int is negative, do nothing. | - | ||||||||||||||||||
| 7893 | 5b. Otherwise, if the int is found in the result of step (3) at index I, replace | - | ||||||||||||||||||
| 7894 | the string-ref with a string-ref for the (complete) I'th replacement string. | - | ||||||||||||||||||
| 7895 | 5c. Otherwise, do nothing. | - | ||||||||||||||||||
| 7896 | 6. Concatenate all string refs into a single result string. | - | ||||||||||||||||||
| 7897 | */ | - | ||||||||||||||||||
| 7898 | - | |||||||||||||||||||
| 7899 | namespace { | - | ||||||||||||||||||
| 7900 | struct Part | - | ||||||||||||||||||
| 7901 | { | - | ||||||||||||||||||
| 7902 | Part() : stringRef(), number(0) {} never executed: end of block | 0 | ||||||||||||||||||
| 7903 | Part(const QString &s, int pos, int len, int num = -1) Q_DECL_NOTHROW | - | ||||||||||||||||||
| 7904 | : stringRef(&s, pos, len), number(num) {} executed 1547777 times by 331 tests: end of blockExecuted by:
| 1547777 | ||||||||||||||||||
| 7905 | - | |||||||||||||||||||
| 7906 | QStringRef stringRef; | - | ||||||||||||||||||
| 7907 | int number; | - | ||||||||||||||||||
| 7908 | }; | - | ||||||||||||||||||
| 7909 | } // unnamed namespace | - | ||||||||||||||||||
| 7910 | - | |||||||||||||||||||
| 7911 | template <> | - | ||||||||||||||||||
| 7912 | class QTypeInfo<Part> : public QTypeInfoMerger<Part, QStringRef, int> {}; // Q_DECLARE_METATYPE | - | ||||||||||||||||||
| 7913 | - | |||||||||||||||||||
| 7914 | - | |||||||||||||||||||
| 7915 | namespace { | - | ||||||||||||||||||
| 7916 | - | |||||||||||||||||||
| 7917 | enum { ExpectedParts = 32 }; | - | ||||||||||||||||||
| 7918 | - | |||||||||||||||||||
| 7919 | typedef QVarLengthArray<Part, ExpectedParts> ParseResult; | - | ||||||||||||||||||
| 7920 | typedef QVarLengthArray<int, ExpectedParts/2> ArgIndexToPlaceholderMap; | - | ||||||||||||||||||
| 7921 | - | |||||||||||||||||||
| 7922 | static ParseResult parseMultiArgFormatString(const QString &s) | - | ||||||||||||||||||
| 7923 | { | - | ||||||||||||||||||
| 7924 | ParseResult result; | - | ||||||||||||||||||
| 7925 | - | |||||||||||||||||||
| 7926 | const QChar *uc = s.constData(); | - | ||||||||||||||||||
| 7927 | const int len = s.size(); | - | ||||||||||||||||||
| 7928 | const int end = len - 1; | - | ||||||||||||||||||
| 7929 | int i = 0; | - | ||||||||||||||||||
| 7930 | int last = 0; | - | ||||||||||||||||||
| 7931 | - | |||||||||||||||||||
| 7932 | while (i < end) {
| 180495-6706850 | ||||||||||||||||||
| 7933 | if (uc[i] == QLatin1Char('%')) {
| 691605-6015245 | ||||||||||||||||||
| 7934 | int percent = i; | - | ||||||||||||||||||
| 7935 | int number = getEscape(uc, &i, len); | - | ||||||||||||||||||
| 7936 | if (number != -1) {
| 6-691599 | ||||||||||||||||||
| 7937 | if (last != percent)
| 10727-680872 | ||||||||||||||||||
| 7938 | result.push_back(Part(s, last, percent - last)); // literal text (incl. failed placeholders) executed 680872 times by 331 tests: result.push_back(Part(s, last, percent - last));Executed by:
| 680872 | ||||||||||||||||||
| 7939 | result.push_back(Part(s, percent, i - percent, number)); // parsed placeholder | - | ||||||||||||||||||
| 7940 | last = i; | - | ||||||||||||||||||
| 7941 | continue; executed 691599 times by 331 tests: continue;Executed by:
| 691599 | ||||||||||||||||||
| 7942 | } | - | ||||||||||||||||||
| 7943 | } executed 6 times by 1 test: end of blockExecuted by:
| 6 | ||||||||||||||||||
| 7944 | ++i; | - | ||||||||||||||||||
| 7945 | } executed 6015251 times by 331 tests: end of blockExecuted by:
| 6015251 | ||||||||||||||||||
| 7946 | - | |||||||||||||||||||
| 7947 | if (last < len)
| 5189-175306 | ||||||||||||||||||
| 7948 | result.push_back(Part(s, last, len - last)); // trailing literal text executed 175306 times by 313 tests: result.push_back(Part(s, last, len - last));Executed by:
| 175306 | ||||||||||||||||||
| 7949 | - | |||||||||||||||||||
| 7950 | return result; executed 180495 times by 331 tests: return result;Executed by:
| 180495 | ||||||||||||||||||
| 7951 | } | - | ||||||||||||||||||
| 7952 | - | |||||||||||||||||||
| 7953 | static ArgIndexToPlaceholderMap makeArgIndexToPlaceholderMap(const ParseResult &parts) | - | ||||||||||||||||||
| 7954 | { | - | ||||||||||||||||||
| 7955 | ArgIndexToPlaceholderMap result; | - | ||||||||||||||||||
| 7956 | - | |||||||||||||||||||
| 7957 | for (ParseResult::const_iterator it = parts.begin(), end = parts.end(); it != end; ++it) {
| 180495-1547777 | ||||||||||||||||||
| 7958 | if (it->number >= 0)
| 691599-856178 | ||||||||||||||||||
| 7959 | result.push_back(it->number); executed 691599 times by 331 tests: result.push_back(it->number);Executed by:
| 691599 | ||||||||||||||||||
| 7960 | } executed 1547777 times by 331 tests: end of blockExecuted by:
| 1547777 | ||||||||||||||||||
| 7961 | - | |||||||||||||||||||
| 7962 | std::sort(result.begin(), result.end()); | - | ||||||||||||||||||
| 7963 | result.erase(std::unique(result.begin(), result.end()), | - | ||||||||||||||||||
| 7964 | result.end()); | - | ||||||||||||||||||
| 7965 | - | |||||||||||||||||||
| 7966 | return result; executed 180495 times by 331 tests: return result;Executed by:
| 180495 | ||||||||||||||||||
| 7967 | } | - | ||||||||||||||||||
| 7968 | - | |||||||||||||||||||
| 7969 | static int resolveStringRefsAndReturnTotalSize(ParseResult &parts, const ArgIndexToPlaceholderMap &argIndexToPlaceholderMap, const QString *args[]) | - | ||||||||||||||||||
| 7970 | { | - | ||||||||||||||||||
| 7971 | int totalSize = 0; | - | ||||||||||||||||||
| 7972 | for (ParseResult::iterator pit = parts.begin(), end = parts.end(); pit != end; ++pit) {
| 180495-1547777 | ||||||||||||||||||
| 7973 | if (pit->number != -1) {
| 691599-856178 | ||||||||||||||||||
| 7974 | const ArgIndexToPlaceholderMap::const_iterator ait | - | ||||||||||||||||||
| 7975 | = std::find(argIndexToPlaceholderMap.begin(), argIndexToPlaceholderMap.end(), pit->number); | - | ||||||||||||||||||
| 7976 | if (ait != argIndexToPlaceholderMap.end())
| 29-691570 | ||||||||||||||||||
| 7977 | pit->stringRef = QStringRef(args[ait - argIndexToPlaceholderMap.begin()]); executed 691570 times by 331 tests: pit->stringRef = QStringRef(args[ait - argIndexToPlaceholderMap.begin()]);Executed by:
| 691570 | ||||||||||||||||||
| 7978 | } executed 691599 times by 331 tests: end of blockExecuted by:
| 691599 | ||||||||||||||||||
| 7979 | totalSize += pit->stringRef.size(); | - | ||||||||||||||||||
| 7980 | } executed 1547777 times by 331 tests: end of blockExecuted by:
| 1547777 | ||||||||||||||||||
| 7981 | return totalSize; executed 180495 times by 331 tests: return totalSize;Executed by:
| 180495 | ||||||||||||||||||
| 7982 | } | - | ||||||||||||||||||
| 7983 | - | |||||||||||||||||||
| 7984 | } // unnamed namespace | - | ||||||||||||||||||
| 7985 | - | |||||||||||||||||||
| 7986 | QString QString::multiArg(int numArgs, const QString **args) const | - | ||||||||||||||||||
| 7987 | { | - | ||||||||||||||||||
| 7988 | // Step 1-2 above | - | ||||||||||||||||||
| 7989 | ParseResult parts = parseMultiArgFormatString(*this); | - | ||||||||||||||||||
| 7990 | - | |||||||||||||||||||
| 7991 | // 3-4 | - | ||||||||||||||||||
| 7992 | ArgIndexToPlaceholderMap argIndexToPlaceholderMap = makeArgIndexToPlaceholderMap(parts); | - | ||||||||||||||||||
| 7993 | - | |||||||||||||||||||
| 7994 | if (argIndexToPlaceholderMap.size() > numArgs) // 3a
| 27-180468 | ||||||||||||||||||
| 7995 | argIndexToPlaceholderMap.resize(numArgs); executed 27 times by 2 tests: argIndexToPlaceholderMap.resize(numArgs);Executed by:
| 27 | ||||||||||||||||||
| 7996 | else if (argIndexToPlaceholderMap.size() < numArgs) // 3b
| 0-180468 | ||||||||||||||||||
| 7997 | qWarning("QString::arg: %d argument(s) missing in %s", never executed: QMessageLogger(__FILE__, 7997, __PRETTY_FUNCTION__).warning("QString::arg: %d argument(s) missing in %s", numArgs - argIndexToPlaceholderMap.size(), toLocal8Bit().data()); | 0 | ||||||||||||||||||
| 7998 | numArgs - argIndexToPlaceholderMap.size(), toLocal8Bit().data()); never executed: QMessageLogger(__FILE__, 7997, __PRETTY_FUNCTION__).warning("QString::arg: %d argument(s) missing in %s", numArgs - argIndexToPlaceholderMap.size(), toLocal8Bit().data()); | 0 | ||||||||||||||||||
| 7999 | - | |||||||||||||||||||
| 8000 | // 5 | - | ||||||||||||||||||
| 8001 | const int totalSize = resolveStringRefsAndReturnTotalSize(parts, argIndexToPlaceholderMap, args); | - | ||||||||||||||||||
| 8002 | - | |||||||||||||||||||
| 8003 | // 6: | - | ||||||||||||||||||
| 8004 | QString result(totalSize, Qt::Uninitialized); | - | ||||||||||||||||||
| 8005 | QChar *out = result.data(); | - | ||||||||||||||||||
| 8006 | - | |||||||||||||||||||
| 8007 | for (ParseResult::const_iterator it = parts.begin(), end = parts.end(); it != end; ++it) {
| 180495-1547777 | ||||||||||||||||||
| 8008 | if (const int sz = it->stringRef.size()) {
| 3326-1544451 | ||||||||||||||||||
| 8009 | memcpy(out, it->stringRef.constData(), sz * sizeof(QChar)); | - | ||||||||||||||||||
| 8010 | out += sz; | - | ||||||||||||||||||
| 8011 | } executed 1544451 times by 331 tests: end of blockExecuted by:
| 1544451 | ||||||||||||||||||
| 8012 | } executed 1547777 times by 331 tests: end of blockExecuted by:
| 1547777 | ||||||||||||||||||
| 8013 | - | |||||||||||||||||||
| 8014 | return result; executed 180495 times by 331 tests: return result;Executed by:
| 180495 | ||||||||||||||||||
| 8015 | } | - | ||||||||||||||||||
| 8016 | - | |||||||||||||||||||
| 8017 | - | |||||||||||||||||||
| 8018 | /*! \fn QString QString::fromCFString(CFStringRef string) | - | ||||||||||||||||||
| 8019 | \since 5.2 | - | ||||||||||||||||||
| 8020 | - | |||||||||||||||||||
| 8021 | Constructs a new QString containing a copy of the \a string CFString. | - | ||||||||||||||||||
| 8022 | - | |||||||||||||||||||
| 8023 | \note this function is only available on \macos and iOS. | - | ||||||||||||||||||
| 8024 | */ | - | ||||||||||||||||||
| 8025 | - | |||||||||||||||||||
| 8026 | /*! \fn CFStringRef QString::toCFString() const | - | ||||||||||||||||||
| 8027 | \since 5.2 | - | ||||||||||||||||||
| 8028 | - | |||||||||||||||||||
| 8029 | Creates a CFString from a QString. The caller owns the CFString and is | - | ||||||||||||||||||
| 8030 | responsible for releasing it. | - | ||||||||||||||||||
| 8031 | - | |||||||||||||||||||
| 8032 | \note this function is only available on \macos and iOS. | - | ||||||||||||||||||
| 8033 | */ | - | ||||||||||||||||||
| 8034 | - | |||||||||||||||||||
| 8035 | /*! \fn QString QString::fromNSString(const NSString *string) | - | ||||||||||||||||||
| 8036 | \since 5.2 | - | ||||||||||||||||||
| 8037 | - | |||||||||||||||||||
| 8038 | Constructs a new QString containing a copy of the \a string NSString. | - | ||||||||||||||||||
| 8039 | - | |||||||||||||||||||
| 8040 | \note this function is only available on \macos and iOS. | - | ||||||||||||||||||
| 8041 | */ | - | ||||||||||||||||||
| 8042 | - | |||||||||||||||||||
| 8043 | /*! \fn NSString QString::toNSString() const | - | ||||||||||||||||||
| 8044 | \since 5.2 | - | ||||||||||||||||||
| 8045 | - | |||||||||||||||||||
| 8046 | Creates a NSString from a QString. The NSString is autoreleased. | - | ||||||||||||||||||
| 8047 | - | |||||||||||||||||||
| 8048 | \note this function is only available on \macos and iOS. | - | ||||||||||||||||||
| 8049 | */ | - | ||||||||||||||||||
| 8050 | - | |||||||||||||||||||
| 8051 | /*! \fn bool QString::isSimpleText() const | - | ||||||||||||||||||
| 8052 | - | |||||||||||||||||||
| 8053 | \internal | - | ||||||||||||||||||
| 8054 | */ | - | ||||||||||||||||||
| 8055 | bool QString::isSimpleText() const | - | ||||||||||||||||||
| 8056 | { | - | ||||||||||||||||||
| 8057 | const ushort *p = d->data(); | - | ||||||||||||||||||
| 8058 | const ushort * const end = p + d->size; | - | ||||||||||||||||||
| 8059 | while (p < end) {
| 0 | ||||||||||||||||||
| 8060 | ushort uc = *p; | - | ||||||||||||||||||
| 8061 | // sort out regions of complex text formatting | - | ||||||||||||||||||
| 8062 | if (uc > 0x058f && (uc < 0x1100 || uc > 0xfb0f)) {
| 0 | ||||||||||||||||||
| 8063 | return false; never executed: return false; | 0 | ||||||||||||||||||
| 8064 | } | - | ||||||||||||||||||
| 8065 | p++; | - | ||||||||||||||||||
| 8066 | } never executed: end of block | 0 | ||||||||||||||||||
| 8067 | - | |||||||||||||||||||
| 8068 | return true; never executed: return true; | 0 | ||||||||||||||||||
| 8069 | } | - | ||||||||||||||||||
| 8070 | - | |||||||||||||||||||
| 8071 | /*! \fn bool QString::isRightToLeft() const | - | ||||||||||||||||||
| 8072 | - | |||||||||||||||||||
| 8073 | Returns \c true if the string is read right to left. | - | ||||||||||||||||||
| 8074 | */ | - | ||||||||||||||||||
| 8075 | bool QString::isRightToLeft() const | - | ||||||||||||||||||
| 8076 | { | - | ||||||||||||||||||
| 8077 | const ushort *p = d->data(); | - | ||||||||||||||||||
| 8078 | const ushort * const end = p + d->size; | - | ||||||||||||||||||
| 8079 | while (p < end) {
| 101798-783037 | ||||||||||||||||||
| 8080 | uint ucs4 = *p; | - | ||||||||||||||||||
| 8081 | if (QChar::isHighSurrogate(ucs4) && p < end - 1) {
| 0-783027 | ||||||||||||||||||
| 8082 | ushort low = p[1]; | - | ||||||||||||||||||
| 8083 | if (QChar::isLowSurrogate(low)) {
| 0-10 | ||||||||||||||||||
| 8084 | ucs4 = QChar::surrogateToUcs4(ucs4, low); | - | ||||||||||||||||||
| 8085 | ++p; | - | ||||||||||||||||||
| 8086 | } executed 10 times by 2 tests: end of blockExecuted by:
| 10 | ||||||||||||||||||
| 8087 | } executed 10 times by 2 tests: end of blockExecuted by:
| 10 | ||||||||||||||||||
| 8088 | switch (QChar::direction(ucs4)) | - | ||||||||||||||||||
| 8089 | { | - | ||||||||||||||||||
| 8090 | case QChar::DirL: executed 71112 times by 93 tests: case QChar::DirL:Executed by:
| 71112 | ||||||||||||||||||
| 8091 | return false; executed 71112 times by 93 tests: return false;Executed by:
| 71112 | ||||||||||||||||||
| 8092 | case QChar::DirR: executed 572 times by 5 tests: case QChar::DirR:Executed by:
| 572 | ||||||||||||||||||
| 8093 | case QChar::DirAL: executed 21 times by 5 tests: case QChar::DirAL:Executed by:
| 21 | ||||||||||||||||||
| 8094 | return true; executed 593 times by 9 tests: return true;Executed by:
| 593 | ||||||||||||||||||
| 8095 | default: executed 711332 times by 61 tests: default:Executed by:
| 711332 | ||||||||||||||||||
| 8096 | break; executed 711332 times by 61 tests: break;Executed by:
| 711332 | ||||||||||||||||||
| 8097 | } | - | ||||||||||||||||||
| 8098 | ++p; | - | ||||||||||||||||||
| 8099 | } executed 711332 times by 61 tests: end of blockExecuted by:
| 711332 | ||||||||||||||||||
| 8100 | return false; executed 101798 times by 52 tests: return false;Executed by:
| 101798 | ||||||||||||||||||
| 8101 | } | - | ||||||||||||||||||
| 8102 | - | |||||||||||||||||||
| 8103 | /*! \fn QChar *QString::data() | - | ||||||||||||||||||
| 8104 | - | |||||||||||||||||||
| 8105 | Returns a pointer to the data stored in the QString. The pointer | - | ||||||||||||||||||
| 8106 | can be used to access and modify the characters that compose the | - | ||||||||||||||||||
| 8107 | string. For convenience, the data is '\\0'-terminated. | - | ||||||||||||||||||
| 8108 | - | |||||||||||||||||||
| 8109 | Example: | - | ||||||||||||||||||
| 8110 | - | |||||||||||||||||||
| 8111 | \snippet qstring/main.cpp 19 | - | ||||||||||||||||||
| 8112 | - | |||||||||||||||||||
| 8113 | Note that the pointer remains valid only as long as the string is | - | ||||||||||||||||||
| 8114 | not modified by other means. For read-only access, constData() is | - | ||||||||||||||||||
| 8115 | faster because it never causes a \l{deep copy} to occur. | - | ||||||||||||||||||
| 8116 | - | |||||||||||||||||||
| 8117 | \sa constData(), operator[]() | - | ||||||||||||||||||
| 8118 | */ | - | ||||||||||||||||||
| 8119 | - | |||||||||||||||||||
| 8120 | /*! \fn const QChar *QString::data() const | - | ||||||||||||||||||
| 8121 | - | |||||||||||||||||||
| 8122 | \overload | - | ||||||||||||||||||
| 8123 | */ | - | ||||||||||||||||||
| 8124 | - | |||||||||||||||||||
| 8125 | /*! \fn const QChar *QString::constData() const | - | ||||||||||||||||||
| 8126 | - | |||||||||||||||||||
| 8127 | Returns a pointer to the data stored in the QString. The pointer | - | ||||||||||||||||||
| 8128 | can be used to access the characters that compose the string. For | - | ||||||||||||||||||
| 8129 | convenience, the data is '\\0'-terminated. | - | ||||||||||||||||||
| 8130 | - | |||||||||||||||||||
| 8131 | Note that the pointer remains valid only as long as the string is | - | ||||||||||||||||||
| 8132 | not modified. | - | ||||||||||||||||||
| 8133 | - | |||||||||||||||||||
| 8134 | \sa data(), operator[]() | - | ||||||||||||||||||
| 8135 | */ | - | ||||||||||||||||||
| 8136 | - | |||||||||||||||||||
| 8137 | /*! \fn void QString::push_front(const QString &other) | - | ||||||||||||||||||
| 8138 | - | |||||||||||||||||||
| 8139 | This function is provided for STL compatibility, prepending the | - | ||||||||||||||||||
| 8140 | given \a other string to the beginning of this string. It is | - | ||||||||||||||||||
| 8141 | equivalent to \c prepend(other). | - | ||||||||||||||||||
| 8142 | - | |||||||||||||||||||
| 8143 | \sa prepend() | - | ||||||||||||||||||
| 8144 | */ | - | ||||||||||||||||||
| 8145 | - | |||||||||||||||||||
| 8146 | /*! \fn void QString::push_front(QChar ch) | - | ||||||||||||||||||
| 8147 | - | |||||||||||||||||||
| 8148 | \overload | - | ||||||||||||||||||
| 8149 | - | |||||||||||||||||||
| 8150 | Prepends the given \a ch character to the beginning of this string. | - | ||||||||||||||||||
| 8151 | */ | - | ||||||||||||||||||
| 8152 | - | |||||||||||||||||||
| 8153 | /*! \fn void QString::push_back(const QString &other) | - | ||||||||||||||||||
| 8154 | - | |||||||||||||||||||
| 8155 | This function is provided for STL compatibility, appending the | - | ||||||||||||||||||
| 8156 | given \a other string onto the end of this string. It is | - | ||||||||||||||||||
| 8157 | equivalent to \c append(other). | - | ||||||||||||||||||
| 8158 | - | |||||||||||||||||||
| 8159 | \sa append() | - | ||||||||||||||||||
| 8160 | */ | - | ||||||||||||||||||
| 8161 | - | |||||||||||||||||||
| 8162 | /*! \fn void QString::push_back(QChar ch) | - | ||||||||||||||||||
| 8163 | - | |||||||||||||||||||
| 8164 | \overload | - | ||||||||||||||||||
| 8165 | - | |||||||||||||||||||
| 8166 | Appends the given \a ch character onto the end of this string. | - | ||||||||||||||||||
| 8167 | */ | - | ||||||||||||||||||
| 8168 | - | |||||||||||||||||||
| 8169 | /*! | - | ||||||||||||||||||
| 8170 | \fn std::string QString::toStdString() const | - | ||||||||||||||||||
| 8171 | - | |||||||||||||||||||
| 8172 | Returns a std::string object with the data contained in this | - | ||||||||||||||||||
| 8173 | QString. The Unicode data is converted into 8-bit characters using | - | ||||||||||||||||||
| 8174 | the toUtf8() function. | - | ||||||||||||||||||
| 8175 | - | |||||||||||||||||||
| 8176 | This method is mostly useful to pass a QString to a function | - | ||||||||||||||||||
| 8177 | that accepts a std::string object. | - | ||||||||||||||||||
| 8178 | - | |||||||||||||||||||
| 8179 | \sa toLatin1(), toUtf8(), toLocal8Bit(), QByteArray::toStdString() | - | ||||||||||||||||||
| 8180 | */ | - | ||||||||||||||||||
| 8181 | - | |||||||||||||||||||
| 8182 | /*! | - | ||||||||||||||||||
| 8183 | Constructs a QString that uses the first \a size Unicode characters | - | ||||||||||||||||||
| 8184 | in the array \a unicode. The data in \a unicode is \e not | - | ||||||||||||||||||
| 8185 | copied. The caller must be able to guarantee that \a unicode will | - | ||||||||||||||||||
| 8186 | not be deleted or modified as long as the QString (or an | - | ||||||||||||||||||
| 8187 | unmodified copy of it) exists. | - | ||||||||||||||||||
| 8188 | - | |||||||||||||||||||
| 8189 | Any attempts to modify the QString or copies of it will cause it | - | ||||||||||||||||||
| 8190 | to create a deep copy of the data, ensuring that the raw data | - | ||||||||||||||||||
| 8191 | isn't modified. | - | ||||||||||||||||||
| 8192 | - | |||||||||||||||||||
| 8193 | Here's an example of how we can use a QRegExp on raw data in | - | ||||||||||||||||||
| 8194 | memory without requiring to copy the data into a QString: | - | ||||||||||||||||||
| 8195 | - | |||||||||||||||||||
| 8196 | \snippet qstring/main.cpp 22 | - | ||||||||||||||||||
| 8197 | \snippet qstring/main.cpp 23 | - | ||||||||||||||||||
| 8198 | - | |||||||||||||||||||
| 8199 | \warning A string created with fromRawData() is \e not | - | ||||||||||||||||||
| 8200 | '\\0'-terminated, unless the raw data contains a '\\0' character | - | ||||||||||||||||||
| 8201 | at position \a size. This means unicode() will \e not return a | - | ||||||||||||||||||
| 8202 | '\\0'-terminated string (although utf16() does, at the cost of | - | ||||||||||||||||||
| 8203 | copying the raw data). | - | ||||||||||||||||||
| 8204 | - | |||||||||||||||||||
| 8205 | \sa fromUtf16(), setRawData() | - | ||||||||||||||||||
| 8206 | */ | - | ||||||||||||||||||
| 8207 | QString QString::fromRawData(const QChar *unicode, int size) | - | ||||||||||||||||||
| 8208 | { | - | ||||||||||||||||||
| 8209 | Data *x; | - | ||||||||||||||||||
| 8210 | if (!unicode) {
| 2-65226 | ||||||||||||||||||
| 8211 | x = Data::sharedNull(); | - | ||||||||||||||||||
| 8212 | } else if (!size) { executed 2 times by 1 test: end of blockExecuted by:
| 2-65215 | ||||||||||||||||||
| 8213 | x = Data::allocate(0); | - | ||||||||||||||||||
| 8214 | } else { executed 11 times by 1 test: end of blockExecuted by:
| 11 | ||||||||||||||||||
| 8215 | x = Data::fromRawData(reinterpret_cast<const ushort *>(unicode), size); | - | ||||||||||||||||||
| 8216 | Q_CHECK_PTR(x); never executed: qBadAlloc();
| 0-65215 | ||||||||||||||||||
| 8217 | } executed 65215 times by 87 tests: end of blockExecuted by:
| 65215 | ||||||||||||||||||
| 8218 | QStringDataPtr dataPtr = { x }; | - | ||||||||||||||||||
| 8219 | return QString(dataPtr); executed 65228 times by 87 tests: return QString(dataPtr);Executed by:
| 65228 | ||||||||||||||||||
| 8220 | } | - | ||||||||||||||||||
| 8221 | - | |||||||||||||||||||
| 8222 | /*! | - | ||||||||||||||||||
| 8223 | \since 4.7 | - | ||||||||||||||||||
| 8224 | - | |||||||||||||||||||
| 8225 | Resets the QString to use the first \a size Unicode characters | - | ||||||||||||||||||
| 8226 | in the array \a unicode. The data in \a unicode is \e not | - | ||||||||||||||||||
| 8227 | copied. The caller must be able to guarantee that \a unicode will | - | ||||||||||||||||||
| 8228 | not be deleted or modified as long as the QString (or an | - | ||||||||||||||||||
| 8229 | unmodified copy of it) exists. | - | ||||||||||||||||||
| 8230 | - | |||||||||||||||||||
| 8231 | This function can be used instead of fromRawData() to re-use | - | ||||||||||||||||||
| 8232 | existings QString objects to save memory re-allocations. | - | ||||||||||||||||||
| 8233 | - | |||||||||||||||||||
| 8234 | \sa fromRawData() | - | ||||||||||||||||||
| 8235 | */ | - | ||||||||||||||||||
| 8236 | QString &QString::setRawData(const QChar *unicode, int size) | - | ||||||||||||||||||
| 8237 | { | - | ||||||||||||||||||
| 8238 | if (d->ref.isShared() || d->alloc) {
| 1-745 | ||||||||||||||||||
| 8239 | *this = fromRawData(unicode, size); | - | ||||||||||||||||||
| 8240 | } else { executed 746 times by 2 tests: end of blockExecuted by:
| 746 | ||||||||||||||||||
| 8241 | if (unicode) {
| 0-575 | ||||||||||||||||||
| 8242 | d->size = size; | - | ||||||||||||||||||
| 8243 | d->offset = reinterpret_cast<const char *>(unicode) - reinterpret_cast<char *>(d); | - | ||||||||||||||||||
| 8244 | } else { executed 575 times by 2 tests: end of blockExecuted by:
| 575 | ||||||||||||||||||
| 8245 | d->offset = sizeof(QStringData); | - | ||||||||||||||||||
| 8246 | d->size = 0; | - | ||||||||||||||||||
| 8247 | } never executed: end of block | 0 | ||||||||||||||||||
| 8248 | } | - | ||||||||||||||||||
| 8249 | return *this; executed 1321 times by 2 tests: return *this;Executed by:
| 1321 | ||||||||||||||||||
| 8250 | } | - | ||||||||||||||||||
| 8251 | - | |||||||||||||||||||
| 8252 | /*! \fn QString QString::fromStdU16String(const std::u16string &str) | - | ||||||||||||||||||
| 8253 | \since 5.5 | - | ||||||||||||||||||
| 8254 | - | |||||||||||||||||||
| 8255 | Returns a copy of the \a str string. The given string is assumed | - | ||||||||||||||||||
| 8256 | to be encoded in UTF-16. | - | ||||||||||||||||||
| 8257 | - | |||||||||||||||||||
| 8258 | \sa fromUtf16(), fromStdWString(), fromStdU32String() | - | ||||||||||||||||||
| 8259 | */ | - | ||||||||||||||||||
| 8260 | - | |||||||||||||||||||
| 8261 | /*! | - | ||||||||||||||||||
| 8262 | \fn std::u16string QString::toStdU16String() const | - | ||||||||||||||||||
| 8263 | \since 5.5 | - | ||||||||||||||||||
| 8264 | - | |||||||||||||||||||
| 8265 | Returns a std::u16string object with the data contained in this | - | ||||||||||||||||||
| 8266 | QString. The Unicode data is the same as returned by the utf16() | - | ||||||||||||||||||
| 8267 | method. | - | ||||||||||||||||||
| 8268 | - | |||||||||||||||||||
| 8269 | \sa utf16(), toStdWString(), toStdU32String() | - | ||||||||||||||||||
| 8270 | */ | - | ||||||||||||||||||
| 8271 | - | |||||||||||||||||||
| 8272 | /*! \fn QString QString::fromStdU32String(const std::u32string &str) | - | ||||||||||||||||||
| 8273 | \since 5.5 | - | ||||||||||||||||||
| 8274 | - | |||||||||||||||||||
| 8275 | Returns a copy of the \a str string. The given string is assumed | - | ||||||||||||||||||
| 8276 | to be encoded in UCS-4. | - | ||||||||||||||||||
| 8277 | - | |||||||||||||||||||
| 8278 | \sa fromUcs4(), fromStdWString(), fromStdU16String() | - | ||||||||||||||||||
| 8279 | */ | - | ||||||||||||||||||
| 8280 | - | |||||||||||||||||||
| 8281 | /*! | - | ||||||||||||||||||
| 8282 | \fn std::u32string QString::toStdU32String() const | - | ||||||||||||||||||
| 8283 | \since 5.5 | - | ||||||||||||||||||
| 8284 | - | |||||||||||||||||||
| 8285 | Returns a std::u32string object with the data contained in this | - | ||||||||||||||||||
| 8286 | QString. The Unicode data is the same as returned by the toUcs4() | - | ||||||||||||||||||
| 8287 | method. | - | ||||||||||||||||||
| 8288 | - | |||||||||||||||||||
| 8289 | \sa toUcs4(), toStdWString(), toStdU16String() | - | ||||||||||||||||||
| 8290 | */ | - | ||||||||||||||||||
| 8291 | - | |||||||||||||||||||
| 8292 | /*! \class QLatin1String | - | ||||||||||||||||||
| 8293 | \inmodule QtCore | - | ||||||||||||||||||
| 8294 | \brief The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal. | - | ||||||||||||||||||
| 8295 | - | |||||||||||||||||||
| 8296 | \ingroup string-processing | - | ||||||||||||||||||
| 8297 | \reentrant | - | ||||||||||||||||||
| 8298 | - | |||||||||||||||||||
| 8299 | Many of QString's member functions are overloaded to accept | - | ||||||||||||||||||
| 8300 | \c{const char *} instead of QString. This includes the copy | - | ||||||||||||||||||
| 8301 | constructor, the assignment operator, the comparison operators, | - | ||||||||||||||||||
| 8302 | and various other functions such as \l{QString::insert()}{insert()}, \l{QString::replace()}{replace()}, | - | ||||||||||||||||||
| 8303 | and \l{QString::indexOf()}{indexOf()}. These functions | - | ||||||||||||||||||
| 8304 | are usually optimized to avoid constructing a QString object for | - | ||||||||||||||||||
| 8305 | the \c{const char *} data. For example, assuming \c str is a | - | ||||||||||||||||||
| 8306 | QString, | - | ||||||||||||||||||
| 8307 | - | |||||||||||||||||||
| 8308 | \snippet code/src_corelib_tools_qstring.cpp 3 | - | ||||||||||||||||||
| 8309 | - | |||||||||||||||||||
| 8310 | is much faster than | - | ||||||||||||||||||
| 8311 | - | |||||||||||||||||||
| 8312 | \snippet code/src_corelib_tools_qstring.cpp 4 | - | ||||||||||||||||||
| 8313 | - | |||||||||||||||||||
| 8314 | because it doesn't construct four temporary QString objects and | - | ||||||||||||||||||
| 8315 | make a deep copy of the character data. | - | ||||||||||||||||||
| 8316 | - | |||||||||||||||||||
| 8317 | Applications that define \c QT_NO_CAST_FROM_ASCII (as explained | - | ||||||||||||||||||
| 8318 | in the QString documentation) don't have access to QString's | - | ||||||||||||||||||
| 8319 | \c{const char *} API. To provide an efficient way of specifying | - | ||||||||||||||||||
| 8320 | constant Latin-1 strings, Qt provides the QLatin1String, which is | - | ||||||||||||||||||
| 8321 | just a very thin wrapper around a \c{const char *}. Using | - | ||||||||||||||||||
| 8322 | QLatin1String, the example code above becomes | - | ||||||||||||||||||
| 8323 | - | |||||||||||||||||||
| 8324 | \snippet code/src_corelib_tools_qstring.cpp 5 | - | ||||||||||||||||||
| 8325 | - | |||||||||||||||||||
| 8326 | This is a bit longer to type, but it provides exactly the same | - | ||||||||||||||||||
| 8327 | benefits as the first version of the code, and is faster than | - | ||||||||||||||||||
| 8328 | converting the Latin-1 strings using QString::fromLatin1(). | - | ||||||||||||||||||
| 8329 | - | |||||||||||||||||||
| 8330 | Thanks to the QString(QLatin1String) constructor, | - | ||||||||||||||||||
| 8331 | QLatin1String can be used everywhere a QString is expected. For | - | ||||||||||||||||||
| 8332 | example: | - | ||||||||||||||||||
| 8333 | - | |||||||||||||||||||
| 8334 | \snippet code/src_corelib_tools_qstring.cpp 6 | - | ||||||||||||||||||
| 8335 | - | |||||||||||||||||||
| 8336 | \note If the function you're calling with a QLatin1String | - | ||||||||||||||||||
| 8337 | argument isn't actually overloaded to take QLatin1String, the | - | ||||||||||||||||||
| 8338 | implicit conversion to QString will trigger a memory allocation, | - | ||||||||||||||||||
| 8339 | which is usually what you want to avoid by using QLatin1String | - | ||||||||||||||||||
| 8340 | in the first place. In those cases, using QStringLiteral may be | - | ||||||||||||||||||
| 8341 | the better option. | - | ||||||||||||||||||
| 8342 | - | |||||||||||||||||||
| 8343 | \sa QString, QLatin1Char, {QStringLiteral()}{QStringLiteral} | - | ||||||||||||||||||
| 8344 | */ | - | ||||||||||||||||||
| 8345 | - | |||||||||||||||||||
| 8346 | /*! \fn QLatin1String::QLatin1String() | - | ||||||||||||||||||
| 8347 | \since 5.6 | - | ||||||||||||||||||
| 8348 | - | |||||||||||||||||||
| 8349 | Constructs a QLatin1String object that stores a nullptr. | - | ||||||||||||||||||
| 8350 | */ | - | ||||||||||||||||||
| 8351 | - | |||||||||||||||||||
| 8352 | /*! \fn QLatin1String::QLatin1String(const char *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 QLatin1String::QLatin1String(const char *str, int size) | - | ||||||||||||||||||
| 8364 | - | |||||||||||||||||||
| 8365 | Constructs a QLatin1String object that stores \a str with \a size. | - | ||||||||||||||||||
| 8366 | - | |||||||||||||||||||
| 8367 | The string data is \e not copied. The caller must be able to | - | ||||||||||||||||||
| 8368 | guarantee that \a str will not be deleted or modified as long as | - | ||||||||||||||||||
| 8369 | the QLatin1String object exists. | - | ||||||||||||||||||
| 8370 | - | |||||||||||||||||||
| 8371 | \sa latin1() | - | ||||||||||||||||||
| 8372 | */ | - | ||||||||||||||||||
| 8373 | - | |||||||||||||||||||
| 8374 | /*! \fn QLatin1String::QLatin1String(const QByteArray &str) | - | ||||||||||||||||||
| 8375 | - | |||||||||||||||||||
| 8376 | Constructs a QLatin1String object that stores \a str. | - | ||||||||||||||||||
| 8377 | - | |||||||||||||||||||
| 8378 | The string data is \e not copied. The caller must be able to | - | ||||||||||||||||||
| 8379 | guarantee that \a str will not be deleted or modified as long as | - | ||||||||||||||||||
| 8380 | the QLatin1String object exists. | - | ||||||||||||||||||
| 8381 | - | |||||||||||||||||||
| 8382 | \sa latin1() | - | ||||||||||||||||||
| 8383 | */ | - | ||||||||||||||||||
| 8384 | - | |||||||||||||||||||
| 8385 | /*! \fn const char *QLatin1String::latin1() const | - | ||||||||||||||||||
| 8386 | - | |||||||||||||||||||
| 8387 | Returns the Latin-1 string stored in this object. | - | ||||||||||||||||||
| 8388 | */ | - | ||||||||||||||||||
| 8389 | - | |||||||||||||||||||
| 8390 | /*! \fn const char *QLatin1String::data() const | - | ||||||||||||||||||
| 8391 | - | |||||||||||||||||||
| 8392 | Returns the Latin-1 string stored in this object. | - | ||||||||||||||||||
| 8393 | */ | - | ||||||||||||||||||
| 8394 | - | |||||||||||||||||||
| 8395 | /*! \fn int QLatin1String::size() const | - | ||||||||||||||||||
| 8396 | - | |||||||||||||||||||
| 8397 | Returns the size of the Latin-1 string stored in this object. | - | ||||||||||||||||||
| 8398 | */ | - | ||||||||||||||||||
| 8399 | - | |||||||||||||||||||
| 8400 | /*! \fn bool QLatin1String::operator==(const QString &other) const | - | ||||||||||||||||||
| 8401 | - | |||||||||||||||||||
| 8402 | Returns \c true if this string is equal to string \a other; | - | ||||||||||||||||||
| 8403 | otherwise returns \c false. | - | ||||||||||||||||||
| 8404 | - | |||||||||||||||||||
| 8405 | The comparison is based exclusively on the numeric Unicode values | - | ||||||||||||||||||
| 8406 | of the characters and is very fast, but is not what a human would | - | ||||||||||||||||||
| 8407 | expect. Consider sorting user-interface strings with | - | ||||||||||||||||||
| 8408 | QString::localeAwareCompare(). | - | ||||||||||||||||||
| 8409 | */ | - | ||||||||||||||||||
| 8410 | - | |||||||||||||||||||
| 8411 | /*! | - | ||||||||||||||||||
| 8412 | \fn bool QLatin1String::operator==(const char *other) const | - | ||||||||||||||||||
| 8413 | \since 4.3 | - | ||||||||||||||||||
| 8414 | \overload | - | ||||||||||||||||||
| 8415 | - | |||||||||||||||||||
| 8416 | The \a other const char pointer is converted to a QString using | - | ||||||||||||||||||
| 8417 | the QString::fromUtf8() function. | - | ||||||||||||||||||
| 8418 | - | |||||||||||||||||||
| 8419 | You can disable this operator by defining \c | - | ||||||||||||||||||
| 8420 | QT_NO_CAST_FROM_ASCII when you compile your applications. This | - | ||||||||||||||||||
| 8421 | can be useful if you want to ensure that all user-visible strings | - | ||||||||||||||||||
| 8422 | go through QObject::tr(), for example. | - | ||||||||||||||||||
| 8423 | */ | - | ||||||||||||||||||
| 8424 | - | |||||||||||||||||||
| 8425 | /*! | - | ||||||||||||||||||
| 8426 | \fn bool QLatin1String::operator==(const QByteArray &other) const | - | ||||||||||||||||||
| 8427 | \since 5.0 | - | ||||||||||||||||||
| 8428 | \overload | - | ||||||||||||||||||
| 8429 | - | |||||||||||||||||||
| 8430 | The \a other byte array is converted to a QString using | - | ||||||||||||||||||
| 8431 | the QString::fromUtf8() function. | - | ||||||||||||||||||
| 8432 | - | |||||||||||||||||||
| 8433 | You can disable this operator by defining \c | - | ||||||||||||||||||
| 8434 | QT_NO_CAST_FROM_ASCII when you compile your applications. This | - | ||||||||||||||||||
| 8435 | can be useful if you want to ensure that all user-visible strings | - | ||||||||||||||||||
| 8436 | go through QObject::tr(), for example. | - | ||||||||||||||||||
| 8437 | */ | - | ||||||||||||||||||
| 8438 | - | |||||||||||||||||||
| 8439 | /*! \fn bool QLatin1String::operator!=(const QString &other) const | - | ||||||||||||||||||
| 8440 | - | |||||||||||||||||||
| 8441 | Returns \c true if this string is not equal to string \a other; | - | ||||||||||||||||||
| 8442 | otherwise returns \c false. | - | ||||||||||||||||||
| 8443 | - | |||||||||||||||||||
| 8444 | The comparison is based exclusively on the numeric Unicode values | - | ||||||||||||||||||
| 8445 | of the characters and is very fast, but is not what a human would | - | ||||||||||||||||||
| 8446 | expect. Consider sorting user-interface strings with | - | ||||||||||||||||||
| 8447 | QString::localeAwareCompare(). | - | ||||||||||||||||||
| 8448 | */ | - | ||||||||||||||||||
| 8449 | - | |||||||||||||||||||
| 8450 | /*! | - | ||||||||||||||||||
| 8451 | \fn bool QLatin1String::operator!=(const char *other) const | - | ||||||||||||||||||
| 8452 | \since 4.3 | - | ||||||||||||||||||
| 8453 | \overload operator!=() | - | ||||||||||||||||||
| 8454 | - | |||||||||||||||||||
| 8455 | The \a other const char pointer is converted to a QString using | - | ||||||||||||||||||
| 8456 | the QString::fromUtf8() function. | - | ||||||||||||||||||
| 8457 | - | |||||||||||||||||||
| 8458 | You can disable this operator by defining \c | - | ||||||||||||||||||
| 8459 | QT_NO_CAST_FROM_ASCII when you compile your applications. This | - | ||||||||||||||||||
| 8460 | can be useful if you want to ensure that all user-visible strings | - | ||||||||||||||||||
| 8461 | go through QObject::tr(), for example. | - | ||||||||||||||||||
| 8462 | */ | - | ||||||||||||||||||
| 8463 | - | |||||||||||||||||||
| 8464 | /*! | - | ||||||||||||||||||
| 8465 | \fn bool QLatin1String::operator!=(const QByteArray &other) const | - | ||||||||||||||||||
| 8466 | \since 5.0 | - | ||||||||||||||||||
| 8467 | \overload operator!=() | - | ||||||||||||||||||
| 8468 | - | |||||||||||||||||||
| 8469 | The \a other byte array is converted to a QString using | - | ||||||||||||||||||
| 8470 | the QString::fromUtf8() function. | - | ||||||||||||||||||
| 8471 | - | |||||||||||||||||||
| 8472 | You can disable this operator by defining \c | - | ||||||||||||||||||
| 8473 | QT_NO_CAST_FROM_ASCII when you compile your applications. This | - | ||||||||||||||||||
| 8474 | can be useful if you want to ensure that all user-visible strings | - | ||||||||||||||||||
| 8475 | go through QObject::tr(), for example. | - | ||||||||||||||||||
| 8476 | */ | - | ||||||||||||||||||
| 8477 | - | |||||||||||||||||||
| 8478 | /*! | - | ||||||||||||||||||
| 8479 | \fn bool QLatin1String::operator>(const QString &other) const | - | ||||||||||||||||||
| 8480 | - | |||||||||||||||||||
| 8481 | Returns \c true if this string is lexically greater than string \a | - | ||||||||||||||||||
| 8482 | other; otherwise returns \c false. | - | ||||||||||||||||||
| 8483 | - | |||||||||||||||||||
| 8484 | The comparison is based exclusively on the numeric Unicode values | - | ||||||||||||||||||
| 8485 | of the characters and is very fast, but is not what a human would | - | ||||||||||||||||||
| 8486 | expect. Consider sorting user-interface strings with | - | ||||||||||||||||||
| 8487 | QString::localeAwareCompare(). | - | ||||||||||||||||||
| 8488 | */ | - | ||||||||||||||||||
| 8489 | - | |||||||||||||||||||
| 8490 | /*! | - | ||||||||||||||||||
| 8491 | \fn bool QLatin1String::operator>(const char *other) const | - | ||||||||||||||||||
| 8492 | \since 4.3 | - | ||||||||||||||||||
| 8493 | \overload | - | ||||||||||||||||||
| 8494 | - | |||||||||||||||||||
| 8495 | The \a other const char pointer is converted to a QString using | - | ||||||||||||||||||
| 8496 | the QString::fromUtf8() function. | - | ||||||||||||||||||
| 8497 | - | |||||||||||||||||||
| 8498 | You can disable this operator by defining \c QT_NO_CAST_FROM_ASCII | - | ||||||||||||||||||
| 8499 | when you compile your applications. This can be useful if you want | - | ||||||||||||||||||
| 8500 | to ensure that all user-visible strings go through QObject::tr(), | - | ||||||||||||||||||
| 8501 | for example. | - | ||||||||||||||||||
| 8502 | */ | - | ||||||||||||||||||
| 8503 | - | |||||||||||||||||||
| 8504 | /*! | - | ||||||||||||||||||
| 8505 | \fn bool QLatin1String::operator>(const QByteArray &other) const | - | ||||||||||||||||||
| 8506 | \since 5.0 | - | ||||||||||||||||||
| 8507 | \overload | - | ||||||||||||||||||
| 8508 | - | |||||||||||||||||||
| 8509 | The \a other const char pointer is converted to a QString using | - | ||||||||||||||||||
| 8510 | the QString::fromUtf8() function. | - | ||||||||||||||||||
| 8511 | - | |||||||||||||||||||
| 8512 | You can disable this operator by defining \c QT_NO_CAST_FROM_ASCII | - | ||||||||||||||||||
| 8513 | when you compile your applications. This can be useful if you want | - | ||||||||||||||||||
| 8514 | to ensure that all user-visible strings go through QObject::tr(), | - | ||||||||||||||||||
| 8515 | for example. | - | ||||||||||||||||||
| 8516 | */ | - | ||||||||||||||||||
| 8517 | - | |||||||||||||||||||
| 8518 | /*! | - | ||||||||||||||||||
| 8519 | \fn bool QLatin1String::operator<(const QString &other) const | - | ||||||||||||||||||
| 8520 | - | |||||||||||||||||||
| 8521 | Returns \c true if this string is lexically less than the \a other | - | ||||||||||||||||||
| 8522 | string; otherwise returns \c false. | - | ||||||||||||||||||
| 8523 | - | |||||||||||||||||||
| 8524 | The comparison is based exclusively on the numeric Unicode values | - | ||||||||||||||||||
| 8525 | of the characters and is very fast, but is not what a human would | - | ||||||||||||||||||
| 8526 | expect. Consider sorting user-interface strings using the | - | ||||||||||||||||||
| 8527 | QString::localeAwareCompare() function. | - | ||||||||||||||||||
| 8528 | */ | - | ||||||||||||||||||
| 8529 | - | |||||||||||||||||||
| 8530 | /*! | - | ||||||||||||||||||
| 8531 | \fn bool QLatin1String::operator<(const char *other) const | - | ||||||||||||||||||
| 8532 | \since 4.3 | - | ||||||||||||||||||
| 8533 | \overload | - | ||||||||||||||||||
| 8534 | - | |||||||||||||||||||
| 8535 | The \a other const char pointer is converted to a QString using | - | ||||||||||||||||||
| 8536 | the QString::fromUtf8() function. | - | ||||||||||||||||||
| 8537 | - | |||||||||||||||||||
| 8538 | You can disable this operator by defining \c | - | ||||||||||||||||||
| 8539 | QT_NO_CAST_FROM_ASCII when you compile your applications. This | - | ||||||||||||||||||
| 8540 | can be useful if you want to ensure that all user-visible strings | - | ||||||||||||||||||
| 8541 | go through QObject::tr(), for example. | - | ||||||||||||||||||
| 8542 | */ | - | ||||||||||||||||||
| 8543 | - | |||||||||||||||||||
| 8544 | /*! | - | ||||||||||||||||||
| 8545 | \fn bool QLatin1String::operator<(const QByteArray &other) const | - | ||||||||||||||||||
| 8546 | \since 5.0 | - | ||||||||||||||||||
| 8547 | \overload | - | ||||||||||||||||||
| 8548 | - | |||||||||||||||||||
| 8549 | The \a other const char pointer is converted to a QString using | - | ||||||||||||||||||
| 8550 | the QString::fromUtf8() function. | - | ||||||||||||||||||
| 8551 | - | |||||||||||||||||||
| 8552 | You can disable this operator by defining \c | - | ||||||||||||||||||
| 8553 | QT_NO_CAST_FROM_ASCII when you compile your applications. This | - | ||||||||||||||||||
| 8554 | can be useful if you want to ensure that all user-visible strings | - | ||||||||||||||||||
| 8555 | go through QObject::tr(), for example. | - | ||||||||||||||||||
| 8556 | */ | - | ||||||||||||||||||
| 8557 | - | |||||||||||||||||||
| 8558 | /*! | - | ||||||||||||||||||
| 8559 | \fn bool QLatin1String::operator>=(const QString &other) const | - | ||||||||||||||||||
| 8560 | - | |||||||||||||||||||
| 8561 | Returns \c true if this string is lexically greater than or equal | - | ||||||||||||||||||
| 8562 | to string \a other; otherwise returns \c false. | - | ||||||||||||||||||
| 8563 | - | |||||||||||||||||||
| 8564 | The comparison is based exclusively on the numeric Unicode values | - | ||||||||||||||||||
| 8565 | of the characters and is very fast, but is not what a human would | - | ||||||||||||||||||
| 8566 | expect. Consider sorting user-interface strings with | - | ||||||||||||||||||
| 8567 | QString::localeAwareCompare(). | - | ||||||||||||||||||
| 8568 | */ | - | ||||||||||||||||||
| 8569 | - | |||||||||||||||||||
| 8570 | /*! | - | ||||||||||||||||||
| 8571 | \fn bool QLatin1String::operator>=(const char *other) const | - | ||||||||||||||||||
| 8572 | \since 4.3 | - | ||||||||||||||||||
| 8573 | \overload | - | ||||||||||||||||||
| 8574 | - | |||||||||||||||||||
| 8575 | The \a other const char pointer is converted to a QString using | - | ||||||||||||||||||
| 8576 | the QString::fromUtf8() function. | - | ||||||||||||||||||
| 8577 | - | |||||||||||||||||||
| 8578 | You can disable this operator by defining \c | - | ||||||||||||||||||
| 8579 | QT_NO_CAST_FROM_ASCII when you compile your applications. This | - | ||||||||||||||||||
| 8580 | can be useful if you want to ensure that all user-visible strings | - | ||||||||||||||||||
| 8581 | go through QObject::tr(), for example. | - | ||||||||||||||||||
| 8582 | */ | - | ||||||||||||||||||
| 8583 | - | |||||||||||||||||||
| 8584 | /*! | - | ||||||||||||||||||
| 8585 | \fn bool QLatin1String::operator>=(const QByteArray &other) const | - | ||||||||||||||||||
| 8586 | \since 5.0 | - | ||||||||||||||||||
| 8587 | \overload | - | ||||||||||||||||||
| 8588 | - | |||||||||||||||||||
| 8589 | The \a other array is converted to a QString using | - | ||||||||||||||||||
| 8590 | the QString::fromUtf8() function. | - | ||||||||||||||||||
| 8591 | - | |||||||||||||||||||
| 8592 | You can disable this operator by defining \c | - | ||||||||||||||||||
| 8593 | QT_NO_CAST_FROM_ASCII when you compile your applications. This | - | ||||||||||||||||||
| 8594 | can be useful if you want to ensure that all user-visible strings | - | ||||||||||||||||||
| 8595 | go through QObject::tr(), for example. | - | ||||||||||||||||||
| 8596 | */ | - | ||||||||||||||||||
| 8597 | - | |||||||||||||||||||
| 8598 | /*! \fn bool QLatin1String::operator<=(const QString &other) const | - | ||||||||||||||||||
| 8599 | - | |||||||||||||||||||
| 8600 | Returns \c true if this string is lexically less than or equal | - | ||||||||||||||||||
| 8601 | to string \a other; otherwise returns \c false. | - | ||||||||||||||||||
| 8602 | - | |||||||||||||||||||
| 8603 | The comparison is based exclusively on the numeric Unicode values | - | ||||||||||||||||||
| 8604 | of the characters and is very fast, but is not what a human would | - | ||||||||||||||||||
| 8605 | expect. Consider sorting user-interface strings with | - | ||||||||||||||||||
| 8606 | QString::localeAwareCompare(). | - | ||||||||||||||||||
| 8607 | */ | - | ||||||||||||||||||
| 8608 | - | |||||||||||||||||||
| 8609 | /*! | - | ||||||||||||||||||
| 8610 | \fn bool QLatin1String::operator<=(const char *other) const | - | ||||||||||||||||||
| 8611 | \since 4.3 | - | ||||||||||||||||||
| 8612 | \overload | - | ||||||||||||||||||
| 8613 | - | |||||||||||||||||||
| 8614 | The \a other const char pointer is converted to a QString using | - | ||||||||||||||||||
| 8615 | the QString::fromUtf8() function. | - | ||||||||||||||||||
| 8616 | - | |||||||||||||||||||
| 8617 | You can disable this operator by defining \c | - | ||||||||||||||||||
| 8618 | QT_NO_CAST_FROM_ASCII when you compile your applications. This | - | ||||||||||||||||||
| 8619 | can be useful if you want to ensure that all user-visible strings | - | ||||||||||||||||||
| 8620 | go through QObject::tr(), for example. | - | ||||||||||||||||||
| 8621 | */ | - | ||||||||||||||||||
| 8622 | - | |||||||||||||||||||
| 8623 | /*! | - | ||||||||||||||||||
| 8624 | \fn bool QLatin1String::operator<=(const QByteArray &other) const | - | ||||||||||||||||||
| 8625 | \since 5.0 | - | ||||||||||||||||||
| 8626 | \overload | - | ||||||||||||||||||
| 8627 | - | |||||||||||||||||||
| 8628 | The \a other array is converted to a QString using | - | ||||||||||||||||||
| 8629 | the QString::fromUtf8() function. | - | ||||||||||||||||||
| 8630 | - | |||||||||||||||||||
| 8631 | You can disable this operator by defining \c | - | ||||||||||||||||||
| 8632 | QT_NO_CAST_FROM_ASCII when you compile your applications. This | - | ||||||||||||||||||
| 8633 | can be useful if you want to ensure that all user-visible strings | - | ||||||||||||||||||
| 8634 | go through QObject::tr(), for example. | - | ||||||||||||||||||
| 8635 | */ | - | ||||||||||||||||||
| 8636 | - | |||||||||||||||||||
| 8637 | - | |||||||||||||||||||
| 8638 | /*! \fn bool operator==(QLatin1String s1, QLatin1String s2) | - | ||||||||||||||||||
| 8639 | \relates QLatin1String | - | ||||||||||||||||||
| 8640 | - | |||||||||||||||||||
| 8641 | Returns \c true if string \a s1 is lexically equal to string \a s2; otherwise | - | ||||||||||||||||||
| 8642 | returns \c false. | - | ||||||||||||||||||
| 8643 | */ | - | ||||||||||||||||||
| 8644 | /*! \fn bool operator!=(QLatin1String s1, QLatin1String s2) | - | ||||||||||||||||||
| 8645 | \relates QLatin1String | - | ||||||||||||||||||
| 8646 | - | |||||||||||||||||||
| 8647 | Returns \c true if string \a s1 is lexically unequal to string \a s2; otherwise | - | ||||||||||||||||||
| 8648 | returns \c false. | - | ||||||||||||||||||
| 8649 | */ | - | ||||||||||||||||||
| 8650 | /*! \fn bool operator<(QLatin1String s1, QLatin1String s2) | - | ||||||||||||||||||
| 8651 | \relates QLatin1String | - | ||||||||||||||||||
| 8652 | - | |||||||||||||||||||
| 8653 | Returns \c true if string \a s1 is lexically smaller than string \a s2; otherwise | - | ||||||||||||||||||
| 8654 | returns \c false. | - | ||||||||||||||||||
| 8655 | */ | - | ||||||||||||||||||
| 8656 | /*! \fn bool operator<=(QLatin1String s1, QLatin1String s2) | - | ||||||||||||||||||
| 8657 | \relates QLatin1String | - | ||||||||||||||||||
| 8658 | - | |||||||||||||||||||
| 8659 | Returns \c true if string \a s1 is lexically smaller than or equal to string \a s2; otherwise | - | ||||||||||||||||||
| 8660 | returns \c false. | - | ||||||||||||||||||
| 8661 | */ | - | ||||||||||||||||||
| 8662 | /*! \fn bool operator>(QLatin1String s1, QLatin1String s2) | - | ||||||||||||||||||
| 8663 | \relates QLatin1String | - | ||||||||||||||||||
| 8664 | - | |||||||||||||||||||
| 8665 | Returns \c true if string \a s1 is lexically greater than string \a s2; otherwise | - | ||||||||||||||||||
| 8666 | returns \c false. | - | ||||||||||||||||||
| 8667 | */ | - | ||||||||||||||||||
| 8668 | /*! \fn bool operator>=(QLatin1String s1, QLatin1String s2) | - | ||||||||||||||||||
| 8669 | \relates QLatin1String | - | ||||||||||||||||||
| 8670 | - | |||||||||||||||||||
| 8671 | Returns \c true if string \a s1 is lexically greater than or equal to | - | ||||||||||||||||||
| 8672 | string \a s2; otherwise returns \c false. | - | ||||||||||||||||||
| 8673 | */ | - | ||||||||||||||||||
| 8674 | - | |||||||||||||||||||
| 8675 | - | |||||||||||||||||||
| 8676 | #if !defined(QT_NO_DATASTREAM) || (defined(QT_BOOTSTRAPPED) && !defined(QT_BUILD_QMAKE)) | - | ||||||||||||||||||
| 8677 | /*! | - | ||||||||||||||||||
| 8678 | \fn QDataStream &operator<<(QDataStream &stream, const QString &string) | - | ||||||||||||||||||
| 8679 | \relates QString | - | ||||||||||||||||||
| 8680 | - | |||||||||||||||||||
| 8681 | Writes the given \a string to the specified \a stream. | - | ||||||||||||||||||
| 8682 | - | |||||||||||||||||||
| 8683 | \sa {Serializing Qt Data Types} | - | ||||||||||||||||||
| 8684 | */ | - | ||||||||||||||||||
| 8685 | - | |||||||||||||||||||
| 8686 | QDataStream &operator<<(QDataStream &out, const QString &str) | - | ||||||||||||||||||
| 8687 | { | - | ||||||||||||||||||
| 8688 | if (out.version() == 1) {
| 0-15252 | ||||||||||||||||||
| 8689 | out << str.toLatin1(); | - | ||||||||||||||||||
| 8690 | } else { never executed: end of block | 0 | ||||||||||||||||||
| 8691 | if (!str.isNull() || out.version() < 3) {
| 1-14893 | ||||||||||||||||||
| 8692 | if ((out.byteOrder() == QDataStream::BigEndian) == (QSysInfo::ByteOrder == QSysInfo::BigEndian)) {
| 0-14894 | ||||||||||||||||||
| 8693 | out.writeBytes(reinterpret_cast<const char *>(str.unicode()), sizeof(QChar) * str.length()); | - | ||||||||||||||||||
| 8694 | } else { never executed: end of block | 0 | ||||||||||||||||||
| 8695 | QVarLengthArray<ushort> buffer(str.length()); | - | ||||||||||||||||||
| 8696 | const ushort *data = reinterpret_cast<const ushort *>(str.constData()); | - | ||||||||||||||||||
| 8697 | for (int i = 0; i < str.length(); i++) {
| 14894-46886 | ||||||||||||||||||
| 8698 | buffer[i] = qbswap(*data); | - | ||||||||||||||||||
| 8699 | ++data; | - | ||||||||||||||||||
| 8700 | } executed 46886 times by 28 tests: end of blockExecuted by:
| 46886 | ||||||||||||||||||
| 8701 | out.writeBytes(reinterpret_cast<const char *>(buffer.data()), sizeof(ushort) * buffer.size()); | - | ||||||||||||||||||
| 8702 | } executed 14894 times by 28 tests: end of blockExecuted by:
| 14894 | ||||||||||||||||||
| 8703 | } else { | - | ||||||||||||||||||
| 8704 | // write null marker | - | ||||||||||||||||||
| 8705 | out << (quint32)0xffffffff; | - | ||||||||||||||||||
| 8706 | } executed 358 times by 12 tests: end of blockExecuted by:
| 358 | ||||||||||||||||||
| 8707 | } | - | ||||||||||||||||||
| 8708 | return out; executed 15252 times by 28 tests: return out;Executed by:
| 15252 | ||||||||||||||||||
| 8709 | } | - | ||||||||||||||||||
| 8710 | - | |||||||||||||||||||
| 8711 | /*! | - | ||||||||||||||||||
| 8712 | \fn QDataStream &operator>>(QDataStream &stream, QString &string) | - | ||||||||||||||||||
| 8713 | \relates QString | - | ||||||||||||||||||
| 8714 | - | |||||||||||||||||||
| 8715 | Reads a string from the specified \a stream into the given \a string. | - | ||||||||||||||||||
| 8716 | - | |||||||||||||||||||
| 8717 | \sa {Serializing Qt Data Types} | - | ||||||||||||||||||
| 8718 | */ | - | ||||||||||||||||||
| 8719 | - | |||||||||||||||||||
| 8720 | QDataStream &operator>>(QDataStream &in, QString &str) | - | ||||||||||||||||||
| 8721 | { | - | ||||||||||||||||||
| 8722 | if (in.version() == 1) {
| 0-15825 | ||||||||||||||||||
| 8723 | QByteArray l; | - | ||||||||||||||||||
| 8724 | in >> l; | - | ||||||||||||||||||
| 8725 | str = QString::fromLatin1(l); | - | ||||||||||||||||||
| 8726 | } else { never executed: end of block | 0 | ||||||||||||||||||
| 8727 | quint32 bytes = 0; | - | ||||||||||||||||||
| 8728 | in >> bytes; // read size of string | - | ||||||||||||||||||
| 8729 | if (bytes == 0xffffffff) { // null string
| 354-15471 | ||||||||||||||||||
| 8730 | str.clear(); | - | ||||||||||||||||||
| 8731 | } else if (bytes > 0) { // not empty executed 354 times by 12 tests: end of blockExecuted by:
| 354-15074 | ||||||||||||||||||
| 8732 | if (bytes & 0x1) {
| 27-15047 | ||||||||||||||||||
| 8733 | str.clear(); | - | ||||||||||||||||||
| 8734 | in.setStatus(QDataStream::ReadCorruptData); | - | ||||||||||||||||||
| 8735 | return in; executed 27 times by 1 test: return in;Executed by:
| 27 | ||||||||||||||||||
| 8736 | } | - | ||||||||||||||||||
| 8737 | - | |||||||||||||||||||
| 8738 | const quint32 Step = 1024 * 1024; | - | ||||||||||||||||||
| 8739 | quint32 len = bytes / 2; | - | ||||||||||||||||||
| 8740 | quint32 allocated = 0; | - | ||||||||||||||||||
| 8741 | - | |||||||||||||||||||
| 8742 | while (allocated < len) {
| 15033-15059 | ||||||||||||||||||
| 8743 | int blockSize = qMin(Step, len - allocated); | - | ||||||||||||||||||
| 8744 | str.resize(allocated + blockSize); | - | ||||||||||||||||||
| 8745 | if (in.readRawData(reinterpret_cast<char *>(str.data()) + allocated * 2,
| 14-15045 | ||||||||||||||||||
| 8746 | blockSize * 2) != blockSize * 2) {
| 14-15045 | ||||||||||||||||||
| 8747 | str.clear(); | - | ||||||||||||||||||
| 8748 | in.setStatus(QDataStream::ReadPastEnd); | - | ||||||||||||||||||
| 8749 | return in; executed 14 times by 1 test: return in;Executed by:
| 14 | ||||||||||||||||||
| 8750 | } | - | ||||||||||||||||||
| 8751 | allocated += blockSize; | - | ||||||||||||||||||
| 8752 | } executed 15045 times by 28 tests: end of blockExecuted by:
| 15045 | ||||||||||||||||||
| 8753 | - | |||||||||||||||||||
| 8754 | if ((in.byteOrder() == QDataStream::BigEndian)
| 0-15033 | ||||||||||||||||||
| 8755 | != (QSysInfo::ByteOrder == QSysInfo::BigEndian)) {
| 0-15033 | ||||||||||||||||||
| 8756 | ushort *data = reinterpret_cast<ushort *>(str.data()); | - | ||||||||||||||||||
| 8757 | while (len--) {
| 15033-12630580 | ||||||||||||||||||
| 8758 | *data = qbswap(*data); | - | ||||||||||||||||||
| 8759 | ++data; | - | ||||||||||||||||||
| 8760 | } executed 12630580 times by 28 tests: end of blockExecuted by:
| 12630580 | ||||||||||||||||||
| 8761 | } executed 15033 times by 28 tests: end of blockExecuted by:
| 15033 | ||||||||||||||||||
| 8762 | } else { executed 15033 times by 28 tests: end of blockExecuted by:
| 15033 | ||||||||||||||||||
| 8763 | str = QString(QLatin1String("")); | - | ||||||||||||||||||
| 8764 | } executed 397 times by 5 tests: end of blockExecuted by:
| 397 | ||||||||||||||||||
| 8765 | } | - | ||||||||||||||||||
| 8766 | return in; executed 15784 times by 28 tests: return in;Executed by:
| 15784 | ||||||||||||||||||
| 8767 | } | - | ||||||||||||||||||
| 8768 | #endif // QT_NO_DATASTREAM | - | ||||||||||||||||||
| 8769 | - | |||||||||||||||||||
| 8770 | - | |||||||||||||||||||
| 8771 | - | |||||||||||||||||||
| 8772 | - | |||||||||||||||||||
| 8773 | /*! | - | ||||||||||||||||||
| 8774 | \class QStringRef | - | ||||||||||||||||||
| 8775 | \inmodule QtCore | - | ||||||||||||||||||
| 8776 | \since 4.3 | - | ||||||||||||||||||
| 8777 | \brief The QStringRef class provides a thin wrapper around QString substrings. | - | ||||||||||||||||||
| 8778 | \reentrant | - | ||||||||||||||||||
| 8779 | \ingroup tools | - | ||||||||||||||||||
| 8780 | \ingroup string-processing | - | ||||||||||||||||||
| 8781 | - | |||||||||||||||||||
| 8782 | QStringRef provides a read-only subset of the QString API. | - | ||||||||||||||||||
| 8783 | - | |||||||||||||||||||
| 8784 | A string reference explicitly references a portion of a string() | - | ||||||||||||||||||
| 8785 | with a given size(), starting at a specific position(). Calling | - | ||||||||||||||||||
| 8786 | toString() returns a copy of the data as a real QString instance. | - | ||||||||||||||||||
| 8787 | - | |||||||||||||||||||
| 8788 | This class is designed to improve the performance of substring | - | ||||||||||||||||||
| 8789 | handling when manipulating substrings obtained from existing QString | - | ||||||||||||||||||
| 8790 | instances. QStringRef avoids the memory allocation and reference | - | ||||||||||||||||||
| 8791 | counting overhead of a standard QString by simply referencing a | - | ||||||||||||||||||
| 8792 | part of the original string. This can prove to be advantageous in | - | ||||||||||||||||||
| 8793 | low level code, such as that used in a parser, at the expense of | - | ||||||||||||||||||
| 8794 | potentially more complex code. | - | ||||||||||||||||||
| 8795 | - | |||||||||||||||||||
| 8796 | For most users, there are no semantic benefits to using QStringRef | - | ||||||||||||||||||
| 8797 | instead of QString since QStringRef requires attention to be paid | - | ||||||||||||||||||
| 8798 | to memory management issues, potentially making code more complex | - | ||||||||||||||||||
| 8799 | to write and maintain. | - | ||||||||||||||||||
| 8800 | - | |||||||||||||||||||
| 8801 | \warning A QStringRef is only valid as long as the referenced | - | ||||||||||||||||||
| 8802 | string exists. If the original string is deleted, the string | - | ||||||||||||||||||
| 8803 | reference points to an invalid memory location. | - | ||||||||||||||||||
| 8804 | - | |||||||||||||||||||
| 8805 | We suggest that you only use this class in stable code where profiling | - | ||||||||||||||||||
| 8806 | has clearly identified that performance improvements can be made by | - | ||||||||||||||||||
| 8807 | replacing standard string operations with the optimized substring | - | ||||||||||||||||||
| 8808 | handling provided by this class. | - | ||||||||||||||||||
| 8809 | - | |||||||||||||||||||
| 8810 | \sa {Implicitly Shared Classes} | - | ||||||||||||||||||
| 8811 | */ | - | ||||||||||||||||||
| 8812 | - | |||||||||||||||||||
| 8813 | /*! | - | ||||||||||||||||||
| 8814 | \typedef QStringRef::size_type | - | ||||||||||||||||||
| 8815 | \internal | - | ||||||||||||||||||
| 8816 | */ | - | ||||||||||||||||||
| 8817 | - | |||||||||||||||||||
| 8818 | /*! | - | ||||||||||||||||||
| 8819 | \typedef QStringRef::value_type | - | ||||||||||||||||||
| 8820 | \internal | - | ||||||||||||||||||
| 8821 | */ | - | ||||||||||||||||||
| 8822 | - | |||||||||||||||||||
| 8823 | /*! | - | ||||||||||||||||||
| 8824 | \typedef QStringRef::const_pointer | - | ||||||||||||||||||
| 8825 | \internal | - | ||||||||||||||||||
| 8826 | */ | - | ||||||||||||||||||
| 8827 | - | |||||||||||||||||||
| 8828 | /*! | - | ||||||||||||||||||
| 8829 | \typedef QStringRef::const_reference | - | ||||||||||||||||||
| 8830 | \internal | - | ||||||||||||||||||
| 8831 | */ | - | ||||||||||||||||||
| 8832 | - | |||||||||||||||||||
| 8833 | /*! | - | ||||||||||||||||||
| 8834 | \typedef QStringRef::const_iterator | - | ||||||||||||||||||
| 8835 | \since 5.4 | - | ||||||||||||||||||
| 8836 | - | |||||||||||||||||||
| 8837 | This typedef provides an STL-style const iterator for QStringRef. | - | ||||||||||||||||||
| 8838 | - | |||||||||||||||||||
| 8839 | \sa QStringRef::const_reverse_iterator | - | ||||||||||||||||||
| 8840 | */ | - | ||||||||||||||||||
| 8841 | - | |||||||||||||||||||
| 8842 | /*! | - | ||||||||||||||||||
| 8843 | \typedef QStringRef::const_reverse_iterator | - | ||||||||||||||||||
| 8844 | \since 5.7 | - | ||||||||||||||||||
| 8845 | - | |||||||||||||||||||
| 8846 | This typedef provides an STL-style const reverse iterator for QStringRef. | - | ||||||||||||||||||
| 8847 | - | |||||||||||||||||||
| 8848 | \sa QStringRef::const_iterator | - | ||||||||||||||||||
| 8849 | */ | - | ||||||||||||||||||
| 8850 | - | |||||||||||||||||||
| 8851 | /*! | - | ||||||||||||||||||
| 8852 | \fn QStringRef::QStringRef() | - | ||||||||||||||||||
| 8853 | - | |||||||||||||||||||
| 8854 | Constructs an empty string reference. | - | ||||||||||||||||||
| 8855 | */ | - | ||||||||||||||||||
| 8856 | - | |||||||||||||||||||
| 8857 | /*! \fn QStringRef::QStringRef(const QString *string, int position, int length) | - | ||||||||||||||||||
| 8858 | - | |||||||||||||||||||
| 8859 | Constructs a string reference to the range of characters in the given | - | ||||||||||||||||||
| 8860 | \a string specified by the starting \a position and \a length in characters. | - | ||||||||||||||||||
| 8861 | - | |||||||||||||||||||
| 8862 | \warning This function exists to improve performance as much as possible, | - | ||||||||||||||||||
| 8863 | and performs no bounds checking. For program correctness, \a position and | - | ||||||||||||||||||
| 8864 | \a length must describe a valid substring of \a string. | - | ||||||||||||||||||
| 8865 | - | |||||||||||||||||||
| 8866 | This means that the starting \a position must be positive or 0 and smaller | - | ||||||||||||||||||
| 8867 | than \a string's length, and \a length must be positive or 0 but smaller than | - | ||||||||||||||||||
| 8868 | the string's length minus the starting \a position; | - | ||||||||||||||||||
| 8869 | i.e, 0 <= position < string->length() and | - | ||||||||||||||||||
| 8870 | 0 <= length <= string->length() - position must both be satisfied. | - | ||||||||||||||||||
| 8871 | */ | - | ||||||||||||||||||
| 8872 | - | |||||||||||||||||||
| 8873 | /*! \fn QStringRef::QStringRef(const QString *string) | - | ||||||||||||||||||
| 8874 | - | |||||||||||||||||||
| 8875 | Constructs a string reference to the given \a string. | - | ||||||||||||||||||
| 8876 | */ | - | ||||||||||||||||||
| 8877 | - | |||||||||||||||||||
| 8878 | /*! \fn QStringRef::QStringRef(const QStringRef &other) | - | ||||||||||||||||||
| 8879 | - | |||||||||||||||||||
| 8880 | Constructs a copy of the \a other string reference. | - | ||||||||||||||||||
| 8881 | */ | - | ||||||||||||||||||
| 8882 | /*! | - | ||||||||||||||||||
| 8883 | \fn QStringRef::~QStringRef() | - | ||||||||||||||||||
| 8884 | - | |||||||||||||||||||
| 8885 | Destroys the string reference. | - | ||||||||||||||||||
| 8886 | - | |||||||||||||||||||
| 8887 | Since this class is only used to refer to string data, and does not take | - | ||||||||||||||||||
| 8888 | ownership of it, no memory is freed when instances are destroyed. | - | ||||||||||||||||||
| 8889 | */ | - | ||||||||||||||||||
| 8890 | - | |||||||||||||||||||
| 8891 | /*! | - | ||||||||||||||||||
| 8892 | \fn int QStringRef::position() const | - | ||||||||||||||||||
| 8893 | - | |||||||||||||||||||
| 8894 | Returns the starting position in the referenced string that is referred to | - | ||||||||||||||||||
| 8895 | by the string reference. | - | ||||||||||||||||||
| 8896 | - | |||||||||||||||||||
| 8897 | \sa size(), string() | - | ||||||||||||||||||
| 8898 | */ | - | ||||||||||||||||||
| 8899 | - | |||||||||||||||||||
| 8900 | /*! | - | ||||||||||||||||||
| 8901 | \fn int QStringRef::size() const | - | ||||||||||||||||||
| 8902 | - | |||||||||||||||||||
| 8903 | Returns the number of characters referred to by the string reference. | - | ||||||||||||||||||
| 8904 | Equivalent to length() and count(). | - | ||||||||||||||||||
| 8905 | - | |||||||||||||||||||
| 8906 | \sa position(), string() | - | ||||||||||||||||||
| 8907 | */ | - | ||||||||||||||||||
| 8908 | /*! | - | ||||||||||||||||||
| 8909 | \fn int QStringRef::count() const | - | ||||||||||||||||||
| 8910 | Returns the number of characters referred to by the string reference. | - | ||||||||||||||||||
| 8911 | Equivalent to size() and length(). | - | ||||||||||||||||||
| 8912 | - | |||||||||||||||||||
| 8913 | \sa position(), string() | - | ||||||||||||||||||
| 8914 | */ | - | ||||||||||||||||||
| 8915 | /*! | - | ||||||||||||||||||
| 8916 | \fn int QStringRef::length() const | - | ||||||||||||||||||
| 8917 | Returns the number of characters referred to by the string reference. | - | ||||||||||||||||||
| 8918 | Equivalent to size() and count(). | - | ||||||||||||||||||
| 8919 | - | |||||||||||||||||||
| 8920 | \sa position(), string() | - | ||||||||||||||||||
| 8921 | */ | - | ||||||||||||||||||
| 8922 | - | |||||||||||||||||||
| 8923 | - | |||||||||||||||||||
| 8924 | /*! | - | ||||||||||||||||||
| 8925 | \fn bool QStringRef::isEmpty() const | - | ||||||||||||||||||
| 8926 | - | |||||||||||||||||||
| 8927 | Returns \c true if the string reference has no characters; otherwise returns | - | ||||||||||||||||||
| 8928 | \c false. | - | ||||||||||||||||||
| 8929 | - | |||||||||||||||||||
| 8930 | A string reference is empty if its size is zero. | - | ||||||||||||||||||
| 8931 | - | |||||||||||||||||||
| 8932 | \sa size() | - | ||||||||||||||||||
| 8933 | */ | - | ||||||||||||||||||
| 8934 | - | |||||||||||||||||||
| 8935 | /*! | - | ||||||||||||||||||
| 8936 | \fn bool QStringRef::isNull() const | - | ||||||||||||||||||
| 8937 | - | |||||||||||||||||||
| 8938 | Returns \c true if string() returns a null pointer or a pointer to a | - | ||||||||||||||||||
| 8939 | null string; otherwise returns \c true. | - | ||||||||||||||||||
| 8940 | - | |||||||||||||||||||
| 8941 | \sa size() | - | ||||||||||||||||||
| 8942 | */ | - | ||||||||||||||||||
| 8943 | - | |||||||||||||||||||
| 8944 | /*! | - | ||||||||||||||||||
| 8945 | \fn const QString *QStringRef::string() const | - | ||||||||||||||||||
| 8946 | - | |||||||||||||||||||
| 8947 | Returns a pointer to the string referred to by the string reference, or | - | ||||||||||||||||||
| 8948 | 0 if it does not reference a string. | - | ||||||||||||||||||
| 8949 | - | |||||||||||||||||||
| 8950 | \sa unicode() | - | ||||||||||||||||||
| 8951 | */ | - | ||||||||||||||||||
| 8952 | - | |||||||||||||||||||
| 8953 | - | |||||||||||||||||||
| 8954 | /*! | - | ||||||||||||||||||
| 8955 | \fn const QChar *QStringRef::unicode() const | - | ||||||||||||||||||
| 8956 | - | |||||||||||||||||||
| 8957 | Returns a Unicode representation of the string reference. Since | - | ||||||||||||||||||
| 8958 | the data stems directly from the referenced string, it is not | - | ||||||||||||||||||
| 8959 | null-terminated unless the string reference includes the string's | - | ||||||||||||||||||
| 8960 | null terminator. | - | ||||||||||||||||||
| 8961 | - | |||||||||||||||||||
| 8962 | \sa string() | - | ||||||||||||||||||
| 8963 | */ | - | ||||||||||||||||||
| 8964 | - | |||||||||||||||||||
| 8965 | /*! | - | ||||||||||||||||||
| 8966 | \fn const QChar *QStringRef::data() const | - | ||||||||||||||||||
| 8967 | - | |||||||||||||||||||
| 8968 | Same as unicode(). | - | ||||||||||||||||||
| 8969 | */ | - | ||||||||||||||||||
| 8970 | - | |||||||||||||||||||
| 8971 | /*! | - | ||||||||||||||||||
| 8972 | \fn const QChar *QStringRef::constData() const | - | ||||||||||||||||||
| 8973 | - | |||||||||||||||||||
| 8974 | Same as unicode(). | - | ||||||||||||||||||
| 8975 | */ | - | ||||||||||||||||||
| 8976 | - | |||||||||||||||||||
| 8977 | /*! | - | ||||||||||||||||||
| 8978 | \fn QStringRef::const_iterator QStringRef::begin() const | - | ||||||||||||||||||
| 8979 | \since 5.4 | - | ||||||||||||||||||
| 8980 | - | |||||||||||||||||||
| 8981 | Returns a const \l{STL-style iterators}{STL-style iterator} pointing to the first character in | - | ||||||||||||||||||
| 8982 | the string. | - | ||||||||||||||||||
| 8983 | - | |||||||||||||||||||
| 8984 | \sa cbegin(), end(), rbegin(), rend() | - | ||||||||||||||||||
| 8985 | */ | - | ||||||||||||||||||
| 8986 | - | |||||||||||||||||||
| 8987 | /*! | - | ||||||||||||||||||
| 8988 | \fn QStringRef::const_iterator QStringRef::cbegin() const | - | ||||||||||||||||||
| 8989 | \since 5.4 | - | ||||||||||||||||||
| 8990 | - | |||||||||||||||||||
| 8991 | Same as begin(). | - | ||||||||||||||||||
| 8992 | - | |||||||||||||||||||
| 8993 | \sa begin(), cend(), rbegin(), rend() | - | ||||||||||||||||||
| 8994 | */ | - | ||||||||||||||||||
| 8995 | - | |||||||||||||||||||
| 8996 | /*! | - | ||||||||||||||||||
| 8997 | \fn QStringRef::const_iterator QStringRef::end() const | - | ||||||||||||||||||
| 8998 | \since 5.4 | - | ||||||||||||||||||
| 8999 | - | |||||||||||||||||||
| 9000 | Returns a const \l{STL-style iterators}{STL-style iterator} pointing to the imaginary | - | ||||||||||||||||||
| 9001 | character after the last character in the list. | - | ||||||||||||||||||
| 9002 | - | |||||||||||||||||||
| 9003 | \sa cbegin(), end(), rbegin(), rend() | - | ||||||||||||||||||
| 9004 | */ | - | ||||||||||||||||||
| 9005 | - | |||||||||||||||||||
| 9006 | /*! \fn QStringRef::const_iterator QStringRef::cend() const | - | ||||||||||||||||||
| 9007 | \since 5.4 | - | ||||||||||||||||||
| 9008 | - | |||||||||||||||||||
| 9009 | Same as end(). | - | ||||||||||||||||||
| 9010 | - | |||||||||||||||||||
| 9011 | \sa end(), cbegin(), rbegin(), rend() | - | ||||||||||||||||||
| 9012 | */ | - | ||||||||||||||||||
| 9013 | - | |||||||||||||||||||
| 9014 | /*! | - | ||||||||||||||||||
| 9015 | \fn QStringRef::const_reverse_iterator QStringRef::rbegin() const | - | ||||||||||||||||||
| 9016 | \since 5.7 | - | ||||||||||||||||||
| 9017 | - | |||||||||||||||||||
| 9018 | Returns a const \l{STL-style iterators}{STL-style} reverse iterator pointing to the first | - | ||||||||||||||||||
| 9019 | character in the string, in reverse order. | - | ||||||||||||||||||
| 9020 | - | |||||||||||||||||||
| 9021 | \sa begin(), crbegin(), rend() | - | ||||||||||||||||||
| 9022 | */ | - | ||||||||||||||||||
| 9023 | - | |||||||||||||||||||
| 9024 | /*! | - | ||||||||||||||||||
| 9025 | \fn QStringRef::const_reverse_iterator QStringRef::crbegin() const | - | ||||||||||||||||||
| 9026 | \since 5.7 | - | ||||||||||||||||||
| 9027 | - | |||||||||||||||||||
| 9028 | Same as rbegin(). | - | ||||||||||||||||||
| 9029 | - | |||||||||||||||||||
| 9030 | \sa begin(), rbegin(), rend() | - | ||||||||||||||||||
| 9031 | */ | - | ||||||||||||||||||
| 9032 | - | |||||||||||||||||||
| 9033 | /*! | - | ||||||||||||||||||
| 9034 | \fn QStringRef::const_reverse_iterator QStringRef::rend() const | - | ||||||||||||||||||
| 9035 | \since 5.7 | - | ||||||||||||||||||
| 9036 | - | |||||||||||||||||||
| 9037 | Returns a \l{STL-style iterators}{STL-style} reverse iterator pointing to one past | - | ||||||||||||||||||
| 9038 | the last character in the string, in reverse order. | - | ||||||||||||||||||
| 9039 | - | |||||||||||||||||||
| 9040 | \sa end(), crend(), rbegin() | - | ||||||||||||||||||
| 9041 | */ | - | ||||||||||||||||||
| 9042 | - | |||||||||||||||||||
| 9043 | - | |||||||||||||||||||
| 9044 | /*! | - | ||||||||||||||||||
| 9045 | \fn QStringRef::const_reverse_iterator QStringRef::crend() const | - | ||||||||||||||||||
| 9046 | \since 5.7 | - | ||||||||||||||||||
| 9047 | - | |||||||||||||||||||
| 9048 | Same as rend(). | - | ||||||||||||||||||
| 9049 | - | |||||||||||||||||||
| 9050 | \sa end(), rend(), rbegin() | - | ||||||||||||||||||
| 9051 | */ | - | ||||||||||||||||||
| 9052 | - | |||||||||||||||||||
| 9053 | /*! | - | ||||||||||||||||||
| 9054 | Returns a copy of the string reference as a QString object. | - | ||||||||||||||||||
| 9055 | - | |||||||||||||||||||
| 9056 | If the string reference is not a complete reference of the string | - | ||||||||||||||||||
| 9057 | (meaning that position() is 0 and size() equals string()->size()), | - | ||||||||||||||||||
| 9058 | this function will allocate a new string to return. | - | ||||||||||||||||||
| 9059 | - | |||||||||||||||||||
| 9060 | \sa string() | - | ||||||||||||||||||
| 9061 | */ | - | ||||||||||||||||||
| 9062 | - | |||||||||||||||||||
| 9063 | QString QStringRef::toString() const { | - | ||||||||||||||||||
| 9064 | if (!m_string)
| 8012-402702 | ||||||||||||||||||
| 9065 | return QString(); executed 8012 times by 38 tests: return QString();Executed by:
| 8012 | ||||||||||||||||||
| 9066 | if (m_size && m_position == 0 && m_size == m_string->size())
| 1040-401662 | ||||||||||||||||||
| 9067 | return *m_string; executed 68705 times by 131 tests: return *m_string;Executed by:
| 68705 | ||||||||||||||||||
| 9068 | return QString(m_string->unicode() + m_position, m_size); executed 333997 times by 88 tests: return QString(m_string->unicode() + m_position, m_size);Executed by:
| 333997 | ||||||||||||||||||
| 9069 | } | - | ||||||||||||||||||
| 9070 | - | |||||||||||||||||||
| 9071 | - | |||||||||||||||||||
| 9072 | /*! \relates QStringRef | - | ||||||||||||||||||
| 9073 | - | |||||||||||||||||||
| 9074 | Returns \c true if string reference \a s1 is lexically equal to string reference \a s2; otherwise | - | ||||||||||||||||||
| 9075 | returns \c false. | - | ||||||||||||||||||
| 9076 | */ | - | ||||||||||||||||||
| 9077 | bool operator==(const QStringRef &s1,const QStringRef &s2) Q_DECL_NOTHROW | - | ||||||||||||||||||
| 9078 | { executed 2511992 times by 48 tests: return (s1.size() == s2.size() &&return (s1.size() == s2.size() && qMemEquals((const ushort *)s1.unicode(), (const ushort *)s2.unicode(), s1.size()));Executed by:
executed 2511992 times by 48 tests: return (s1.size() == s2.size() && qMemEquals((const ushort *)s1.unicode(), (const ushort *)s2.unicode(), s1.size()));Executed by:
| 2511992 | ||||||||||||||||||
| 9079 | qMemEquals((const ushort *)s1.unicode(), (const ushort *)s2.unicode(), s1.size())); executed 2511992 times by 48 tests: return (s1.size() == s2.size() && qMemEquals((const ushort *)s1.unicode(), (const ushort *)s2.unicode(), s1.size()));Executed by:
| 2511992 | ||||||||||||||||||
| 9080 | } | - | ||||||||||||||||||
| 9081 | - | |||||||||||||||||||
| 9082 | /*! \relates QStringRef | - | ||||||||||||||||||
| 9083 | - | |||||||||||||||||||
| 9084 | Returns \c true if string \a s1 is lexically equal to string reference \a s2; otherwise | - | ||||||||||||||||||
| 9085 | returns \c false. | - | ||||||||||||||||||
| 9086 | */ | - | ||||||||||||||||||
| 9087 | bool operator==(const QString &s1,const QStringRef &s2) Q_DECL_NOTHROW | - | ||||||||||||||||||
| 9088 | { executed 280789 times by 121 tests: return (s1.size() == s2.size() &&return (s1.size() == s2.size() && qMemEquals((const ushort *)s1.unicode(), (const ushort *)s2.unicode(), s1.size()));Executed by:
executed 280789 times by 121 tests: return (s1.size() == s2.size() && qMemEquals((const ushort *)s1.unicode(), (const ushort *)s2.unicode(), s1.size()));Executed by:
| 280789 | ||||||||||||||||||
| 9089 | qMemEquals((const ushort *)s1.unicode(), (const ushort *)s2.unicode(), s1.size())); executed 280789 times by 121 tests: return (s1.size() == s2.size() && qMemEquals((const ushort *)s1.unicode(), (const ushort *)s2.unicode(), s1.size()));Executed by:
| 280789 | ||||||||||||||||||
| 9090 | } | - | ||||||||||||||||||
| 9091 | - | |||||||||||||||||||
| 9092 | /*! \relates QStringRef | - | ||||||||||||||||||
| 9093 | - | |||||||||||||||||||
| 9094 | Returns \c true if string \a s1 is lexically equal to string reference \a s2; otherwise | - | ||||||||||||||||||
| 9095 | returns \c false. | - | ||||||||||||||||||
| 9096 | */ | - | ||||||||||||||||||
| 9097 | bool operator==(QLatin1String s1, const QStringRef &s2) Q_DECL_NOTHROW | - | ||||||||||||||||||
| 9098 | { | - | ||||||||||||||||||
| 9099 | if (s1.size() != s2.size())
| 656355-840026 | ||||||||||||||||||
| 9100 | return false; executed 840026 times by 66 tests: return false;Executed by:
| 840026 | ||||||||||||||||||
| 9101 | - | |||||||||||||||||||
| 9102 | const uchar *c = reinterpret_cast<const uchar *>(s1.latin1()); | - | ||||||||||||||||||
| 9103 | if (!c)
| 0-656355 | ||||||||||||||||||
| 9104 | return s2.isEmpty(); never executed: return s2.isEmpty(); | 0 | ||||||||||||||||||
| 9105 | return ucstrncmp(s2.unicode(), c, s2.size()) == 0; executed 656355 times by 53 tests: return ucstrncmp(s2.unicode(), c, s2.size()) == 0;Executed by:
| 656355 | ||||||||||||||||||
| 9106 | } | - | ||||||||||||||||||
| 9107 | - | |||||||||||||||||||
| 9108 | /*! | - | ||||||||||||||||||
| 9109 | \relates QStringRef | - | ||||||||||||||||||
| 9110 | - | |||||||||||||||||||
| 9111 | Returns \c true if string reference \a s1 is lexically less than | - | ||||||||||||||||||
| 9112 | string reference \a s2; otherwise returns \c false. | - | ||||||||||||||||||
| 9113 | - | |||||||||||||||||||
| 9114 | The comparison is based exclusively on the numeric Unicode values | - | ||||||||||||||||||
| 9115 | of the characters and is very fast, but is not what a human would | - | ||||||||||||||||||
| 9116 | expect. Consider sorting user-interface strings using the | - | ||||||||||||||||||
| 9117 | QString::localeAwareCompare() function. | - | ||||||||||||||||||
| 9118 | */ | - | ||||||||||||||||||
| 9119 | bool operator<(const QStringRef &s1,const QStringRef &s2) Q_DECL_NOTHROW | - | ||||||||||||||||||
| 9120 | { | - | ||||||||||||||||||
| 9121 | return ucstrcmp(s1.constData(), s1.length(), s2.constData(), s2.length()) < 0; executed 3346 times by 14 tests: return ucstrcmp(s1.constData(), s1.length(), s2.constData(), s2.length()) < 0;Executed by:
| 3346 | ||||||||||||||||||
| 9122 | } | - | ||||||||||||||||||
| 9123 | - | |||||||||||||||||||
| 9124 | /*!\fn bool operator<=(const QStringRef &s1,const QStringRef &s2) | - | ||||||||||||||||||
| 9125 | - | |||||||||||||||||||
| 9126 | \relates QStringRef | - | ||||||||||||||||||
| 9127 | - | |||||||||||||||||||
| 9128 | Returns \c true if string reference \a s1 is lexically less than | - | ||||||||||||||||||
| 9129 | or equal to string reference \a s2; otherwise returns \c false. | - | ||||||||||||||||||
| 9130 | - | |||||||||||||||||||
| 9131 | The comparison is based exclusively on the numeric Unicode values | - | ||||||||||||||||||
| 9132 | of the characters and is very fast, but is not what a human would | - | ||||||||||||||||||
| 9133 | expect. Consider sorting user-interface strings using the | - | ||||||||||||||||||
| 9134 | QString::localeAwareCompare() function. | - | ||||||||||||||||||
| 9135 | */ | - | ||||||||||||||||||
| 9136 | - | |||||||||||||||||||
| 9137 | /*!\fn bool operator>=(const QStringRef &s1,const QStringRef &s2) | - | ||||||||||||||||||
| 9138 | - | |||||||||||||||||||
| 9139 | \relates QStringRef | - | ||||||||||||||||||
| 9140 | - | |||||||||||||||||||
| 9141 | Returns \c true if string reference \a s1 is lexically greater than | - | ||||||||||||||||||
| 9142 | or equal to string reference \a s2; otherwise returns \c false. | - | ||||||||||||||||||
| 9143 | - | |||||||||||||||||||
| 9144 | The comparison is based exclusively on the numeric Unicode values | - | ||||||||||||||||||
| 9145 | of the characters and is very fast, but is not what a human would | - | ||||||||||||||||||
| 9146 | expect. Consider sorting user-interface strings using the | - | ||||||||||||||||||
| 9147 | QString::localeAwareCompare() function. | - | ||||||||||||||||||
| 9148 | */ | - | ||||||||||||||||||
| 9149 | - | |||||||||||||||||||
| 9150 | /*!\fn bool operator>(const QStringRef &s1,const QStringRef &s2) | - | ||||||||||||||||||
| 9151 | - | |||||||||||||||||||
| 9152 | \relates QStringRef | - | ||||||||||||||||||
| 9153 | - | |||||||||||||||||||
| 9154 | Returns \c true if string reference \a s1 is lexically greater than | - | ||||||||||||||||||
| 9155 | string reference \a s2; otherwise returns \c false. | - | ||||||||||||||||||
| 9156 | - | |||||||||||||||||||
| 9157 | The comparison is based exclusively on the numeric Unicode values | - | ||||||||||||||||||
| 9158 | of the characters and is very fast, but is not what a human would | - | ||||||||||||||||||
| 9159 | expect. Consider sorting user-interface strings using the | - | ||||||||||||||||||
| 9160 | QString::localeAwareCompare() function. | - | ||||||||||||||||||
| 9161 | */ | - | ||||||||||||||||||
| 9162 | - | |||||||||||||||||||
| 9163 | - | |||||||||||||||||||
| 9164 | /*! | - | ||||||||||||||||||
| 9165 | \fn const QChar QStringRef::at(int position) const | - | ||||||||||||||||||
| 9166 | - | |||||||||||||||||||
| 9167 | Returns the character at the given index \a position in the | - | ||||||||||||||||||
| 9168 | string reference. | - | ||||||||||||||||||
| 9169 | - | |||||||||||||||||||
| 9170 | The \a position must be a valid index position in the string | - | ||||||||||||||||||
| 9171 | (i.e., 0 <= \a position < size()). | - | ||||||||||||||||||
| 9172 | */ | - | ||||||||||||||||||
| 9173 | - | |||||||||||||||||||
| 9174 | /*! | - | ||||||||||||||||||
| 9175 | \fn QChar QStringRef::operator[](int position) const | - | ||||||||||||||||||
| 9176 | \since 5.7 | - | ||||||||||||||||||
| 9177 | - | |||||||||||||||||||
| 9178 | Returns the character at the given index \a position in the | - | ||||||||||||||||||
| 9179 | string reference. | - | ||||||||||||||||||
| 9180 | - | |||||||||||||||||||
| 9181 | The \a position must be a valid index position in the string | - | ||||||||||||||||||
| 9182 | reference (i.e., 0 <= \a position < size()). | - | ||||||||||||||||||
| 9183 | - | |||||||||||||||||||
| 9184 | \sa at() | - | ||||||||||||||||||
| 9185 | */ | - | ||||||||||||||||||
| 9186 | - | |||||||||||||||||||
| 9187 | /*! | - | ||||||||||||||||||
| 9188 | \fn void QStringRef::clear() | - | ||||||||||||||||||
| 9189 | - | |||||||||||||||||||
| 9190 | Clears the contents of the string reference by making it null and empty. | - | ||||||||||||||||||
| 9191 | - | |||||||||||||||||||
| 9192 | \sa isEmpty(), isNull() | - | ||||||||||||||||||
| 9193 | */ | - | ||||||||||||||||||
| 9194 | - | |||||||||||||||||||
| 9195 | /*! | - | ||||||||||||||||||
| 9196 | \fn QStringRef &QStringRef::operator=(const QStringRef &other) | - | ||||||||||||||||||
| 9197 | - | |||||||||||||||||||
| 9198 | Assigns the \a other string reference to this string reference, and | - | ||||||||||||||||||
| 9199 | returns the result. | - | ||||||||||||||||||
| 9200 | */ | - | ||||||||||||||||||
| 9201 | - | |||||||||||||||||||
| 9202 | /*! | - | ||||||||||||||||||
| 9203 | \fn QStringRef &QStringRef::operator=(const QString *string) | - | ||||||||||||||||||
| 9204 | - | |||||||||||||||||||
| 9205 | Constructs a string reference to the given \a string and assigns it to | - | ||||||||||||||||||
| 9206 | this string reference, returning the result. | - | ||||||||||||||||||
| 9207 | */ | - | ||||||||||||||||||
| 9208 | - | |||||||||||||||||||
| 9209 | /*! | - | ||||||||||||||||||
| 9210 | \fn bool QStringRef::operator==(const char * s) const | - | ||||||||||||||||||
| 9211 | - | |||||||||||||||||||
| 9212 | \overload operator==() | - | ||||||||||||||||||
| 9213 | - | |||||||||||||||||||
| 9214 | The \a s byte array is converted to a QStringRef using the | - | ||||||||||||||||||
| 9215 | fromUtf8() function. This function stops conversion at the | - | ||||||||||||||||||
| 9216 | first NUL character found, or the end of the byte array. | - | ||||||||||||||||||
| 9217 | - | |||||||||||||||||||
| 9218 | You can disable this operator by defining \c | - | ||||||||||||||||||
| 9219 | QT_NO_CAST_FROM_ASCII when you compile your applications. This | - | ||||||||||||||||||
| 9220 | can be useful if you want to ensure that all user-visible strings | - | ||||||||||||||||||
| 9221 | go through QObject::tr(), for example. | - | ||||||||||||||||||
| 9222 | - | |||||||||||||||||||
| 9223 | Returns \c true if this string is lexically equal to the parameter | - | ||||||||||||||||||
| 9224 | string \a s. Otherwise returns \c false. | - | ||||||||||||||||||
| 9225 | - | |||||||||||||||||||
| 9226 | */ | - | ||||||||||||||||||
| 9227 | - | |||||||||||||||||||
| 9228 | /*! | - | ||||||||||||||||||
| 9229 | \fn bool QStringRef::operator!=(const char * s) const | - | ||||||||||||||||||
| 9230 | - | |||||||||||||||||||
| 9231 | \overload operator!=() | - | ||||||||||||||||||
| 9232 | - | |||||||||||||||||||
| 9233 | The \a s const char pointer is converted to a QStringRef using | - | ||||||||||||||||||
| 9234 | the fromUtf8() function. | - | ||||||||||||||||||
| 9235 | - | |||||||||||||||||||
| 9236 | You can disable this operator by defining \c | - | ||||||||||||||||||
| 9237 | QT_NO_CAST_FROM_ASCII when you compile your applications. This | - | ||||||||||||||||||
| 9238 | can be useful if you want to ensure that all user-visible strings | - | ||||||||||||||||||
| 9239 | go through QObject::tr(), for example. | - | ||||||||||||||||||
| 9240 | - | |||||||||||||||||||
| 9241 | Returns \c true if this string is not lexically equal to the parameter | - | ||||||||||||||||||
| 9242 | string \a s. Otherwise returns \c false. | - | ||||||||||||||||||
| 9243 | */ | - | ||||||||||||||||||
| 9244 | - | |||||||||||||||||||
| 9245 | /*! | - | ||||||||||||||||||
| 9246 | \fn bool QStringRef::operator<(const char * s) const | - | ||||||||||||||||||
| 9247 | - | |||||||||||||||||||
| 9248 | \overload operator<() | - | ||||||||||||||||||
| 9249 | - | |||||||||||||||||||
| 9250 | The \a s const char pointer is converted to a QStringRef using | - | ||||||||||||||||||
| 9251 | the fromUtf8() function. | - | ||||||||||||||||||
| 9252 | - | |||||||||||||||||||
| 9253 | You can disable this operator by defining \c | - | ||||||||||||||||||
| 9254 | QT_NO_CAST_FROM_ASCII when you compile your applications. This | - | ||||||||||||||||||
| 9255 | can be useful if you want to ensure that all user-visible strings | - | ||||||||||||||||||
| 9256 | go through QObject::tr(), for example. | - | ||||||||||||||||||
| 9257 | - | |||||||||||||||||||
| 9258 | Returns \c true if this string is lexically smaller than the parameter | - | ||||||||||||||||||
| 9259 | string \a s. Otherwise returns \c false. | - | ||||||||||||||||||
| 9260 | */ | - | ||||||||||||||||||
| 9261 | - | |||||||||||||||||||
| 9262 | /*! | - | ||||||||||||||||||
| 9263 | \fn bool QStringRef::operator<=(const char * s) const | - | ||||||||||||||||||
| 9264 | - | |||||||||||||||||||
| 9265 | \overload operator<=() | - | ||||||||||||||||||
| 9266 | - | |||||||||||||||||||
| 9267 | The \a s const char pointer is converted to a QStringRef using | - | ||||||||||||||||||
| 9268 | the fromUtf8() function. | - | ||||||||||||||||||
| 9269 | - | |||||||||||||||||||
| 9270 | You can disable this operator by defining \c | - | ||||||||||||||||||
| 9271 | QT_NO_CAST_FROM_ASCII when you compile your applications. This | - | ||||||||||||||||||
| 9272 | can be useful if you want to ensure that all user-visible strings | - | ||||||||||||||||||
| 9273 | go through QObject::tr(), for example. | - | ||||||||||||||||||
| 9274 | - | |||||||||||||||||||
| 9275 | Returns \c true if this string is lexically smaller than or equal to the parameter | - | ||||||||||||||||||
| 9276 | string \a s. Otherwise returns \c false. | - | ||||||||||||||||||
| 9277 | */ | - | ||||||||||||||||||
| 9278 | - | |||||||||||||||||||
| 9279 | /*! | - | ||||||||||||||||||
| 9280 | \fn bool QStringRef::operator>(const char * s) const | - | ||||||||||||||||||
| 9281 | - | |||||||||||||||||||
| 9282 | - | |||||||||||||||||||
| 9283 | \overload operator>() | - | ||||||||||||||||||
| 9284 | - | |||||||||||||||||||
| 9285 | The \a s const char pointer is converted to a QStringRef using | - | ||||||||||||||||||
| 9286 | the fromUtf8() function. | - | ||||||||||||||||||
| 9287 | - | |||||||||||||||||||
| 9288 | You can disable this operator by defining \c | - | ||||||||||||||||||
| 9289 | QT_NO_CAST_FROM_ASCII when you compile your applications. This | - | ||||||||||||||||||
| 9290 | can be useful if you want to ensure that all user-visible strings | - | ||||||||||||||||||
| 9291 | go through QObject::tr(), for example. | - | ||||||||||||||||||
| 9292 | - | |||||||||||||||||||
| 9293 | Returns \c true if this string is lexically greater than the parameter | - | ||||||||||||||||||
| 9294 | string \a s. Otherwise returns \c false. | - | ||||||||||||||||||
| 9295 | */ | - | ||||||||||||||||||
| 9296 | - | |||||||||||||||||||
| 9297 | /*! | - | ||||||||||||||||||
| 9298 | \fn bool QStringRef::operator>= (const char * s) const | - | ||||||||||||||||||
| 9299 | - | |||||||||||||||||||
| 9300 | \overload operator>=() | - | ||||||||||||||||||
| 9301 | - | |||||||||||||||||||
| 9302 | The \a s const char pointer is converted to a QStringRef using | - | ||||||||||||||||||
| 9303 | the fromUtf8() function. | - | ||||||||||||||||||
| 9304 | - | |||||||||||||||||||
| 9305 | You can disable this operator by defining \c | - | ||||||||||||||||||
| 9306 | QT_NO_CAST_FROM_ASCII when you compile your applications. This | - | ||||||||||||||||||
| 9307 | can be useful if you want to ensure that all user-visible strings | - | ||||||||||||||||||
| 9308 | go through QObject::tr(), for example. | - | ||||||||||||||||||
| 9309 | - | |||||||||||||||||||
| 9310 | Returns \c true if this string is lexically greater than or equal to the | - | ||||||||||||||||||
| 9311 | parameter string \a s. Otherwise returns \c false. | - | ||||||||||||||||||
| 9312 | */ | - | ||||||||||||||||||
| 9313 | /*! | - | ||||||||||||||||||
| 9314 | \typedef QString::Data | - | ||||||||||||||||||
| 9315 | \internal | - | ||||||||||||||||||
| 9316 | */ | - | ||||||||||||||||||
| 9317 | - | |||||||||||||||||||
| 9318 | /*! | - | ||||||||||||||||||
| 9319 | \typedef QString::DataPtr | - | ||||||||||||||||||
| 9320 | \internal | - | ||||||||||||||||||
| 9321 | */ | - | ||||||||||||||||||
| 9322 | - | |||||||||||||||||||
| 9323 | /*! | - | ||||||||||||||||||
| 9324 | \fn DataPtr & QString::data_ptr() | - | ||||||||||||||||||
| 9325 | \internal | - | ||||||||||||||||||
| 9326 | */ | - | ||||||||||||||||||
| 9327 | - | |||||||||||||||||||
| 9328 | - | |||||||||||||||||||
| 9329 | - | |||||||||||||||||||
| 9330 | /*! Appends the string reference to \a string, and returns a new | - | ||||||||||||||||||
| 9331 | reference to the combined string data. | - | ||||||||||||||||||
| 9332 | */ | - | ||||||||||||||||||
| 9333 | QStringRef QStringRef::appendTo(QString *string) const | - | ||||||||||||||||||
| 9334 | { | - | ||||||||||||||||||
| 9335 | if (!string)
| 0-8 | ||||||||||||||||||
| 9336 | return QStringRef(); never executed: return QStringRef(); | 0 | ||||||||||||||||||
| 9337 | int pos = string->size(); | - | ||||||||||||||||||
| 9338 | string->insert(pos, unicode(), size()); | - | ||||||||||||||||||
| 9339 | return QStringRef(string, pos, size()); executed 8 times by 1 test: return QStringRef(string, pos, size());Executed by:
| 8 | ||||||||||||||||||
| 9340 | } | - | ||||||||||||||||||
| 9341 | - | |||||||||||||||||||
| 9342 | /*! | - | ||||||||||||||||||
| 9343 | \fn int QStringRef::compare(const QStringRef &s1, const QString &s2, Qt::CaseSensitivity cs = Qt::CaseSensitive) | - | ||||||||||||||||||
| 9344 | \since 4.5 | - | ||||||||||||||||||
| 9345 | - | |||||||||||||||||||
| 9346 | Compares the string \a s1 with the string \a s2 and returns an | - | ||||||||||||||||||
| 9347 | integer less than, equal to, or greater than zero if \a s1 | - | ||||||||||||||||||
| 9348 | is less than, equal to, or greater than \a s2. | - | ||||||||||||||||||
| 9349 | - | |||||||||||||||||||
| 9350 | If \a cs is Qt::CaseSensitive, the comparison is case sensitive; | - | ||||||||||||||||||
| 9351 | otherwise the comparison is case insensitive. | - | ||||||||||||||||||
| 9352 | */ | - | ||||||||||||||||||
| 9353 | - | |||||||||||||||||||
| 9354 | /*! | - | ||||||||||||||||||
| 9355 | \fn int QStringRef::compare(const QStringRef &s1, const QStringRef &s2, Qt::CaseSensitivity cs = Qt::CaseSensitive) | - | ||||||||||||||||||
| 9356 | \since 4.5 | - | ||||||||||||||||||
| 9357 | \overload | - | ||||||||||||||||||
| 9358 | - | |||||||||||||||||||
| 9359 | Compares the string \a s1 with the string \a s2 and returns an | - | ||||||||||||||||||
| 9360 | integer less than, equal to, or greater than zero if \a s1 | - | ||||||||||||||||||
| 9361 | is less than, equal to, or greater than \a s2. | - | ||||||||||||||||||
| 9362 | - | |||||||||||||||||||
| 9363 | If \a cs is Qt::CaseSensitive, the comparison is case sensitive; | - | ||||||||||||||||||
| 9364 | otherwise the comparison is case insensitive. | - | ||||||||||||||||||
| 9365 | */ | - | ||||||||||||||||||
| 9366 | - | |||||||||||||||||||
| 9367 | /*! | - | ||||||||||||||||||
| 9368 | \fn int QStringRef::compare(const QStringRef &s1, QLatin1String s2, Qt::CaseSensitivity cs = Qt::CaseSensitive) | - | ||||||||||||||||||
| 9369 | \since 4.5 | - | ||||||||||||||||||
| 9370 | \overload | - | ||||||||||||||||||
| 9371 | - | |||||||||||||||||||
| 9372 | Compares the string \a s1 with the string \a s2 and returns an | - | ||||||||||||||||||
| 9373 | integer less than, equal to, or greater than zero if \a s1 | - | ||||||||||||||||||
| 9374 | is less than, equal to, or greater than \a s2. | - | ||||||||||||||||||
| 9375 | - | |||||||||||||||||||
| 9376 | If \a cs is Qt::CaseSensitive, the comparison is case sensitive; | - | ||||||||||||||||||
| 9377 | otherwise the comparison is case insensitive. | - | ||||||||||||||||||
| 9378 | */ | - | ||||||||||||||||||
| 9379 | - | |||||||||||||||||||
| 9380 | /*! | - | ||||||||||||||||||
| 9381 | \overload | - | ||||||||||||||||||
| 9382 | \fn int QStringRef::compare(const QString &other, Qt::CaseSensitivity cs = Qt::CaseSensitive) const | - | ||||||||||||||||||
| 9383 | \since 4.5 | - | ||||||||||||||||||
| 9384 | - | |||||||||||||||||||
| 9385 | Compares this string with the \a other string and returns an | - | ||||||||||||||||||
| 9386 | integer less than, equal to, or greater than zero if this string | - | ||||||||||||||||||
| 9387 | is less than, equal to, or greater than the \a other string. | - | ||||||||||||||||||
| 9388 | - | |||||||||||||||||||
| 9389 | If \a cs is Qt::CaseSensitive, the comparison is case sensitive; | - | ||||||||||||||||||
| 9390 | otherwise the comparison is case insensitive. | - | ||||||||||||||||||
| 9391 | - | |||||||||||||||||||
| 9392 | Equivalent to \c {compare(*this, other, cs)}. | - | ||||||||||||||||||
| 9393 | - | |||||||||||||||||||
| 9394 | \sa QString::compare() | - | ||||||||||||||||||
| 9395 | */ | - | ||||||||||||||||||
| 9396 | - | |||||||||||||||||||
| 9397 | /*! | - | ||||||||||||||||||
| 9398 | \overload | - | ||||||||||||||||||
| 9399 | \fn int QStringRef::compare(const QStringRef &other, Qt::CaseSensitivity cs = Qt::CaseSensitive) const | - | ||||||||||||||||||
| 9400 | \since 4.5 | - | ||||||||||||||||||
| 9401 | - | |||||||||||||||||||
| 9402 | Compares this string with the \a other string and returns an | - | ||||||||||||||||||
| 9403 | integer less than, equal to, or greater than zero if this string | - | ||||||||||||||||||
| 9404 | is less than, equal to, or greater than the \a other string. | - | ||||||||||||||||||
| 9405 | - | |||||||||||||||||||
| 9406 | If \a cs is Qt::CaseSensitive, the comparison is case sensitive; | - | ||||||||||||||||||
| 9407 | otherwise the comparison is case insensitive. | - | ||||||||||||||||||
| 9408 | - | |||||||||||||||||||
| 9409 | Equivalent to \c {compare(*this, other, cs)}. | - | ||||||||||||||||||
| 9410 | - | |||||||||||||||||||
| 9411 | \sa QString::compare() | - | ||||||||||||||||||
| 9412 | */ | - | ||||||||||||||||||
| 9413 | - | |||||||||||||||||||
| 9414 | /*! | - | ||||||||||||||||||
| 9415 | \overload | - | ||||||||||||||||||
| 9416 | \fn int QStringRef::compare(QLatin1String other, Qt::CaseSensitivity cs = Qt::CaseSensitive) const | - | ||||||||||||||||||
| 9417 | \since 4.5 | - | ||||||||||||||||||
| 9418 | - | |||||||||||||||||||
| 9419 | Compares this string with the \a other string and returns an | - | ||||||||||||||||||
| 9420 | integer less than, equal to, or greater than zero if this string | - | ||||||||||||||||||
| 9421 | is less than, equal to, or greater than the \a other string. | - | ||||||||||||||||||
| 9422 | - | |||||||||||||||||||
| 9423 | If \a cs is Qt::CaseSensitive, the comparison is case sensitive; | - | ||||||||||||||||||
| 9424 | otherwise the comparison is case insensitive. | - | ||||||||||||||||||
| 9425 | - | |||||||||||||||||||
| 9426 | Equivalent to \c {compare(*this, other, cs)}. | - | ||||||||||||||||||
| 9427 | - | |||||||||||||||||||
| 9428 | \sa QString::compare() | - | ||||||||||||||||||
| 9429 | */ | - | ||||||||||||||||||
| 9430 | - | |||||||||||||||||||
| 9431 | /*! | - | ||||||||||||||||||
| 9432 | \fn int QStringRef::localeAwareCompare(const QStringRef &s1, const QString & s2) | - | ||||||||||||||||||
| 9433 | \since 4.5 | - | ||||||||||||||||||
| 9434 | - | |||||||||||||||||||
| 9435 | Compares \a s1 with \a s2 and returns an integer less than, equal | - | ||||||||||||||||||
| 9436 | to, or greater than zero if \a s1 is less than, equal to, or | - | ||||||||||||||||||
| 9437 | greater than \a s2. | - | ||||||||||||||||||
| 9438 | - | |||||||||||||||||||
| 9439 | The comparison is performed in a locale- and also | - | ||||||||||||||||||
| 9440 | platform-dependent manner. Use this function to present sorted | - | ||||||||||||||||||
| 9441 | lists of strings to the user. | - | ||||||||||||||||||
| 9442 | - | |||||||||||||||||||
| 9443 | On \macos and iOS, this function compares according the | - | ||||||||||||||||||
| 9444 | "Order for sorted lists" setting in the International prefereces panel. | - | ||||||||||||||||||
| 9445 | - | |||||||||||||||||||
| 9446 | \sa compare(), QLocale | - | ||||||||||||||||||
| 9447 | */ | - | ||||||||||||||||||
| 9448 | - | |||||||||||||||||||
| 9449 | /*! | - | ||||||||||||||||||
| 9450 | \fn int QStringRef::localeAwareCompare(const QStringRef &s1, const QStringRef & s2) | - | ||||||||||||||||||
| 9451 | \since 4.5 | - | ||||||||||||||||||
| 9452 | \overload | - | ||||||||||||||||||
| 9453 | - | |||||||||||||||||||
| 9454 | Compares \a s1 with \a s2 and returns an integer less than, equal | - | ||||||||||||||||||
| 9455 | to, or greater than zero if \a s1 is less than, equal to, or | - | ||||||||||||||||||
| 9456 | greater than \a s2. | - | ||||||||||||||||||
| 9457 | - | |||||||||||||||||||
| 9458 | The comparison is performed in a locale- and also | - | ||||||||||||||||||
| 9459 | platform-dependent manner. Use this function to present sorted | - | ||||||||||||||||||
| 9460 | lists of strings to the user. | - | ||||||||||||||||||
| 9461 | - | |||||||||||||||||||
| 9462 | */ | - | ||||||||||||||||||
| 9463 | - | |||||||||||||||||||
| 9464 | /*! | - | ||||||||||||||||||
| 9465 | \fn int QStringRef::localeAwareCompare(const QString &other) const | - | ||||||||||||||||||
| 9466 | \since 4.5 | - | ||||||||||||||||||
| 9467 | \overload | - | ||||||||||||||||||
| 9468 | - | |||||||||||||||||||
| 9469 | Compares this string with the \a other string and returns an | - | ||||||||||||||||||
| 9470 | integer less than, equal to, or greater than zero if this string | - | ||||||||||||||||||
| 9471 | is less than, equal to, or greater than the \a other string. | - | ||||||||||||||||||
| 9472 | - | |||||||||||||||||||
| 9473 | The comparison is performed in a locale- and also | - | ||||||||||||||||||
| 9474 | platform-dependent manner. Use this function to present sorted | - | ||||||||||||||||||
| 9475 | lists of strings to the user. | - | ||||||||||||||||||
| 9476 | */ | - | ||||||||||||||||||
| 9477 | - | |||||||||||||||||||
| 9478 | /*! | - | ||||||||||||||||||
| 9479 | \fn int QStringRef::localeAwareCompare(const QStringRef &other) const | - | ||||||||||||||||||
| 9480 | \since 4.5 | - | ||||||||||||||||||
| 9481 | \overload | - | ||||||||||||||||||
| 9482 | - | |||||||||||||||||||
| 9483 | Compares this string with the \a other string and returns an | - | ||||||||||||||||||
| 9484 | integer less than, equal to, or greater than zero if this string | - | ||||||||||||||||||
| 9485 | is less than, equal to, or greater than the \a other string. | - | ||||||||||||||||||
| 9486 | - | |||||||||||||||||||
| 9487 | The comparison is performed in a locale- and also | - | ||||||||||||||||||
| 9488 | platform-dependent manner. Use this function to present sorted | - | ||||||||||||||||||
| 9489 | lists of strings to the user. | - | ||||||||||||||||||
| 9490 | */ | - | ||||||||||||||||||
| 9491 | - | |||||||||||||||||||
| 9492 | /*! | - | ||||||||||||||||||
| 9493 | \fn QString &QString::append(const QStringRef &reference) | - | ||||||||||||||||||
| 9494 | \since 4.4 | - | ||||||||||||||||||
| 9495 | - | |||||||||||||||||||
| 9496 | Appends the given string \a reference to this string and returns the result. | - | ||||||||||||||||||
| 9497 | */ | - | ||||||||||||||||||
| 9498 | QString &QString::append(const QStringRef &str) | - | ||||||||||||||||||
| 9499 | { | - | ||||||||||||||||||
| 9500 | if (str.string() == this) {
| 0-7514 | ||||||||||||||||||
| 9501 | str.appendTo(this); | - | ||||||||||||||||||
| 9502 | } else if (!str.isNull()) { never executed: end of block
| 0-7508 | ||||||||||||||||||
| 9503 | int oldSize = size(); | - | ||||||||||||||||||
| 9504 | resize(oldSize + str.size()); | - | ||||||||||||||||||
| 9505 | memcpy(data() + oldSize, str.unicode(), str.size() * sizeof(QChar)); | - | ||||||||||||||||||
| 9506 | } executed 7508 times by 20 tests: end of blockExecuted by:
| 7508 | ||||||||||||||||||
| 9507 | return *this; executed 7514 times by 20 tests: return *this;Executed by:
| 7514 | ||||||||||||||||||
| 9508 | } | - | ||||||||||||||||||
| 9509 | - | |||||||||||||||||||
| 9510 | /*! | - | ||||||||||||||||||
| 9511 | \fn QStringRef::left(int n) const | - | ||||||||||||||||||
| 9512 | \since 5.2 | - | ||||||||||||||||||
| 9513 | - | |||||||||||||||||||
| 9514 | Returns a substring reference to the \a n leftmost characters | - | ||||||||||||||||||
| 9515 | of the string. | - | ||||||||||||||||||
| 9516 | - | |||||||||||||||||||
| 9517 | If \a n is greater than or equal to size(), or less than zero, | - | ||||||||||||||||||
| 9518 | a reference to the entire string is returned. | - | ||||||||||||||||||
| 9519 | - | |||||||||||||||||||
| 9520 | \sa right(), mid(), startsWith() | - | ||||||||||||||||||
| 9521 | */ | - | ||||||||||||||||||
| 9522 | QStringRef QStringRef::left(int n) const | - | ||||||||||||||||||
| 9523 | { | - | ||||||||||||||||||
| 9524 | if (uint(n) >= uint(m_size))
| 163-527 | ||||||||||||||||||
| 9525 | return *this; executed 527 times by 15 tests: return *this;Executed by:
| 527 | ||||||||||||||||||
| 9526 | return QStringRef(m_string, m_position, n); executed 163 times by 10 tests: return QStringRef(m_string, m_position, n);Executed by:
| 163 | ||||||||||||||||||
| 9527 | } | - | ||||||||||||||||||
| 9528 | - | |||||||||||||||||||
| 9529 | /*! | - | ||||||||||||||||||
| 9530 | \since 4.4 | - | ||||||||||||||||||
| 9531 | - | |||||||||||||||||||
| 9532 | Returns a substring reference to the \a n leftmost characters | - | ||||||||||||||||||
| 9533 | of the string. | - | ||||||||||||||||||
| 9534 | - | |||||||||||||||||||
| 9535 | If \a n is greater than or equal to size(), or less than zero, | - | ||||||||||||||||||
| 9536 | a reference to the entire string is returned. | - | ||||||||||||||||||
| 9537 | - | |||||||||||||||||||
| 9538 | \snippet qstring/main.cpp leftRef | - | ||||||||||||||||||
| 9539 | - | |||||||||||||||||||
| 9540 | \sa left(), rightRef(), midRef(), startsWith() | - | ||||||||||||||||||
| 9541 | */ | - | ||||||||||||||||||
| 9542 | QStringRef QString::leftRef(int n) const | - | ||||||||||||||||||
| 9543 | { | - | ||||||||||||||||||
| 9544 | if (uint(n) >= uint(d->size))
| 28977-49321 | ||||||||||||||||||
| 9545 | n = d->size; executed 49321 times by 14 tests: n = d->size;Executed by:
| 49321 | ||||||||||||||||||
| 9546 | return QStringRef(this, 0, n); executed 78298 times by 25 tests: return QStringRef(this, 0, n);Executed by:
| 78298 | ||||||||||||||||||
| 9547 | } | - | ||||||||||||||||||
| 9548 | - | |||||||||||||||||||
| 9549 | /*! | - | ||||||||||||||||||
| 9550 | \fn QStringRef::right(int n) const | - | ||||||||||||||||||
| 9551 | \since 5.2 | - | ||||||||||||||||||
| 9552 | - | |||||||||||||||||||
| 9553 | Returns a substring reference to the \a n rightmost characters | - | ||||||||||||||||||
| 9554 | of the string. | - | ||||||||||||||||||
| 9555 | - | |||||||||||||||||||
| 9556 | If \a n is greater than or equal to size(), or less than zero, | - | ||||||||||||||||||
| 9557 | a reference to the entire string is returned. | - | ||||||||||||||||||
| 9558 | - | |||||||||||||||||||
| 9559 | \sa left(), mid(), endsWith() | - | ||||||||||||||||||
| 9560 | */ | - | ||||||||||||||||||
| 9561 | QStringRef QStringRef::right(int n) const | - | ||||||||||||||||||
| 9562 | { | - | ||||||||||||||||||
| 9563 | if (uint(n) >= uint(m_size))
| 10-382 | ||||||||||||||||||
| 9564 | return *this; executed 10 times by 2 tests: return *this;Executed by:
| 10 | ||||||||||||||||||
| 9565 | return QStringRef(m_string, m_size - n + m_position, n); executed 382 times by 7 tests: return QStringRef(m_string, m_size - n + m_position, n);Executed by:
| 382 | ||||||||||||||||||
| 9566 | } | - | ||||||||||||||||||
| 9567 | - | |||||||||||||||||||
| 9568 | /*! | - | ||||||||||||||||||
| 9569 | \since 4.4 | - | ||||||||||||||||||
| 9570 | - | |||||||||||||||||||
| 9571 | Returns a substring reference to the \a n rightmost characters | - | ||||||||||||||||||
| 9572 | of the string. | - | ||||||||||||||||||
| 9573 | - | |||||||||||||||||||
| 9574 | If \a n is greater than or equal to size(), or less than zero, | - | ||||||||||||||||||
| 9575 | a reference to the entire string is returned. | - | ||||||||||||||||||
| 9576 | - | |||||||||||||||||||
| 9577 | \snippet qstring/main.cpp rightRef | - | ||||||||||||||||||
| 9578 | - | |||||||||||||||||||
| 9579 | \sa right(), leftRef(), midRef(), endsWith() | - | ||||||||||||||||||
| 9580 | */ | - | ||||||||||||||||||
| 9581 | QStringRef QString::rightRef(int n) const | - | ||||||||||||||||||
| 9582 | { | - | ||||||||||||||||||
| 9583 | if (uint(n) >= uint(d->size))
| 4-2619 | ||||||||||||||||||
| 9584 | n = d->size; executed 4 times by 1 test: n = d->size;Executed by:
| 4 | ||||||||||||||||||
| 9585 | return QStringRef(this, d->size - n, n); executed 2623 times by 33 tests: return QStringRef(this, d->size - n, n);Executed by:
| 2623 | ||||||||||||||||||
| 9586 | } | - | ||||||||||||||||||
| 9587 | - | |||||||||||||||||||
| 9588 | /*! | - | ||||||||||||||||||
| 9589 | \fn QStringRef::mid(int position, int n = -1) const | - | ||||||||||||||||||
| 9590 | \since 5.2 | - | ||||||||||||||||||
| 9591 | - | |||||||||||||||||||
| 9592 | Returns a substring reference to \a n characters of this string, | - | ||||||||||||||||||
| 9593 | starting at the specified \a position. | - | ||||||||||||||||||
| 9594 | - | |||||||||||||||||||
| 9595 | If the \a position exceeds the length of the string, a null | - | ||||||||||||||||||
| 9596 | reference is returned. | - | ||||||||||||||||||
| 9597 | - | |||||||||||||||||||
| 9598 | If there are less than \a n characters available in the string, | - | ||||||||||||||||||
| 9599 | starting at the given \a position, or if \a n is -1 (default), the | - | ||||||||||||||||||
| 9600 | function returns all characters from the specified \a position | - | ||||||||||||||||||
| 9601 | onwards. | - | ||||||||||||||||||
| 9602 | - | |||||||||||||||||||
| 9603 | \sa left(), right() | - | ||||||||||||||||||
| 9604 | */ | - | ||||||||||||||||||
| 9605 | QStringRef QStringRef::mid(int pos, int n) const | - | ||||||||||||||||||
| 9606 | { | - | ||||||||||||||||||
| 9607 | using namespace QtPrivate; | - | ||||||||||||||||||
| 9608 | switch (QContainerImplHelper::mid(m_size, &pos, &n)) { | - | ||||||||||||||||||
| 9609 | case QContainerImplHelper::Null: executed 31 times by 2 tests: case QContainerImplHelper::Null:Executed by:
| 31 | ||||||||||||||||||
| 9610 | return QStringRef(); executed 31 times by 2 tests: return QStringRef();Executed by:
| 31 | ||||||||||||||||||
| 9611 | case QContainerImplHelper::Empty: executed 3092 times by 21 tests: case QContainerImplHelper::Empty:Executed by:
| 3092 | ||||||||||||||||||
| 9612 | return QStringRef(m_string, 0, 0); executed 3092 times by 21 tests: return QStringRef(m_string, 0, 0);Executed by:
| 3092 | ||||||||||||||||||
| 9613 | case QContainerImplHelper::Full: executed 34883 times by 150 tests: case QContainerImplHelper::Full:Executed by:
| 34883 | ||||||||||||||||||
| 9614 | return *this; executed 34883 times by 150 tests: return *this;Executed by:
| 34883 | ||||||||||||||||||
| 9615 | case QContainerImplHelper::Subset: executed 67473 times by 220 tests: case QContainerImplHelper::Subset:Executed by:
| 67473 | ||||||||||||||||||
| 9616 | return QStringRef(m_string, pos + m_position, n); executed 67473 times by 220 tests: return QStringRef(m_string, pos + m_position, n);Executed by:
| 67473 | ||||||||||||||||||
| 9617 | } | - | ||||||||||||||||||
| 9618 | Q_UNREACHABLE(); | - | ||||||||||||||||||
| 9619 | return QStringRef(); never executed: return QStringRef(); | 0 | ||||||||||||||||||
| 9620 | } | - | ||||||||||||||||||
| 9621 | - | |||||||||||||||||||
| 9622 | /*! | - | ||||||||||||||||||
| 9623 | \since 4.4 | - | ||||||||||||||||||
| 9624 | - | |||||||||||||||||||
| 9625 | Returns a substring reference to \a n characters of this string, | - | ||||||||||||||||||
| 9626 | starting at the specified \a position. | - | ||||||||||||||||||
| 9627 | - | |||||||||||||||||||
| 9628 | If the \a position exceeds the length of the string, a null | - | ||||||||||||||||||
| 9629 | reference is returned. | - | ||||||||||||||||||
| 9630 | - | |||||||||||||||||||
| 9631 | If there are less than \a n characters available in the string, | - | ||||||||||||||||||
| 9632 | starting at the given \a position, or if \a n is -1 (default), the | - | ||||||||||||||||||
| 9633 | function returns all characters from the specified \a position | - | ||||||||||||||||||
| 9634 | onwards. | - | ||||||||||||||||||
| 9635 | - | |||||||||||||||||||
| 9636 | Example: | - | ||||||||||||||||||
| 9637 | - | |||||||||||||||||||
| 9638 | \snippet qstring/main.cpp midRef | - | ||||||||||||||||||
| 9639 | - | |||||||||||||||||||
| 9640 | \sa mid(), leftRef(), rightRef() | - | ||||||||||||||||||
| 9641 | */ | - | ||||||||||||||||||
| 9642 | QStringRef QString::midRef(int position, int n) const | - | ||||||||||||||||||
| 9643 | { | - | ||||||||||||||||||
| 9644 | using namespace QtPrivate; | - | ||||||||||||||||||
| 9645 | switch (QContainerImplHelper::mid(d->size, &position, &n)) { | - | ||||||||||||||||||
| 9646 | case QContainerImplHelper::Null: executed 285 times by 2 tests: case QContainerImplHelper::Null:Executed by:
| 285 | ||||||||||||||||||
| 9647 | return QStringRef(); executed 285 times by 2 tests: return QStringRef();Executed by:
| 285 | ||||||||||||||||||
| 9648 | case QContainerImplHelper::Empty: executed 1841 times by 19 tests: case QContainerImplHelper::Empty:Executed by:
| 1841 | ||||||||||||||||||
| 9649 | return QStringRef(this, 0, 0); executed 1841 times by 19 tests: return QStringRef(this, 0, 0);Executed by:
| 1841 | ||||||||||||||||||
| 9650 | case QContainerImplHelper::Full: executed 41759 times by 42 tests: case QContainerImplHelper::Full:Executed by:
| 41759 | ||||||||||||||||||
| 9651 | return QStringRef(this, 0, d->size); executed 41759 times by 42 tests: return QStringRef(this, 0, d->size);Executed by:
| 41759 | ||||||||||||||||||
| 9652 | case QContainerImplHelper::Subset: executed 64470 times by 200 tests: case QContainerImplHelper::Subset:Executed by:
| 64470 | ||||||||||||||||||
| 9653 | return QStringRef(this, position, n); executed 64470 times by 200 tests: return QStringRef(this, position, n);Executed by:
| 64470 | ||||||||||||||||||
| 9654 | } | - | ||||||||||||||||||
| 9655 | Q_UNREACHABLE(); | - | ||||||||||||||||||
| 9656 | return QStringRef(); never executed: return QStringRef(); | 0 | ||||||||||||||||||
| 9657 | } | - | ||||||||||||||||||
| 9658 | - | |||||||||||||||||||
| 9659 | /*! | - | ||||||||||||||||||
| 9660 | \fn void QStringRef::truncate(int position) | - | ||||||||||||||||||
| 9661 | \since 5.6 | - | ||||||||||||||||||
| 9662 | - | |||||||||||||||||||
| 9663 | Truncates the string at the given \a position index. | - | ||||||||||||||||||
| 9664 | - | |||||||||||||||||||
| 9665 | If the specified \a position index is beyond the end of the | - | ||||||||||||||||||
| 9666 | string, nothing happens. | - | ||||||||||||||||||
| 9667 | - | |||||||||||||||||||
| 9668 | If \a position is negative, it is equivalent to passing zero. | - | ||||||||||||||||||
| 9669 | - | |||||||||||||||||||
| 9670 | \sa QString::truncate() | - | ||||||||||||||||||
| 9671 | */ | - | ||||||||||||||||||
| 9672 | - | |||||||||||||||||||
| 9673 | /*! | - | ||||||||||||||||||
| 9674 | \since 4.8 | - | ||||||||||||||||||
| 9675 | - | |||||||||||||||||||
| 9676 | Returns the index position of the first occurrence of the string \a | - | ||||||||||||||||||
| 9677 | str in this string reference, searching forward from index position | - | ||||||||||||||||||
| 9678 | \a from. Returns -1 if \a str is not found. | - | ||||||||||||||||||
| 9679 | - | |||||||||||||||||||
| 9680 | If \a cs is Qt::CaseSensitive (default), the search is case | - | ||||||||||||||||||
| 9681 | sensitive; otherwise the search is case insensitive. | - | ||||||||||||||||||
| 9682 | - | |||||||||||||||||||
| 9683 | If \a from is -1, the search starts at the last character; if it is | - | ||||||||||||||||||
| 9684 | -2, at the next to last character and so on. | - | ||||||||||||||||||
| 9685 | - | |||||||||||||||||||
| 9686 | \sa QString::indexOf(), lastIndexOf(), contains(), count() | - | ||||||||||||||||||
| 9687 | */ | - | ||||||||||||||||||
| 9688 | int QStringRef::indexOf(const QString &str, int from, Qt::CaseSensitivity cs) const | - | ||||||||||||||||||
| 9689 | { | - | ||||||||||||||||||
| 9690 | return qFindString(unicode(), length(), from, str.unicode(), str.length(), cs); executed 200 times by 2 tests: return qFindString(unicode(), length(), from, str.unicode(), str.length(), cs);Executed by:
| 200 | ||||||||||||||||||
| 9691 | } | - | ||||||||||||||||||
| 9692 | - | |||||||||||||||||||
| 9693 | /*! | - | ||||||||||||||||||
| 9694 | \since 4.8 | - | ||||||||||||||||||
| 9695 | \overload indexOf() | - | ||||||||||||||||||
| 9696 | - | |||||||||||||||||||
| 9697 | Returns the index position of the first occurrence of the | - | ||||||||||||||||||
| 9698 | character \a ch in the string reference, searching forward from | - | ||||||||||||||||||
| 9699 | index position \a from. Returns -1 if \a ch could not be found. | - | ||||||||||||||||||
| 9700 | - | |||||||||||||||||||
| 9701 | \sa QString::indexOf(), lastIndexOf(), contains(), count() | - | ||||||||||||||||||
| 9702 | */ | - | ||||||||||||||||||
| 9703 | int QStringRef::indexOf(QChar ch, int from, Qt::CaseSensitivity cs) const | - | ||||||||||||||||||
| 9704 | { | - | ||||||||||||||||||
| 9705 | return findChar(unicode(), length(), ch, from, cs); executed 52119 times by 26 tests: return findChar(unicode(), length(), ch, from, cs);Executed by:
| 52119 | ||||||||||||||||||
| 9706 | } | - | ||||||||||||||||||
| 9707 | - | |||||||||||||||||||
| 9708 | /*! | - | ||||||||||||||||||
| 9709 | \since 4.8 | - | ||||||||||||||||||
| 9710 | - | |||||||||||||||||||
| 9711 | Returns the index position of the first occurrence of the string \a | - | ||||||||||||||||||
| 9712 | str in this string reference, searching forward from index position | - | ||||||||||||||||||
| 9713 | \a from. Returns -1 if \a str is not found. | - | ||||||||||||||||||
| 9714 | - | |||||||||||||||||||
| 9715 | If \a cs is Qt::CaseSensitive (default), the search is case | - | ||||||||||||||||||
| 9716 | sensitive; otherwise the search is case insensitive. | - | ||||||||||||||||||
| 9717 | - | |||||||||||||||||||
| 9718 | If \a from is -1, the search starts at the last character; if it is | - | ||||||||||||||||||
| 9719 | -2, at the next to last character and so on. | - | ||||||||||||||||||
| 9720 | - | |||||||||||||||||||
| 9721 | \sa QString::indexOf(), lastIndexOf(), contains(), count() | - | ||||||||||||||||||
| 9722 | */ | - | ||||||||||||||||||
| 9723 | int QStringRef::indexOf(QLatin1String str, int from, Qt::CaseSensitivity cs) const | - | ||||||||||||||||||
| 9724 | { | - | ||||||||||||||||||
| 9725 | return qt_find_latin1_string(unicode(), size(), str, from, cs); never executed: return qt_find_latin1_string(unicode(), size(), str, from, cs); | 0 | ||||||||||||||||||
| 9726 | } | - | ||||||||||||||||||
| 9727 | - | |||||||||||||||||||
| 9728 | /*! | - | ||||||||||||||||||
| 9729 | \since 4.8 | - | ||||||||||||||||||
| 9730 | - | |||||||||||||||||||
| 9731 | \overload indexOf() | - | ||||||||||||||||||
| 9732 | - | |||||||||||||||||||
| 9733 | Returns the index position of the first occurrence of the string | - | ||||||||||||||||||
| 9734 | reference \a str in this string reference, searching forward from | - | ||||||||||||||||||
| 9735 | index position \a from. Returns -1 if \a str is not found. | - | ||||||||||||||||||
| 9736 | - | |||||||||||||||||||
| 9737 | If \a cs is Qt::CaseSensitive (default), the search is case | - | ||||||||||||||||||
| 9738 | sensitive; otherwise the search is case insensitive. | - | ||||||||||||||||||
| 9739 | - | |||||||||||||||||||
| 9740 | \sa QString::indexOf(), lastIndexOf(), contains(), count() | - | ||||||||||||||||||
| 9741 | */ | - | ||||||||||||||||||
| 9742 | int QStringRef::indexOf(const QStringRef &str, int from, Qt::CaseSensitivity cs) const | - | ||||||||||||||||||
| 9743 | { | - | ||||||||||||||||||
| 9744 | 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 | ||||||||||||||||||
| 9745 | } | - | ||||||||||||||||||
| 9746 | - | |||||||||||||||||||
| 9747 | /*! | - | ||||||||||||||||||
| 9748 | \since 4.8 | - | ||||||||||||||||||
| 9749 | - | |||||||||||||||||||
| 9750 | Returns the index position of the last occurrence of the string \a | - | ||||||||||||||||||
| 9751 | str in this string reference, searching backward from index position | - | ||||||||||||||||||
| 9752 | \a from. If \a from is -1 (default), the search starts at the last | - | ||||||||||||||||||
| 9753 | character; if \a from is -2, at the next to last character and so | - | ||||||||||||||||||
| 9754 | on. Returns -1 if \a str is not found. | - | ||||||||||||||||||
| 9755 | - | |||||||||||||||||||
| 9756 | If \a cs is Qt::CaseSensitive (default), the search is case | - | ||||||||||||||||||
| 9757 | sensitive; otherwise the search is case insensitive. | - | ||||||||||||||||||
| 9758 | - | |||||||||||||||||||
| 9759 | \sa QString::lastIndexOf(), indexOf(), contains(), count() | - | ||||||||||||||||||
| 9760 | */ | - | ||||||||||||||||||
| 9761 | int QStringRef::lastIndexOf(const QString &str, int from, Qt::CaseSensitivity cs) const | - | ||||||||||||||||||
| 9762 | { | - | ||||||||||||||||||
| 9763 | const int sl = str.size(); | - | ||||||||||||||||||
| 9764 | if (sl == 1)
| 50-53 | ||||||||||||||||||
| 9765 | return lastIndexOf(str.at(0), from, cs); executed 53 times by 1 test: return lastIndexOf(str.at(0), from, cs);Executed by:
| 53 | ||||||||||||||||||
| 9766 | - | |||||||||||||||||||
| 9767 | const int l = size();; | - | ||||||||||||||||||
| 9768 | if (from < 0)
| 7-43 | ||||||||||||||||||
| 9769 | from += l; executed 43 times by 1 test: from += l;Executed by:
| 43 | ||||||||||||||||||
| 9770 | int delta = l - sl; | - | ||||||||||||||||||
| 9771 | if (from == l && sl == 0)
| 1-48 | ||||||||||||||||||
| 9772 | return from; executed 1 time by 1 test: return from;Executed by:
| 1 | ||||||||||||||||||
| 9773 | if (uint(from) >= uint(l) || delta < 0)
| 7-41 | ||||||||||||||||||
| 9774 | return -1; executed 15 times by 1 test: return -1;Executed by:
| 15 | ||||||||||||||||||
| 9775 | if (from > delta)
| 5-29 | ||||||||||||||||||
| 9776 | from = delta; executed 29 times by 1 test: from = delta;Executed by:
| 29 | ||||||||||||||||||
| 9777 | - | |||||||||||||||||||
| 9778 | 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 | ||||||||||||||||||
| 9779 | 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 | ||||||||||||||||||
| 9780 | } | - | ||||||||||||||||||
| 9781 | - | |||||||||||||||||||
| 9782 | /*! | - | ||||||||||||||||||
| 9783 | \since 4.8 | - | ||||||||||||||||||
| 9784 | \overload lastIndexOf() | - | ||||||||||||||||||
| 9785 | - | |||||||||||||||||||
| 9786 | Returns the index position of the last occurrence of the character | - | ||||||||||||||||||
| 9787 | \a ch, searching backward from position \a from. | - | ||||||||||||||||||
| 9788 | - | |||||||||||||||||||
| 9789 | \sa QString::lastIndexOf(), indexOf(), contains(), count() | - | ||||||||||||||||||
| 9790 | */ | - | ||||||||||||||||||
| 9791 | int QStringRef::lastIndexOf(QChar ch, int from, Qt::CaseSensitivity cs) const | - | ||||||||||||||||||
| 9792 | { | - | ||||||||||||||||||
| 9793 | 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 | ||||||||||||||||||
| 9794 | } | - | ||||||||||||||||||
| 9795 | - | |||||||||||||||||||
| 9796 | /*! | - | ||||||||||||||||||
| 9797 | \since 4.8 | - | ||||||||||||||||||
| 9798 | \overload lastIndexOf() | - | ||||||||||||||||||
| 9799 | - | |||||||||||||||||||
| 9800 | Returns the index position of the last occurrence of the string \a | - | ||||||||||||||||||
| 9801 | str in this string reference, searching backward from index position | - | ||||||||||||||||||
| 9802 | \a from. If \a from is -1 (default), the search starts at the last | - | ||||||||||||||||||
| 9803 | character; if \a from is -2, at the next to last character and so | - | ||||||||||||||||||
| 9804 | on. Returns -1 if \a str is not found. | - | ||||||||||||||||||
| 9805 | - | |||||||||||||||||||
| 9806 | If \a cs is Qt::CaseSensitive (default), the search is case | - | ||||||||||||||||||
| 9807 | sensitive; otherwise the search is case insensitive. | - | ||||||||||||||||||
| 9808 | - | |||||||||||||||||||
| 9809 | \sa QString::lastIndexOf(), indexOf(), contains(), count() | - | ||||||||||||||||||
| 9810 | */ | - | ||||||||||||||||||
| 9811 | int QStringRef::lastIndexOf(QLatin1String str, int from, Qt::CaseSensitivity cs) const | - | ||||||||||||||||||
| 9812 | { | - | ||||||||||||||||||
| 9813 | const int sl = str.size(); | - | ||||||||||||||||||
| 9814 | if (sl == 1)
| 0 | ||||||||||||||||||
| 9815 | return lastIndexOf(QLatin1Char(str.latin1()[0]), from, cs); never executed: return lastIndexOf(QLatin1Char(str.latin1()[0]), from, cs); | 0 | ||||||||||||||||||
| 9816 | - | |||||||||||||||||||
| 9817 | const int l = size(); | - | ||||||||||||||||||
| 9818 | if (from < 0)
| 0 | ||||||||||||||||||
| 9819 | from += l; never executed: from += l; | 0 | ||||||||||||||||||
| 9820 | int delta = l - sl; | - | ||||||||||||||||||
| 9821 | if (from == l && sl == 0)
| 0 | ||||||||||||||||||
| 9822 | return from; never executed: return from; | 0 | ||||||||||||||||||
| 9823 | if (uint(from) >= uint(l) || delta < 0)
| 0 | ||||||||||||||||||
| 9824 | return -1; never executed: return -1; | 0 | ||||||||||||||||||
| 9825 | if (from > delta)
| 0 | ||||||||||||||||||
| 9826 | from = delta; never executed: from = delta; | 0 | ||||||||||||||||||
| 9827 | - | |||||||||||||||||||
| 9828 | QVarLengthArray<ushort> s(sl); | - | ||||||||||||||||||
| 9829 | qt_from_latin1(s.data(), str.latin1(), sl); | - | ||||||||||||||||||
| 9830 | - | |||||||||||||||||||
| 9831 | 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 | ||||||||||||||||||
| 9832 | } | - | ||||||||||||||||||
| 9833 | - | |||||||||||||||||||
| 9834 | /*! | - | ||||||||||||||||||
| 9835 | \since 4.8 | - | ||||||||||||||||||
| 9836 | \overload lastIndexOf() | - | ||||||||||||||||||
| 9837 | - | |||||||||||||||||||
| 9838 | Returns the index position of the last occurrence of the string | - | ||||||||||||||||||
| 9839 | reference \a str in this string reference, searching backward from | - | ||||||||||||||||||
| 9840 | index position \a from. If \a from is -1 (default), the search | - | ||||||||||||||||||
| 9841 | starts at the last character; if \a from is -2, at the next to last | - | ||||||||||||||||||
| 9842 | character and so on. Returns -1 if \a str is not found. | - | ||||||||||||||||||
| 9843 | - | |||||||||||||||||||
| 9844 | If \a cs is Qt::CaseSensitive (default), the search is case | - | ||||||||||||||||||
| 9845 | sensitive; otherwise the search is case insensitive. | - | ||||||||||||||||||
| 9846 | - | |||||||||||||||||||
| 9847 | \sa QString::lastIndexOf(), indexOf(), contains(), count() | - | ||||||||||||||||||
| 9848 | */ | - | ||||||||||||||||||
| 9849 | int QStringRef::lastIndexOf(const QStringRef &str, int from, Qt::CaseSensitivity cs) const | - | ||||||||||||||||||
| 9850 | { | - | ||||||||||||||||||
| 9851 | const int sl = str.size(); | - | ||||||||||||||||||
| 9852 | if (sl == 1)
| 50-53 | ||||||||||||||||||
| 9853 | return lastIndexOf(str.at(0), from, cs); executed 53 times by 1 test: return lastIndexOf(str.at(0), from, cs);Executed by:
| 53 | ||||||||||||||||||
| 9854 | - | |||||||||||||||||||
| 9855 | const int l = size(); | - | ||||||||||||||||||
| 9856 | if (from < 0)
| 7-43 | ||||||||||||||||||
| 9857 | from += l; executed 43 times by 1 test: from += l;Executed by:
| 43 | ||||||||||||||||||
| 9858 | int delta = l - sl; | - | ||||||||||||||||||
| 9859 | if (from == l && sl == 0)
| 1-48 | ||||||||||||||||||
| 9860 | return from; executed 1 time by 1 test: return from;Executed by:
| 1 | ||||||||||||||||||
| 9861 | if (uint(from) >= uint(l) || delta < 0)
| 7-41 | ||||||||||||||||||
| 9862 | return -1; executed 15 times by 1 test: return -1;Executed by:
| 15 | ||||||||||||||||||
| 9863 | if (from > delta)
| 5-29 | ||||||||||||||||||
| 9864 | from = delta; executed 29 times by 1 test: from = delta;Executed by:
| 29 | ||||||||||||||||||
| 9865 | - | |||||||||||||||||||
| 9866 | 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 | ||||||||||||||||||
| 9867 | 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 | ||||||||||||||||||
| 9868 | 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 | ||||||||||||||||||
| 9869 | } | - | ||||||||||||||||||
| 9870 | - | |||||||||||||||||||
| 9871 | /*! | - | ||||||||||||||||||
| 9872 | \since 4.8 | - | ||||||||||||||||||
| 9873 | Returns the number of (potentially overlapping) occurrences of | - | ||||||||||||||||||
| 9874 | the string \a str in this string reference. | - | ||||||||||||||||||
| 9875 | - | |||||||||||||||||||
| 9876 | If \a cs is Qt::CaseSensitive (default), the search is | - | ||||||||||||||||||
| 9877 | case sensitive; otherwise the search is case insensitive. | - | ||||||||||||||||||
| 9878 | - | |||||||||||||||||||
| 9879 | \sa QString::count(), contains(), indexOf() | - | ||||||||||||||||||
| 9880 | */ | - | ||||||||||||||||||
| 9881 | int QStringRef::count(const QString &str, Qt::CaseSensitivity cs) const | - | ||||||||||||||||||
| 9882 | { | - | ||||||||||||||||||
| 9883 | 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 | ||||||||||||||||||
| 9884 | } | - | ||||||||||||||||||
| 9885 | - | |||||||||||||||||||
| 9886 | /*! | - | ||||||||||||||||||
| 9887 | \since 4.8 | - | ||||||||||||||||||
| 9888 | \overload count() | - | ||||||||||||||||||
| 9889 | - | |||||||||||||||||||
| 9890 | Returns the number of occurrences of the character \a ch in the | - | ||||||||||||||||||
| 9891 | string reference. | - | ||||||||||||||||||
| 9892 | - | |||||||||||||||||||
| 9893 | If \a cs is Qt::CaseSensitive (default), the search is | - | ||||||||||||||||||
| 9894 | case sensitive; otherwise the search is case insensitive. | - | ||||||||||||||||||
| 9895 | - | |||||||||||||||||||
| 9896 | \sa QString::count(), contains(), indexOf() | - | ||||||||||||||||||
| 9897 | */ | - | ||||||||||||||||||
| 9898 | int QStringRef::count(QChar ch, Qt::CaseSensitivity cs) const | - | ||||||||||||||||||
| 9899 | { | - | ||||||||||||||||||
| 9900 | 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 | ||||||||||||||||||
| 9901 | } | - | ||||||||||||||||||
| 9902 | - | |||||||||||||||||||
| 9903 | /*! | - | ||||||||||||||||||
| 9904 | \since 4.8 | - | ||||||||||||||||||
| 9905 | \overload count() | - | ||||||||||||||||||
| 9906 | - | |||||||||||||||||||
| 9907 | Returns the number of (potentially overlapping) occurrences of the | - | ||||||||||||||||||
| 9908 | string reference \a str in this string reference. | - | ||||||||||||||||||
| 9909 | - | |||||||||||||||||||
| 9910 | If \a cs is Qt::CaseSensitive (default), the search is | - | ||||||||||||||||||
| 9911 | case sensitive; otherwise the search is case insensitive. | - | ||||||||||||||||||
| 9912 | - | |||||||||||||||||||
| 9913 | \sa QString::count(), contains(), indexOf() | - | ||||||||||||||||||
| 9914 | */ | - | ||||||||||||||||||
| 9915 | int QStringRef::count(const QStringRef &str, Qt::CaseSensitivity cs) const | - | ||||||||||||||||||
| 9916 | { | - | ||||||||||||||||||
| 9917 | 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 | ||||||||||||||||||
| 9918 | } | - | ||||||||||||||||||
| 9919 | - | |||||||||||||||||||
| 9920 | /*! | - | ||||||||||||||||||
| 9921 | \since 4.8 | - | ||||||||||||||||||
| 9922 | - | |||||||||||||||||||
| 9923 | Returns \c true if the string reference starts with \a str; otherwise | - | ||||||||||||||||||
| 9924 | returns \c false. | - | ||||||||||||||||||
| 9925 | - | |||||||||||||||||||
| 9926 | If \a cs is Qt::CaseSensitive (default), the search is | - | ||||||||||||||||||
| 9927 | case sensitive; otherwise the search is case insensitive. | - | ||||||||||||||||||
| 9928 | - | |||||||||||||||||||
| 9929 | \sa QString::startsWith(), endsWith() | - | ||||||||||||||||||
| 9930 | */ | - | ||||||||||||||||||
| 9931 | bool QStringRef::startsWith(const QString &str, Qt::CaseSensitivity cs) const | - | ||||||||||||||||||
| 9932 | { | - | ||||||||||||||||||
| 9933 | return qt_starts_with(isNull() ? 0 : unicode(), size(), executed 68 times by 3 tests: return qt_starts_with(isNull() ? 0 : unicode(), size(), str.isNull() ? 0 : str.unicode(), str.size(), cs);Executed by:
| 68 | ||||||||||||||||||
| 9934 | str.isNull() ? 0 : str.unicode(), str.size(), cs); executed 68 times by 3 tests: return qt_starts_with(isNull() ? 0 : unicode(), size(), str.isNull() ? 0 : str.unicode(), str.size(), cs);Executed by:
| 68 | ||||||||||||||||||
| 9935 | } | - | ||||||||||||||||||
| 9936 | - | |||||||||||||||||||
| 9937 | /*! | - | ||||||||||||||||||
| 9938 | \since 4.8 | - | ||||||||||||||||||
| 9939 | \overload startsWith() | - | ||||||||||||||||||
| 9940 | \sa QString::startsWith(), endsWith() | - | ||||||||||||||||||
| 9941 | */ | - | ||||||||||||||||||
| 9942 | bool QStringRef::startsWith(QLatin1String str, Qt::CaseSensitivity cs) const | - | ||||||||||||||||||
| 9943 | { | - | ||||||||||||||||||
| 9944 | return qt_starts_with(isNull() ? 0 : unicode(), size(), str, cs); executed 5479 times by 28 tests: return qt_starts_with(isNull() ? 0 : unicode(), size(), str, cs);Executed by:
| 5479 | ||||||||||||||||||
| 9945 | } | - | ||||||||||||||||||
| 9946 | - | |||||||||||||||||||
| 9947 | /*! | - | ||||||||||||||||||
| 9948 | \since 4.8 | - | ||||||||||||||||||
| 9949 | \overload startsWith() | - | ||||||||||||||||||
| 9950 | \sa QString::startsWith(), endsWith() | - | ||||||||||||||||||
| 9951 | */ | - | ||||||||||||||||||
| 9952 | bool QStringRef::startsWith(const QStringRef &str, Qt::CaseSensitivity cs) const | - | ||||||||||||||||||
| 9953 | { | - | ||||||||||||||||||
| 9954 | 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 | ||||||||||||||||||
| 9955 | 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 | ||||||||||||||||||
| 9956 | } | - | ||||||||||||||||||
| 9957 | - | |||||||||||||||||||
| 9958 | /*! | - | ||||||||||||||||||
| 9959 | \since 4.8 | - | ||||||||||||||||||
| 9960 | \overload startsWith() | - | ||||||||||||||||||
| 9961 | - | |||||||||||||||||||
| 9962 | Returns \c true if the string reference starts with \a ch; otherwise | - | ||||||||||||||||||
| 9963 | returns \c false. | - | ||||||||||||||||||
| 9964 | - | |||||||||||||||||||
| 9965 | If \a cs is Qt::CaseSensitive (default), the search is case | - | ||||||||||||||||||
| 9966 | sensitive; otherwise the search is case insensitive. | - | ||||||||||||||||||
| 9967 | - | |||||||||||||||||||
| 9968 | \sa QString::startsWith(), endsWith() | - | ||||||||||||||||||
| 9969 | */ | - | ||||||||||||||||||
| 9970 | bool QStringRef::startsWith(QChar ch, Qt::CaseSensitivity cs) const | - | ||||||||||||||||||
| 9971 | { | - | ||||||||||||||||||
| 9972 | if (!isEmpty()) {
| 17-93315 | ||||||||||||||||||
| 9973 | const ushort *data = reinterpret_cast<const ushort*>(unicode()); | - | ||||||||||||||||||
| 9974 | return (cs == Qt::CaseSensitive executed 93315 times by 185 tests: return (cs == Qt::CaseSensitive ? data[0] == ch : foldCase(data[0]) == foldCase(ch.unicode()));Executed by:
| 93315 | ||||||||||||||||||
| 9975 | ? data[0] == ch executed 93315 times by 185 tests: return (cs == Qt::CaseSensitive ? data[0] == ch : foldCase(data[0]) == foldCase(ch.unicode()));Executed by:
| 93315 | ||||||||||||||||||
| 9976 | : foldCase(data[0]) == foldCase(ch.unicode())); executed 93315 times by 185 tests: return (cs == Qt::CaseSensitive ? data[0] == ch : foldCase(data[0]) == foldCase(ch.unicode()));Executed by:
| 93315 | ||||||||||||||||||
| 9977 | } else { | - | ||||||||||||||||||
| 9978 | return false; executed 17 times by 2 tests: return false;Executed by:
| 17 | ||||||||||||||||||
| 9979 | } | - | ||||||||||||||||||
| 9980 | } | - | ||||||||||||||||||
| 9981 | - | |||||||||||||||||||
| 9982 | /*! | - | ||||||||||||||||||
| 9983 | \since 4.8 | - | ||||||||||||||||||
| 9984 | Returns \c true if the string reference ends with \a str; otherwise | - | ||||||||||||||||||
| 9985 | returns \c false. | - | ||||||||||||||||||
| 9986 | - | |||||||||||||||||||
| 9987 | If \a cs is Qt::CaseSensitive (default), the search is case | - | ||||||||||||||||||
| 9988 | sensitive; otherwise the search is case insensitive. | - | ||||||||||||||||||
| 9989 | - | |||||||||||||||||||
| 9990 | \sa QString::endsWith(), startsWith() | - | ||||||||||||||||||
| 9991 | */ | - | ||||||||||||||||||
| 9992 | bool QStringRef::endsWith(const QString &str, Qt::CaseSensitivity cs) const | - | ||||||||||||||||||
| 9993 | { | - | ||||||||||||||||||
| 9994 | return qt_ends_with(isNull() ? 0 : unicode(), size(), executed 70 times by 4 tests: return qt_ends_with(isNull() ? 0 : unicode(), size(), str.isNull() ? 0 : str.unicode(), str.size(), cs);Executed by:
| 70 | ||||||||||||||||||
| 9995 | str.isNull() ? 0 : str.unicode(), str.size(), cs); executed 70 times by 4 tests: return qt_ends_with(isNull() ? 0 : unicode(), size(), str.isNull() ? 0 : str.unicode(), str.size(), cs);Executed by:
| 70 | ||||||||||||||||||
| 9996 | } | - | ||||||||||||||||||
| 9997 | - | |||||||||||||||||||
| 9998 | /*! | - | ||||||||||||||||||
| 9999 | \since 4.8 | - | ||||||||||||||||||
| 10000 | \overload endsWith() | - | ||||||||||||||||||
| 10001 | - | |||||||||||||||||||
| 10002 | Returns \c true if the string reference ends with \a ch; otherwise | - | ||||||||||||||||||
| 10003 | returns \c false. | - | ||||||||||||||||||
| 10004 | - | |||||||||||||||||||
| 10005 | If \a cs is Qt::CaseSensitive (default), the search is case | - | ||||||||||||||||||
| 10006 | sensitive; otherwise the search is case insensitive. | - | ||||||||||||||||||
| 10007 | - | |||||||||||||||||||
| 10008 | \sa QString::endsWith(), endsWith() | - | ||||||||||||||||||
| 10009 | */ | - | ||||||||||||||||||
| 10010 | bool QStringRef::endsWith(QChar ch, Qt::CaseSensitivity cs) const | - | ||||||||||||||||||
| 10011 | { | - | ||||||||||||||||||
| 10012 | if (!isEmpty()) {
| 6-24148 | ||||||||||||||||||
| 10013 | const ushort *data = reinterpret_cast<const ushort*>(unicode()); | - | ||||||||||||||||||
| 10014 | const int size = length(); | - | ||||||||||||||||||
| 10015 | return (cs == Qt::CaseSensitive executed 24148 times by 10 tests: return (cs == Qt::CaseSensitive ? data[size - 1] == ch : foldCase(data[size - 1]) == foldCase(ch.unicode()));Executed by:
| 24148 | ||||||||||||||||||
| 10016 | ? data[size - 1] == ch executed 24148 times by 10 tests: return (cs == Qt::CaseSensitive ? data[size - 1] == ch : foldCase(data[size - 1]) == foldCase(ch.unicode()));Executed by:
| 24148 | ||||||||||||||||||
| 10017 | : foldCase(data[size - 1]) == foldCase(ch.unicode())); executed 24148 times by 10 tests: return (cs == Qt::CaseSensitive ? data[size - 1] == ch : foldCase(data[size - 1]) == foldCase(ch.unicode()));Executed by:
| 24148 | ||||||||||||||||||
| 10018 | } else { | - | ||||||||||||||||||
| 10019 | return false; executed 6 times by 1 test: return false;Executed by:
| 6 | ||||||||||||||||||
| 10020 | } | - | ||||||||||||||||||
| 10021 | } | - | ||||||||||||||||||
| 10022 | - | |||||||||||||||||||
| 10023 | /*! | - | ||||||||||||||||||
| 10024 | \since 4.8 | - | ||||||||||||||||||
| 10025 | \overload endsWith() | - | ||||||||||||||||||
| 10026 | \sa QString::endsWith(), endsWith() | - | ||||||||||||||||||
| 10027 | */ | - | ||||||||||||||||||
| 10028 | bool QStringRef::endsWith(QLatin1String str, Qt::CaseSensitivity cs) const | - | ||||||||||||||||||
| 10029 | { | - | ||||||||||||||||||
| 10030 | 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 | ||||||||||||||||||
| 10031 | } | - | ||||||||||||||||||
| 10032 | - | |||||||||||||||||||
| 10033 | /*! | - | ||||||||||||||||||
| 10034 | \since 4.8 | - | ||||||||||||||||||
| 10035 | \overload endsWith() | - | ||||||||||||||||||
| 10036 | \sa QString::endsWith(), endsWith() | - | ||||||||||||||||||
| 10037 | */ | - | ||||||||||||||||||
| 10038 | bool QStringRef::endsWith(const QStringRef &str, Qt::CaseSensitivity cs) const | - | ||||||||||||||||||
| 10039 | { | - | ||||||||||||||||||
| 10040 | 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 | ||||||||||||||||||
| 10041 | 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 | ||||||||||||||||||
| 10042 | } | - | ||||||||||||||||||
| 10043 | - | |||||||||||||||||||
| 10044 | - | |||||||||||||||||||
| 10045 | /*! \fn bool QStringRef::contains(const QString &str, Qt::CaseSensitivity cs = Qt::CaseSensitive) const | - | ||||||||||||||||||
| 10046 | - | |||||||||||||||||||
| 10047 | \since 4.8 | - | ||||||||||||||||||
| 10048 | Returns \c true if this string reference contains an occurrence of | - | ||||||||||||||||||
| 10049 | the string \a str; otherwise returns \c false. | - | ||||||||||||||||||
| 10050 | - | |||||||||||||||||||
| 10051 | If \a cs is Qt::CaseSensitive (default), the search is | - | ||||||||||||||||||
| 10052 | case sensitive; otherwise the search is case insensitive. | - | ||||||||||||||||||
| 10053 | - | |||||||||||||||||||
| 10054 | \sa indexOf(), count() | - | ||||||||||||||||||
| 10055 | */ | - | ||||||||||||||||||
| 10056 | - | |||||||||||||||||||
| 10057 | /*! \fn bool QStringRef::contains(QChar ch, Qt::CaseSensitivity cs = Qt::CaseSensitive) const | - | ||||||||||||||||||
| 10058 | - | |||||||||||||||||||
| 10059 | \overload contains() | - | ||||||||||||||||||
| 10060 | \since 4.8 | - | ||||||||||||||||||
| 10061 | - | |||||||||||||||||||
| 10062 | Returns \c true if this string contains an occurrence of the | - | ||||||||||||||||||
| 10063 | character \a ch; otherwise returns \c false. | - | ||||||||||||||||||
| 10064 | - | |||||||||||||||||||
| 10065 | If \a cs is Qt::CaseSensitive (default), the search is | - | ||||||||||||||||||
| 10066 | case sensitive; otherwise the search is case insensitive. | - | ||||||||||||||||||
| 10067 | - | |||||||||||||||||||
| 10068 | */ | - | ||||||||||||||||||
| 10069 | - | |||||||||||||||||||
| 10070 | /*! \fn bool QStringRef::contains(const QStringRef &str, Qt::CaseSensitivity cs = Qt::CaseSensitive) const | - | ||||||||||||||||||
| 10071 | \overload contains() | - | ||||||||||||||||||
| 10072 | \since 4.8 | - | ||||||||||||||||||
| 10073 | - | |||||||||||||||||||
| 10074 | Returns \c true if this string reference contains an occurrence of | - | ||||||||||||||||||
| 10075 | the string reference \a str; otherwise returns \c false. | - | ||||||||||||||||||
| 10076 | - | |||||||||||||||||||
| 10077 | If \a cs is Qt::CaseSensitive (default), the search is | - | ||||||||||||||||||
| 10078 | case sensitive; otherwise the search is case insensitive. | - | ||||||||||||||||||
| 10079 | - | |||||||||||||||||||
| 10080 | \sa indexOf(), count() | - | ||||||||||||||||||
| 10081 | */ | - | ||||||||||||||||||
| 10082 | - | |||||||||||||||||||
| 10083 | /*! \fn bool QStringRef::contains(QLatin1String str, Qt::CaseSensitivity cs) const | - | ||||||||||||||||||
| 10084 | \since 4,8 | - | ||||||||||||||||||
| 10085 | \overload contains() | - | ||||||||||||||||||
| 10086 | - | |||||||||||||||||||
| 10087 | Returns \c true if this string reference contains an occurrence of | - | ||||||||||||||||||
| 10088 | the string \a str; otherwise returns \c false. | - | ||||||||||||||||||
| 10089 | - | |||||||||||||||||||
| 10090 | If \a cs is Qt::CaseSensitive (default), the search is | - | ||||||||||||||||||
| 10091 | case sensitive; otherwise the search is case insensitive. | - | ||||||||||||||||||
| 10092 | - | |||||||||||||||||||
| 10093 | \sa indexOf(), count() | - | ||||||||||||||||||
| 10094 | */ | - | ||||||||||||||||||
| 10095 | - | |||||||||||||||||||
| 10096 | static inline int qt_last_index_of(const QChar *haystack, int haystackLen, QChar needle, | - | ||||||||||||||||||
| 10097 | int from, Qt::CaseSensitivity cs) | - | ||||||||||||||||||
| 10098 | { | - | ||||||||||||||||||
| 10099 | ushort c = needle.unicode(); | - | ||||||||||||||||||
| 10100 | if (from < 0)
| 7319-256550 | ||||||||||||||||||
| 10101 | from += haystackLen; executed 256550 times by 303 tests: from += haystackLen;Executed by:
| 256550 | ||||||||||||||||||
| 10102 | if (uint(from) >= uint(haystackLen))
| 1243-262626 | ||||||||||||||||||
| 10103 | return -1; executed 1243 times by 14 tests: return -1;Executed by:
| 1243 | ||||||||||||||||||
| 10104 | if (from >= 0) {
| 0-262626 | ||||||||||||||||||
| 10105 | const ushort *b = reinterpret_cast<const ushort*>(haystack); | - | ||||||||||||||||||
| 10106 | const ushort *n = b + from; | - | ||||||||||||||||||
| 10107 | if (cs == Qt::CaseSensitive) {
| 32-262594 | ||||||||||||||||||
| 10108 | for (; n >= b; --n)
| 7415-4147227 | ||||||||||||||||||
| 10109 | if (*n == c)
| 255179-3892048 | ||||||||||||||||||
| 10110 | return n - b; executed 255179 times by 285 tests: return n - b;Executed by:
| 255179 | ||||||||||||||||||
| 10111 | } else { executed 7415 times by 190 tests: end of blockExecuted by:
| 7415 | ||||||||||||||||||
| 10112 | c = foldCase(c); | - | ||||||||||||||||||
| 10113 | for (; n >= b; --n)
| 8-56 | ||||||||||||||||||
| 10114 | if (foldCase(*n) == c)
| 24-32 | ||||||||||||||||||
| 10115 | return n - b; executed 24 times by 2 tests: return n - b;Executed by:
| 24 | ||||||||||||||||||
| 10116 | } executed 8 times by 2 tests: end of blockExecuted by:
| 8 | ||||||||||||||||||
| 10117 | } | - | ||||||||||||||||||
| 10118 | return -1; executed 7423 times by 190 tests: return -1;Executed by:
| 7423 | ||||||||||||||||||
| 10119 | - | |||||||||||||||||||
| 10120 | - | |||||||||||||||||||
| 10121 | } | - | ||||||||||||||||||
| 10122 | - | |||||||||||||||||||
| 10123 | static inline int qt_string_count(const QChar *haystack, int haystackLen, | - | ||||||||||||||||||
| 10124 | const QChar *needle, int needleLen, | - | ||||||||||||||||||
| 10125 | Qt::CaseSensitivity cs) | - | ||||||||||||||||||
| 10126 | { | - | ||||||||||||||||||
| 10127 | int num = 0; | - | ||||||||||||||||||
| 10128 | int i = -1; | - | ||||||||||||||||||
| 10129 | if (haystackLen > 500 && needleLen > 5) {
| 0-18 | ||||||||||||||||||
| 10130 | QStringMatcher matcher(needle, needleLen, cs); | - | ||||||||||||||||||
| 10131 | while ((i = matcher.indexIn(haystack, haystackLen, i + 1)) != -1)
| 0 | ||||||||||||||||||
| 10132 | ++num; never executed: ++num; | 0 | ||||||||||||||||||
| 10133 | } else { never executed: end of block | 0 | ||||||||||||||||||
| 10134 | while ((i = qFindString(haystack, haystackLen, i + 1, needle, needleLen, cs)) != -1)
| 20-20628 | ||||||||||||||||||
| 10135 | ++num; executed 20628 times by 5 tests: ++num;Executed by:
| 20628 | ||||||||||||||||||
| 10136 | } executed 20 times by 5 tests: end of blockExecuted by:
| 20 | ||||||||||||||||||
| 10137 | return num; executed 20 times by 5 tests: return num;Executed by:
| 20 | ||||||||||||||||||
| 10138 | } | - | ||||||||||||||||||
| 10139 | - | |||||||||||||||||||
| 10140 | static inline int qt_string_count(const QChar *unicode, int size, QChar ch, | - | ||||||||||||||||||
| 10141 | Qt::CaseSensitivity cs) | - | ||||||||||||||||||
| 10142 | { | - | ||||||||||||||||||
| 10143 | ushort c = ch.unicode(); | - | ||||||||||||||||||
| 10144 | int num = 0; | - | ||||||||||||||||||
| 10145 | const ushort *b = reinterpret_cast<const ushort*>(unicode); | - | ||||||||||||||||||
| 10146 | const ushort *i = b + size; | - | ||||||||||||||||||
| 10147 | if (cs == Qt::CaseSensitive) {
| 2-54675 | ||||||||||||||||||
| 10148 | while (i != b)
| 54675-530412 | ||||||||||||||||||
| 10149 | if (*--i == c)
| 15161-515251 | ||||||||||||||||||
| 10150 | ++num; executed 15161 times by 29 tests: ++num;Executed by:
| 15161 | ||||||||||||||||||
| 10151 | } else { executed 54675 times by 30 tests: end of blockExecuted by:
| 54675 | ||||||||||||||||||
| 10152 | c = foldCase(c); | - | ||||||||||||||||||
| 10153 | while (i != b)
| 2-30 | ||||||||||||||||||
| 10154 | if (foldCase(*(--i)) == c)
| 6-24 | ||||||||||||||||||
| 10155 | ++num; executed 6 times by 2 tests: ++num;Executed by:
| 6 | ||||||||||||||||||
| 10156 | } executed 2 times by 2 tests: end of blockExecuted by:
| 2 | ||||||||||||||||||
| 10157 | return num; executed 54677 times by 30 tests: return num;Executed by:
| 54677 | ||||||||||||||||||
| 10158 | } | - | ||||||||||||||||||
| 10159 | - | |||||||||||||||||||
| 10160 | static inline int qt_find_latin1_string(const QChar *haystack, int size, | - | ||||||||||||||||||
| 10161 | QLatin1String needle, | - | ||||||||||||||||||
| 10162 | int from, Qt::CaseSensitivity cs) | - | ||||||||||||||||||
| 10163 | { | - | ||||||||||||||||||
| 10164 | if (size < needle.size())
| 2811-7708 | ||||||||||||||||||
| 10165 | return -1; executed 2811 times by 30 tests: return -1;Executed by:
| 2811 | ||||||||||||||||||
| 10166 | - | |||||||||||||||||||
| 10167 | const char *latin1 = needle.latin1(); | - | ||||||||||||||||||
| 10168 | int len = needle.size(); | - | ||||||||||||||||||
| 10169 | QVarLengthArray<ushort> s(len); | - | ||||||||||||||||||
| 10170 | qt_from_latin1(s.data(), latin1, len); | - | ||||||||||||||||||
| 10171 | - | |||||||||||||||||||
| 10172 | return qFindString(haystack, size, from, executed 7708 times by 181 tests: return qFindString(haystack, size, from, reinterpret_cast<const QChar*>(s.constData()), len, cs);Executed by:
| 7708 | ||||||||||||||||||
| 10173 | reinterpret_cast<const QChar*>(s.constData()), len, cs); executed 7708 times by 181 tests: return qFindString(haystack, size, from, reinterpret_cast<const QChar*>(s.constData()), len, cs);Executed by:
| 7708 | ||||||||||||||||||
| 10174 | } | - | ||||||||||||||||||
| 10175 | - | |||||||||||||||||||
| 10176 | static inline bool qt_starts_with(const QChar *haystack, int haystackLen, | - | ||||||||||||||||||
| 10177 | const QChar *needle, int needleLen, Qt::CaseSensitivity cs) | - | ||||||||||||||||||
| 10178 | { | - | ||||||||||||||||||
| 10179 | if (!haystack)
| 264-432338 | ||||||||||||||||||
| 10180 | return !needle; executed 264 times by 8 tests: return !needle;Executed by:
| 264 | ||||||||||||||||||
| 10181 | if (haystackLen == 0)
| 23-432315 | ||||||||||||||||||
| 10182 | return needleLen == 0; executed 23 times by 5 tests: return needleLen == 0;Executed by:
| 23 | ||||||||||||||||||
| 10183 | if (needleLen > haystackLen)
| 101241-331074 | ||||||||||||||||||
| 10184 | return false; executed 101241 times by 28 tests: return false;Executed by:
| 101241 | ||||||||||||||||||
| 10185 | - | |||||||||||||||||||
| 10186 | const ushort *h = reinterpret_cast<const ushort*>(haystack); | - | ||||||||||||||||||
| 10187 | const ushort *n = reinterpret_cast<const ushort*>(needle); | - | ||||||||||||||||||
| 10188 | - | |||||||||||||||||||
| 10189 | if (cs == Qt::CaseSensitive) {
| 2203-328871 | ||||||||||||||||||
| 10190 | return qMemEquals(h, n, needleLen); executed 328871 times by 113 tests: return qMemEquals(h, n, needleLen);Executed by:
| 328871 | ||||||||||||||||||
| 10191 | } else { | - | ||||||||||||||||||
| 10192 | uint last = 0; | - | ||||||||||||||||||
| 10193 | uint olast = 0; | - | ||||||||||||||||||
| 10194 | for (int i = 0; i < needleLen; ++i)
| 613-5659 | ||||||||||||||||||
| 10195 | if (foldCase(h[i], last) != foldCase(n[i], olast))
| 1590-4069 | ||||||||||||||||||
| 10196 | return false; executed 1590 times by 13 tests: return false;Executed by:
| 1590 | ||||||||||||||||||
| 10197 | } executed 613 times by 21 tests: end of blockExecuted by:
| 613 | ||||||||||||||||||
| 10198 | return true; executed 613 times by 21 tests: return true;Executed by:
| 613 | ||||||||||||||||||
| 10199 | } | - | ||||||||||||||||||
| 10200 | - | |||||||||||||||||||
| 10201 | static inline bool qt_starts_with(const QChar *haystack, int haystackLen, | - | ||||||||||||||||||
| 10202 | QLatin1String needle, Qt::CaseSensitivity cs) | - | ||||||||||||||||||
| 10203 | { | - | ||||||||||||||||||
| 10204 | if (!haystack)
| 6767-251067 | ||||||||||||||||||
| 10205 | return !needle.latin1(); executed 6767 times by 53 tests: return !needle.latin1();Executed by:
| 6767 | ||||||||||||||||||
| 10206 | if (haystackLen == 0)
| 1953-249114 | ||||||||||||||||||
| 10207 | return !needle.latin1() || *needle.latin1() == 0; executed 1953 times by 11 tests: return !needle.latin1() || *needle.latin1() == 0;Executed by:
| 1953 | ||||||||||||||||||
| 10208 | const int slen = needle.size(); | - | ||||||||||||||||||
| 10209 | if (slen > haystackLen)
| 84528-164586 | ||||||||||||||||||
| 10210 | return false; executed 164586 times by 136 tests: return false;Executed by:
| 164586 | ||||||||||||||||||
| 10211 | const ushort *data = reinterpret_cast<const ushort*>(haystack); | - | ||||||||||||||||||
| 10212 | const uchar *latin = reinterpret_cast<const uchar*>(needle.latin1()); | - | ||||||||||||||||||
| 10213 | if (cs == Qt::CaseSensitive) {
| 3673-80855 | ||||||||||||||||||
| 10214 | return ucstrncmp(haystack, latin, slen) == 0; executed 80855 times by 233 tests: return ucstrncmp(haystack, latin, slen) == 0;Executed by:
| 80855 | ||||||||||||||||||
| 10215 | } else { | - | ||||||||||||||||||
| 10216 | for (int i = 0; i < slen; ++i)
| 34-3803 | ||||||||||||||||||
| 10217 | if (foldCase(data[i]) != foldCase((ushort)latin[i]))
| 164-3639 | ||||||||||||||||||
| 10218 | return false; executed 3639 times by 15 tests: return false;Executed by:
| 3639 | ||||||||||||||||||
| 10219 | } executed 34 times by 4 tests: end of blockExecuted by:
| 34 | ||||||||||||||||||
| 10220 | return true; executed 34 times by 4 tests: return true;Executed by:
| 34 | ||||||||||||||||||
| 10221 | } | - | ||||||||||||||||||
| 10222 | - | |||||||||||||||||||
| 10223 | static inline bool qt_ends_with(const QChar *haystack, int haystackLen, | - | ||||||||||||||||||
| 10224 | const QChar *needle, int needleLen, Qt::CaseSensitivity cs) | - | ||||||||||||||||||
| 10225 | { | - | ||||||||||||||||||
| 10226 | if (!haystack)
| 6-4562 | ||||||||||||||||||
| 10227 | return !needle; executed 6 times by 2 tests: return !needle;Executed by:
| 6 | ||||||||||||||||||
| 10228 | if (haystackLen == 0)
| 6-4556 | ||||||||||||||||||
| 10229 | return needleLen == 0; executed 6 times by 2 tests: return needleLen == 0;Executed by:
| 6 | ||||||||||||||||||
| 10230 | const int pos = haystackLen - needleLen; | - | ||||||||||||||||||
| 10231 | if (pos < 0)
| 212-4344 | ||||||||||||||||||
| 10232 | return false; executed 212 times by 24 tests: return false;Executed by:
| 212 | ||||||||||||||||||
| 10233 | - | |||||||||||||||||||
| 10234 | const ushort *h = reinterpret_cast<const ushort*>(haystack); | - | ||||||||||||||||||
| 10235 | const ushort *n = reinterpret_cast<const ushort*>(needle); | - | ||||||||||||||||||
| 10236 | - | |||||||||||||||||||
| 10237 | if (cs == Qt::CaseSensitive) {
| 23-4321 | ||||||||||||||||||
| 10238 | return qMemEquals(h + pos, n, needleLen); executed 4321 times by 52 tests: return qMemEquals(h + pos, n, needleLen);Executed by:
| 4321 | ||||||||||||||||||
| 10239 | } else { | - | ||||||||||||||||||
| 10240 | uint last = 0; | - | ||||||||||||||||||
| 10241 | uint olast = 0; | - | ||||||||||||||||||
| 10242 | for (int i = 0; i < needleLen; i++)
| 14-24 | ||||||||||||||||||
| 10243 | if (foldCase(h[pos+i], last) != foldCase(n[i], olast))
| 9-15 | ||||||||||||||||||
| 10244 | return false; executed 9 times by 4 tests: return false;Executed by:
| 9 | ||||||||||||||||||
| 10245 | } executed 14 times by 4 tests: end of blockExecuted by:
| 14 | ||||||||||||||||||
| 10246 | return true; executed 14 times by 4 tests: return true;Executed by:
| 14 | ||||||||||||||||||
| 10247 | } | - | ||||||||||||||||||
| 10248 | - | |||||||||||||||||||
| 10249 | - | |||||||||||||||||||
| 10250 | static inline bool qt_ends_with(const QChar *haystack, int haystackLen, | - | ||||||||||||||||||
| 10251 | QLatin1String needle, Qt::CaseSensitivity cs) | - | ||||||||||||||||||
| 10252 | { | - | ||||||||||||||||||
| 10253 | if (!haystack)
| 201-146201 | ||||||||||||||||||
| 10254 | return !needle.latin1(); executed 201 times by 13 tests: return !needle.latin1();Executed by:
| 201 | ||||||||||||||||||
| 10255 | if (haystackLen == 0)
| 14-146187 | ||||||||||||||||||
| 10256 | return !needle.latin1() || *needle.latin1() == 0; executed 14 times by 3 tests: return !needle.latin1() || *needle.latin1() == 0;Executed by:
| 14 | ||||||||||||||||||
| 10257 | const int slen = needle.size(); | - | ||||||||||||||||||
| 10258 | int pos = haystackLen - slen; | - | ||||||||||||||||||
| 10259 | if (pos < 0)
| 49748-96439 | ||||||||||||||||||
| 10260 | return false; executed 49748 times by 11 tests: return false;Executed by:
| 49748 | ||||||||||||||||||
| 10261 | const uchar *latin = reinterpret_cast<const uchar*>(needle.latin1()); | - | ||||||||||||||||||
| 10262 | const ushort *data = reinterpret_cast<const ushort*>(haystack); | - | ||||||||||||||||||
| 10263 | if (cs == Qt::CaseSensitive) {
| 566-95873 | ||||||||||||||||||
| 10264 | return ucstrncmp(haystack + pos, latin, slen) == 0; executed 95873 times by 121 tests: return ucstrncmp(haystack + pos, latin, slen) == 0;Executed by:
| 95873 | ||||||||||||||||||
| 10265 | } else { | - | ||||||||||||||||||
| 10266 | for (int i = 0; i < slen; i++)
| 511-1125 | ||||||||||||||||||
| 10267 | if (foldCase(data[pos+i]) != foldCase((ushort)latin[i]))
| 55-1070 | ||||||||||||||||||
| 10268 | return false; executed 55 times by 7 tests: return false;Executed by:
| 55 | ||||||||||||||||||
| 10269 | } executed 511 times by 16 tests: end of blockExecuted by:
| 511 | ||||||||||||||||||
| 10270 | return true; executed 511 times by 16 tests: return true;Executed by:
| 511 | ||||||||||||||||||
| 10271 | } | - | ||||||||||||||||||
| 10272 | - | |||||||||||||||||||
| 10273 | /*! | - | ||||||||||||||||||
| 10274 | \since 4.8 | - | ||||||||||||||||||
| 10275 | - | |||||||||||||||||||
| 10276 | Returns a Latin-1 representation of the string as a QByteArray. | - | ||||||||||||||||||
| 10277 | - | |||||||||||||||||||
| 10278 | The returned byte array is undefined if the string contains non-Latin1 | - | ||||||||||||||||||
| 10279 | characters. Those characters may be suppressed or replaced with a | - | ||||||||||||||||||
| 10280 | question mark. | - | ||||||||||||||||||
| 10281 | - | |||||||||||||||||||
| 10282 | \sa toUtf8(), toLocal8Bit(), QTextCodec | - | ||||||||||||||||||
| 10283 | */ | - | ||||||||||||||||||
| 10284 | QByteArray QStringRef::toLatin1() const | - | ||||||||||||||||||
| 10285 | { | - | ||||||||||||||||||
| 10286 | return QString::toLatin1_helper(unicode(), length()); executed 4355 times by 10 tests: return QString::toLatin1_helper(unicode(), length());Executed by:
| 4355 | ||||||||||||||||||
| 10287 | } | - | ||||||||||||||||||
| 10288 | - | |||||||||||||||||||
| 10289 | /*! | - | ||||||||||||||||||
| 10290 | \fn QByteArray QStringRef::toAscii() const | - | ||||||||||||||||||
| 10291 | \since 4.8 | - | ||||||||||||||||||
| 10292 | \deprecated | - | ||||||||||||||||||
| 10293 | - | |||||||||||||||||||
| 10294 | Returns an 8-bit representation of the string as a QByteArray. | - | ||||||||||||||||||
| 10295 | - | |||||||||||||||||||
| 10296 | This function does the same as toLatin1(). | - | ||||||||||||||||||
| 10297 | - | |||||||||||||||||||
| 10298 | Note that, despite the name, this function does not necessarily return an US-ASCII | - | ||||||||||||||||||
| 10299 | (ANSI X3.4-1986) string and its result may not be US-ASCII compatible. | - | ||||||||||||||||||
| 10300 | - | |||||||||||||||||||
| 10301 | \sa toLatin1(), toUtf8(), toLocal8Bit(), QTextCodec | - | ||||||||||||||||||
| 10302 | */ | - | ||||||||||||||||||
| 10303 | - | |||||||||||||||||||
| 10304 | /*! | - | ||||||||||||||||||
| 10305 | \since 4.8 | - | ||||||||||||||||||
| 10306 | - | |||||||||||||||||||
| 10307 | Returns the local 8-bit representation of the string as a | - | ||||||||||||||||||
| 10308 | QByteArray. The returned byte array is undefined if the string | - | ||||||||||||||||||
| 10309 | contains characters not supported by the local 8-bit encoding. | - | ||||||||||||||||||
| 10310 | - | |||||||||||||||||||
| 10311 | QTextCodec::codecForLocale() is used to perform the conversion from | - | ||||||||||||||||||
| 10312 | Unicode. If the locale encoding could not be determined, this function | - | ||||||||||||||||||
| 10313 | does the same as toLatin1(). | - | ||||||||||||||||||
| 10314 | - | |||||||||||||||||||
| 10315 | If this string contains any characters that cannot be encoded in the | - | ||||||||||||||||||
| 10316 | locale, the returned byte array is undefined. Those characters may be | - | ||||||||||||||||||
| 10317 | suppressed or replaced by another. | - | ||||||||||||||||||
| 10318 | - | |||||||||||||||||||
| 10319 | \sa toLatin1(), toUtf8(), QTextCodec | - | ||||||||||||||||||
| 10320 | */ | - | ||||||||||||||||||
| 10321 | QByteArray QStringRef::toLocal8Bit() const | - | ||||||||||||||||||
| 10322 | { | - | ||||||||||||||||||
| 10323 | #ifndef QT_NO_TEXTCODEC | - | ||||||||||||||||||
| 10324 | QTextCodec *localeCodec = QTextCodec::codecForLocale(); | - | ||||||||||||||||||
| 10325 | if (localeCodec)
| 0-8 | ||||||||||||||||||
| 10326 | return localeCodec->fromUnicode(unicode(), length()); executed 8 times by 2 tests: return localeCodec->fromUnicode(unicode(), length());Executed by:
| 8 | ||||||||||||||||||
| 10327 | #endif // QT_NO_TEXTCODEC | - | ||||||||||||||||||
| 10328 | return toLatin1(); never executed: return toLatin1(); | 0 | ||||||||||||||||||
| 10329 | } | - | ||||||||||||||||||
| 10330 | - | |||||||||||||||||||
| 10331 | /*! | - | ||||||||||||||||||
| 10332 | \since 4.8 | - | ||||||||||||||||||
| 10333 | - | |||||||||||||||||||
| 10334 | Returns a UTF-8 representation of the string as a QByteArray. | - | ||||||||||||||||||
| 10335 | - | |||||||||||||||||||
| 10336 | UTF-8 is a Unicode codec and can represent all characters in a Unicode | - | ||||||||||||||||||
| 10337 | string like QString. | - | ||||||||||||||||||
| 10338 | - | |||||||||||||||||||
| 10339 | \sa toLatin1(), toLocal8Bit(), QTextCodec | - | ||||||||||||||||||
| 10340 | */ | - | ||||||||||||||||||
| 10341 | QByteArray QStringRef::toUtf8() const | - | ||||||||||||||||||
| 10342 | { | - | ||||||||||||||||||
| 10343 | if (isNull())
| 0-4688 | ||||||||||||||||||
| 10344 | return QByteArray(); never executed: return QByteArray(); | 0 | ||||||||||||||||||
| 10345 | - | |||||||||||||||||||
| 10346 | return QUtf8::convertFromUnicode(constData(), length()); executed 4688 times by 3 tests: return QUtf8::convertFromUnicode(constData(), length());Executed by:
| 4688 | ||||||||||||||||||
| 10347 | } | - | ||||||||||||||||||
| 10348 | - | |||||||||||||||||||
| 10349 | /*! | - | ||||||||||||||||||
| 10350 | \since 4.8 | - | ||||||||||||||||||
| 10351 | - | |||||||||||||||||||
| 10352 | Returns a UCS-4/UTF-32 representation of the string as a QVector<uint>. | - | ||||||||||||||||||
| 10353 | - | |||||||||||||||||||
| 10354 | UCS-4 is a Unicode codec and therefore it is lossless. All characters from | - | ||||||||||||||||||
| 10355 | this string will be encoded in UCS-4. Any invalid sequence of code units in | - | ||||||||||||||||||
| 10356 | this string is replaced by the Unicode's replacement character | - | ||||||||||||||||||
| 10357 | (QChar::ReplacementCharacter, which corresponds to \c{U+FFFD}). | - | ||||||||||||||||||
| 10358 | - | |||||||||||||||||||
| 10359 | The returned vector is not NUL terminated. | - | ||||||||||||||||||
| 10360 | - | |||||||||||||||||||
| 10361 | \sa toUtf8(), toLatin1(), toLocal8Bit(), QTextCodec | - | ||||||||||||||||||
| 10362 | */ | - | ||||||||||||||||||
| 10363 | QVector<uint> QStringRef::toUcs4() const | - | ||||||||||||||||||
| 10364 | { | - | ||||||||||||||||||
| 10365 | QVector<uint> v(length()); | - | ||||||||||||||||||
| 10366 | uint *a = v.data(); | - | ||||||||||||||||||
| 10367 | int len = QString::toUcs4_helper(reinterpret_cast<const ushort *>(unicode()), length(), a); | - | ||||||||||||||||||
| 10368 | v.resize(len); | - | ||||||||||||||||||
| 10369 | return v; never executed: return v; | 0 | ||||||||||||||||||
| 10370 | } | - | ||||||||||||||||||
| 10371 | - | |||||||||||||||||||
| 10372 | /*! | - | ||||||||||||||||||
| 10373 | Returns a string that has whitespace removed from the start and | - | ||||||||||||||||||
| 10374 | the end. | - | ||||||||||||||||||
| 10375 | - | |||||||||||||||||||
| 10376 | Whitespace means any character for which QChar::isSpace() returns | - | ||||||||||||||||||
| 10377 | \c true. This includes the ASCII characters '\\t', '\\n', '\\v', | - | ||||||||||||||||||
| 10378 | '\\f', '\\r', and ' '. | - | ||||||||||||||||||
| 10379 | - | |||||||||||||||||||
| 10380 | Unlike QString::simplified(), trimmed() leaves internal whitespace alone. | - | ||||||||||||||||||
| 10381 | - | |||||||||||||||||||
| 10382 | \since 5.1 | - | ||||||||||||||||||
| 10383 | - | |||||||||||||||||||
| 10384 | \sa QString::trimmed() | - | ||||||||||||||||||
| 10385 | */ | - | ||||||||||||||||||
| 10386 | QStringRef QStringRef::trimmed() const | - | ||||||||||||||||||
| 10387 | { | - | ||||||||||||||||||
| 10388 | const QChar *begin = cbegin(); | - | ||||||||||||||||||
| 10389 | const QChar *end = cend(); | - | ||||||||||||||||||
| 10390 | QStringAlgorithms<const QStringRef>::trimmed_helper_positions(begin, end); | - | ||||||||||||||||||
| 10391 | if (begin == cbegin() && end == cend())
| 19-37679 | ||||||||||||||||||
| 10392 | return *this; executed 37647 times by 134 tests: return *this;Executed by:
| 37647 | ||||||||||||||||||
| 10393 | if (begin == end)
| 3-48 | ||||||||||||||||||
| 10394 | return QStringRef(); executed 3 times by 2 tests: return QStringRef();Executed by:
| 3 | ||||||||||||||||||
| 10395 | int position = m_position + (begin - cbegin()); | - | ||||||||||||||||||
| 10396 | return QStringRef(m_string, position, end - begin); executed 48 times by 6 tests: return QStringRef(m_string, position, end - begin);Executed by:
| 48 | ||||||||||||||||||
| 10397 | } | - | ||||||||||||||||||
| 10398 | - | |||||||||||||||||||
| 10399 | /*! | - | ||||||||||||||||||
| 10400 | Returns the string converted to a \c{long long} using base \a | - | ||||||||||||||||||
| 10401 | base, which is 10 by default and must be between 2 and 36, or 0. | - | ||||||||||||||||||
| 10402 | Returns 0 if the conversion fails. | - | ||||||||||||||||||
| 10403 | - | |||||||||||||||||||
| 10404 | If a conversion error occurs, *\a{ok} is set to \c false; otherwise | - | ||||||||||||||||||
| 10405 | *\a{ok} is set to \c true. | - | ||||||||||||||||||
| 10406 | - | |||||||||||||||||||
| 10407 | If \a base is 0, the C language convention is used: If the string | - | ||||||||||||||||||
| 10408 | begins with "0x", base 16 is used; if the string begins with "0", | - | ||||||||||||||||||
| 10409 | base 8 is used; otherwise, base 10 is used. | - | ||||||||||||||||||
| 10410 | - | |||||||||||||||||||
| 10411 | The string conversion will always happen in the 'C' locale. For locale | - | ||||||||||||||||||
| 10412 | dependent conversion use QLocale::toLongLong() | - | ||||||||||||||||||
| 10413 | - | |||||||||||||||||||
| 10414 | \sa QString::toLongLong() | - | ||||||||||||||||||
| 10415 | - | |||||||||||||||||||
| 10416 | \since 5.1 | - | ||||||||||||||||||
| 10417 | */ | - | ||||||||||||||||||
| 10418 | - | |||||||||||||||||||
| 10419 | qint64 QStringRef::toLongLong(bool *ok, int base) const | - | ||||||||||||||||||
| 10420 | { | - | ||||||||||||||||||
| 10421 | return QString::toIntegral_helper<qint64>(constData(), size(), ok, base); executed 46772 times by 2 tests: return QString::toIntegral_helper<qint64>(constData(), size(), ok, base);Executed by:
| 46772 | ||||||||||||||||||
| 10422 | } | - | ||||||||||||||||||
| 10423 | - | |||||||||||||||||||
| 10424 | /*! | - | ||||||||||||||||||
| 10425 | Returns the string converted to an \c{unsigned long long} using base \a | - | ||||||||||||||||||
| 10426 | base, which is 10 by default and must be between 2 and 36, or 0. | - | ||||||||||||||||||
| 10427 | Returns 0 if the conversion fails. | - | ||||||||||||||||||
| 10428 | - | |||||||||||||||||||
| 10429 | If a conversion error occurs, *\a{ok} is set to \c false; otherwise | - | ||||||||||||||||||
| 10430 | *\a{ok} is set to \c true. | - | ||||||||||||||||||
| 10431 | - | |||||||||||||||||||
| 10432 | If \a base is 0, the C language convention is used: If the string | - | ||||||||||||||||||
| 10433 | begins with "0x", base 16 is used; if the string begins with "0", | - | ||||||||||||||||||
| 10434 | base 8 is used; otherwise, base 10 is used. | - | ||||||||||||||||||
| 10435 | - | |||||||||||||||||||
| 10436 | The string conversion will always happen in the 'C' locale. For locale | - | ||||||||||||||||||
| 10437 | dependent conversion use QLocale::toULongLong() | - | ||||||||||||||||||
| 10438 | - | |||||||||||||||||||
| 10439 | \sa QString::toULongLong() | - | ||||||||||||||||||
| 10440 | - | |||||||||||||||||||
| 10441 | \since 5.1 | - | ||||||||||||||||||
| 10442 | */ | - | ||||||||||||||||||
| 10443 | - | |||||||||||||||||||
| 10444 | quint64 QStringRef::toULongLong(bool *ok, int base) const | - | ||||||||||||||||||
| 10445 | { | - | ||||||||||||||||||
| 10446 | 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 | ||||||||||||||||||
| 10447 | } | - | ||||||||||||||||||
| 10448 | - | |||||||||||||||||||
| 10449 | /*! | - | ||||||||||||||||||
| 10450 | \fn long QStringRef::toLong(bool *ok, int base) const | - | ||||||||||||||||||
| 10451 | - | |||||||||||||||||||
| 10452 | Returns the string converted to a \c long using base \a | - | ||||||||||||||||||
| 10453 | base, which is 10 by default and must be between 2 and 36, or 0. | - | ||||||||||||||||||
| 10454 | Returns 0 if the conversion fails. | - | ||||||||||||||||||
| 10455 | - | |||||||||||||||||||
| 10456 | If a conversion error occurs, *\a{ok} is set to \c false; otherwise | - | ||||||||||||||||||
| 10457 | *\a{ok} is set to \c true. | - | ||||||||||||||||||
| 10458 | - | |||||||||||||||||||
| 10459 | If \a base is 0, the C language convention is used: If the string | - | ||||||||||||||||||
| 10460 | begins with "0x", base 16 is used; if the string begins with "0", | - | ||||||||||||||||||
| 10461 | base 8 is used; otherwise, base 10 is used. | - | ||||||||||||||||||
| 10462 | - | |||||||||||||||||||
| 10463 | The string conversion will always happen in the 'C' locale. For locale | - | ||||||||||||||||||
| 10464 | dependent conversion use QLocale::toLong() | - | ||||||||||||||||||
| 10465 | - | |||||||||||||||||||
| 10466 | \sa QString::toLong() | - | ||||||||||||||||||
| 10467 | - | |||||||||||||||||||
| 10468 | \since 5.1 | - | ||||||||||||||||||
| 10469 | */ | - | ||||||||||||||||||
| 10470 | - | |||||||||||||||||||
| 10471 | long QStringRef::toLong(bool *ok, int base) const | - | ||||||||||||||||||
| 10472 | { | - | ||||||||||||||||||
| 10473 | 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 | ||||||||||||||||||
| 10474 | } | - | ||||||||||||||||||
| 10475 | - | |||||||||||||||||||
| 10476 | /*! | - | ||||||||||||||||||
| 10477 | \fn ulong QStringRef::toULong(bool *ok, int base) const | - | ||||||||||||||||||
| 10478 | - | |||||||||||||||||||
| 10479 | Returns the string converted to an \c{unsigned long} using base \a | - | ||||||||||||||||||
| 10480 | base, which is 10 by default and must be between 2 and 36, or 0. | - | ||||||||||||||||||
| 10481 | Returns 0 if the conversion fails. | - | ||||||||||||||||||
| 10482 | - | |||||||||||||||||||
| 10483 | If a conversion error occurs, *\a{ok} is set to \c false; otherwise | - | ||||||||||||||||||
| 10484 | *\a{ok} is set to \c true. | - | ||||||||||||||||||
| 10485 | - | |||||||||||||||||||
| 10486 | If \a base is 0, the C language convention is used: If the string | - | ||||||||||||||||||
| 10487 | begins with "0x", base 16 is used; if the string begins with "0", | - | ||||||||||||||||||
| 10488 | base 8 is used; otherwise, base 10 is used. | - | ||||||||||||||||||
| 10489 | - | |||||||||||||||||||
| 10490 | The string conversion will always happen in the 'C' locale. For locale | - | ||||||||||||||||||
| 10491 | dependent conversion use QLocale::toULongLong() | - | ||||||||||||||||||
| 10492 | - | |||||||||||||||||||
| 10493 | \sa QString::toULong() | - | ||||||||||||||||||
| 10494 | - | |||||||||||||||||||
| 10495 | \since 5.1 | - | ||||||||||||||||||
| 10496 | */ | - | ||||||||||||||||||
| 10497 | - | |||||||||||||||||||
| 10498 | ulong QStringRef::toULong(bool *ok, int base) const | - | ||||||||||||||||||
| 10499 | { | - | ||||||||||||||||||
| 10500 | 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 | ||||||||||||||||||
| 10501 | } | - | ||||||||||||||||||
| 10502 | - | |||||||||||||||||||
| 10503 | - | |||||||||||||||||||
| 10504 | /*! | - | ||||||||||||||||||
| 10505 | Returns the string converted to an \c int using base \a | - | ||||||||||||||||||
| 10506 | base, which is 10 by default and must be between 2 and 36, or 0. | - | ||||||||||||||||||
| 10507 | Returns 0 if the conversion fails. | - | ||||||||||||||||||
| 10508 | - | |||||||||||||||||||
| 10509 | If a conversion error occurs, *\a{ok} is set to \c false; otherwise | - | ||||||||||||||||||
| 10510 | *\a{ok} is set to \c true. | - | ||||||||||||||||||
| 10511 | - | |||||||||||||||||||
| 10512 | If \a base is 0, the C language convention is used: If the string | - | ||||||||||||||||||
| 10513 | begins with "0x", base 16 is used; if the string begins with "0", | - | ||||||||||||||||||
| 10514 | base 8 is used; otherwise, base 10 is used. | - | ||||||||||||||||||
| 10515 | - | |||||||||||||||||||
| 10516 | The string conversion will always happen in the 'C' locale. For locale | - | ||||||||||||||||||
| 10517 | dependent conversion use QLocale::toInt() | - | ||||||||||||||||||
| 10518 | - | |||||||||||||||||||
| 10519 | \sa QString::toInt() | - | ||||||||||||||||||
| 10520 | - | |||||||||||||||||||
| 10521 | \since 5.1 | - | ||||||||||||||||||
| 10522 | */ | - | ||||||||||||||||||
| 10523 | - | |||||||||||||||||||
| 10524 | int QStringRef::toInt(bool *ok, int base) const | - | ||||||||||||||||||
| 10525 | { | - | ||||||||||||||||||
| 10526 | return QString::toIntegral_helper<int>(constData(), size(), ok, base); executed 14732 times by 16 tests: return QString::toIntegral_helper<int>(constData(), size(), ok, base);Executed by:
| 14732 | ||||||||||||||||||
| 10527 | } | - | ||||||||||||||||||
| 10528 | - | |||||||||||||||||||
| 10529 | /*! | - | ||||||||||||||||||
| 10530 | Returns the string converted to an \c{unsigned int} using base \a | - | ||||||||||||||||||
| 10531 | base, which is 10 by default and must be between 2 and 36, or 0. | - | ||||||||||||||||||
| 10532 | Returns 0 if the conversion fails. | - | ||||||||||||||||||
| 10533 | - | |||||||||||||||||||
| 10534 | If a conversion error occurs, *\a{ok} is set to \c false; otherwise | - | ||||||||||||||||||
| 10535 | *\a{ok} is set to \c true. | - | ||||||||||||||||||
| 10536 | - | |||||||||||||||||||
| 10537 | If \a base is 0, the C language convention is used: If the string | - | ||||||||||||||||||
| 10538 | begins with "0x", base 16 is used; if the string begins with "0", | - | ||||||||||||||||||
| 10539 | base 8 is used; otherwise, base 10 is used. | - | ||||||||||||||||||
| 10540 | - | |||||||||||||||||||
| 10541 | The string conversion will always happen in the 'C' locale. For locale | - | ||||||||||||||||||
| 10542 | dependent conversion use QLocale::toUInt() | - | ||||||||||||||||||
| 10543 | - | |||||||||||||||||||
| 10544 | \sa QString::toUInt() | - | ||||||||||||||||||
| 10545 | - | |||||||||||||||||||
| 10546 | \since 5.1 | - | ||||||||||||||||||
| 10547 | */ | - | ||||||||||||||||||
| 10548 | - | |||||||||||||||||||
| 10549 | uint QStringRef::toUInt(bool *ok, int base) const | - | ||||||||||||||||||
| 10550 | { | - | ||||||||||||||||||
| 10551 | return QString::toIntegral_helper<uint>(constData(), size(), ok, base); executed 1684 times by 5 tests: return QString::toIntegral_helper<uint>(constData(), size(), ok, base);Executed by:
| 1684 | ||||||||||||||||||
| 10552 | } | - | ||||||||||||||||||
| 10553 | - | |||||||||||||||||||
| 10554 | /*! | - | ||||||||||||||||||
| 10555 | Returns the string converted to a \c short using base \a | - | ||||||||||||||||||
| 10556 | base, which is 10 by default and must be between 2 and 36, or 0. | - | ||||||||||||||||||
| 10557 | Returns 0 if the conversion fails. | - | ||||||||||||||||||
| 10558 | - | |||||||||||||||||||
| 10559 | If a conversion error occurs, *\a{ok} is set to \c false; otherwise | - | ||||||||||||||||||
| 10560 | *\a{ok} is set to \c true. | - | ||||||||||||||||||
| 10561 | - | |||||||||||||||||||
| 10562 | If \a base is 0, the C language convention is used: If the string | - | ||||||||||||||||||
| 10563 | begins with "0x", base 16 is used; if the string begins with "0", | - | ||||||||||||||||||
| 10564 | base 8 is used; otherwise, base 10 is used. | - | ||||||||||||||||||
| 10565 | - | |||||||||||||||||||
| 10566 | The string conversion will always happen in the 'C' locale. For locale | - | ||||||||||||||||||
| 10567 | dependent conversion use QLocale::toShort() | - | ||||||||||||||||||
| 10568 | - | |||||||||||||||||||
| 10569 | \sa QString::toShort() | - | ||||||||||||||||||
| 10570 | - | |||||||||||||||||||
| 10571 | \since 5.1 | - | ||||||||||||||||||
| 10572 | */ | - | ||||||||||||||||||
| 10573 | - | |||||||||||||||||||
| 10574 | short QStringRef::toShort(bool *ok, int base) const | - | ||||||||||||||||||
| 10575 | { | - | ||||||||||||||||||
| 10576 | 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 | ||||||||||||||||||
| 10577 | } | - | ||||||||||||||||||
| 10578 | - | |||||||||||||||||||
| 10579 | /*! | - | ||||||||||||||||||
| 10580 | Returns the string converted to an \c{unsigned short} using base \a | - | ||||||||||||||||||
| 10581 | base, which is 10 by default and must be between 2 and 36, or 0. | - | ||||||||||||||||||
| 10582 | Returns 0 if the conversion fails. | - | ||||||||||||||||||
| 10583 | - | |||||||||||||||||||
| 10584 | If a conversion error occurs, *\a{ok} is set to \c false; otherwise | - | ||||||||||||||||||
| 10585 | *\a{ok} is set to \c true. | - | ||||||||||||||||||
| 10586 | - | |||||||||||||||||||
| 10587 | If \a base is 0, the C language convention is used: If the string | - | ||||||||||||||||||
| 10588 | begins with "0x", base 16 is used; if the string begins with "0", | - | ||||||||||||||||||
| 10589 | base 8 is used; otherwise, base 10 is used. | - | ||||||||||||||||||
| 10590 | - | |||||||||||||||||||
| 10591 | The string conversion will always happen in the 'C' locale. For locale | - | ||||||||||||||||||
| 10592 | dependent conversion use QLocale::toUShort() | - | ||||||||||||||||||
| 10593 | - | |||||||||||||||||||
| 10594 | \sa QString::toUShort() | - | ||||||||||||||||||
| 10595 | - | |||||||||||||||||||
| 10596 | \since 5.1 | - | ||||||||||||||||||
| 10597 | */ | - | ||||||||||||||||||
| 10598 | - | |||||||||||||||||||
| 10599 | ushort QStringRef::toUShort(bool *ok, int base) const | - | ||||||||||||||||||
| 10600 | { | - | ||||||||||||||||||
| 10601 | 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 | ||||||||||||||||||
| 10602 | } | - | ||||||||||||||||||
| 10603 | - | |||||||||||||||||||
| 10604 | - | |||||||||||||||||||
| 10605 | /*! | - | ||||||||||||||||||
| 10606 | Returns the string converted to a \c double value. | - | ||||||||||||||||||
| 10607 | - | |||||||||||||||||||
| 10608 | Returns 0.0 if the conversion fails. | - | ||||||||||||||||||
| 10609 | - | |||||||||||||||||||
| 10610 | If a conversion error occurs, \c{*}\a{ok} is set to \c false; | - | ||||||||||||||||||
| 10611 | otherwise \c{*}\a{ok} is set to \c true. | - | ||||||||||||||||||
| 10612 | - | |||||||||||||||||||
| 10613 | The string conversion will always happen in the 'C' locale. For locale | - | ||||||||||||||||||
| 10614 | dependent conversion use QLocale::toDouble() | - | ||||||||||||||||||
| 10615 | - | |||||||||||||||||||
| 10616 | For historic reasons, this function does not handle | - | ||||||||||||||||||
| 10617 | thousands group separators. If you need to convert such numbers, | - | ||||||||||||||||||
| 10618 | use QLocale::toDouble(). | - | ||||||||||||||||||
| 10619 | - | |||||||||||||||||||
| 10620 | \sa QString::toDouble() | - | ||||||||||||||||||
| 10621 | - | |||||||||||||||||||
| 10622 | \since 5.1 | - | ||||||||||||||||||
| 10623 | */ | - | ||||||||||||||||||
| 10624 | - | |||||||||||||||||||
| 10625 | double QStringRef::toDouble(bool *ok) const | - | ||||||||||||||||||
| 10626 | { | - | ||||||||||||||||||
| 10627 | return QLocaleData::c()->stringToDouble(constData(), size(), ok, QLocale::RejectGroupSeparator); executed 84 times by 4 tests: return QLocaleData::c()->stringToDouble(constData(), size(), ok, QLocale::RejectGroupSeparator);Executed by:
| 84 | ||||||||||||||||||
| 10628 | } | - | ||||||||||||||||||
| 10629 | - | |||||||||||||||||||
| 10630 | /*! | - | ||||||||||||||||||
| 10631 | Returns the string converted to a \c float value. | - | ||||||||||||||||||
| 10632 | - | |||||||||||||||||||
| 10633 | If a conversion error occurs, *\a{ok} is set to \c false; otherwise | - | ||||||||||||||||||
| 10634 | *\a{ok} is set to \c true. Returns 0.0 if the conversion fails. | - | ||||||||||||||||||
| 10635 | - | |||||||||||||||||||
| 10636 | The string conversion will always happen in the 'C' locale. For locale | - | ||||||||||||||||||
| 10637 | dependent conversion use QLocale::toFloat() | - | ||||||||||||||||||
| 10638 | - | |||||||||||||||||||
| 10639 | \sa QString::toFloat() | - | ||||||||||||||||||
| 10640 | - | |||||||||||||||||||
| 10641 | \since 5.1 | - | ||||||||||||||||||
| 10642 | */ | - | ||||||||||||||||||
| 10643 | - | |||||||||||||||||||
| 10644 | float QStringRef::toFloat(bool *ok) const | - | ||||||||||||||||||
| 10645 | { | - | ||||||||||||||||||
| 10646 | return QLocaleData::convertDoubleToFloat(toDouble(ok), ok); executed 15 times by 1 test: return QLocaleData::convertDoubleToFloat(toDouble(ok), ok);Executed by:
| 15 | ||||||||||||||||||
| 10647 | } | - | ||||||||||||||||||
| 10648 | - | |||||||||||||||||||
| 10649 | /*! | - | ||||||||||||||||||
| 10650 | \obsolete | - | ||||||||||||||||||
| 10651 | \fn QString Qt::escape(const QString &plain) | - | ||||||||||||||||||
| 10652 | - | |||||||||||||||||||
| 10653 | Use QString::toHtmlEscaped() instead. | - | ||||||||||||||||||
| 10654 | */ | - | ||||||||||||||||||
| 10655 | - | |||||||||||||||||||
| 10656 | /*! | - | ||||||||||||||||||
| 10657 | \since 5.0 | - | ||||||||||||||||||
| 10658 | - | |||||||||||||||||||
| 10659 | Converts a plain text string to an HTML string with | - | ||||||||||||||||||
| 10660 | HTML metacharacters \c{<}, \c{>}, \c{&}, and \c{"} replaced by HTML | - | ||||||||||||||||||
| 10661 | entities. | - | ||||||||||||||||||
| 10662 | - | |||||||||||||||||||
| 10663 | Example: | - | ||||||||||||||||||
| 10664 | - | |||||||||||||||||||
| 10665 | \snippet code/src_corelib_tools_qstring.cpp 7 | - | ||||||||||||||||||
| 10666 | */ | - | ||||||||||||||||||
| 10667 | QString QString::toHtmlEscaped() const | - | ||||||||||||||||||
| 10668 | { | - | ||||||||||||||||||
| 10669 | QString rich; | - | ||||||||||||||||||
| 10670 | const int len = length(); | - | ||||||||||||||||||
| 10671 | rich.reserve(int(len * 1.1)); | - | ||||||||||||||||||
| 10672 | for (int i = 0; i < len; ++i) {
| 2656-23789 | ||||||||||||||||||
| 10673 | if (at(i) == QLatin1Char('<'))
| 737-23052 | ||||||||||||||||||
| 10674 | rich += QLatin1String("<"); executed 737 times by 4 tests: rich += QLatin1String("<");Executed by:
| 737 | ||||||||||||||||||
| 10675 | else if (at(i) == QLatin1Char('>'))
| 737-22315 | ||||||||||||||||||
| 10676 | rich += QLatin1String(">"); executed 737 times by 4 tests: rich += QLatin1String(">");Executed by:
| 737 | ||||||||||||||||||
| 10677 | else if (at(i) == QLatin1Char('&'))
| 5-22310 | ||||||||||||||||||
| 10678 | rich += QLatin1String("&"); executed 5 times by 2 tests: rich += QLatin1String("&");Executed by:
| 5 | ||||||||||||||||||
| 10679 | else if (at(i) == QLatin1Char('"'))
| 6-22304 | ||||||||||||||||||
| 10680 | rich += QLatin1String("""); executed 6 times by 2 tests: rich += QLatin1String(""");Executed by:
| 6 | ||||||||||||||||||
| 10681 | else | - | ||||||||||||||||||
| 10682 | rich += at(i); executed 22304 times by 20 tests: rich += at(i);Executed by:
| 22304 | ||||||||||||||||||
| 10683 | } | - | ||||||||||||||||||
| 10684 | rich.squeeze(); | - | ||||||||||||||||||
| 10685 | return rich; executed 2656 times by 20 tests: return rich;Executed by:
| 2656 | ||||||||||||||||||
| 10686 | } | - | ||||||||||||||||||
| 10687 | - | |||||||||||||||||||
| 10688 | /*! | - | ||||||||||||||||||
| 10689 | \macro QStringLiteral(str) | - | ||||||||||||||||||
| 10690 | \relates QString | - | ||||||||||||||||||
| 10691 | - | |||||||||||||||||||
| 10692 | The macro generates the data for a QString out of \a str at compile time if the compiler supports it. | - | ||||||||||||||||||
| 10693 | Creating a QString from it is free in this case, and the generated string data is stored in | - | ||||||||||||||||||
| 10694 | the read-only segment of the compiled object file. | - | ||||||||||||||||||
| 10695 | - | |||||||||||||||||||
| 10696 | For compilers not supporting the creation of compile time strings, QStringLiteral will fall back to | - | ||||||||||||||||||
| 10697 | QString::fromUtf8(). | - | ||||||||||||||||||
| 10698 | - | |||||||||||||||||||
| 10699 | If you have code looking like: | - | ||||||||||||||||||
| 10700 | \code | - | ||||||||||||||||||
| 10701 | if (node.hasAttribute("http-contents-length")) //... | - | ||||||||||||||||||
| 10702 | \endcode | - | ||||||||||||||||||
| 10703 | One temporary QString will be created to be passed as the hasAttribute function parameter. | - | ||||||||||||||||||
| 10704 | This can be quite expensive, as it involves a memory allocation and the copy and the conversion | - | ||||||||||||||||||
| 10705 | of the data into QString's internal encoding. | - | ||||||||||||||||||
| 10706 | - | |||||||||||||||||||
| 10707 | This can be avoided by doing | - | ||||||||||||||||||
| 10708 | \code | - | ||||||||||||||||||
| 10709 | if (node.hasAttribute(QStringLiteral("http-contents-length"))) //... | - | ||||||||||||||||||
| 10710 | \endcode | - | ||||||||||||||||||
| 10711 | Then the QString's internal data will be generated at compile time and no conversion or allocation | - | ||||||||||||||||||
| 10712 | will occur at runtime | - | ||||||||||||||||||
| 10713 | - | |||||||||||||||||||
| 10714 | Using QStringLiteral instead of a double quoted ascii literal can significantly speed up creation | - | ||||||||||||||||||
| 10715 | of QString's from data known at compile time. | - | ||||||||||||||||||
| 10716 | - | |||||||||||||||||||
| 10717 | If the compiler is C++11 enabled the string \a str can actually contain unicode data. | - | ||||||||||||||||||
| 10718 | - | |||||||||||||||||||
| 10719 | \note There are still a few cases in which QLatin1String is more efficient than QStringLiteral: | - | ||||||||||||||||||
| 10720 | If it is passed to a function that has an overload that takes the QLatin1String directly, without | - | ||||||||||||||||||
| 10721 | conversion to QString. For instance, this is the case of QString::operator== | - | ||||||||||||||||||
| 10722 | \code | - | ||||||||||||||||||
| 10723 | if (attribute.name() == QLatin1String("http-contents-length")) //... | - | ||||||||||||||||||
| 10724 | \endcode | - | ||||||||||||||||||
| 10725 | - | |||||||||||||||||||
| 10726 | \note There are some restrictions when using the MSVC 2010 or 2012 compilers. The example snippets | - | ||||||||||||||||||
| 10727 | provided here fail to compile with them. | - | ||||||||||||||||||
| 10728 | \list | - | ||||||||||||||||||
| 10729 | \li Concatenated string literals cannot be used with QStringLiteral. | - | ||||||||||||||||||
| 10730 | \code | - | ||||||||||||||||||
| 10731 | QString s = QStringLiteral("a" "b"); | - | ||||||||||||||||||
| 10732 | \endcode | - | ||||||||||||||||||
| 10733 | \li QStringLiteral cannot be used to initialize lists or arrays of QString. | - | ||||||||||||||||||
| 10734 | \code | - | ||||||||||||||||||
| 10735 | QString a[] = { QStringLiteral("a"), QStringLiteral("b") }; | - | ||||||||||||||||||
| 10736 | \endcode | - | ||||||||||||||||||
| 10737 | \endlist | - | ||||||||||||||||||
| 10738 | */ | - | ||||||||||||||||||
| 10739 | - | |||||||||||||||||||
| 10740 | /*! | - | ||||||||||||||||||
| 10741 | \internal | - | ||||||||||||||||||
| 10742 | */ | - | ||||||||||||||||||
| 10743 | void QAbstractConcatenable::appendLatin1To(const char *a, int len, QChar *out) Q_DECL_NOTHROW | - | ||||||||||||||||||
| 10744 | { | - | ||||||||||||||||||
| 10745 | qt_from_latin1(reinterpret_cast<ushort *>(out), a, uint(len)); | - | ||||||||||||||||||
| 10746 | } executed 130482 times by 513 tests: end of blockExecuted by:
| 130482 | ||||||||||||||||||
| 10747 | - | |||||||||||||||||||
| 10748 | QT_END_NAMESPACE | - | ||||||||||||||||||
| Source code | Switch to Preprocessed file |