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 | |
15 | QT_BEGIN_NAMESPACE |
16 | |
17 | class QRegularExpression; |
18 | |
19 | #if !defined(QT_NO_JAVA_STYLE_ITERATORS) |
20 | using QStringListIterator = QListIterator<QString>; |
21 | using QMutableStringListIterator = QMutableListIterator<QString>; |
22 | #endif |
23 | |
24 | |
25 | namespace QtPrivate { |
26 | void Q_CORE_EXPORT QStringList_sort(QStringList *that, Qt::CaseSensitivity cs); |
27 | qsizetype Q_CORE_EXPORT QStringList_removeDuplicates(QStringList *that); |
28 | QString Q_CORE_EXPORT QStringList_join(const QStringList *that, QStringView sep); |
29 | QString Q_CORE_EXPORT QStringList_join(const QStringList *that, const QChar *sep, qsizetype seplen); |
30 | Q_CORE_EXPORT QString QStringList_join(const QStringList &list, QLatin1StringView sep); |
31 | QStringList Q_CORE_EXPORT QStringList_filter(const QStringList *that, QStringView str, |
32 | Qt::CaseSensitivity cs); |
33 | bool Q_CORE_EXPORT QStringList_contains(const QStringList *that, QStringView str, Qt::CaseSensitivity cs); |
34 | bool Q_CORE_EXPORT QStringList_contains(const QStringList *that, QLatin1StringView str, Qt::CaseSensitivity cs); |
35 | void Q_CORE_EXPORT QStringList_replaceInStrings(QStringList *that, QStringView before, QStringView after, |
36 | Qt::CaseSensitivity cs); |
37 | |
38 | #if QT_CONFIG(regularexpression) |
39 | void Q_CORE_EXPORT QStringList_replaceInStrings(QStringList *that, const QRegularExpression &rx, const QString &after); |
40 | QStringList Q_CORE_EXPORT QStringList_filter(const QStringList *that, const QRegularExpression &re); |
41 | qsizetype Q_CORE_EXPORT QStringList_indexOf(const QStringList *that, const QRegularExpression &re, qsizetype from); |
42 | qsizetype Q_CORE_EXPORT QStringList_lastIndexOf(const QStringList *that, const QRegularExpression &re, qsizetype from); |
43 | #endif // QT_CONFIG(regularexpression) |
44 | } |
45 | |
46 | #ifdef Q_QDOC |
47 | class QStringList : public QList<QString> |
48 | #else |
49 | template <> struct QListSpecialMethods<QString> : QListSpecialMethodsBase<QString> |
50 | #endif |
51 | { |
52 | #ifdef Q_QDOC |
53 | public: |
54 | using QList<QString>::QList; |
55 | QStringList(const QString &str); |
56 | QStringList(const QList<QString> &other); |
57 | QStringList(QList<QString> &&other); |
58 | |
59 | QStringList &operator=(const QList<QString> &other); |
60 | QStringList &operator=(QList<QString> &&other); |
61 | QStringList operator+(const QStringList &other) const; |
62 | QStringList &operator<<(const QString &str); |
63 | QStringList &operator<<(const QStringList &other); |
64 | QStringList &operator<<(const QList<QString> &other); |
65 | private: |
66 | #endif |
67 | |
68 | public: |
69 | inline void sort(Qt::CaseSensitivity cs = Qt::CaseSensitive) |
70 | { QtPrivate::QStringList_sort(that: self(), cs); } |
71 | inline qsizetype removeDuplicates() |
72 | { return QtPrivate::QStringList_removeDuplicates(that: self()); } |
73 | |
74 | inline QString join(QStringView sep) const |
75 | { return QtPrivate::QStringList_join(that: self(), sep); } |
76 | inline QString join(QLatin1StringView sep) const |
77 | { return QtPrivate::QStringList_join(list: *self(), sep); } |
78 | inline QString join(QChar sep) const |
79 | { return QtPrivate::QStringList_join(that: self(), sep: &sep, seplen: 1); } |
80 | |
81 | inline QStringList filter(QStringView str, Qt::CaseSensitivity cs = Qt::CaseSensitive) const |
82 | { return QtPrivate::QStringList_filter(that: self(), str, cs); } |
83 | inline QStringList &replaceInStrings(QStringView before, QStringView after, Qt::CaseSensitivity cs = Qt::CaseSensitive) |
84 | { |
85 | QtPrivate::QStringList_replaceInStrings(that: self(), before, after, cs); |
86 | return *self(); |
87 | } |
88 | |
89 | inline QString join(const QString &sep) const |
90 | { return QtPrivate::QStringList_join(that: self(), sep: sep.constData(), seplen: sep.size()); } |
91 | inline QStringList filter(const QString &str, Qt::CaseSensitivity cs = Qt::CaseSensitive) const |
92 | { return QtPrivate::QStringList_filter(that: self(), str, cs); } |
93 | inline QStringList &replaceInStrings(const QString &before, const QString &after, Qt::CaseSensitivity cs = Qt::CaseSensitive) |
94 | { |
95 | QtPrivate::QStringList_replaceInStrings(that: self(), before, after, cs); |
96 | return *self(); |
97 | } |
98 | inline QStringList &replaceInStrings(const QString &before, QStringView after, Qt::CaseSensitivity cs = Qt::CaseSensitive) |
99 | { |
100 | QtPrivate::QStringList_replaceInStrings(that: self(), before, after, cs); |
101 | return *self(); |
102 | } |
103 | inline QStringList &replaceInStrings(QStringView before, const QString &after, Qt::CaseSensitivity cs = Qt::CaseSensitive) |
104 | { |
105 | QtPrivate::QStringList_replaceInStrings(that: self(), before, after, cs); |
106 | return *self(); |
107 | } |
108 | using QListSpecialMethodsBase<QString>::contains; |
109 | using QListSpecialMethodsBase<QString>::indexOf; |
110 | using QListSpecialMethodsBase<QString>::lastIndexOf; |
111 | |
112 | inline bool contains(QLatin1StringView str, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept |
113 | { return QtPrivate::QStringList_contains(that: self(), str, cs); } |
114 | inline bool contains(QStringView str, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept |
115 | { return QtPrivate::QStringList_contains(that: self(), str, cs); } |
116 | |
117 | inline bool contains(const QString &str, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept |
118 | { return QtPrivate::QStringList_contains(that: self(), str, cs); } |
119 | qsizetype indexOf(const QString &str, qsizetype from = 0) const noexcept |
120 | { return indexOf(t: QStringView(str), from); } |
121 | qsizetype lastIndexOf(const QString &str, qsizetype from = -1) const noexcept |
122 | { return lastIndexOf(t: QStringView(str), from); } |
123 | |
124 | #if QT_CONFIG(regularexpression) |
125 | inline QStringList filter(const QRegularExpression &re) const |
126 | { return QtPrivate::QStringList_filter(that: self(), re); } |
127 | inline QStringList &replaceInStrings(const QRegularExpression &re, const QString &after) |
128 | { |
129 | QtPrivate::QStringList_replaceInStrings(that: self(), rx: re, after); |
130 | return *self(); |
131 | } |
132 | inline qsizetype indexOf(const QRegularExpression &re, qsizetype from = 0) const |
133 | { return QtPrivate::QStringList_indexOf(that: self(), re, from); } |
134 | inline qsizetype lastIndexOf(const QRegularExpression &re, qsizetype from = -1) const |
135 | { return QtPrivate::QStringList_lastIndexOf(that: self(), re, from); } |
136 | #endif // QT_CONFIG(regularexpression) |
137 | }; |
138 | |
139 | QT_END_NAMESPACE |
140 | |
141 | #endif // QSTRINGLIST_H |
142 | |