From 6b9cad8b05c2a71880fa587c0dda0a8b16797e96 Mon Sep 17 00:00:00 2001 From: Eike Ziller Date: Mon, 7 Sep 2020 09:56:49 +0200 Subject: KSyntaxHighlighting: Use QStringView instead of QStringRef QStringRef will be removed for Qt6, or moved into a Qt 5 compatibility library, but the QString API will be removed. Switch to QStringView instead. Task-number: QTCREATORBUG-24098 Change-Id: Ia3cab3de24ba36b5db64e1eff18d92e66ccd3d94 Reviewed-by: hjk --- .../syntax-highlighting/src/lib/contextswitch.cpp | 2 +- .../syntax-highlighting/src/lib/contextswitch_p.h | 2 +- .../syntax-highlighting/src/lib/definition.cpp | 6 +++--- .../syntax-highlighting/src/lib/definition_p.h | 2 +- .../3rdparty/syntax-highlighting/src/lib/format.cpp | 4 ++-- .../syntax-highlighting/src/lib/keywordlist.cpp | 17 +++++++++++++---- .../syntax-highlighting/src/lib/keywordlist_p.h | 11 ++++------- .../3rdparty/syntax-highlighting/src/lib/rule.cpp | 19 ++++++++++--------- .../3rdparty/syntax-highlighting/src/lib/rule_p.h | 4 ++-- src/libs/3rdparty/syntax-highlighting/src/lib/xml_p.h | 2 +- 10 files changed, 38 insertions(+), 31 deletions(-) (limited to 'src/libs/3rdparty/syntax-highlighting/src') diff --git a/src/libs/3rdparty/syntax-highlighting/src/lib/contextswitch.cpp b/src/libs/3rdparty/syntax-highlighting/src/lib/contextswitch.cpp index 2536792154..8d353b9174 100644 --- a/src/libs/3rdparty/syntax-highlighting/src/lib/contextswitch.cpp +++ b/src/libs/3rdparty/syntax-highlighting/src/lib/contextswitch.cpp @@ -44,7 +44,7 @@ Context *ContextSwitch::context() const return m_context; } -void ContextSwitch::parse(const QStringRef &contextInstr) +void ContextSwitch::parse(const QStringView &contextInstr) { if (contextInstr.isEmpty() || contextInstr == QLatin1String("#stay")) return; diff --git a/src/libs/3rdparty/syntax-highlighting/src/lib/contextswitch_p.h b/src/libs/3rdparty/syntax-highlighting/src/lib/contextswitch_p.h index 79fb86f044..46579fcb61 100644 --- a/src/libs/3rdparty/syntax-highlighting/src/lib/contextswitch_p.h +++ b/src/libs/3rdparty/syntax-highlighting/src/lib/contextswitch_p.h @@ -42,7 +42,7 @@ public: int popCount() const; Context *context() const; - void parse(const QStringRef &contextInstr); + void parse(const QStringView &contextInstr); void resolve(const Definition &def); private: diff --git a/src/libs/3rdparty/syntax-highlighting/src/lib/definition.cpp b/src/libs/3rdparty/syntax-highlighting/src/lib/definition.cpp index 913a74da08..c0fa860dc9 100644 --- a/src/libs/3rdparty/syntax-highlighting/src/lib/definition.cpp +++ b/src/libs/3rdparty/syntax-highlighting/src/lib/definition.cpp @@ -779,15 +779,15 @@ void DefinitionData::loadSpellchecking(QXmlStreamReader &reader) } } -bool DefinitionData::checkKateVersion(const QStringRef &verStr) +bool DefinitionData::checkKateVersion(const QStringView &verStr) { const auto idx = verStr.indexOf(QLatin1Char('.')); if (idx <= 0) { qCWarning(Log) << "Skipping" << fileName << "due to having no valid kateversion attribute:" << verStr; return false; } - const auto major = verStr.left(idx).toInt(); - const auto minor = verStr.mid(idx + 1).toInt(); + const auto major = verStr.left(idx).toString().toInt(); + const auto minor = verStr.mid(idx + 1).toString().toInt(); if (major > SyntaxHighlighting_VERSION_MAJOR || (major == SyntaxHighlighting_VERSION_MAJOR && minor > SyntaxHighlighting_VERSION_MINOR)) { qCWarning(Log) << "Skipping" << fileName << "due to being too new, version:" << verStr; diff --git a/src/libs/3rdparty/syntax-highlighting/src/lib/definition_p.h b/src/libs/3rdparty/syntax-highlighting/src/lib/definition_p.h index c654d632c9..9e707908ba 100644 --- a/src/libs/3rdparty/syntax-highlighting/src/lib/definition_p.h +++ b/src/libs/3rdparty/syntax-highlighting/src/lib/definition_p.h @@ -68,7 +68,7 @@ public: void loadComments(QXmlStreamReader &reader); void loadFoldingIgnoreList(QXmlStreamReader &reader); void loadSpellchecking(QXmlStreamReader &reader); - bool checkKateVersion(const QStringRef &verStr); + bool checkKateVersion(const QStringView &verStr); void resolveIncludeKeywords(); diff --git a/src/libs/3rdparty/syntax-highlighting/src/lib/format.cpp b/src/libs/3rdparty/syntax-highlighting/src/lib/format.cpp index 4c8adbedc6..adc78e2e63 100644 --- a/src/libs/3rdparty/syntax-highlighting/src/lib/format.cpp +++ b/src/libs/3rdparty/syntax-highlighting/src/lib/format.cpp @@ -35,7 +35,7 @@ using namespace KSyntaxHighlighting; -static Theme::TextStyle stringToDefaultFormat(const QStringRef &str) +static Theme::TextStyle stringToDefaultFormat(const QStringView &str) { if (!str.startsWith(QLatin1String("ds"))) return Theme::Normal; @@ -243,7 +243,7 @@ void FormatPrivate::load(QXmlStreamReader &reader) name = reader.attributes().value(QStringLiteral("name")).toString(); defaultStyle = stringToDefaultFormat(reader.attributes().value(QStringLiteral("defStyleNum"))); - QStringRef attribute = reader.attributes().value(QStringLiteral("color")); + QStringView attribute = reader.attributes().value(QStringLiteral("color")); if (!attribute.isEmpty()) { style.textColor = QColor(attribute.toString()).rgba(); } diff --git a/src/libs/3rdparty/syntax-highlighting/src/lib/keywordlist.cpp b/src/libs/3rdparty/syntax-highlighting/src/lib/keywordlist.cpp index 7cbbaecacf..d82408d801 100644 --- a/src/libs/3rdparty/syntax-highlighting/src/lib/keywordlist.cpp +++ b/src/libs/3rdparty/syntax-highlighting/src/lib/keywordlist.cpp @@ -32,7 +32,7 @@ using namespace KSyntaxHighlighting; -bool KeywordList::contains(const QStringRef &str, Qt::CaseSensitivity caseSensitive) const +bool KeywordList::contains(const QStringView &str, Qt::CaseSensitivity caseSensitive) const { /** * get right vector to search in @@ -42,7 +42,12 @@ bool KeywordList::contains(const QStringRef &str, Qt::CaseSensitivity caseSensit /** * search with right predicate */ - return std::binary_search(vectorToSearch.begin(), vectorToSearch.end(), str, [caseSensitive](const QStringRef &a, const QStringRef &b) { return a.compare(b, caseSensitive) < 0; }); + return std::binary_search(vectorToSearch.begin(), + vectorToSearch.end(), + str, + [caseSensitive](const QStringView &a, const QStringView &b) { + return a.compare(b, caseSensitive) < 0; + }); } void KeywordList::load(QXmlStreamReader &reader) @@ -100,13 +105,17 @@ void KeywordList::initLookupForCaseSensitivity(Qt::CaseSensitivity caseSensitive */ vectorToSort.reserve(m_keywords.size()); for (const auto &keyword : qAsConst(m_keywords)) { - vectorToSort.push_back(&keyword); + vectorToSort.emplace_back(keyword); } /** * sort with right predicate */ - std::sort(vectorToSort.begin(), vectorToSort.end(), [caseSensitive](const QStringRef &a, const QStringRef &b) { return a.compare(b, caseSensitive) < 0; }); + std::sort(vectorToSort.begin(), + vectorToSort.end(), + [caseSensitive](const QStringView &a, const QStringView &b) { + return a.compare(b, caseSensitive) < 0; + }); } void KeywordList::resolveIncludeKeywords(DefinitionData &def) diff --git a/src/libs/3rdparty/syntax-highlighting/src/lib/keywordlist_p.h b/src/libs/3rdparty/syntax-highlighting/src/lib/keywordlist_p.h index e21149e909..de39a8731b 100644 --- a/src/libs/3rdparty/syntax-highlighting/src/lib/keywordlist_p.h +++ b/src/libs/3rdparty/syntax-highlighting/src/lib/keywordlist_p.h @@ -68,13 +68,10 @@ public: } /** Checks if @p str is a keyword in this list. */ - bool contains(const QStringRef &str) const - { - return contains(str, m_caseSensitive); - } + bool contains(const QStringView &str) const { return contains(str, m_caseSensitive); } /** Checks if @p str is a keyword in this list, overriding the global case-sensitivity setting. */ - bool contains(const QStringRef &str, Qt::CaseSensitivity caseSensitive) const; + bool contains(const QStringView &str, Qt::CaseSensitivity caseSensitive) const; void load(QXmlStreamReader &reader); void setCaseSensitivity(Qt::CaseSensitivity caseSensitive); @@ -105,12 +102,12 @@ private: /** * case-sensitive sorted string references to m_keywords for lookup */ - std::vector m_keywordsSortedCaseSensitive; + std::vector m_keywordsSortedCaseSensitive; /** * case-insensitive sorted string references to m_keywords for lookup */ - std::vector m_keywordsSortedCaseInsensitive; + std::vector m_keywordsSortedCaseInsensitive; }; } diff --git a/src/libs/3rdparty/syntax-highlighting/src/lib/rule.cpp b/src/libs/3rdparty/syntax-highlighting/src/lib/rule.cpp index 0d7d843c00..cb79a73e67 100644 --- a/src/libs/3rdparty/syntax-highlighting/src/lib/rule.cpp +++ b/src/libs/3rdparty/syntax-highlighting/src/lib/rule.cpp @@ -134,7 +134,7 @@ void Rule::resolveContext() m_context.resolve(m_def.definition()); // cache for DefinitionData::wordDelimiters, is accessed VERY often - m_wordDelimiter = &DefinitionData::get(m_def.definition())->wordDelimiters; + m_wordDelimiter = DefinitionData::get(m_def.definition())->wordDelimiters; } void Rule::resolveAttributeFormat(Context *lookupContext) @@ -156,7 +156,7 @@ bool Rule::doLoad(QXmlStreamReader &reader) return true; } -Rule::Ptr Rule::create(const QStringRef &name) +Rule::Ptr Rule::create(const QStringView &name) { Rule *rule = nullptr; if (name == QLatin1String("AnyChar")) @@ -418,7 +418,7 @@ bool IncludeRules::includeAttribute() const bool IncludeRules::doLoad(QXmlStreamReader &reader) { - const auto s = reader.attributes().value(QLatin1String("context")); + const auto s = reader.attributes().value(QLatin1String("context")).toString(); #if QT_VERSION < QT_VERSION_CHECK(5, 15, 0) const auto split = s.split(QLatin1String("##"), QString::KeepEmptyParts); #else @@ -426,9 +426,9 @@ bool IncludeRules::doLoad(QXmlStreamReader &reader) #endif if (split.isEmpty()) return false; - m_contextName = split.at(0).toString(); + m_contextName = split.at(0); if (split.size() > 1) - m_defName = split.at(1).toString(); + m_defName = split.at(1); m_includeAttribute = Xml::attrToBool(reader.attributes().value(QLatin1String("includeAttrib"))); return !m_contextName.isEmpty() || !m_defName.isEmpty(); @@ -486,10 +486,11 @@ MatchResult KeywordListRule::doMatch(const QString &text, int offset, const QStr return offset; if (m_hasCaseSensitivityOverride) { - if (m_keywordList->contains(text.midRef(offset, newOffset - offset), m_caseSensitivityOverride)) + if (m_keywordList->contains(QStringView(text).mid(offset, newOffset - offset), + m_caseSensitivityOverride)) return newOffset; } else { - if (m_keywordList->contains(text.midRef(offset, newOffset - offset))) + if (m_keywordList->contains(QStringView(text).mid(offset, newOffset - offset))) return newOffset; } @@ -613,7 +614,7 @@ MatchResult StringDetect::doMatch(const QString &text, int offset, const QString */ const auto &pattern = m_dynamic ? replaceCaptures(m_string, captures, false) : m_string; - if (text.midRef(offset, pattern.size()).compare(pattern, m_caseSensitivity) == 0) + if (QStringView(text).mid(offset, pattern.size()).compare(pattern, m_caseSensitivity) == 0) return offset + pattern.size(); return offset; } @@ -637,7 +638,7 @@ MatchResult WordDetect::doMatch(const QString &text, int offset, const QStringLi if (offset > 0 && !isWordDelimiter(text.at(offset - 1)) && !isWordDelimiter(text.at(offset))) return offset; - if (text.midRef(offset, m_word.size()).compare(m_word, m_caseSensitivity) != 0) + if (QStringView(text).mid(offset, m_word.size()).compare(m_word, m_caseSensitivity) != 0) return offset; if (text.size() == offset + m_word.size() || isWordDelimiter(text.at(offset + m_word.size())) || isWordDelimiter(text.at(offset + m_word.size() - 1))) diff --git a/src/libs/3rdparty/syntax-highlighting/src/lib/rule_p.h b/src/libs/3rdparty/syntax-highlighting/src/lib/rule_p.h index c30ea29a54..484687bc0a 100644 --- a/src/libs/3rdparty/syntax-highlighting/src/lib/rule_p.h +++ b/src/libs/3rdparty/syntax-highlighting/src/lib/rule_p.h @@ -100,7 +100,7 @@ public: virtual MatchResult doMatch(const QString &text, int offset, const QStringList &captures) const = 0; - static Rule::Ptr create(const QStringRef &name); + static Rule::Ptr create(const QStringView &name); protected: virtual bool doLoad(QXmlStreamReader &reader); @@ -121,7 +121,7 @@ private: bool m_lookAhead = false; // cache for DefinitionData::wordDelimiters, is accessed VERY often - QStringRef m_wordDelimiter; + QStringView m_wordDelimiter; protected: bool m_dynamic = false; diff --git a/src/libs/3rdparty/syntax-highlighting/src/lib/xml_p.h b/src/libs/3rdparty/syntax-highlighting/src/lib/xml_p.h index 6d73edfb52..2e785a200f 100644 --- a/src/libs/3rdparty/syntax-highlighting/src/lib/xml_p.h +++ b/src/libs/3rdparty/syntax-highlighting/src/lib/xml_p.h @@ -32,7 +32,7 @@ namespace KSyntaxHighlighting namespace Xml { /** Parse a xs:boolean attribute. */ -inline bool attrToBool(const QStringRef &str) +inline bool attrToBool(const QStringView &str) { return str == QLatin1String("1") || str.compare(QLatin1String("true"), Qt::CaseInsensitive) == 0; } -- cgit v1.2.3