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 | |
55 | QT_BEGIN_HEADER |
56 | |
57 | QT_BEGIN_NAMESPACE |
58 | |
59 | QT_MODULE(Core) |
60 | |
61 | class QRegExp; |
62 | |
63 | typedef QListIterator<QString> QStringListIterator; |
64 | typedef QMutableListIterator<QString> QMutableStringListIterator; |
65 | |
66 | class QStringList : public QList<QString> |
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; } |
91 | inline QStringList &operator<<(const QStringList &l) |
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) |
103 | using QList<QString>::indexOf; |
104 | using QList<QString>::lastIndexOf; |
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 { |
132 | void Q_CORE_EXPORT QStringList_sort(QStringList *that); |
133 | int Q_CORE_EXPORT QStringList_removeDuplicates(QStringList *that); |
134 | QString Q_CORE_EXPORT QStringList_join(const QStringList *that, const QString &sep); |
135 | QStringList Q_CORE_EXPORT QStringList_filter(const QStringList *that, const QString &str, |
136 | Qt::CaseSensitivity cs); |
137 | |
138 | QBool Q_CORE_EXPORT QStringList_contains(const QStringList *that, const QString &str, Qt::CaseSensitivity cs); |
139 | void Q_CORE_EXPORT QStringList_replaceInStrings(QStringList *that, const QString &before, const QString &after, |
140 | Qt::CaseSensitivity cs); |
141 | |
142 | #ifndef QT_NO_REGEXP |
143 | void Q_CORE_EXPORT QStringList_replaceInStrings(QStringList *that, const QRegExp &rx, const QString &after); |
144 | QStringList Q_CORE_EXPORT QStringList_filter(const QStringList *that, const QRegExp &re); |
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 | { |
154 | QtPrivate::QStringList_sort(this); |
155 | } |
156 | |
157 | inline int QStringList::removeDuplicates() |
158 | { |
159 | return QtPrivate::QStringList_removeDuplicates(this); |
160 | } |
161 | |
162 | inline QString QStringList::join(const QString &sep) const |
163 | { |
164 | return QtPrivate::QStringList_join(this, sep); |
165 | } |
166 | |
167 | inline QStringList QStringList::filter(const QString &str, Qt::CaseSensitivity cs) const |
168 | { |
169 | return QtPrivate::QStringList_filter(this, str, cs); |
170 | } |
171 | |
172 | inline QBool QStringList::contains(const QString &str, Qt::CaseSensitivity cs) const |
173 | { |
174 | return QtPrivate::QStringList_contains(this, str, cs); |
175 | } |
176 | |
177 | inline QStringList &QStringList::replaceInStrings(const QString &before, const QString &after, Qt::CaseSensitivity cs) |
178 | { |
179 | QtPrivate::QStringList_replaceInStrings(this, before, after, cs); |
180 | return *this; |
181 | } |
182 | |
183 | #ifndef QT_NO_REGEXP |
184 | inline QStringList &QStringList::replaceInStrings(const QRegExp &rx, const QString &after) |
185 | { |
186 | QtPrivate::QStringList_replaceInStrings(this, rx, after); |
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 |
223 | : QString::SkipEmptyParts); |
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 |
231 | : QString::SkipEmptyParts); |
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 |
240 | : QString::SkipEmptyParts); |
241 | } |
242 | #endif // QT_NO_REGEXP |
243 | |
244 | #endif // QT3_SUPPORT |
245 | |
246 | |
247 | #ifndef QT_NO_DATASTREAM |
248 | inline QDataStream &operator>>(QDataStream &in, QStringList &list) |
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 | |
258 | QT_END_NAMESPACE |
259 | |
260 | QT_END_HEADER |
261 | |
262 | #endif // QSTRINGLIST_H |
263 | |