diff --git a/autotests/kservicetest.cpp b/autotests/kservicetest.cpp --- a/autotests/kservicetest.cpp +++ b/autotests/kservicetest.cpp @@ -29,8 +29,7 @@ #include #include #include -#include <../src/services/kserviceutil_p.h> -#include <../src/services/ktraderparsetree_p.h> +#include <../src/services/kserviceutil_p.h> // for KServiceUtilPrivate #include #include @@ -601,7 +600,7 @@ void KServiceTest::testSubseqConstraints() { auto test = [](const char* pattern, const char* text, bool sensitive) { - return KTraderParse::ParseTreeSubsequenceMATCH::isSubseq( + return KService::isSubseq( QString(pattern), QString(text), sensitive? Qt::CaseSensitive : Qt::CaseInsensitive diff --git a/src/services/kservice.h b/src/services/kservice.h --- a/src/services/kservice.h +++ b/src/services/kservice.h @@ -568,6 +568,13 @@ */ operator KPluginName() const; + /** + * Returns true if @p pattern matches a subsequence of the string @p text. + * For instance the pattern "libremath" matches the text "LibreOffice Math", assuming + * @p cs is Qt::CaseInsensitive. + */ + static bool isSubseq(const QString& pattern, const QString& text, Qt::CaseSensitivity cs = Qt::CaseSensitive); + private: friend class KBuildServiceFactory; diff --git a/src/services/kservice.cpp b/src/services/kservice.cpp --- a/src/services/kservice.cpp +++ b/src/services/kservice.cpp @@ -857,6 +857,22 @@ return QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QLatin1String("/applications/") + result; } +bool KService::isSubseq(const QString &pattern, const QString &text, Qt::CaseSensitivity cs) +{ + if (pattern.isEmpty()) { + return false; + } + const bool chk_case = cs == Qt::CaseSensitive; + + QString::const_iterator i = text.constBegin(), j = pattern.constBegin(); + for (; i != text.constEnd() && j != pattern.constEnd(); ++i) { + if ((chk_case && *i == *j) || (!chk_case && i->toLower() == j->toLower())) { + ++j; + } + } + return j == pattern.constEnd(); +} + bool KService::isApplication() const { Q_D(const KService); diff --git a/src/services/ktraderparsetree.cpp b/src/services/ktraderparsetree.cpp --- a/src/services/ktraderparsetree.cpp +++ b/src/services/ktraderparsetree.cpp @@ -438,27 +438,10 @@ if (c1.type != ParseContext::T_STRING || c2.type != ParseContext::T_STRING) { return false; } - _context->b = ParseTreeSubsequenceMATCH::isSubseq(c1.str, c2.str, m_cs); + _context->b = KService::isSubseq(c1.str, c2.str, m_cs); return true; } -bool ParseTreeSubsequenceMATCH:: -isSubseq(const QString& pattern, const QString& text, Qt::CaseSensitivity cs) -{ - if (pattern.isEmpty()) { - return false; - } - bool chk_case = cs == Qt::CaseSensitive; - - QString::const_iterator i = text.constBegin(), j = pattern.constBegin(); - for (; i != text.constEnd() && j != pattern.constEnd(); ++i) { - if ((chk_case && *i == *j) || (!chk_case && i->toLower() == j->toLower())) { - ++j; - } - } - return j == pattern.constEnd(); -} - bool ParseTreeIN::eval(ParseContext *_context) const { _context->type = ParseContext::T_BOOL; diff --git a/src/services/ktraderparsetree_p.h b/src/services/ktraderparsetree_p.h --- a/src/services/ktraderparsetree_p.h +++ b/src/services/ktraderparsetree_p.h @@ -248,8 +248,6 @@ bool eval(ParseContext *_context) const override; - static bool isSubseq(const QString& pattern, const QString& text, Qt::CaseSensitivity cs); - protected: ParseTreeBase::Ptr m_pLeft; ParseTreeBase::Ptr m_pRight;