1
/****************************************************************************
3
** Copyright (C) 1992-2005 Trolltech AS. All rights reserved.
5
** This file is part of the core module of the Qt Toolkit.
7
** This file may be distributed under the terms of the Q Public License
8
** as defined by Trolltech AS of Norway and appearing in the file
9
** LICENSE.QPL included in the packaging of this file.
11
** This file may be distributed and/or modified under the terms of the
12
** GNU General Public License version 2 as published by the Free Software
13
** Foundation and appearing in the file LICENSE.GPL included in the
14
** packaging of this file.
16
** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
17
** information about Qt Commercial License Agreements.
18
** See http://www.trolltech.com/qpl/ for QPL licensing information.
19
** See http://www.trolltech.com/gpl/ for GPL licensing information.
21
** Contact info@trolltech.com if any conditions of this licensing are
24
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
25
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
27
****************************************************************************/
32
#include "QtCore/qalgorithms.h"
33
#include "QtCore/qdatastream.h"
34
#include "QtCore/qlist.h"
35
#include "QtCore/qregexp.h"
36
#include "QtCore/qstring.h"
37
#include "QtCore/qstringmatcher.h"
39
#ifdef QT_INCLUDE_COMPAT
40
#include <qvaluelist.h>
45
typedef QListIterator<QString> QStringListIterator;
46
typedef QMutableListIterator<QString> QMutableStringListIterator;
48
class QStringList : public QList<QString>
51
inline QStringList() { }
52
inline explicit QStringList(const QString &i) { append(i); }
53
inline QStringList(const QStringList &l) : QList<QString>(l) { }
54
inline QStringList(const QList<QString> &l) : QList<QString>(l) { }
58
inline QString join(const QString &sep) const;
60
inline QStringList filter(const QString &str, Qt::CaseSensitivity cs = Qt::CaseSensitive) const;
61
inline QBool contains(const QString &str, Qt::CaseSensitivity cs = Qt::CaseSensitive) const;
63
inline QStringList &replaceInStrings(const QString &before, const QString &after, Qt::CaseSensitivity cs = Qt::CaseSensitive);
65
inline QStringList operator+(const QStringList &other) const
66
{ QStringList n = *this; n += other; return n; }
67
inline QStringList &operator<<(const QString &str)
68
{ append(str); return *this; }
69
inline QStringList &operator<<(const QStringList &l)
70
{ *this += l; return *this; }
73
inline QStringList filter(const QRegExp &rx) const;
74
inline QStringList &replaceInStrings(const QRegExp &rx, const QString &after);
75
inline int indexOf(const QRegExp &rx, int from = 0) const;
76
inline int lastIndexOf(const QRegExp &rx, int from = -1) const;
78
#if !defined(Q_NO_USING_KEYWORD)
79
using QList<QString>::indexOf;
80
using QList<QString>::lastIndexOf;
82
inline int indexOf(const QString &str, int from = 0) const
83
{ return QList<QString>::indexOf(str, from); }
84
inline int lastIndexOf(const QString &str, int from = -1) const
85
{ return QList<QString>::lastIndexOf(str, from); }
88
static inline QT3_SUPPORT QStringList split(const QString &sep, const QString &str, bool allowEmptyEntries = false);
89
static inline QT3_SUPPORT QStringList split(const QChar &sep, const QString &str, bool allowEmptyEntries = false);
90
inline QT3_SUPPORT QStringList grep(const QString &str, bool cs = true) const
91
{ return filter(str, cs ? Qt::CaseSensitive : Qt::CaseInsensitive); }
94
static inline QT3_SUPPORT QStringList split(const QRegExp &sep, const QString &str, bool allowEmptyEntries = false);
95
inline QT3_SUPPORT QStringList grep(const QRegExp &rx) const { return filter(rx); }
96
inline QT3_SUPPORT QStringList &gres(const QRegExp &rx, const QString &after)
97
{ return replaceInStrings(rx, after); }
99
inline QT3_SUPPORT QStringList &gres(const QString &before, const QString &after, bool cs = true)
100
{ return replaceInStrings(before, after, cs ? Qt::CaseSensitive : Qt::CaseInsensitive); }
102
inline Iterator QT3_SUPPORT fromLast() { return (isEmpty() ? end() : --end()); }
103
inline ConstIterator QT3_SUPPORT fromLast() const { return (isEmpty() ? end() : --end()); }
107
namespace QtPrivate {
108
void Q_CORE_EXPORT QStringList_sort(QStringList *that);
109
QString Q_CORE_EXPORT QStringList_join(const QStringList *that, const QString &sep);
110
QStringList Q_CORE_EXPORT QStringList_filter(const QStringList *that, const QString &str,
111
Qt::CaseSensitivity cs);
113
QBool Q_CORE_EXPORT QStringList_contains(const QStringList *that, const QString &str, Qt::CaseSensitivity cs);
114
void Q_CORE_EXPORT QStringList_replaceInStrings(QStringList *that, const QString &before, const QString &after,
115
Qt::CaseSensitivity cs);
118
void Q_CORE_EXPORT QStringList_replaceInStrings(QStringList *that, const QRegExp &rx, const QString &after);
119
QStringList Q_CORE_EXPORT QStringList_filter(const QStringList *that, const QRegExp &re);
120
int Q_CORE_EXPORT QStringList_indexOf(const QStringList *that, const QRegExp &rx, int from);
121
int Q_CORE_EXPORT QStringList_lastIndexOf(const QStringList *that, const QRegExp &rx, int from);
125
inline void QStringList::sort()
127
QtPrivate::QStringList_sort(this);
130
inline QString QStringList::join(const QString &sep) const
132
return QtPrivate::QStringList_join(this, sep);
135
inline QStringList QStringList::filter(const QString &str, Qt::CaseSensitivity cs) const
137
return QtPrivate::QStringList_filter(this, str, cs);
140
inline QBool QStringList::contains(const QString &str, Qt::CaseSensitivity cs) const
142
return QtPrivate::QStringList_contains(this, str, cs);
145
inline QStringList &QStringList::replaceInStrings(const QString &before, const QString &after, Qt::CaseSensitivity cs)
147
QtPrivate::QStringList_replaceInStrings(this, before, after, cs);
152
inline QStringList &QStringList::replaceInStrings(const QRegExp &rx, const QString &after)
154
QtPrivate::QStringList_replaceInStrings(this, rx, after);
158
inline QStringList QStringList::filter(const QRegExp &rx) const
160
return QtPrivate::QStringList_filter(this, rx);
163
inline int QStringList::indexOf(const QRegExp &rx, int from) const
165
return QtPrivate::QStringList_indexOf(this, rx, from);
168
inline int QStringList::lastIndexOf(const QRegExp &rx, int from) const
170
return QtPrivate::QStringList_lastIndexOf(this, rx, from);
176
inline QStringList QStringList::split(const QChar &sep, const QString &str, bool allowEmptyEntries)
179
return QStringList();
180
return str.split(sep, allowEmptyEntries ? QString::KeepEmptyParts
181
: QString::SkipEmptyParts);
184
inline QStringList QStringList::split(const QString &sep, const QString &str, bool allowEmptyEntries)
187
return QStringList();
188
return str.split(sep, allowEmptyEntries ? QString::KeepEmptyParts
189
: QString::SkipEmptyParts);
193
inline QStringList QStringList::split(const QRegExp &sep, const QString &str, bool allowEmptyEntries)
196
return QStringList();
197
return str.split(sep, allowEmptyEntries ? QString::KeepEmptyParts
198
: QString::SkipEmptyParts);
200
#endif // QT_NO_REGEXP
202
#endif // QT3_SUPPORT
205
#ifndef QT_NO_DATASTREAM
206
inline QDataStream &operator>>(QDataStream &in, QStringList &list)
208
return operator>>(in, static_cast<QList<QString> &>(list));
210
inline QDataStream &operator<<(QDataStream &out, const QStringList &list)
212
return operator<<(out, static_cast<const QList<QString> &>(list));
214
#endif // QT_NO_DATASTREAM
216
#endif // QSTRINGLIST_H