QtBase  v6.3.1
qstringlist.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2020 The Qt Company Ltd.
4 ** Copyright (C) 2016 Intel Corporation.
5 ** Contact: https://www.qt.io/licensing/
6 **
7 ** This file is part of the QtCore module of the Qt Toolkit.
8 **
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** Commercial License Usage
11 ** Licensees holding valid commercial Qt licenses may use this file in
12 ** accordance with the commercial license agreement provided with the
13 ** Software or, alternatively, in accordance with the terms contained in
14 ** a written agreement between you and The Qt Company. For licensing terms
15 ** and conditions see https://www.qt.io/terms-conditions. For further
16 ** information use the contact form at https://www.qt.io/contact-us.
17 **
18 ** GNU Lesser General Public License Usage
19 ** Alternatively, this file may be used under the terms of the GNU Lesser
20 ** General Public License version 3 as published by the Free Software
21 ** Foundation and appearing in the file LICENSE.LGPL3 included in the
22 ** packaging of this file. Please review the following information to
23 ** ensure the GNU Lesser General Public License version 3 requirements
24 ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
25 **
26 ** GNU General Public License Usage
27 ** Alternatively, this file may be used under the terms of the GNU
28 ** General Public License version 2.0 or (at your option) the GNU General
29 ** Public license version 3 or any later version approved by the KDE Free
30 ** Qt Foundation. The licenses are as published by the Free Software
31 ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
32 ** included in the packaging of this file. Please review the following
33 ** information to ensure the GNU General Public License requirements will
34 ** be met: https://www.gnu.org/licenses/gpl-2.0.html and
35 ** https://www.gnu.org/licenses/gpl-3.0.html.
36 **
37 ** $QT_END_LICENSE$
38 **
39 ****************************************************************************/
40 
41 #include <QtCore/qlist.h>
42 
43 #ifndef QSTRINGLIST_H
44 #define QSTRINGLIST_H
45 
46 #include <QtCore/qalgorithms.h>
47 #include <QtCore/qcontainertools_impl.h>
48 #include <QtCore/qstring.h>
49 #include <QtCore/qstringmatcher.h>
50 
52 
53 class QRegularExpression;
54 
55 #if !defined(QT_NO_JAVA_STYLE_ITERATORS)
56 using QStringListIterator = QListIterator<QString>;
57 using QMutableStringListIterator = QMutableListIterator<QString>;
58 #endif
59 
60 
61 namespace QtPrivate {
62  void Q_CORE_EXPORT QStringList_sort(QStringList *that, Qt::CaseSensitivity cs);
64  QString Q_CORE_EXPORT QStringList_join(const QStringList *that, QStringView sep);
65  QString Q_CORE_EXPORT QStringList_join(const QStringList *that, const QChar *sep, qsizetype seplen);
66  Q_CORE_EXPORT QString QStringList_join(const QStringList &list, QLatin1String sep);
67  QStringList Q_CORE_EXPORT QStringList_filter(const QStringList *that, QStringView str,
69  bool Q_CORE_EXPORT QStringList_contains(const QStringList *that, QStringView str, Qt::CaseSensitivity cs);
70  bool Q_CORE_EXPORT QStringList_contains(const QStringList *that, QLatin1String str, Qt::CaseSensitivity cs);
71  void Q_CORE_EXPORT QStringList_replaceInStrings(QStringList *that, QStringView before, QStringView after,
73 
74 #if QT_CONFIG(regularexpression)
75  void Q_CORE_EXPORT QStringList_replaceInStrings(QStringList *that, const QRegularExpression &rx, const QString &after);
76  QStringList Q_CORE_EXPORT QStringList_filter(const QStringList *that, const QRegularExpression &re);
77  qsizetype Q_CORE_EXPORT QStringList_indexOf(const QStringList *that, const QRegularExpression &re, qsizetype from);
78  qsizetype Q_CORE_EXPORT QStringList_lastIndexOf(const QStringList *that, const QRegularExpression &re, qsizetype from);
79 #endif // QT_CONFIG(regularexpression)
80 }
81 
82 #ifdef Q_QDOC
83 class QStringList : public QList<QString>
84 #else
85 template <> struct QListSpecialMethods<QString> : QListSpecialMethodsBase<QString>
86 #endif
87 {
88 #ifdef Q_QDOC
89 public:
91  QStringList(const QString &str);
94 
95  QStringList &operator=(const QList<QString> &other);
96  QStringList &operator=(QList<QString> &&other);
97  QStringList operator+(const QStringList &other) const;
101 private:
102 #endif
103 
104 public:
106  { QtPrivate::QStringList_sort(self(), cs); }
108  { return QtPrivate::QStringList_removeDuplicates(self()); }
109 
110  inline QString join(QStringView sep) const
111  { return QtPrivate::QStringList_join(self(), sep); }
112  inline QString join(QLatin1String sep) const
113  { return QtPrivate::QStringList_join(*self(), sep); }
114  inline QString join(QChar sep) const
115  { return QtPrivate::QStringList_join(self(), &sep, 1); }
116 
118  { return QtPrivate::QStringList_filter(self(), str, cs); }
120  {
121  QtPrivate::QStringList_replaceInStrings(self(), before, after, cs);
122  return *self();
123  }
124 
125 #if QT_STRINGVIEW_LEVEL < 2
126  inline QString join(const QString &sep) const
127  { return QtPrivate::QStringList_join(self(), sep.constData(), sep.length()); }
129  { return QtPrivate::QStringList_filter(self(), str, cs); }
131  {
132  QtPrivate::QStringList_replaceInStrings(self(), before, after, cs);
133  return *self();
134  }
136  {
137  QtPrivate::QStringList_replaceInStrings(self(), before, after, cs);
138  return *self();
139  }
141  {
142  QtPrivate::QStringList_replaceInStrings(self(), before, after, cs);
143  return *self();
144  }
145 #endif
149 
151  { return QtPrivate::QStringList_contains(self(), str, cs); }
153  { return QtPrivate::QStringList_contains(self(), str, cs); }
154 
155 #if QT_STRINGVIEW_LEVEL < 2
156  inline bool contains(const QString &str, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept
157  { return QtPrivate::QStringList_contains(self(), str, cs); }
158  qsizetype indexOf(const QString &str, qsizetype from = 0) const noexcept
159  { return indexOf(QStringView(str), from); }
160  qsizetype lastIndexOf(const QString &str, qsizetype from = -1) const noexcept
161  { return lastIndexOf(QStringView(str), from); }
162 #endif
163 
164 #if QT_CONFIG(regularexpression)
165  inline QStringList filter(const QRegularExpression &re) const
166  { return QtPrivate::QStringList_filter(self(), re); }
167  inline QStringList &replaceInStrings(const QRegularExpression &re, const QString &after)
168  {
169  QtPrivate::QStringList_replaceInStrings(self(), re, after);
170  return *self();
171  }
172  inline qsizetype indexOf(const QRegularExpression &re, qsizetype from = 0) const
173  { return QtPrivate::QStringList_indexOf(self(), re, from); }
174  inline qsizetype lastIndexOf(const QRegularExpression &re, qsizetype from = -1) const
175  { return QtPrivate::QStringList_lastIndexOf(self(), re, from); }
176 #endif // QT_CONFIG(regularexpression)
177 };
178 
180 
181 #endif // QSTRINGLIST_H
The QChar class provides a 16-bit Unicode character.
Definition: qchar.h:84
The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal.
Definition: qstring.h:84
Definition: qlist.h:108
The QRegularExpression class provides pattern matching using regular expressions.
The QString class provides a Unicode character string.
Definition: qstring.h:388
const QChar * constData() const
Definition: qstring.h:1234
qsizetype length() const
Definition: qstring.h:415
The QStringList class provides a list of strings.
The QStringView class provides a unified view on UTF-16 strings with a read-only subset of the QStrin...
Definition: qstringview.h:122
float rx
QString str
[2]
auto it unsigned count const
Definition: hb-iter.hh:848
QTextStream & operator<<(QTextStream &stream, const QStringList &list)
CaseSensitivity
Definition: qnamespace.h:1282
@ CaseSensitive
Definition: qnamespace.h:1284
void Q_CORE_EXPORT QStringList_replaceInStrings(QStringList *that, QStringView before, QStringView after, Qt::CaseSensitivity cs)
bool Q_CORE_EXPORT QStringList_contains(const QStringList *that, QStringView str, Qt::CaseSensitivity cs)
QString Q_CORE_EXPORT QStringList_join(const QStringList *that, QStringView sep)
qsizetype Q_CORE_EXPORT QStringList_removeDuplicates(QStringList *that)
Q_CORE_EXPORT Q_DECL_PURE_FUNCTION qsizetype lastIndexOf(QByteArrayView haystack, qsizetype from, QByteArrayView needle) noexcept
QStringList Q_CORE_EXPORT QStringList_filter(const QStringList *that, QStringView str, Qt::CaseSensitivity cs)
void Q_CORE_EXPORT QStringList_sort(QStringList *that, Qt::CaseSensitivity cs)
qsizetype indexOf(const QList< V > &list, const U &u, qsizetype from) noexcept
QString operator+(const ProString &one, const ProString &two)
Definition: proitems.cpp:281
QList< QString > QStringList
Definition: qcontainerfwd.h:64
ptrdiff_t qsizetype
Definition: qglobal.h:308
GLint GLint GLint GLint GLint GLint GLint GLbitfield GLenum filter
QListIterator< QString > QStringListIterator
Definition: qstringlist.h:56
QMutableListIterator< QString > QMutableStringListIterator
Definition: qstringlist.h:57
QSharedPointer< T > other(t)
[5]
QStringList list
[0]
QString join(QLatin1String sep) const
Definition: qstringlist.h:112
bool contains(const QString &str, Qt::CaseSensitivity cs=Qt::CaseSensitive) const noexcept
Definition: qstringlist.h:156
qsizetype lastIndexOf(const QString &str, qsizetype from=-1) const noexcept
Definition: qstringlist.h:160
void sort(Qt::CaseSensitivity cs=Qt::CaseSensitive)
Definition: qstringlist.h:105
QString join(const QString &sep) const
Definition: qstringlist.h:126
QStringList & replaceInStrings(const QString &before, QStringView after, Qt::CaseSensitivity cs=Qt::CaseSensitive)
Definition: qstringlist.h:135
QString join(QStringView sep) const
Definition: qstringlist.h:110
qsizetype indexOf(const QString &str, qsizetype from=0) const noexcept
Definition: qstringlist.h:158
bool contains(QLatin1String str, Qt::CaseSensitivity cs=Qt::CaseSensitive) const noexcept
Definition: qstringlist.h:150
QStringList filter(const QString &str, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Definition: qstringlist.h:128
QStringList & replaceInStrings(QStringView before, const QString &after, Qt::CaseSensitivity cs=Qt::CaseSensitive)
Definition: qstringlist.h:140
QString join(QChar sep) const
Definition: qstringlist.h:114
QStringList & replaceInStrings(const QString &before, const QString &after, Qt::CaseSensitivity cs=Qt::CaseSensitive)
Definition: qstringlist.h:130
QStringList & replaceInStrings(QStringView before, QStringView after, Qt::CaseSensitivity cs=Qt::CaseSensitive)
Definition: qstringlist.h:119
QStringList filter(QStringView str, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Definition: qstringlist.h:117
bool contains(QStringView str, Qt::CaseSensitivity cs=Qt::CaseSensitive) const noexcept
Definition: qstringlist.h:152