00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042 #ifndef QSTRINGLIST_H
00043 #define QSTRINGLIST_H
00044
00045 #include <QtCore/qalgorithms.h>
00046 #include <QtCore/qdatastream.h>
00047 #include <QtCore/qlist.h>
00048 #include <QtCore/qregexp.h>
00049 #include <QtCore/qstring.h>
00050 #include <QtCore/qstringmatcher.h>
00051 #ifdef QT_INCLUDE_COMPAT
00052 #include <Qt3Support/q3valuelist.h>
00053 #endif
00054
00055 QT_BEGIN_HEADER
00056
00057 QT_BEGIN_NAMESPACE
00058
00059 QT_MODULE(Core)
00060
00061 class QRegExp;
00062
00063 typedef QListIterator<QString> QStringListIterator;
00064 typedef QMutableListIterator<QString> QMutableStringListIterator;
00065
00066 class QStringList : public QList<QString>
00067 {
00068 public:
00069 inline QStringList() { }
00070 inline explicit QStringList(const QString &i) { append(i); }
00071 inline QStringList(const QStringList &l) : QList<QString>(l) { }
00072 inline QStringList(const QList<QString> &l) : QList<QString>(l) { }
00073
00074 inline void sort();
00075 inline int removeDuplicates();
00076
00077 inline QString join(const QString &sep) const;
00078
00079 inline QStringList filter(const QString &str, Qt::CaseSensitivity cs = Qt::CaseSensitive) const;
00080 inline QBool contains(const QString &str, Qt::CaseSensitivity cs = Qt::CaseSensitive) const;
00081
00082 inline QStringList &replaceInStrings(const QString &before, const QString &after, Qt::CaseSensitivity cs = Qt::CaseSensitive);
00083
00084 inline QStringList operator+(const QStringList &other) const
00085 { QStringList n = *this; n += other; return n; }
00086 inline QStringList &operator<<(const QString &str)
00087 { append(str); return *this; }
00088 inline QStringList &operator<<(const QStringList &l)
00089 { *this += l; return *this; }
00090
00091 #ifndef QT_NO_REGEXP
00092 inline QStringList filter(const QRegExp &rx) const;
00093 inline QStringList &replaceInStrings(const QRegExp &rx, const QString &after);
00094 inline int indexOf(const QRegExp &rx, int from = 0) const;
00095 inline int lastIndexOf(const QRegExp &rx, int from = -1) const;
00096 inline int indexOf(QRegExp &rx, int from = 0) const;
00097 inline int lastIndexOf(QRegExp &rx, int from = -1) const;
00098 #endif
00099 #if !defined(Q_NO_USING_KEYWORD)
00100 using QList<QString>::indexOf;
00101 using QList<QString>::lastIndexOf;
00102 #else
00103 inline int indexOf(const QString &str, int from = 0) const
00104 { return QList<QString>::indexOf(str, from); }
00105 inline int lastIndexOf(const QString &str, int from = -1) const
00106 { return QList<QString>::lastIndexOf(str, from); }
00107 #endif
00108 #ifdef QT3_SUPPORT
00109 static inline QT3_SUPPORT QStringList split(const QString &sep, const QString &str, bool allowEmptyEntries = false);
00110 static inline QT3_SUPPORT QStringList split(const QChar &sep, const QString &str, bool allowEmptyEntries = false);
00111 inline QT3_SUPPORT QStringList grep(const QString &str, bool cs = true) const
00112 { return filter(str, cs ? Qt::CaseSensitive : Qt::CaseInsensitive); }
00113
00114 #ifndef QT_NO_REGEXP
00115 static inline QT3_SUPPORT QStringList split(const QRegExp &sep, const QString &str, bool allowEmptyEntries = false);
00116 inline QT3_SUPPORT QStringList grep(const QRegExp &rx) const { return filter(rx); }
00117 inline QT3_SUPPORT QStringList &gres(const QRegExp &rx, const QString &after)
00118 { return replaceInStrings(rx, after); }
00119 #endif
00120 inline QT3_SUPPORT QStringList &gres(const QString &before, const QString &after, bool cs = true)
00121 { return replaceInStrings(before, after, cs ? Qt::CaseSensitive : Qt::CaseInsensitive); }
00122
00123 inline Iterator QT3_SUPPORT fromLast() { return (isEmpty() ? end() : --end()); }
00124 inline ConstIterator QT3_SUPPORT fromLast() const { return (isEmpty() ? end() : --end()); }
00125 #endif
00126 };
00127
00128 namespace QtPrivate {
00129 void Q_CORE_EXPORT QStringList_sort(QStringList *that);
00130 int Q_CORE_EXPORT QStringList_removeDuplicates(QStringList *that);
00131 QString Q_CORE_EXPORT QStringList_join(const QStringList *that, const QString &sep);
00132 QStringList Q_CORE_EXPORT QStringList_filter(const QStringList *that, const QString &str,
00133 Qt::CaseSensitivity cs);
00134
00135 QBool Q_CORE_EXPORT QStringList_contains(const QStringList *that, const QString &str, Qt::CaseSensitivity cs);
00136 void Q_CORE_EXPORT QStringList_replaceInStrings(QStringList *that, const QString &before, const QString &after,
00137 Qt::CaseSensitivity cs);
00138
00139 #ifndef QT_NO_REGEXP
00140 void Q_CORE_EXPORT QStringList_replaceInStrings(QStringList *that, const QRegExp &rx, const QString &after);
00141 QStringList Q_CORE_EXPORT QStringList_filter(const QStringList *that, const QRegExp &re);
00142 int Q_CORE_EXPORT QStringList_indexOf(const QStringList *that, const QRegExp &rx, int from);
00143 int Q_CORE_EXPORT QStringList_lastIndexOf(const QStringList *that, const QRegExp &rx, int from);
00144 int Q_CORE_EXPORT QStringList_indexOf(const QStringList *that, QRegExp &rx, int from);
00145 int Q_CORE_EXPORT QStringList_lastIndexOf(const QStringList *that, QRegExp &rx, int from);
00146 #endif
00147 }
00148
00149 inline void QStringList::sort()
00150 {
00151 QtPrivate::QStringList_sort(this);
00152 }
00153
00154 inline int QStringList::removeDuplicates()
00155 {
00156 return QtPrivate::QStringList_removeDuplicates(this);
00157 }
00158
00159 inline QString QStringList::join(const QString &sep) const
00160 {
00161 return QtPrivate::QStringList_join(this, sep);
00162 }
00163
00164 inline QStringList QStringList::filter(const QString &str, Qt::CaseSensitivity cs) const
00165 {
00166 return QtPrivate::QStringList_filter(this, str, cs);
00167 }
00168
00169 inline QBool QStringList::contains(const QString &str, Qt::CaseSensitivity cs) const
00170 {
00171 return QtPrivate::QStringList_contains(this, str, cs);
00172 }
00173
00174 inline QStringList &QStringList::replaceInStrings(const QString &before, const QString &after, Qt::CaseSensitivity cs)
00175 {
00176 QtPrivate::QStringList_replaceInStrings(this, before, after, cs);
00177 return *this;
00178 }
00179
00180 #ifndef QT_NO_REGEXP
00181 inline QStringList &QStringList::replaceInStrings(const QRegExp &rx, const QString &after)
00182 {
00183 QtPrivate::QStringList_replaceInStrings(this, rx, after);
00184 return *this;
00185 }
00186
00187 inline QStringList QStringList::filter(const QRegExp &rx) const
00188 {
00189 return QtPrivate::QStringList_filter(this, rx);
00190 }
00191
00192 inline int QStringList::indexOf(const QRegExp &rx, int from) const
00193 {
00194 return QtPrivate::QStringList_indexOf(this, rx, from);
00195 }
00196
00197 inline int QStringList::lastIndexOf(const QRegExp &rx, int from) const
00198 {
00199 return QtPrivate::QStringList_lastIndexOf(this, rx, from);
00200 }
00201
00202 inline int QStringList::indexOf(QRegExp &rx, int from) const
00203 {
00204 return QtPrivate::QStringList_indexOf(this, rx, from);
00205 }
00206
00207 inline int QStringList::lastIndexOf(QRegExp &rx, int from) const
00208 {
00209 return QtPrivate::QStringList_lastIndexOf(this, rx, from);
00210 }
00211 #endif
00212
00213
00214 #ifdef QT3_SUPPORT
00215 inline QStringList QStringList::split(const QChar &sep, const QString &str, bool allowEmptyEntries)
00216 {
00217 if (str.isEmpty())
00218 return QStringList();
00219 return str.split(sep, allowEmptyEntries ? QString::KeepEmptyParts
00220 : QString::SkipEmptyParts);
00221 }
00222
00223 inline QStringList QStringList::split(const QString &sep, const QString &str, bool allowEmptyEntries)
00224 {
00225 if (str.isEmpty())
00226 return QStringList();
00227 return str.split(sep, allowEmptyEntries ? QString::KeepEmptyParts
00228 : QString::SkipEmptyParts);
00229 }
00230
00231 #ifndef QT_NO_REGEXP
00232 inline QStringList QStringList::split(const QRegExp &sep, const QString &str, bool allowEmptyEntries)
00233 {
00234 if (str.isEmpty())
00235 return QStringList();
00236 return str.split(sep, allowEmptyEntries ? QString::KeepEmptyParts
00237 : QString::SkipEmptyParts);
00238 }
00239 #endif // QT_NO_REGEXP
00240
00241 #endif // QT3_SUPPORT
00242
00243
00244 #ifndef QT_NO_DATASTREAM
00245 inline QDataStream &operator>>(QDataStream &in, QStringList &list)
00246 {
00247 return operator>>(in, static_cast<QList<QString> &>(list));
00248 }
00249 inline QDataStream &operator<<(QDataStream &out, const QStringList &list)
00250 {
00251 return operator<<(out, static_cast<const QList<QString> &>(list));
00252 }
00253 #endif // QT_NO_DATASTREAM
00254
00255 QT_END_NAMESPACE
00256
00257 QT_END_HEADER
00258
00259 #endif // QSTRINGLIST_H