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
51QT_BEGIN_NAMESPACE
52
53class QRegularExpression;
54
55#if !defined(QT_NO_JAVA_STYLE_ITERATORS)
56using QStringListIterator = QListIterator<QString>;
57using QMutableStringListIterator = QMutableListIterator<QString>;
58#endif
59
60
61namespace QtPrivate {
62 void Q_CORE_EXPORT QStringList_sort(QStringList *that, Qt::CaseSensitivity cs);
63 qsizetype Q_CORE_EXPORT QStringList_removeDuplicates(QStringList *that);
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,
68 Qt::CaseSensitivity cs);
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,
72 Qt::CaseSensitivity cs);
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
83class QStringList : public QList<QString>
84#else
85template <> struct QListSpecialMethods<QString> : QListSpecialMethodsBase<QString>
86#endif
87{
88#ifdef Q_QDOC
89public:
90 using QList<QString>::QList;
91 QStringList(const QString &str);
92 QStringList(const QList<QString> &other);
93 QStringList(QList<QString> &&other);
94
95 QStringList &operator=(const QList<QString> &other);
96 QStringList &operator=(QList<QString> &&other);
97 QStringList operator+(const QStringList &other) const;
98 QStringList &operator<<(const QString &str);
99 QStringList &operator<<(const QStringList &other);
100 QStringList &operator<<(const QList<QString> &other);
101private:
102#endif
103
104public:
105 inline void sort(Qt::CaseSensitivity cs = Qt::CaseSensitive)
106 { QtPrivate::QStringList_sort(self(), cs); }
107 inline qsizetype removeDuplicates()
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
117 inline QStringList filter(QStringView str, Qt::CaseSensitivity cs = Qt::CaseSensitive) const
118 { return QtPrivate::QStringList_filter(self(), str, cs); }
119 inline QStringList &replaceInStrings(QStringView before, QStringView after, Qt::CaseSensitivity cs = Qt::CaseSensitive)
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()); }
128 inline QStringList filter(const QString &str, Qt::CaseSensitivity cs = Qt::CaseSensitive) const
129 { return QtPrivate::QStringList_filter(self(), str, cs); }
130 inline QStringList &replaceInStrings(const QString &before, const QString &after, Qt::CaseSensitivity cs = Qt::CaseSensitive)
131 {
132 QtPrivate::QStringList_replaceInStrings(self(), before, after, cs);
133 return *self();
134 }
135 inline QStringList &replaceInStrings(const QString &before, QStringView after, Qt::CaseSensitivity cs = Qt::CaseSensitive)
136 {
137 QtPrivate::QStringList_replaceInStrings(self(), before, after, cs);
138 return *self();
139 }
140 inline QStringList &replaceInStrings(QStringView before, const QString &after, Qt::CaseSensitivity cs = Qt::CaseSensitive)
141 {
142 QtPrivate::QStringList_replaceInStrings(self(), before, after, cs);
143 return *self();
144 }
145#endif
146 using QListSpecialMethodsBase<QString>::contains;
147 using QListSpecialMethodsBase<QString>::indexOf;
148 using QListSpecialMethodsBase<QString>::lastIndexOf;
149
150 inline bool contains(QLatin1String str, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept
151 { return QtPrivate::QStringList_contains(self(), str, cs); }
152 inline bool contains(QStringView str, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept
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
179QT_END_NAMESPACE
180
181#endif // QSTRINGLIST_H
182