Qt 4.8
qstringlist.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 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 #ifndef QSTRINGLIST_H
43 #define QSTRINGLIST_H
44 
45 #include <QtCore/qalgorithms.h>
46 #include <QtCore/qdatastream.h>
47 #include <QtCore/qlist.h>
48 #include <QtCore/qregexp.h>
49 #include <QtCore/qstring.h>
50 #include <QtCore/qstringmatcher.h>
51 #ifdef QT_INCLUDE_COMPAT
52 #include <Qt3Support/q3valuelist.h>
53 #endif
54 
56 
58 
59 QT_MODULE(Core)
60 
62 
63 typedef QListIterator<QString> QStringListIterator;
64 typedef QMutableListIterator<QString> QMutableStringListIterator;
65 
67 {
68 public:
69  inline QStringList() { }
70  inline explicit QStringList(const QString &i) { append(i); }
71  inline QStringList(const QStringList &l) : QList<QString>(l) { }
72  inline QStringList(const QList<QString> &l) : QList<QString>(l) { }
73 #ifdef Q_COMPILER_INITIALIZER_LISTS
74  inline QStringList(std::initializer_list<QString> args) : QList<QString>(args) { }
75 #endif
76 
77  inline void sort();
78  inline int removeDuplicates();
79 
80  inline QString join(const QString &sep) const;
81 
82  inline QStringList filter(const QString &str, Qt::CaseSensitivity cs = Qt::CaseSensitive) const;
83  inline QBool contains(const QString &str, Qt::CaseSensitivity cs = Qt::CaseSensitive) const;
84 
85  inline QStringList &replaceInStrings(const QString &before, const QString &after, Qt::CaseSensitivity cs = Qt::CaseSensitive);
86 
87  inline QStringList operator+(const QStringList &other) const
88  { QStringList n = *this; n += other; return n; }
89  inline QStringList &operator<<(const QString &str)
90  { append(str); return *this; }
92  { *this += l; return *this; }
93 
94 #ifndef QT_NO_REGEXP
95  inline QStringList filter(const QRegExp &rx) const;
96  inline QStringList &replaceInStrings(const QRegExp &rx, const QString &after);
97  inline int indexOf(const QRegExp &rx, int from = 0) const;
98  inline int lastIndexOf(const QRegExp &rx, int from = -1) const;
99  inline int indexOf(QRegExp &rx, int from = 0) const;
100  inline int lastIndexOf(QRegExp &rx, int from = -1) const;
101 #endif
102 #if !defined(Q_NO_USING_KEYWORD)
105 #else
106  inline int indexOf(const QString &str, int from = 0) const
107  { return QList<QString>::indexOf(str, from); }
108  inline int lastIndexOf(const QString &str, int from = -1) const
109  { return QList<QString>::lastIndexOf(str, from); }
110 #endif
111 #ifdef QT3_SUPPORT
112  static inline QT3_SUPPORT QStringList split(const QString &sep, const QString &str, bool allowEmptyEntries = false);
113  static inline QT3_SUPPORT QStringList split(const QChar &sep, const QString &str, bool allowEmptyEntries = false);
114  inline QT3_SUPPORT QStringList grep(const QString &str, bool cs = true) const
115  { return filter(str, cs ? Qt::CaseSensitive : Qt::CaseInsensitive); }
116 
117 #ifndef QT_NO_REGEXP
118  static inline QT3_SUPPORT QStringList split(const QRegExp &sep, const QString &str, bool allowEmptyEntries = false);
119  inline QT3_SUPPORT QStringList grep(const QRegExp &rx) const { return filter(rx); }
120  inline QT3_SUPPORT QStringList &gres(const QRegExp &rx, const QString &after)
121  { return replaceInStrings(rx, after); }
122 #endif
123  inline QT3_SUPPORT QStringList &gres(const QString &before, const QString &after, bool cs = true)
124  { return replaceInStrings(before, after, cs ? Qt::CaseSensitive : Qt::CaseInsensitive); }
125 
126  inline Iterator QT3_SUPPORT fromLast() { return (isEmpty() ? end() : --end()); }
127  inline ConstIterator QT3_SUPPORT fromLast() const { return (isEmpty() ? end() : --end()); }
128 #endif
129 };
130 
131 namespace QtPrivate {
134  QString Q_CORE_EXPORT QStringList_join(const QStringList *that, const QString &sep);
137 
139  void Q_CORE_EXPORT QStringList_replaceInStrings(QStringList *that, const QString &before, const QString &after,
141 
142 #ifndef QT_NO_REGEXP
143  void Q_CORE_EXPORT QStringList_replaceInStrings(QStringList *that, const QRegExp &rx, const QString &after);
145  int Q_CORE_EXPORT QStringList_indexOf(const QStringList *that, const QRegExp &rx, int from);
146  int Q_CORE_EXPORT QStringList_lastIndexOf(const QStringList *that, const QRegExp &rx, int from);
147  int Q_CORE_EXPORT QStringList_indexOf(const QStringList *that, QRegExp &rx, int from);
148  int Q_CORE_EXPORT QStringList_lastIndexOf(const QStringList *that, QRegExp &rx, int from);
149 #endif
150 }
151 
152 inline void QStringList::sort()
153 {
155 }
156 
158 {
160 }
161 
162 inline QString QStringList::join(const QString &sep) const
163 {
164  return QtPrivate::QStringList_join(this, sep);
165 }
166 
168 {
169  return QtPrivate::QStringList_filter(this, str, cs);
170 }
171 
173 {
174  return QtPrivate::QStringList_contains(this, str, cs);
175 }
176 
178 {
179  QtPrivate::QStringList_replaceInStrings(this, before, after, cs);
180  return *this;
181 }
182 
183 #ifndef QT_NO_REGEXP
185 {
187  return *this;
188 }
189 
190 inline QStringList QStringList::filter(const QRegExp &rx) const
191 {
192  return QtPrivate::QStringList_filter(this, rx);
193 }
194 
195 inline int QStringList::indexOf(const QRegExp &rx, int from) const
196 {
197  return QtPrivate::QStringList_indexOf(this, rx, from);
198 }
199 
200 inline int QStringList::lastIndexOf(const QRegExp &rx, int from) const
201 {
202  return QtPrivate::QStringList_lastIndexOf(this, rx, from);
203 }
204 
205 inline int QStringList::indexOf(QRegExp &rx, int from) const
206 {
207  return QtPrivate::QStringList_indexOf(this, rx, from);
208 }
209 
210 inline int QStringList::lastIndexOf(QRegExp &rx, int from) const
211 {
212  return QtPrivate::QStringList_lastIndexOf(this, rx, from);
213 }
214 #endif
215 
216 
217 #ifdef QT3_SUPPORT
218 inline QStringList QStringList::split(const QChar &sep, const QString &str, bool allowEmptyEntries)
219 {
220  if (str.isEmpty())
221  return QStringList();
222  return str.split(sep, allowEmptyEntries ? QString::KeepEmptyParts
224 }
225 
226 inline QStringList QStringList::split(const QString &sep, const QString &str, bool allowEmptyEntries)
227 {
228  if (str.isEmpty())
229  return QStringList();
230  return str.split(sep, allowEmptyEntries ? QString::KeepEmptyParts
232 }
233 
234 #ifndef QT_NO_REGEXP
235 inline QStringList QStringList::split(const QRegExp &sep, const QString &str, bool allowEmptyEntries)
236 {
237  if (str.isEmpty())
238  return QStringList();
239  return str.split(sep, allowEmptyEntries ? QString::KeepEmptyParts
241 }
242 #endif // QT_NO_REGEXP
243 
244 #endif // QT3_SUPPORT
245 
246 
247 #ifndef QT_NO_DATASTREAM
249 {
250  return operator>>(in, static_cast<QList<QString> &>(list));
251 }
252 inline QDataStream &operator<<(QDataStream &out, const QStringList &list)
253 {
254  return operator<<(out, static_cast<const QList<QString> &>(list));
255 }
256 #endif // QT_NO_DATASTREAM
257 
259 
261 
262 #endif // QSTRINGLIST_H
void Q_CORE_EXPORT QStringList_sort(QStringList *that)
QStringList filter(const QString &str, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns a list of all the strings containing the substring str.
Definition: qstringlist.h:167
int Q_CORE_EXPORT QStringList_indexOf(const QStringList *that, const QRegExp &rx, int from)
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
int removeDuplicates()
This function removes duplicate entries from a list.
Definition: qstringlist.h:157
#define QT_MODULE(x)
Definition: qglobal.h:2783
The QRegExp class provides pattern matching using regular expressions.
Definition: qregexp.h:61
QBool Q_CORE_EXPORT QStringList_contains(const QStringList *that, const QString &str, Qt::CaseSensitivity cs)
#define QT_BEGIN_HEADER
Definition: qglobal.h:136
QStringList & replaceInStrings(const QString &before, const QString &after, Qt::CaseSensitivity cs=Qt::CaseSensitive)
Returns a string list where every string has had the before text replaced with the after text whereve...
Definition: qstringlist.h:177
void Q_CORE_EXPORT QStringList_replaceInStrings(QStringList *that, const QString &before, const QString &after, Qt::CaseSensitivity cs)
The QString class provides a Unicode character string.
Definition: qstring.h:83
QStringList(const QStringList &l)
Constructs a copy of the other string list.
Definition: qstringlist.h:71
The QChar class provides a 16-bit Unicode character.
Definition: qchar.h:72
iterator Iterator
Qt-style synonym for QList::iterator.
Definition: qlist.h:278
QDataStream & operator<<(QDataStream &out, const QStringList &list)
Definition: qstringlist.h:252
QStringList Q_CORE_EXPORT QStringList_filter(const QStringList *that, const QString &str, Qt::CaseSensitivity cs)
QStringList(const QString &i)
Constructs a string list that contains the given string, str.
Definition: qstringlist.h:70
int Q_CORE_EXPORT QStringList_removeDuplicates(QStringList *that)
QMutableListIterator< QString > QMutableStringListIterator
Definition: qstringlist.h:64
int indexOf(const QRegExp &rx, int from=0) const
Returns the index position of the first exact match of rx in the list, searching forward from index p...
Definition: qstringlist.h:195
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
void sort()
Sorts the list of strings in ascending order (case sensitively).
Definition: qstringlist.h:152
static bool isEmpty(const char *str)
int lastIndexOf(const T &t, int from=-1) const
Returns the index position of the last occurrence of value in the list, searching backward from index...
Definition: qlist.h:862
static void sort(T *array, int count, LessThan lessThan)
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
QStringList()
Constructs an empty string list.
Definition: qstringlist.h:69
QString Q_CORE_EXPORT QStringList_join(const QStringList *that, const QString &sep)
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
QBool contains(const QString &str, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the list contains the string str; otherwise returns false.
Definition: qstringlist.h:172
static void split(QT_FT_Vector *b)
QString join(const QString &sep) const
Joins all the string list&#39;s strings into a single string with each element separated by the given sep...
Definition: qstringlist.h:162
CaseSensitivity
Definition: qnamespace.h:1451
QStringList(const QList< QString > &l)
Constructs a copy of other.
Definition: qstringlist.h:72
int indexOf(const T &t, int from=0) const
Returns the index position of the first occurrence of value in the list, searching forward from index...
Definition: qlist.h:847
#define Q_CORE_EXPORT
Definition: qglobal.h:1449
QStringList operator+(const QStringList &other) const
Returns a string list that is the concatenation of this string list with the other string list...
Definition: qstringlist.h:87
int lastIndexOf(const QRegExp &rx, int from=-1) const
Returns the index position of the last exact match of rx in the list, searching backward from index p...
Definition: qstringlist.h:200
QStringList & operator<<(const QStringList &l)
Appends the other string list to the string list and returns a reference to the latter string list...
Definition: qstringlist.h:91
const_iterator ConstIterator
Qt-style synonym for QList::const_iterator.
Definition: qlist.h:279
QStringList & operator<<(const QString &str)
Appends the given string, str, to this string list and returns a reference to the string list...
Definition: qstringlist.h:89
QFuture< void > filter(Sequence &sequence, FilterFunction filterFunction)
QFactoryLoader * l
QListIterator< QString > QStringListIterator
Definition: qstringlist.h:61
int Q_CORE_EXPORT QStringList_lastIndexOf(const QStringList *that, const QRegExp &rx, int from)
QStringList split(const QString &sep, SplitBehavior behavior=KeepEmptyParts, Qt::CaseSensitivity cs=Qt::CaseSensitive) const Q_REQUIRED_RESULT
Splits the string into substrings wherever sep occurs, and returns the list of those strings...
Definition: qstring.cpp:6526
The QDataStream class provides serialization of binary data to a QIODevice.
Definition: qdatastream.h:71
#define class
static const KeyPair *const end
#define QT_END_HEADER
Definition: qglobal.h:137
QDataStream & operator>>(QDataStream &in, QStringList &list)
Definition: qstringlist.h:248
The QList class is a template class that provides lists.
Definition: qdatastream.h:62