| 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 | Q_CORE_EXPORT QStringList QStringList_filter(const QStringList &that, QLatin1StringView needle, |
| 34 | Qt::CaseSensitivity cs); |
| 35 | Q_CORE_EXPORT QStringList QStringList_filter(const QStringList &that, |
| 36 | const QStringMatcher &matcher); |
| 37 | |
| 38 | bool Q_CORE_EXPORT QStringList_contains(const QStringList *that, QStringView str, Qt::CaseSensitivity cs); |
| 39 | bool Q_CORE_EXPORT QStringList_contains(const QStringList *that, QLatin1StringView str, Qt::CaseSensitivity cs); |
| 40 | void Q_CORE_EXPORT QStringList_replaceInStrings(QStringList *that, QStringView before, QStringView after, |
| 41 | Qt::CaseSensitivity cs); |
| 42 | |
| 43 | qsizetype Q_CORE_EXPORT QStringList_indexOf(const QStringList &that, QStringView str, |
| 44 | qsizetype from, Qt::CaseSensitivity cs); |
| 45 | qsizetype Q_CORE_EXPORT QStringList_indexOf(const QStringList &that, QLatin1StringView str, |
| 46 | qsizetype from, Qt::CaseSensitivity cs); |
| 47 | |
| 48 | Q_CORE_EXPORT qsizetype QStringList_lastIndexOf(const QStringList &that, QStringView str, |
| 49 | qsizetype from, Qt::CaseSensitivity cs); |
| 50 | Q_CORE_EXPORT qsizetype QStringList_lastIndexOf(const QStringList &that, QLatin1StringView str, |
| 51 | qsizetype from, Qt::CaseSensitivity cs); |
| 52 | |
| 53 | #if QT_CONFIG(regularexpression) |
| 54 | void Q_CORE_EXPORT QStringList_replaceInStrings(QStringList *that, const QRegularExpression &rx, const QString &after); |
| 55 | QStringList Q_CORE_EXPORT QStringList_filter(const QStringList *that, const QRegularExpression &re); |
| 56 | qsizetype Q_CORE_EXPORT QStringList_indexOf(const QStringList *that, const QRegularExpression &re, qsizetype from); |
| 57 | qsizetype Q_CORE_EXPORT QStringList_lastIndexOf(const QStringList *that, const QRegularExpression &re, qsizetype from); |
| 58 | #endif // QT_CONFIG(regularexpression) |
| 59 | } |
| 60 | |
| 61 | #ifdef Q_QDOC |
| 62 | class QStringList : public QList<QString> |
| 63 | #else |
| 64 | template <> struct QListSpecialMethods<QString> : QListSpecialMethodsBase<QString> |
| 65 | #endif |
| 66 | { |
| 67 | #ifdef Q_QDOC |
| 68 | public: |
| 69 | using QList<QString>::QList; |
| 70 | QStringList(const QString &str); |
| 71 | QStringList(const QList<QString> &other); |
| 72 | QStringList(QList<QString> &&other); |
| 73 | |
| 74 | QStringList &operator=(const QList<QString> &other); |
| 75 | QStringList &operator=(QList<QString> &&other); |
| 76 | QStringList operator+(const QStringList &other) const; |
| 77 | QStringList &operator<<(const QString &str); |
| 78 | QStringList &operator<<(const QStringList &other); |
| 79 | QStringList &operator<<(const QList<QString> &other); |
| 80 | private: |
| 81 | #endif |
| 82 | |
| 83 | public: |
| 84 | inline void sort(Qt::CaseSensitivity cs = Qt::CaseSensitive) |
| 85 | { QtPrivate::QStringList_sort(that: self(), cs); } |
| 86 | inline qsizetype removeDuplicates() |
| 87 | { return QtPrivate::QStringList_removeDuplicates(that: self()); } |
| 88 | |
| 89 | inline QString join(QStringView sep) const |
| 90 | { return QtPrivate::QStringList_join(that: self(), sep); } |
| 91 | inline QString join(QLatin1StringView sep) const |
| 92 | { return QtPrivate::QStringList_join(list: *self(), sep); } |
| 93 | inline QString join(QChar sep) const |
| 94 | { return QtPrivate::QStringList_join(that: self(), sep: &sep, seplen: 1); } |
| 95 | |
| 96 | QStringList filter(const QStringMatcher &matcher) const |
| 97 | { return QtPrivate::QStringList_filter(that: *self(), matcher); } |
| 98 | QStringList filter(QLatin1StringView needle, Qt::CaseSensitivity cs = Qt::CaseSensitive) const |
| 99 | { return QtPrivate::QStringList_filter(that: *self(), needle, cs); } |
| 100 | inline QStringList filter(QStringView str, Qt::CaseSensitivity cs = Qt::CaseSensitive) const |
| 101 | { return QtPrivate::QStringList_filter(that: self(), str, cs); } |
| 102 | inline QStringList &replaceInStrings(QStringView before, QStringView after, Qt::CaseSensitivity cs = Qt::CaseSensitive) |
| 103 | { |
| 104 | QtPrivate::QStringList_replaceInStrings(that: self(), before, after, cs); |
| 105 | return *self(); |
| 106 | } |
| 107 | |
| 108 | inline QString join(const QString &sep) const |
| 109 | { return QtPrivate::QStringList_join(that: self(), sep: sep.constData(), seplen: sep.size()); } |
| 110 | inline QStringList filter(const QString &str, Qt::CaseSensitivity cs = Qt::CaseSensitive) const |
| 111 | { return QtPrivate::QStringList_filter(that: self(), str, cs); } |
| 112 | inline QStringList &replaceInStrings(const QString &before, const QString &after, Qt::CaseSensitivity cs = Qt::CaseSensitive) |
| 113 | { |
| 114 | QtPrivate::QStringList_replaceInStrings(that: self(), before, after, cs); |
| 115 | return *self(); |
| 116 | } |
| 117 | inline QStringList &replaceInStrings(const QString &before, QStringView after, Qt::CaseSensitivity cs = Qt::CaseSensitive) |
| 118 | { |
| 119 | QtPrivate::QStringList_replaceInStrings(that: self(), before, after, cs); |
| 120 | return *self(); |
| 121 | } |
| 122 | inline QStringList &replaceInStrings(QStringView before, const QString &after, Qt::CaseSensitivity cs = Qt::CaseSensitive) |
| 123 | { |
| 124 | QtPrivate::QStringList_replaceInStrings(that: self(), before, after, cs); |
| 125 | return *self(); |
| 126 | } |
| 127 | using QListSpecialMethodsBase<QString>::contains; |
| 128 | using QListSpecialMethodsBase<QString>::indexOf; |
| 129 | using QListSpecialMethodsBase<QString>::lastIndexOf; |
| 130 | |
| 131 | inline bool contains(QLatin1StringView str, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept |
| 132 | { return QtPrivate::QStringList_contains(that: self(), str, cs); } |
| 133 | inline bool contains(QStringView str, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept |
| 134 | { return QtPrivate::QStringList_contains(that: self(), str, cs); } |
| 135 | |
| 136 | inline bool contains(const QString &str, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept |
| 137 | { return QtPrivate::QStringList_contains(that: self(), str, cs); } |
| 138 | |
| 139 | qsizetype indexOf(const QString &str, qsizetype from = 0, |
| 140 | Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept |
| 141 | { return indexOf(needle: QStringView(str), from, cs); } |
| 142 | qsizetype indexOf(QStringView needle, qsizetype from = 0, |
| 143 | Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept |
| 144 | { return QtPrivate::QStringList_indexOf(that: *self(), str: needle, from, cs); } |
| 145 | qsizetype indexOf(QLatin1StringView needle, qsizetype from = 0, |
| 146 | Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept |
| 147 | { return QtPrivate::QStringList_indexOf(that: *self(), str: needle, from, cs); } |
| 148 | |
| 149 | qsizetype lastIndexOf(const QString &str, qsizetype from = -1, |
| 150 | Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept |
| 151 | { return lastIndexOf(str: QStringView(str), from, cs); } |
| 152 | qsizetype lastIndexOf(QStringView str, qsizetype from = -1, |
| 153 | Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept |
| 154 | { return QtPrivate::QStringList_lastIndexOf(that: *self(), str, from, cs); } |
| 155 | qsizetype lastIndexOf(QLatin1StringView needle, qsizetype from = -1, |
| 156 | Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept |
| 157 | { return QtPrivate::QStringList_lastIndexOf(that: *self(), str: needle, from, cs); } |
| 158 | |
| 159 | #if QT_CONFIG(regularexpression) |
| 160 | inline QStringList filter(const QRegularExpression &re) const |
| 161 | { return QtPrivate::QStringList_filter(that: self(), re); } |
| 162 | inline QStringList &replaceInStrings(const QRegularExpression &re, const QString &after) |
| 163 | { |
| 164 | QtPrivate::QStringList_replaceInStrings(that: self(), rx: re, after); |
| 165 | return *self(); |
| 166 | } |
| 167 | inline qsizetype indexOf(const QRegularExpression &re, qsizetype from = 0) const |
| 168 | { return QtPrivate::QStringList_indexOf(that: self(), re, from); } |
| 169 | inline qsizetype lastIndexOf(const QRegularExpression &re, qsizetype from = -1) const |
| 170 | { return QtPrivate::QStringList_lastIndexOf(that: self(), re, from); } |
| 171 | #endif // QT_CONFIG(regularexpression) |
| 172 | }; |
| 173 | |
| 174 | QT_END_NAMESPACE |
| 175 | |
| 176 | #endif // QSTRINGLIST_H |
| 177 | |