~oif-team/ubuntu/natty/qt4-x11/xi2.1

« back to all changes in this revision

Viewing changes to src/corelib/tools/qstringlist.h

  • Committer: Bazaar Package Importer
  • Author(s): Adam Conrad
  • Date: 2005-08-24 04:09:09 UTC
  • Revision ID: james.westby@ubuntu.com-20050824040909-xmxe9jfr4a0w5671
Tags: upstream-4.0.0
ImportĀ upstreamĀ versionĀ 4.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/****************************************************************************
 
2
**
 
3
** Copyright (C) 1992-2005 Trolltech AS. All rights reserved.
 
4
**
 
5
** This file is part of the core module of the Qt Toolkit.
 
6
**
 
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.
 
10
**
 
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.
 
15
**
 
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.
 
20
**
 
21
** Contact info@trolltech.com if any conditions of this licensing are
 
22
** not clear to you.
 
23
**
 
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.
 
26
**
 
27
****************************************************************************/
 
28
 
 
29
#ifndef QSTRINGLIST_H
 
30
#define QSTRINGLIST_H
 
31
 
 
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"
 
38
 
 
39
#ifdef QT_INCLUDE_COMPAT
 
40
#include <qvaluelist.h>
 
41
#endif
 
42
 
 
43
class QRegExp;
 
44
 
 
45
typedef QListIterator<QString> QStringListIterator;
 
46
typedef QMutableListIterator<QString> QMutableStringListIterator;
 
47
 
 
48
class QStringList : public QList<QString>
 
49
{
 
50
public:
 
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) { }
 
55
 
 
56
    inline void sort();
 
57
 
 
58
    inline QString join(const QString &sep) const;
 
59
 
 
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;
 
62
 
 
63
    inline QStringList &replaceInStrings(const QString &before, const QString &after, Qt::CaseSensitivity cs = Qt::CaseSensitive);
 
64
 
 
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; }
 
71
 
 
72
#ifndef QT_NO_REGEXP
 
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;
 
77
#endif
 
78
#if !defined(Q_NO_USING_KEYWORD)
 
79
    using QList<QString>::indexOf;
 
80
    using QList<QString>::lastIndexOf;
 
81
#else
 
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); }
 
86
#endif
 
87
#ifdef QT3_SUPPORT
 
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); }
 
92
 
 
93
#ifndef QT_NO_REGEXP
 
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); }
 
98
#endif
 
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); }
 
101
 
 
102
    inline Iterator QT3_SUPPORT fromLast() { return (isEmpty() ? end() : --end()); }
 
103
    inline ConstIterator QT3_SUPPORT fromLast() const { return (isEmpty() ? end() : --end()); }
 
104
#endif
 
105
};
 
106
 
 
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);
 
112
 
 
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);
 
116
 
 
117
#ifndef QT_NO_REGEXP
 
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);
 
122
#endif
 
123
}
 
124
 
 
125
inline void QStringList::sort()
 
126
{
 
127
    QtPrivate::QStringList_sort(this);
 
128
}
 
129
 
 
130
inline QString QStringList::join(const QString &sep) const
 
131
{
 
132
    return QtPrivate::QStringList_join(this, sep);
 
133
}
 
134
 
 
135
inline QStringList QStringList::filter(const QString &str, Qt::CaseSensitivity cs) const
 
136
{
 
137
    return QtPrivate::QStringList_filter(this, str, cs);
 
138
}
 
139
 
 
140
inline QBool QStringList::contains(const QString &str, Qt::CaseSensitivity cs) const
 
141
{
 
142
    return QtPrivate::QStringList_contains(this, str, cs);
 
143
}
 
144
 
 
145
inline QStringList &QStringList::replaceInStrings(const QString &before, const QString &after, Qt::CaseSensitivity cs)
 
146
{
 
147
    QtPrivate::QStringList_replaceInStrings(this, before, after, cs);
 
148
    return *this;
 
149
}
 
150
 
 
151
#ifndef QT_NO_REGEXP
 
152
inline QStringList &QStringList::replaceInStrings(const QRegExp &rx, const QString &after)
 
153
{
 
154
    QtPrivate::QStringList_replaceInStrings(this, rx, after);
 
155
    return *this;
 
156
}
 
157
 
 
158
inline QStringList QStringList::filter(const QRegExp &rx) const
 
159
{
 
160
    return QtPrivate::QStringList_filter(this, rx);
 
161
}
 
162
 
 
163
inline int QStringList::indexOf(const QRegExp &rx, int from) const
 
164
{
 
165
    return QtPrivate::QStringList_indexOf(this, rx, from);
 
166
}
 
167
 
 
168
inline int QStringList::lastIndexOf(const QRegExp &rx, int from) const
 
169
{
 
170
    return QtPrivate::QStringList_lastIndexOf(this, rx, from);
 
171
}
 
172
#endif
 
173
 
 
174
 
 
175
#ifdef QT3_SUPPORT
 
176
inline QStringList QStringList::split(const QChar &sep, const QString &str, bool allowEmptyEntries)
 
177
{
 
178
    if (str.isEmpty())
 
179
        return QStringList();
 
180
    return str.split(sep, allowEmptyEntries ? QString::KeepEmptyParts
 
181
                                            : QString::SkipEmptyParts);
 
182
}
 
183
 
 
184
inline QStringList QStringList::split(const QString &sep, const QString &str, bool allowEmptyEntries)
 
185
{
 
186
    if (str.isEmpty())
 
187
        return QStringList();
 
188
    return str.split(sep, allowEmptyEntries ? QString::KeepEmptyParts
 
189
                                            : QString::SkipEmptyParts);
 
190
}
 
191
 
 
192
#ifndef QT_NO_REGEXP
 
193
inline QStringList QStringList::split(const QRegExp &sep, const QString &str, bool allowEmptyEntries)
 
194
{
 
195
    if (str.isEmpty())
 
196
        return QStringList();
 
197
    return str.split(sep, allowEmptyEntries ? QString::KeepEmptyParts
 
198
                                            : QString::SkipEmptyParts);
 
199
}
 
200
#endif // QT_NO_REGEXP
 
201
 
 
202
#endif // QT3_SUPPORT
 
203
 
 
204
 
 
205
#ifndef QT_NO_DATASTREAM
 
206
inline QDataStream &operator>>(QDataStream &in, QStringList &list)
 
207
{
 
208
    return operator>>(in, static_cast<QList<QString> &>(list));
 
209
}
 
210
inline QDataStream &operator<<(QDataStream &out, const QStringList &list)
 
211
{
 
212
    return operator<<(out, static_cast<const QList<QString> &>(list));
 
213
}
 
214
#endif // QT_NO_DATASTREAM
 
215
 
 
216
#endif // QSTRINGLIST_H