| Line | Source Code | Coverage |
|---|
| 1 | /**************************************************************************** | - |
| 2 | ** | - |
| 3 | ** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). | - |
| 4 | ** Contact: http://www.qt-project.org/legal | - |
| 5 | ** | - |
| 6 | ** This file is part of the QtCore module of the Qt Toolkit. | - |
| 7 | ** | - |
| 8 | ** $QT_BEGIN_LICENSE:LGPL$ | - |
| 9 | ** Commercial License Usage | - |
| 10 | ** Licensees holding valid commercial Qt licenses may use this file in | - |
| 11 | ** accordance with the commercial license agreement provided with the | - |
| 12 | ** Software or, alternatively, in accordance with the terms contained in | - |
| 13 | ** a written agreement between you and Digia. For licensing terms and | - |
| 14 | ** conditions see http://qt.digia.com/licensing. For further information | - |
| 15 | ** use the contact form at http://qt.digia.com/contact-us. | - |
| 16 | ** | - |
| 17 | ** GNU Lesser General Public License Usage | - |
| 18 | ** Alternatively, this file may be used under the terms of the GNU Lesser | - |
| 19 | ** General Public License version 2.1 as published by the Free Software | - |
| 20 | ** Foundation and appearing in the file LICENSE.LGPL included in the | - |
| 21 | ** packaging of this file. Please review the following information to | - |
| 22 | ** ensure the GNU Lesser General Public License version 2.1 requirements | - |
| 23 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | - |
| 24 | ** | - |
| 25 | ** In addition, as a special exception, Digia gives you certain additional | - |
| 26 | ** rights. These rights are described in the Digia Qt LGPL Exception | - |
| 27 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | - |
| 28 | ** | - |
| 29 | ** GNU General Public License Usage | - |
| 30 | ** Alternatively, this file may be used under the terms of the GNU | - |
| 31 | ** General Public License version 3.0 as published by the Free Software | - |
| 32 | ** Foundation and appearing in the file LICENSE.GPL included in the | - |
| 33 | ** packaging of this file. Please review the following information to | - |
| 34 | ** ensure the GNU General Public License version 3.0 requirements will be | - |
| 35 | ** met: http://www.gnu.org/copyleft/gpl.html. | - |
| 36 | ** | - |
| 37 | ** | - |
| 38 | ** $QT_END_LICENSE$ | - |
| 39 | ** | - |
| 40 | ****************************************************************************/ | - |
| 41 | | - |
| 42 | #include <qstringlist.h> | - |
| 43 | #include <qset.h> | - |
| 44 | #include <qregularexpression.h> | - |
| 45 | | - |
| 46 | QT_BEGIN_NAMESPACE | - |
| 47 | | - |
| 48 | /*! \typedef QStringListIterator | - |
| 49 | \relates QStringList | - |
| 50 | | - |
| 51 | The QStringListIterator type definition provides a Java-style const | - |
| 52 | iterator for QStringList. | - |
| 53 | | - |
| 54 | QStringList provides both \l{Java-style iterators} and | - |
| 55 | \l{STL-style iterators}. The Java-style const iterator is simply | - |
| 56 | a type definition for QListIterator<QString>. | - |
| 57 | | - |
| 58 | \sa QMutableStringListIterator, QStringList::const_iterator | - |
| 59 | */ | - |
| 60 | | - |
| 61 | /*! \typedef QMutableStringListIterator | - |
| 62 | \relates QStringList | - |
| 63 | | - |
| 64 | The QStringListIterator type definition provides a Java-style | - |
| 65 | non-const iterator for QStringList. | - |
| 66 | | - |
| 67 | QStringList provides both \l{Java-style iterators} and | - |
| 68 | \l{STL-style iterators}. The Java-style non-const iterator is | - |
| 69 | simply a type definition for QMutableListIterator<QString>. | - |
| 70 | | - |
| 71 | \sa QStringListIterator, QStringList::iterator | - |
| 72 | */ | - |
| 73 | | - |
| 74 | /*! | - |
| 75 | \class QStringList | - |
| 76 | \inmodule QtCore | - |
| 77 | \brief The QStringList class provides a list of strings. | - |
| 78 | | - |
| 79 | \ingroup tools | - |
| 80 | \ingroup shared | - |
| 81 | \ingroup string-processing | - |
| 82 | | - |
| 83 | \reentrant | - |
| 84 | | - |
| 85 | QStringList inherits from QList<QString>. Like QList, QStringList is | - |
| 86 | \l{implicitly shared}. It provides fast index-based access as well as fast | - |
| 87 | insertions and removals. Passing string lists as value parameters is both | - |
| 88 | fast and safe. | - |
| 89 | | - |
| 90 | All of QList's functionality also applies to QStringList. For example, you | - |
| 91 | can use isEmpty() to test whether the list is empty, and you can call | - |
| 92 | functions like append(), prepend(), insert(), replace(), removeAll(), | - |
| 93 | removeAt(), removeFirst(), removeLast(), and removeOne() to modify a | - |
| 94 | QStringList. In addition, QStringList provides a few convenience | - |
| 95 | functions that make handling lists of strings easier: | - |
| 96 | | - |
| 97 | \tableofcontents | - |
| 98 | | - |
| 99 | \section1 Adding strings | - |
| 100 | | - |
| 101 | Strings can be added to a list using the \l | - |
| 102 | {QList::append()}{append()}, \l | - |
| 103 | {QList::operator+=()}{operator+=()} and \l | - |
| 104 | {QStringList::operator<<()}{operator<<()} functions. For example: | - |
| 105 | | - |
| 106 | \snippet qstringlist/main.cpp 0 | - |
| 107 | | - |
| 108 | \section1 Iterating over the strings | - |
| 109 | | - |
| 110 | To iterate over a list, you can either use index positions or | - |
| 111 | QList's Java-style and STL-style iterator types: | - |
| 112 | | - |
| 113 | Indexing: | - |
| 114 | | - |
| 115 | \snippet qstringlist/main.cpp 1 | - |
| 116 | | - |
| 117 | Java-style iterator: | - |
| 118 | | - |
| 119 | \snippet qstringlist/main.cpp 2 | - |
| 120 | | - |
| 121 | STL-style iterator: | - |
| 122 | | - |
| 123 | \snippet qstringlist/main.cpp 3 | - |
| 124 | | - |
| 125 | The QStringListIterator class is simply a type definition for | - |
| 126 | QListIterator<QString>. QStringList also provide the | - |
| 127 | QMutableStringListIterator class which is a type definition for | - |
| 128 | QMutableListIterator<QString>. | - |
| 129 | | - |
| 130 | \section1 Manipulating the strings | - |
| 131 | | - |
| 132 | QStringList provides several functions allowing you to manipulate | - |
| 133 | the contents of a list. You can concatenate all the strings in a | - |
| 134 | string list into a single string (with an optional separator) | - |
| 135 | using the join() function. For example: | - |
| 136 | | - |
| 137 | \snippet qstringlist/main.cpp 4 | - |
| 138 | | - |
| 139 | The argument to join can be a single character or a string. | - |
| 140 | | - |
| 141 | To break up a string into a string list, use the QString::split() | - |
| 142 | function: | - |
| 143 | | - |
| 144 | \snippet qstringlist/main.cpp 6 | - |
| 145 | | - |
| 146 | The argument to split can be a single character, a string, or a | - |
| 147 | QRegExp. | - |
| 148 | | - |
| 149 | In addition, the \l {QStringList::operator+()}{operator+()} | - |
| 150 | function allows you to concatenate two string lists into one. To | - |
| 151 | sort a string list, use the sort() function. | - |
| 152 | | - |
| 153 | QString list also provides the filter() function which lets you | - |
| 154 | to extract a new list which contains only those strings which | - |
| 155 | contain a particular substring (or match a particular regular | - |
| 156 | expression): | - |
| 157 | | - |
| 158 | \snippet qstringlist/main.cpp 7 | - |
| 159 | | - |
| 160 | The contains() function tells you whether the list contains a | - |
| 161 | given string, while the indexOf() function returns the index of | - |
| 162 | the first occurrence of the given string. The lastIndexOf() | - |
| 163 | function on the other hand, returns the index of the last | - |
| 164 | occurrence of the string. | - |
| 165 | | - |
| 166 | Finally, the replaceInStrings() function calls QString::replace() | - |
| 167 | on each string in the string list in turn. For example: | - |
| 168 | | - |
| 169 | \snippet qstringlist/main.cpp 8 | - |
| 170 | | - |
| 171 | \sa QString | - |
| 172 | */ | - |
| 173 | | - |
| 174 | /*! | - |
| 175 | \fn QStringList::QStringList() | - |
| 176 | | - |
| 177 | Constructs an empty string list. | - |
| 178 | */ | - |
| 179 | | - |
| 180 | /*! | - |
| 181 | \fn QStringList::QStringList(const QString &str) | - |
| 182 | | - |
| 183 | Constructs a string list that contains the given string, \a | - |
| 184 | str. Longer lists are easily created like this: | - |
| 185 | | - |
| 186 | \snippet qstringlist/main.cpp 9 | - |
| 187 | | - |
| 188 | \sa append() | - |
| 189 | */ | - |
| 190 | | - |
| 191 | /*! | - |
| 192 | \fn QStringList::QStringList(const QStringList &other) | - |
| 193 | | - |
| 194 | Constructs a copy of the \a other string list. | - |
| 195 | | - |
| 196 | This operation takes \l{constant time} because QStringList is | - |
| 197 | \l{implicitly shared}, making the process of returning a | - |
| 198 | QStringList from a function very fast. If a shared instance is | - |
| 199 | modified, it will be copied (copy-on-write), and that takes | - |
| 200 | \l{linear time}. | - |
| 201 | | - |
| 202 | \sa operator=() | - |
| 203 | */ | - |
| 204 | | - |
| 205 | /*! | - |
| 206 | \fn QStringList::QStringList(const QList<QString> &other) | - |
| 207 | | - |
| 208 | Constructs a copy of \a other. | - |
| 209 | | - |
| 210 | This operation takes \l{constant time}, because QStringList is | - |
| 211 | \l{implicitly shared}. This makes returning a QStringList from a | - |
| 212 | function very fast. If a shared instance is modified, it will be | - |
| 213 | copied (copy-on-write), and that takes \l{linear time}. | - |
| 214 | | - |
| 215 | \sa operator=() | - |
| 216 | */ | - |
| 217 | | - |
| 218 | /*! | - |
| 219 | \fn void QStringList::sort(Qt::CaseSensitivity cs) | - |
| 220 | | - |
| 221 | Sorts the list of strings in ascending order. | - |
| 222 | If \a cs is \l Qt::CaseSensitive (the default), the string comparison | - |
| 223 | is case sensitive; otherwise the comparison is case insensitive. | - |
| 224 | | - |
| 225 | Sorting is performed using Qt's qSort() algorithm, | - |
| 226 | which operates in \l{linear-logarithmic time}, i.e. O(\e{n} log \e{n}). | - |
| 227 | | - |
| 228 | If you want to sort your strings in an arbitrary order, consider | - |
| 229 | using the QMap class. For example, you could use a QMap<QString, | - |
| 230 | QString> to create a case-insensitive ordering (e.g. with the keys | - |
| 231 | being lower-case versions of the strings, and the values being the | - |
| 232 | strings), or a QMap<int, QString> to sort the strings by some | - |
| 233 | integer index. | - |
| 234 | | - |
| 235 | \sa qSort() | - |
| 236 | */ | - |
| 237 | | - |
| 238 | static inline bool caseInsensitiveLessThan(const QString &s1, const QString &s2) | - |
| 239 | { | - |
| 240 | return s1.compare(s2, Qt::CaseInsensitive) < 0; executed: return s1.compare(s2, Qt::CaseInsensitive) < 0;Execution Count:16 | 16 |
| 241 | } | - |
| 242 | | - |
| 243 | void QtPrivate::QStringList_sort(QStringList *that, Qt::CaseSensitivity cs) | - |
| 244 | { | - |
| 245 | if (cs == Qt::CaseSensitive) evaluated: cs == Qt::CaseSensitive| yes Evaluation Count:150 | yes Evaluation Count:1 |
| 1-150 |
| 246 | qSort(that->begin(), that->end()); executed: qSort(that->begin(), that->end());Execution Count:150 | 150 |
| 247 | else | - |
| 248 | qSort(that->begin(), that->end(), caseInsensitiveLessThan); executed: qSort(that->begin(), that->end(), caseInsensitiveLessThan);Execution Count:1 | 1 |
| 249 | } | - |
| 250 | | - |
| 251 | | - |
| 252 | /*! | - |
| 253 | \fn QStringList QStringList::filter(const QString &str, Qt::CaseSensitivity cs) const | - |
| 254 | | - |
| 255 | Returns a list of all the strings containing the substring \a str. | - |
| 256 | | - |
| 257 | If \a cs is \l Qt::CaseSensitive (the default), the string | - |
| 258 | comparison is case sensitive; otherwise the comparison is case | - |
| 259 | insensitive. | - |
| 260 | | - |
| 261 | \snippet qstringlist/main.cpp 5 | - |
| 262 | \snippet qstringlist/main.cpp 10 | - |
| 263 | | - |
| 264 | This is equivalent to | - |
| 265 | | - |
| 266 | \snippet qstringlist/main.cpp 11 | - |
| 267 | \snippet qstringlist/main.cpp 12 | - |
| 268 | | - |
| 269 | \sa contains() | - |
| 270 | */ | - |
| 271 | QStringList QtPrivate::QStringList_filter(const QStringList *that, const QString &str, | - |
| 272 | Qt::CaseSensitivity cs) | - |
| 273 | { | - |
| 274 | QStringMatcher matcher(str, cs); executed (the execution status of this line is deduced): QStringMatcher matcher(str, cs); | - |
| 275 | QStringList res; executed (the execution status of this line is deduced): QStringList res; | - |
| 276 | for (int i = 0; i < that->size(); ++i) evaluated: i < that->size()| yes Evaluation Count:1522 | yes Evaluation Count:130 |
| 130-1522 |
| 277 | if (matcher.indexIn(that->at(i)) != -1) evaluated: matcher.indexIn(that->at(i)) != -1| yes Evaluation Count:162 | yes Evaluation Count:1360 |
| 162-1360 |
| 278 | res << that->at(i); executed: res << that->at(i);Execution Count:162 | 162 |
| 279 | return res; executed: return res;Execution Count:130 | 130 |
| 280 | } | - |
| 281 | | - |
| 282 | | - |
| 283 | /*! | - |
| 284 | \fn bool QStringList::contains(const QString &str, Qt::CaseSensitivity cs) const | - |
| 285 | | - |
| 286 | Returns true if the list contains the string \a str; otherwise | - |
| 287 | returns false. The search is case insensitive if \a cs is | - |
| 288 | Qt::CaseInsensitive; the search is case sensitive by default. | - |
| 289 | | - |
| 290 | \sa indexOf(), lastIndexOf(), QString::contains() | - |
| 291 | */ | - |
| 292 | bool QtPrivate::QStringList_contains(const QStringList *that, const QString &str, | - |
| 293 | Qt::CaseSensitivity cs) | - |
| 294 | { | - |
| 295 | for (int i = 0; i < that->size(); ++i) { evaluated: i < that->size()| yes Evaluation Count:7797790 | yes Evaluation Count:64334 |
| 64334-7797790 |
| 296 | const QString & string = that->at(i); executed (the execution status of this line is deduced): const QString & string = that->at(i); | - |
| 297 | if (string.length() == str.length() && str.compare(string, cs) == 0) evaluated: string.length() == str.length()| yes Evaluation Count:934389 | yes Evaluation Count:6862918 |
evaluated: str.compare(string, cs) == 0| yes Evaluation Count:148864 | yes Evaluation Count:785559 |
| 148864-6862918 |
| 298 | return true; executed: return true;Execution Count:148865 | 148865 |
| 299 | } executed: }Execution Count:7648832 | 7648832 |
| 300 | return false; executed: return false;Execution Count:64334 | 64334 |
| 301 | } | - |
| 302 | | - |
| 303 | #ifndef QT_NO_REGEXP | - |
| 304 | /*! | - |
| 305 | \fn QStringList QStringList::filter(const QRegExp &rx) const | - |
| 306 | | - |
| 307 | \overload | - |
| 308 | | - |
| 309 | Returns a list of all the strings that match the regular | - |
| 310 | expression \a rx. | - |
| 311 | */ | - |
| 312 | QStringList QtPrivate::QStringList_filter(const QStringList *that, const QRegExp &rx) | - |
| 313 | { | - |
| 314 | QStringList res; executed (the execution status of this line is deduced): QStringList res; | - |
| 315 | for (int i = 0; i < that->size(); ++i) evaluated: i < that->size()| yes Evaluation Count:25 | yes Evaluation Count:2 |
| 2-25 |
| 316 | if (that->at(i).contains(rx)) evaluated: that->at(i).contains(rx)| yes Evaluation Count:3 | yes Evaluation Count:22 |
| 3-22 |
| 317 | res << that->at(i); executed: res << that->at(i);Execution Count:3 | 3 |
| 318 | return res; executed: return res;Execution Count:2 | 2 |
| 319 | } | - |
| 320 | #endif | - |
| 321 | | - |
| 322 | #ifndef QT_BOOTSTRAPPED | - |
| 323 | #ifndef QT_NO_REGEXP | - |
| 324 | /*! | - |
| 325 | \fn QStringList QStringList::filter(const QRegularExpression &re) const | - |
| 326 | \overload | - |
| 327 | \since 5.0 | - |
| 328 | | - |
| 329 | Returns a list of all the strings that match the regular | - |
| 330 | expression \a re. | - |
| 331 | */ | - |
| 332 | QStringList QtPrivate::QStringList_filter(const QStringList *that, const QRegularExpression &re) | - |
| 333 | { | - |
| 334 | QStringList res; executed (the execution status of this line is deduced): QStringList res; | - |
| 335 | for (int i = 0; i < that->size(); ++i) { evaluated: i < that->size()| yes Evaluation Count:3 | yes Evaluation Count:1 |
| 1-3 |
| 336 | if (that->at(i).contains(re)) evaluated: that->at(i).contains(re)| yes Evaluation Count:2 | yes Evaluation Count:1 |
| 1-2 |
| 337 | res << that->at(i); executed: res << that->at(i);Execution Count:2 | 2 |
| 338 | } executed: }Execution Count:3 | 3 |
| 339 | return res; executed: return res;Execution Count:1 | 1 |
| 340 | } | - |
| 341 | #endif // QT_NO_REGEXP | - |
| 342 | #endif // QT_BOOTSTRAPPED | - |
| 343 | | - |
| 344 | /*! | - |
| 345 | \fn QStringList &QStringList::replaceInStrings(const QString &before, const QString &after, Qt::CaseSensitivity cs) | - |
| 346 | | - |
| 347 | Returns a string list where every string has had the \a before | - |
| 348 | text replaced with the \a after text wherever the \a before text | - |
| 349 | is found. The \a before text is matched case-sensitively or not | - |
| 350 | depending on the \a cs flag. | - |
| 351 | | - |
| 352 | For example: | - |
| 353 | | - |
| 354 | \snippet qstringlist/main.cpp 5 | - |
| 355 | \snippet qstringlist/main.cpp 13 | - |
| 356 | | - |
| 357 | \sa QString::replace() | - |
| 358 | */ | - |
| 359 | void QtPrivate::QStringList_replaceInStrings(QStringList *that, const QString &before, | - |
| 360 | const QString &after, Qt::CaseSensitivity cs) | - |
| 361 | { | - |
| 362 | for (int i = 0; i < that->size(); ++i) evaluated: i < that->size()| yes Evaluation Count:18 | yes Evaluation Count:3 |
| 3-18 |
| 363 | (*that)[i].replace(before, after, cs); executed: (*that)[i].replace(before, after, cs);Execution Count:18 | 18 |
| 364 | } executed: }Execution Count:3 | 3 |
| 365 | | - |
| 366 | | - |
| 367 | #ifndef QT_NO_REGEXP | - |
| 368 | /*! | - |
| 369 | \fn QStringList &QStringList::replaceInStrings(const QRegExp &rx, const QString &after) | - |
| 370 | \overload | - |
| 371 | | - |
| 372 | Replaces every occurrence of the regexp \a rx, in each of the | - |
| 373 | string lists's strings, with \a after. Returns a reference to the | - |
| 374 | string list. | - |
| 375 | | - |
| 376 | For example: | - |
| 377 | | - |
| 378 | \snippet qstringlist/main.cpp 5 | - |
| 379 | \snippet qstringlist/main.cpp 14 | - |
| 380 | | - |
| 381 | For regular expressions that contain \l{capturing parentheses}, | - |
| 382 | occurrences of \b{\\1}, \b{\\2}, ..., in \a after are | - |
| 383 | replaced with \a{rx}.cap(1), \a{rx}.cap(2), ... | - |
| 384 | | - |
| 385 | For example: | - |
| 386 | | - |
| 387 | \snippet qstringlist/main.cpp 5 | - |
| 388 | \snippet qstringlist/main.cpp 15 | - |
| 389 | */ | - |
| 390 | void QtPrivate::QStringList_replaceInStrings(QStringList *that, const QRegExp &rx, const QString &after) | - |
| 391 | { | - |
| 392 | for (int i = 0; i < that->size(); ++i) evaluated: i < that->size()| yes Evaluation Count:6 | yes Evaluation Count:2 |
| 2-6 |
| 393 | (*that)[i].replace(rx, after); executed: (*that)[i].replace(rx, after);Execution Count:6 | 6 |
| 394 | } executed: }Execution Count:2 | 2 |
| 395 | #endif | - |
| 396 | | - |
| 397 | #ifndef QT_BOOTSTRAPPED | - |
| 398 | #ifndef QT_NO_REGEXP | - |
| 399 | /*! | - |
| 400 | \fn QStringList &QStringList::replaceInStrings(const QRegularExpression &re, const QString &after) | - |
| 401 | \overload | - |
| 402 | \since 5.0 | - |
| 403 | | - |
| 404 | Replaces every occurrence of the regular expression \a re, in each of the | - |
| 405 | string lists's strings, with \a after. Returns a reference to the string | - |
| 406 | list. | - |
| 407 | | - |
| 408 | For example: | - |
| 409 | | - |
| 410 | \snippet qstringlist/main.cpp 5 | - |
| 411 | \snippet qstringlist/main.cpp 16 | - |
| 412 | | - |
| 413 | For regular expressions that contain capturing groups, | - |
| 414 | occurrences of \b{\\1}, \b{\\2}, ..., in \a after are | - |
| 415 | replaced with the string captured by the corresponding capturing group. | - |
| 416 | | - |
| 417 | For example: | - |
| 418 | | - |
| 419 | \snippet qstringlist/main.cpp 5 | - |
| 420 | \snippet qstringlist/main.cpp 17 | - |
| 421 | */ | - |
| 422 | void QtPrivate::QStringList_replaceInStrings(QStringList *that, const QRegularExpression &re, const QString &after) | - |
| 423 | { | - |
| 424 | for (int i = 0; i < that->size(); ++i) evaluated: i < that->size()| yes Evaluation Count:6 | yes Evaluation Count:2 |
| 2-6 |
| 425 | (*that)[i].replace(re, after); executed: (*that)[i].replace(re, after);Execution Count:6 | 6 |
| 426 | } executed: }Execution Count:2 | 2 |
| 427 | #endif // QT_NO_REGEXP | - |
| 428 | #endif // QT_BOOTSTRAPPED | - |
| 429 | | - |
| 430 | /*! | - |
| 431 | \fn QString QStringList::join(const QString &separator) const | - |
| 432 | | - |
| 433 | Joins all the string list's strings into a single string with each | - |
| 434 | element separated by the given \a separator (which can be an | - |
| 435 | empty string). | - |
| 436 | | - |
| 437 | \sa QString::split() | - |
| 438 | */ | - |
| 439 | | - |
| 440 | /*! | - |
| 441 | \fn QString QStringList::join(QChar separator) const | - |
| 442 | \since 5.0 | - |
| 443 | \overload join() | - |
| 444 | */ | - |
| 445 | QString QtPrivate::QStringList_join(const QStringList *that, const QChar *sep, int seplen) | - |
| 446 | { | - |
| 447 | int totalLength = 0; executed (the execution status of this line is deduced): int totalLength = 0; | - |
| 448 | const int size = that->size(); executed (the execution status of this line is deduced): const int size = that->size(); | - |
| 449 | | - |
| 450 | for (int i = 0; i < size; ++i) evaluated: i < size| yes Evaluation Count:28250 | yes Evaluation Count:5370 |
| 5370-28250 |
| 451 | totalLength += that->at(i).size(); executed: totalLength += that->at(i).size();Execution Count:28250 | 28250 |
| 452 | | - |
| 453 | if(size > 0) evaluated: size > 0| yes Evaluation Count:5196 | yes Evaluation Count:174 |
| 174-5196 |
| 454 | totalLength += seplen * (size - 1); executed: totalLength += seplen * (size - 1);Execution Count:5196 | 5196 |
| 455 | | - |
| 456 | QString res; executed (the execution status of this line is deduced): QString res; | - |
| 457 | if (totalLength == 0) evaluated: totalLength == 0| yes Evaluation Count:175 | yes Evaluation Count:5195 |
| 175-5195 |
| 458 | return res; executed: return res;Execution Count:175 | 175 |
| 459 | res.reserve(totalLength); executed (the execution status of this line is deduced): res.reserve(totalLength); | - |
| 460 | for (int i = 0; i < that->size(); ++i) { evaluated: i < that->size()| yes Evaluation Count:28249 | yes Evaluation Count:5195 |
| 5195-28249 |
| 461 | if (i) evaluated: i| yes Evaluation Count:23054 | yes Evaluation Count:5195 |
| 5195-23054 |
| 462 | res.append(sep, seplen); executed: res.append(sep, seplen);Execution Count:23054 | 23054 |
| 463 | res += that->at(i); executed (the execution status of this line is deduced): res += that->at(i); | - |
| 464 | } executed: }Execution Count:28249 | 28249 |
| 465 | return res; executed: return res;Execution Count:5195 | 5195 |
| 466 | } | - |
| 467 | | - |
| 468 | /*! | - |
| 469 | \fn QStringList QStringList::operator+(const QStringList &other) const | - |
| 470 | | - |
| 471 | Returns a string list that is the concatenation of this string | - |
| 472 | list with the \a other string list. | - |
| 473 | | - |
| 474 | \sa append() | - |
| 475 | */ | - |
| 476 | | - |
| 477 | /*! | - |
| 478 | \fn QStringList &QStringList::operator<<(const QString &str) | - |
| 479 | | - |
| 480 | Appends the given string, \a str, to this string list and returns | - |
| 481 | a reference to the string list. | - |
| 482 | | - |
| 483 | \sa append() | - |
| 484 | */ | - |
| 485 | | - |
| 486 | /*! | - |
| 487 | \fn QStringList &QStringList::operator<<(const QStringList &other) | - |
| 488 | | - |
| 489 | \overload | - |
| 490 | | - |
| 491 | Appends the \a other string list to the string list and returns a reference to | - |
| 492 | the latter string list. | - |
| 493 | */ | - |
| 494 | | - |
| 495 | #ifndef QT_NO_DATASTREAM | - |
| 496 | /*! | - |
| 497 | \fn QDataStream &operator>>(QDataStream &in, QStringList &list) | - |
| 498 | \relates QStringList | - |
| 499 | | - |
| 500 | Reads a string list from the given \a in stream into the specified | - |
| 501 | \a list. | - |
| 502 | | - |
| 503 | \sa {Serializing Qt Data Types} | - |
| 504 | */ | - |
| 505 | | - |
| 506 | /*! | - |
| 507 | \fn QDataStream &operator<<(QDataStream &out, const QStringList &list) | - |
| 508 | \relates QStringList | - |
| 509 | | - |
| 510 | Writes the given string \a list to the specified \a out stream. | - |
| 511 | | - |
| 512 | \sa {Serializing Qt Data Types} | - |
| 513 | */ | - |
| 514 | #endif // QT_NO_DATASTREAM | - |
| 515 | | - |
| 516 | | - |
| 517 | #ifndef QT_NO_REGEXP | - |
| 518 | static int indexOfMutating(const QStringList *that, QRegExp &rx, int from) | - |
| 519 | { | - |
| 520 | if (from < 0) evaluated: from < 0| yes Evaluation Count:3 | yes Evaluation Count:8 |
| 3-8 |
| 521 | from = qMax(from + that->size(), 0); executed: from = qMax(from + that->size(), 0);Execution Count:3 | 3 |
| 522 | for (int i = from; i < that->size(); ++i) { evaluated: i < that->size()| yes Evaluation Count:50 | yes Evaluation Count:6 |
| 6-50 |
| 523 | if (rx.exactMatch(that->at(i))) evaluated: rx.exactMatch(that->at(i))| yes Evaluation Count:5 | yes Evaluation Count:45 |
| 5-45 |
| 524 | return i; executed: return i;Execution Count:5 | 5 |
| 525 | } executed: }Execution Count:45 | 45 |
| 526 | return -1; executed: return -1;Execution Count:6 | 6 |
| 527 | } | - |
| 528 | | - |
| 529 | static int lastIndexOfMutating(const QStringList *that, QRegExp &rx, int from) | - |
| 530 | { | - |
| 531 | if (from < 0) evaluated: from < 0| yes Evaluation Count:6 | yes Evaluation Count:3 |
| 3-6 |
| 532 | from += that->size(); executed: from += that->size();Execution Count:6 | 6 |
| 533 | else if (from >= that->size()) evaluated: from >= that->size()| yes Evaluation Count:1 | yes Evaluation Count:2 |
| 1-2 |
| 534 | from = that->size() - 1; executed: from = that->size() - 1;Execution Count:1 | 1 |
| 535 | for (int i = from; i >= 0; --i) { evaluated: i >= 0| yes Evaluation Count:17 | yes Evaluation Count:3 |
| 3-17 |
| 536 | if (rx.exactMatch(that->at(i))) evaluated: rx.exactMatch(that->at(i))| yes Evaluation Count:6 | yes Evaluation Count:11 |
| 6-11 |
| 537 | return i; executed: return i;Execution Count:6 | 6 |
| 538 | } executed: }Execution Count:11 | 11 |
| 539 | return -1; executed: return -1;Execution Count:3 | 3 |
| 540 | } | - |
| 541 | | - |
| 542 | /*! | - |
| 543 | \fn int QStringList::indexOf(const QRegExp &rx, int from) const | - |
| 544 | | - |
| 545 | Returns the index position of the first exact match of \a rx in | - |
| 546 | the list, searching forward from index position \a from. Returns | - |
| 547 | -1 if no item matched. | - |
| 548 | | - |
| 549 | By default, this function is case sensitive. | - |
| 550 | | - |
| 551 | \sa lastIndexOf(), contains(), QRegExp::exactMatch() | - |
| 552 | */ | - |
| 553 | int QtPrivate::QStringList_indexOf(const QStringList *that, const QRegExp &rx, int from) | - |
| 554 | { | - |
| 555 | QRegExp rx2(rx); executed (the execution status of this line is deduced): QRegExp rx2(rx); | - |
| 556 | return indexOfMutating(that, rx2, from); executed: return indexOfMutating(that, rx2, from);Execution Count:2 | 2 |
| 557 | } | - |
| 558 | | - |
| 559 | /*! | - |
| 560 | \fn int QStringList::indexOf(QRegExp &rx, int from) const | - |
| 561 | \overload indexOf() | - |
| 562 | \since 4.5 | - |
| 563 | | - |
| 564 | Returns the index position of the first exact match of \a rx in | - |
| 565 | the list, searching forward from index position \a from. Returns | - |
| 566 | -1 if no item matched. | - |
| 567 | | - |
| 568 | By default, this function is case sensitive. | - |
| 569 | | - |
| 570 | If an item matched, the \a rx regular expression will contain the | - |
| 571 | matched objects (see QRegExp::matchedLength, QRegExp::cap). | - |
| 572 | | - |
| 573 | \sa lastIndexOf(), contains(), QRegExp::exactMatch() | - |
| 574 | */ | - |
| 575 | int QtPrivate::QStringList_indexOf(const QStringList *that, QRegExp &rx, int from) | - |
| 576 | { | - |
| 577 | return indexOfMutating(that, rx, from); executed: return indexOfMutating(that, rx, from);Execution Count:9 | 9 |
| 578 | } | - |
| 579 | | - |
| 580 | /*! | - |
| 581 | \fn int QStringList::lastIndexOf(const QRegExp &rx, int from) const | - |
| 582 | | - |
| 583 | Returns the index position of the last exact match of \a rx in | - |
| 584 | the list, searching backward from index position \a from. If \a | - |
| 585 | from is -1 (the default), the search starts at the last item. | - |
| 586 | Returns -1 if no item matched. | - |
| 587 | | - |
| 588 | By default, this function is case sensitive. | - |
| 589 | | - |
| 590 | \sa indexOf(), contains(), QRegExp::exactMatch() | - |
| 591 | */ | - |
| 592 | int QtPrivate::QStringList_lastIndexOf(const QStringList *that, const QRegExp &rx, int from) | - |
| 593 | { | - |
| 594 | QRegExp rx2(rx); executed (the execution status of this line is deduced): QRegExp rx2(rx); | - |
| 595 | return lastIndexOfMutating(that, rx2, from); executed: return lastIndexOfMutating(that, rx2, from);Execution Count:2 | 2 |
| 596 | } | - |
| 597 | | - |
| 598 | /*! | - |
| 599 | \fn int QStringList::lastIndexOf(QRegExp &rx, int from) const | - |
| 600 | \overload lastIndexOf() | - |
| 601 | \since 4.5 | - |
| 602 | | - |
| 603 | Returns the index position of the last exact match of \a rx in | - |
| 604 | the list, searching backward from index position \a from. If \a | - |
| 605 | from is -1 (the default), the search starts at the last item. | - |
| 606 | Returns -1 if no item matched. | - |
| 607 | | - |
| 608 | By default, this function is case sensitive. | - |
| 609 | | - |
| 610 | If an item matched, the \a rx regular expression will contain the | - |
| 611 | matched objects (see QRegExp::matchedLength, QRegExp::cap). | - |
| 612 | | - |
| 613 | \sa indexOf(), contains(), QRegExp::exactMatch() | - |
| 614 | */ | - |
| 615 | int QtPrivate::QStringList_lastIndexOf(const QStringList *that, QRegExp &rx, int from) | - |
| 616 | { | - |
| 617 | return lastIndexOfMutating(that, rx, from); executed: return lastIndexOfMutating(that, rx, from);Execution Count:7 | 7 |
| 618 | } | - |
| 619 | #endif | - |
| 620 | | - |
| 621 | #ifndef QT_BOOTSTRAPPED | - |
| 622 | #ifndef QT_NO_REGEXP | - |
| 623 | /*! | - |
| 624 | \fn int QStringList::indexOf(const QRegularExpression &re, int from) const | - |
| 625 | \overload | - |
| 626 | \since 5.0 | - |
| 627 | | - |
| 628 | Returns the index position of the first match of \a re in | - |
| 629 | the list, searching forward from index position \a from. Returns | - |
| 630 | -1 if no item matched. | - |
| 631 | | - |
| 632 | \sa lastIndexOf() | - |
| 633 | */ | - |
| 634 | int QtPrivate::QStringList_indexOf(const QStringList *that, const QRegularExpression &re, int from) | - |
| 635 | { | - |
| 636 | if (from < 0) evaluated: from < 0| yes Evaluation Count:3 | yes Evaluation Count:6 |
| 3-6 |
| 637 | from = qMax(from + that->size(), 0); executed: from = qMax(from + that->size(), 0);Execution Count:3 | 3 |
| 638 | | - |
| 639 | QString exactPattern = QLatin1String("\\A(?:") + re.pattern() + QLatin1String(")\\z"); executed (the execution status of this line is deduced): QString exactPattern = QLatin1String("\\A(?:") + re.pattern() + QLatin1String(")\\z"); | - |
| 640 | QRegularExpression exactRe(exactPattern, re.patternOptions()); executed (the execution status of this line is deduced): QRegularExpression exactRe(exactPattern, re.patternOptions()); | - |
| 641 | | - |
| 642 | for (int i = from; i < that->size(); ++i) { evaluated: i < that->size()| yes Evaluation Count:16 | yes Evaluation Count:5 |
| 5-16 |
| 643 | QRegularExpressionMatch m = exactRe.match(that->at(i)); executed (the execution status of this line is deduced): QRegularExpressionMatch m = exactRe.match(that->at(i)); | - |
| 644 | if (m.hasMatch()) evaluated: m.hasMatch()| yes Evaluation Count:4 | yes Evaluation Count:12 |
| 4-12 |
| 645 | return i; executed: return i;Execution Count:4 | 4 |
| 646 | } executed: }Execution Count:12 | 12 |
| 647 | return -1; executed: return -1;Execution Count:5 | 5 |
| 648 | } | - |
| 649 | | - |
| 650 | /*! | - |
| 651 | \fn int QStringList::lastIndexOf(const QRegularExpression &re, int from) const | - |
| 652 | \overload | - |
| 653 | \since 5.0 | - |
| 654 | | - |
| 655 | Returns the index position of the last exact match of \a re in | - |
| 656 | the list, searching backward from index position \a from. If \a | - |
| 657 | from is -1 (the default), the search starts at the last item. | - |
| 658 | Returns -1 if no item matched. | - |
| 659 | | - |
| 660 | \sa indexOf() | - |
| 661 | */ | - |
| 662 | int QtPrivate::QStringList_lastIndexOf(const QStringList *that, const QRegularExpression &re, int from) | - |
| 663 | { | - |
| 664 | if (from < 0) evaluated: from < 0| yes Evaluation Count:6 | yes Evaluation Count:3 |
| 3-6 |
| 665 | from += that->size(); executed: from += that->size();Execution Count:6 | 6 |
| 666 | else if (from >= that->size()) evaluated: from >= that->size()| yes Evaluation Count:1 | yes Evaluation Count:2 |
| 1-2 |
| 667 | from = that->size() - 1; executed: from = that->size() - 1;Execution Count:1 | 1 |
| 668 | | - |
| 669 | QString exactPattern = QLatin1String("\\A(?:") + re.pattern() + QLatin1String(")\\z"); executed (the execution status of this line is deduced): QString exactPattern = QLatin1String("\\A(?:") + re.pattern() + QLatin1String(")\\z"); | - |
| 670 | QRegularExpression exactRe(exactPattern, re.patternOptions()); executed (the execution status of this line is deduced): QRegularExpression exactRe(exactPattern, re.patternOptions()); | - |
| 671 | | - |
| 672 | for (int i = from; i >= 0; --i) { evaluated: i >= 0| yes Evaluation Count:17 | yes Evaluation Count:3 |
| 3-17 |
| 673 | QRegularExpressionMatch m = exactRe.match(that->at(i)); executed (the execution status of this line is deduced): QRegularExpressionMatch m = exactRe.match(that->at(i)); | - |
| 674 | if (m.hasMatch()) evaluated: m.hasMatch()| yes Evaluation Count:6 | yes Evaluation Count:11 |
| 6-11 |
| 675 | return i; executed: return i;Execution Count:6 | 6 |
| 676 | } executed: }Execution Count:11 | 11 |
| 677 | return -1; executed: return -1;Execution Count:3 | 3 |
| 678 | } | - |
| 679 | #endif // QT_NO_REGEXP | - |
| 680 | #endif // QT_BOOTSTRAPPED | - |
| 681 | | - |
| 682 | /*! | - |
| 683 | \fn int QStringList::indexOf(const QString &value, int from = 0) const | - |
| 684 | | - |
| 685 | Returns the index position of the first occurrence of \a value in | - |
| 686 | the list, searching forward from index position \a from. Returns | - |
| 687 | -1 if no item matched. | - |
| 688 | | - |
| 689 | \sa lastIndexOf(), contains(), QList::indexOf() | - |
| 690 | */ | - |
| 691 | | - |
| 692 | /*! | - |
| 693 | \fn int QStringList::lastIndexOf(const QString &value, int from = -1) const | - |
| 694 | | - |
| 695 | Returns the index position of the last occurrence of \a value in | - |
| 696 | the list, searching backward from index position \a from. If \a | - |
| 697 | from is -1 (the default), the search starts at the last item. | - |
| 698 | Returns -1 if no item matched. | - |
| 699 | | - |
| 700 | By default, this function is case sensitive. | - |
| 701 | | - |
| 702 | \sa indexOf(), QList::lastIndexOf() | - |
| 703 | */ | - |
| 704 | | - |
| 705 | /*! | - |
| 706 | \fn int QStringList::removeDuplicates() | - |
| 707 | | - |
| 708 | \since 4.5 | - |
| 709 | | - |
| 710 | This function removes duplicate entries from a list. | - |
| 711 | The entries do not have to be sorted. They will retain their | - |
| 712 | original order. | - |
| 713 | | - |
| 714 | Returns the number of removed entries. | - |
| 715 | */ | - |
| 716 | int QtPrivate::QStringList_removeDuplicates(QStringList *that) | - |
| 717 | { | - |
| 718 | int n = that->size(); executed (the execution status of this line is deduced): int n = that->size(); | - |
| 719 | int j = 0; executed (the execution status of this line is deduced): int j = 0; | - |
| 720 | QSet<QString> seen; executed (the execution status of this line is deduced): QSet<QString> seen; | - |
| 721 | seen.reserve(n); executed (the execution status of this line is deduced): seen.reserve(n); | - |
| 722 | for (int i = 0; i < n; ++i) { evaluated: i < n| yes Evaluation Count:4 | yes Evaluation Count:2 |
| 2-4 |
| 723 | const QString &s = that->at(i); executed (the execution status of this line is deduced): const QString &s = that->at(i); | - |
| 724 | if (seen.contains(s)) evaluated: seen.contains(s)| yes Evaluation Count:1 | yes Evaluation Count:3 |
| 1-3 |
| 725 | continue; executed: continue;Execution Count:1 | 1 |
| 726 | seen.insert(s); executed (the execution status of this line is deduced): seen.insert(s); | - |
| 727 | if (j != i) partially evaluated: j != i| no Evaluation Count:0 | yes Evaluation Count:3 |
| 0-3 |
| 728 | (*that)[j] = s; never executed: (*that)[j] = s; | 0 |
| 729 | ++j; executed (the execution status of this line is deduced): ++j; | - |
| 730 | } executed: }Execution Count:3 | 3 |
| 731 | if (n != j) evaluated: n != j| yes Evaluation Count:1 | yes Evaluation Count:1 |
| 1 |
| 732 | that->erase(that->begin() + j, that->end()); executed: that->erase(that->begin() + j, that->end());Execution Count:1 | 1 |
| 733 | return n - j; executed: return n - j;Execution Count:2 | 2 |
| 734 | } | - |
| 735 | | - |
| 736 | /*! \fn QStringList::QStringList(std::initializer_list<QString> args) | - |
| 737 | \since 4.8 | - |
| 738 | | - |
| 739 | Construct a list from a std::initializer_list given by \a args. | - |
| 740 | | - |
| 741 | This constructor is only enabled if the compiler supports C++0x | - |
| 742 | */ | - |
| 743 | | - |
| 744 | | - |
| 745 | QT_END_NAMESPACE | - |
| 746 | | - |
| | |