1// Copyright (C) 2020 The Qt Company Ltd.
2// Copyright (C) 2016 Intel Corporation.
3// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
4
5#include <QtCore/qlist.h>
6
7#ifndef QSTRINGLIST_H
8#define QSTRINGLIST_H
9
10#include <QtCore/qalgorithms.h>
11#include <QtCore/qcontainertools_impl.h>
12#include <QtCore/qstring.h>
13#include <QtCore/qstringmatcher.h>
14
15QT_BEGIN_NAMESPACE
16
17class QLatin1StringMatcher;
18class QRegularExpression;
19
20#if !defined(QT_NO_JAVA_STYLE_ITERATORS)
21using QStringListIterator = QListIterator<QString>;
22using QMutableStringListIterator = QMutableListIterator<QString>;
23#endif
24
25
26namespace QtPrivate {
27 void Q_CORE_EXPORT QStringList_sort(QStringList *that, Qt::CaseSensitivity cs);
28 qsizetype Q_CORE_EXPORT QStringList_removeDuplicates(QStringList *that);
29 QString Q_CORE_EXPORT QStringList_join(const QStringList *that, QStringView sep);
30 QString Q_CORE_EXPORT QStringList_join(const QStringList *that, const QChar *sep, qsizetype seplen);
31 Q_CORE_EXPORT QString QStringList_join(const QStringList &list, QLatin1StringView sep);
32 QStringList Q_CORE_EXPORT QStringList_filter(const QStringList *that, QStringView str,
33 Qt::CaseSensitivity cs);
34 Q_CORE_EXPORT QStringList QStringList_filter(const QStringList &that, QLatin1StringView needle,
35 Qt::CaseSensitivity cs);
36 Q_CORE_EXPORT QStringList QStringList_filter(const QStringList &that,
37 const QStringMatcher &matcher);
38 Q_CORE_EXPORT QStringList QStringList_filter(const QStringList &that,
39 const QLatin1StringMatcher &matcher);
40
41 bool Q_CORE_EXPORT QStringList_contains(const QStringList *that, QStringView str, Qt::CaseSensitivity cs);
42 bool Q_CORE_EXPORT QStringList_contains(const QStringList *that, QLatin1StringView str, Qt::CaseSensitivity cs);
43 void Q_CORE_EXPORT QStringList_replaceInStrings(QStringList *that, QStringView before, QStringView after,
44 Qt::CaseSensitivity cs);
45
46 qsizetype Q_CORE_EXPORT QStringList_indexOf(const QStringList &that, QStringView str,
47 qsizetype from, Qt::CaseSensitivity cs);
48 qsizetype Q_CORE_EXPORT QStringList_indexOf(const QStringList &that, QLatin1StringView str,
49 qsizetype from, Qt::CaseSensitivity cs);
50
51 Q_CORE_EXPORT qsizetype QStringList_lastIndexOf(const QStringList &that, QStringView str,
52 qsizetype from, Qt::CaseSensitivity cs);
53 Q_CORE_EXPORT qsizetype QStringList_lastIndexOf(const QStringList &that, QLatin1StringView str,
54 qsizetype from, Qt::CaseSensitivity cs);
55
56#if QT_CONFIG(regularexpression)
57 void Q_CORE_EXPORT QStringList_replaceInStrings(QStringList *that, const QRegularExpression &rx, const QString &after);
58 QStringList Q_CORE_EXPORT QStringList_filter(const QStringList *that, const QRegularExpression &re);
59 qsizetype Q_CORE_EXPORT QStringList_indexOf(const QStringList *that, const QRegularExpression &re, qsizetype from);
60 qsizetype Q_CORE_EXPORT QStringList_lastIndexOf(const QStringList *that, const QRegularExpression &re, qsizetype from);
61#endif // QT_CONFIG(regularexpression)
62}
63
64#ifdef Q_QDOC
65class QStringList : public QList<QString>
66#else
67template <> struct QListSpecialMethods<QString> : QListSpecialMethodsBase<QString>
68#endif
69{
70#ifdef Q_QDOC
71public:
72 using QList<QString>::QList;
73 QStringList(const QString &str);
74 QStringList(const QList<QString> &other);
75 QStringList(QList<QString> &&other);
76
77 QStringList &operator=(const QList<QString> &other);
78 QStringList &operator=(QList<QString> &&other);
79 QStringList operator+(const QStringList &other) const;
80 QStringList &operator<<(const QString &str);
81 QStringList &operator<<(const QStringList &other);
82 QStringList &operator<<(const QList<QString> &other);
83private:
84#endif
85
86public:
87 inline void sort(Qt::CaseSensitivity cs = Qt::CaseSensitive)
88 { QtPrivate::QStringList_sort(that: self(), cs); }
89 inline qsizetype removeDuplicates()
90 { return QtPrivate::QStringList_removeDuplicates(that: self()); }
91
92 inline QString join(QStringView sep) const
93 { return QtPrivate::QStringList_join(that: self(), sep); }
94 inline QString join(QLatin1StringView sep) const
95 { return QtPrivate::QStringList_join(list: *self(), sep); }
96 inline QString join(QChar sep) const
97 { return QtPrivate::QStringList_join(that: self(), sep: &sep, seplen: 1); }
98
99 QStringList filter(const QStringMatcher &matcher) const
100 { return QtPrivate::QStringList_filter(that: *self(), matcher); }
101 QStringList filter(const QLatin1StringMatcher &matcher) const
102 { return QtPrivate::QStringList_filter(that: *self(), matcher); }
103
104 QStringList filter(QLatin1StringView needle, Qt::CaseSensitivity cs = Qt::CaseSensitive) const
105 { return QtPrivate::QStringList_filter(that: *self(), needle, cs); }
106 inline QStringList filter(QStringView str, Qt::CaseSensitivity cs = Qt::CaseSensitive) const
107 { return QtPrivate::QStringList_filter(that: self(), str, cs); }
108 inline QStringList &replaceInStrings(QStringView before, QStringView after, Qt::CaseSensitivity cs = Qt::CaseSensitive)
109 {
110 QtPrivate::QStringList_replaceInStrings(that: self(), before, after, cs);
111 return *self();
112 }
113
114 inline QString join(const QString &sep) const
115 { return QtPrivate::QStringList_join(that: self(), sep: sep.constData(), seplen: sep.size()); }
116 inline QStringList filter(const QString &str, Qt::CaseSensitivity cs = Qt::CaseSensitive) const
117 { return QtPrivate::QStringList_filter(that: self(), str, cs); }
118 inline QStringList &replaceInStrings(const QString &before, const QString &after, Qt::CaseSensitivity cs = Qt::CaseSensitive)
119 {
120 QtPrivate::QStringList_replaceInStrings(that: self(), before, after, cs);
121 return *self();
122 }
123 inline QStringList &replaceInStrings(const QString &before, QStringView after, Qt::CaseSensitivity cs = Qt::CaseSensitive)
124 {
125 QtPrivate::QStringList_replaceInStrings(that: self(), before, after, cs);
126 return *self();
127 }
128 inline QStringList &replaceInStrings(QStringView before, const QString &after, Qt::CaseSensitivity cs = Qt::CaseSensitive)
129 {
130 QtPrivate::QStringList_replaceInStrings(that: self(), before, after, cs);
131 return *self();
132 }
133 using QListSpecialMethodsBase<QString>::contains;
134 using QListSpecialMethodsBase<QString>::indexOf;
135 using QListSpecialMethodsBase<QString>::lastIndexOf;
136
137 inline bool contains(QLatin1StringView str, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept
138 { return QtPrivate::QStringList_contains(that: self(), str, cs); }
139 inline bool contains(QStringView str, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept
140 { return QtPrivate::QStringList_contains(that: self(), str, cs); }
141
142 inline bool contains(const QString &str, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept
143 { return QtPrivate::QStringList_contains(that: self(), str, cs); }
144
145 qsizetype indexOf(const QString &str, qsizetype from = 0,
146 Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept
147 { return indexOf(needle: QStringView(str), from, cs); }
148 qsizetype indexOf(QStringView needle, qsizetype from = 0,
149 Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept
150 { return QtPrivate::QStringList_indexOf(that: *self(), str: needle, from, cs); }
151 qsizetype indexOf(QLatin1StringView needle, qsizetype from = 0,
152 Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept
153 { return QtPrivate::QStringList_indexOf(that: *self(), str: needle, from, cs); }
154
155 qsizetype lastIndexOf(const QString &str, qsizetype from = -1,
156 Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept
157 { return lastIndexOf(str: QStringView(str), from, cs); }
158 qsizetype lastIndexOf(QStringView str, qsizetype from = -1,
159 Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept
160 { return QtPrivate::QStringList_lastIndexOf(that: *self(), str, from, cs); }
161 qsizetype lastIndexOf(QLatin1StringView needle, qsizetype from = -1,
162 Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept
163 { return QtPrivate::QStringList_lastIndexOf(that: *self(), str: needle, from, cs); }
164
165#if QT_CONFIG(regularexpression)
166 inline QStringList filter(const QRegularExpression &re) const
167 { return QtPrivate::QStringList_filter(that: self(), re); }
168 inline QStringList &replaceInStrings(const QRegularExpression &re, const QString &after)
169 {
170 QtPrivate::QStringList_replaceInStrings(that: self(), rx: re, after);
171 return *self();
172 }
173 inline qsizetype indexOf(const QRegularExpression &re, qsizetype from = 0) const
174 { return QtPrivate::QStringList_indexOf(that: self(), re, from); }
175 inline qsizetype lastIndexOf(const QRegularExpression &re, qsizetype from = -1) const
176 { return QtPrivate::QStringList_lastIndexOf(that: self(), re, from); }
177#endif // QT_CONFIG(regularexpression)
178};
179
180QT_END_NAMESPACE
181
182#endif // QSTRINGLIST_H
183

source code of qtbase/src/corelib/text/qstringlist.h