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