From c2b6d4567036d7be3946345d3b9e3b154eb2ba0f Mon Sep 17 00:00:00 2001 From: David Schulz Date: Wed, 4 Nov 2020 13:43:46 +0100 Subject: Editor: Qt6 compile fixes for KSyntaxHighlighter Change-Id: I65487a3ccb93efeec3be3971f876d317b5a6bfc6 Reviewed-by: Eike Ziller --- .../syntax-highlighting/src/lib/abstracthighlighter_p.h | 4 ---- .../3rdparty/syntax-highlighting/src/lib/contextswitch.cpp | 2 +- .../3rdparty/syntax-highlighting/src/lib/contextswitch_p.h | 2 +- .../3rdparty/syntax-highlighting/src/lib/definition.cpp | 9 +++++---- src/libs/3rdparty/syntax-highlighting/src/lib/definition.h | 2 -- .../3rdparty/syntax-highlighting/src/lib/definition_p.h | 2 +- .../syntax-highlighting/src/lib/definitiondownloader.cpp | 3 ++- src/libs/3rdparty/syntax-highlighting/src/lib/format.cpp | 4 ++-- .../syntax-highlighting/src/lib/htmlhighlighter.cpp | 12 ++++++++++++ .../3rdparty/syntax-highlighting/src/lib/keywordlist.cpp | 2 +- .../3rdparty/syntax-highlighting/src/lib/keywordlist_p.h | 7 ++----- src/libs/3rdparty/syntax-highlighting/src/lib/repository.h | 2 +- src/libs/3rdparty/syntax-highlighting/src/lib/rule.cpp | 14 ++++++++------ src/libs/3rdparty/syntax-highlighting/src/lib/rule_p.h | 2 +- src/libs/3rdparty/syntax-highlighting/src/lib/state.cpp | 2 +- src/libs/3rdparty/syntax-highlighting/src/lib/state_p.h | 4 ---- src/libs/3rdparty/syntax-highlighting/src/lib/xml_p.h | 2 +- 17 files changed, 39 insertions(+), 36 deletions(-) (limited to 'src/libs/3rdparty/syntax-highlighting/src') diff --git a/src/libs/3rdparty/syntax-highlighting/src/lib/abstracthighlighter_p.h b/src/libs/3rdparty/syntax-highlighting/src/lib/abstracthighlighter_p.h index 11332fdcfd3..6128beccfa0 100644 --- a/src/libs/3rdparty/syntax-highlighting/src/lib/abstracthighlighter_p.h +++ b/src/libs/3rdparty/syntax-highlighting/src/lib/abstracthighlighter_p.h @@ -10,10 +10,6 @@ #include "definition.h" #include "theme.h" -QT_BEGIN_NAMESPACE -class QStringList; -QT_END_NAMESPACE - namespace KSyntaxHighlighting { class ContextSwitch; diff --git a/src/libs/3rdparty/syntax-highlighting/src/lib/contextswitch.cpp b/src/libs/3rdparty/syntax-highlighting/src/lib/contextswitch.cpp index 14c50396d84..1ec47591038 100644 --- a/src/libs/3rdparty/syntax-highlighting/src/lib/contextswitch.cpp +++ b/src/libs/3rdparty/syntax-highlighting/src/lib/contextswitch.cpp @@ -27,7 +27,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 c84948d9f7b..e861cbaded4 100644 --- a/src/libs/3rdparty/syntax-highlighting/src/lib/contextswitch_p.h +++ b/src/libs/3rdparty/syntax-highlighting/src/lib/contextswitch_p.h @@ -25,7 +25,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 fd1debe0f2c..0b6975d7756 100644 --- a/src/libs/3rdparty/syntax-highlighting/src/lib/definition.cpp +++ b/src/libs/3rdparty/syntax-highlighting/src/lib/definition.cpp @@ -636,7 +636,8 @@ void DefinitionData::loadGeneral(QXmlStreamReader &reader) wordDelimiters.remove(c); // adapt WordWrapDelimiters - QStringRef wordWrapDeliminatorAttr = reader.attributes().value(QLatin1String("wordWrapDeliminator")); + auto wordWrapDeliminatorAttr = reader.attributes().value( + QLatin1String("wordWrapDeliminator")); if (wordWrapDeliminatorAttr.isEmpty()) wordWrapDelimiters = wordDelimiters; else { @@ -775,15 +776,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.h b/src/libs/3rdparty/syntax-highlighting/src/lib/definition.h index 0cc2df70d02..8226fbdd24f 100644 --- a/src/libs/3rdparty/syntax-highlighting/src/lib/definition.h +++ b/src/libs/3rdparty/syntax-highlighting/src/lib/definition.h @@ -17,8 +17,6 @@ QT_BEGIN_NAMESPACE class QChar; class QString; -class QStringList; -template class QVector; QT_END_NAMESPACE namespace KSyntaxHighlighting 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 c334e31ac0d..274f7640b51 100644 --- a/src/libs/3rdparty/syntax-highlighting/src/lib/definition_p.h +++ b/src/libs/3rdparty/syntax-highlighting/src/lib/definition_p.h @@ -53,7 +53,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/definitiondownloader.cpp b/src/libs/3rdparty/syntax-highlighting/src/lib/definitiondownloader.cpp index 9ec6e366b00..35bb29f82f1 100644 --- a/src/libs/3rdparty/syntax-highlighting/src/lib/definitiondownloader.cpp +++ b/src/libs/3rdparty/syntax-highlighting/src/lib/definitiondownloader.cpp @@ -163,7 +163,8 @@ void DefinitionDownloader::start() { const QString url = QLatin1String("https://www.kate-editor.org/syntax/update-") + QString::number(SyntaxHighlighting_VERSION_MAJOR) + QLatin1Char('.') + QString::number(SyntaxHighlighting_VERSION_MINOR) + QLatin1String(".xml"); auto req = QNetworkRequest(QUrl(url)); - req.setAttribute(QNetworkRequest::FollowRedirectsAttribute, true); + req.setAttribute(QNetworkRequest::RedirectPolicyAttribute, + QNetworkRequest::NoLessSafeRedirectPolicy); auto reply = d->nam->get(req); QObject::connect(reply, &QNetworkReply::finished, this, [=]() { d->definitionListDownloadFinished(reply); }); } diff --git a/src/libs/3rdparty/syntax-highlighting/src/lib/format.cpp b/src/libs/3rdparty/syntax-highlighting/src/lib/format.cpp index b48f0e7d5c8..716ff197af2 100644 --- a/src/libs/3rdparty/syntax-highlighting/src/lib/format.cpp +++ b/src/libs/3rdparty/syntax-highlighting/src/lib/format.cpp @@ -19,7 +19,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; @@ -231,7 +231,7 @@ void FormatPrivate::load(QXmlStreamReader &reader) name = reader.attributes().value(QLatin1String("name")).toString(); defaultStyle = stringToDefaultFormat(reader.attributes().value(QLatin1String("defStyleNum"))); - QStringRef attribute = reader.attributes().value(QLatin1String("color")); + QStringView attribute = reader.attributes().value(QLatin1String("color")); if (!attribute.isEmpty()) { style.textColor = QColor(attribute.toString()).rgba(); } diff --git a/src/libs/3rdparty/syntax-highlighting/src/lib/htmlhighlighter.cpp b/src/libs/3rdparty/syntax-highlighting/src/lib/htmlhighlighter.cpp index 7594d33d231..a95888f40fc 100644 --- a/src/libs/3rdparty/syntax-highlighting/src/lib/htmlhighlighter.cpp +++ b/src/libs/3rdparty/syntax-highlighting/src/lib/htmlhighlighter.cpp @@ -44,13 +44,21 @@ void HtmlHighlighter::setOutputFile(const QString &fileName) return; } d->out.reset(new QTextStream(d->file.get())); +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + d->out->setEncoding(QStringConverter::Utf8); +#else d->out->setCodec("UTF-8"); +#endif } void HtmlHighlighter::setOutputFile(FILE *fileHandle) { d->out.reset(new QTextStream(fileHandle, QIODevice::WriteOnly)); +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + d->out->setEncoding(QStringConverter::Utf8); +#else d->out->setCodec("UTF-8"); +#endif } void HtmlHighlighter::highlightFile(const QString &fileName, const QString &title) @@ -94,7 +102,11 @@ void HtmlHighlighter::highlightData(QIODevice *dev, const QString &title) *d->out << "\">
\n";
 
     QTextStream in(dev);
+#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
+    in.setEncoding(QStringConverter::Utf8);
+#else
     in.setCodec("UTF-8");
+#endif
     while (!in.atEnd()) {
         d->currentLine = in.readLine();
         state = highlightLine(d->currentLine, state);
diff --git a/src/libs/3rdparty/syntax-highlighting/src/lib/keywordlist.cpp b/src/libs/3rdparty/syntax-highlighting/src/lib/keywordlist.cpp
index 8a335c4cc44..b599ce29a18 100644
--- a/src/libs/3rdparty/syntax-highlighting/src/lib/keywordlist.cpp
+++ b/src/libs/3rdparty/syntax-highlighting/src/lib/keywordlist.cpp
@@ -16,7 +16,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
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 bf067cc3cfc..68b1ec6290e 100644
--- a/src/libs/3rdparty/syntax-highlighting/src/lib/keywordlist_p.h
+++ b/src/libs/3rdparty/syntax-highlighting/src/lib/keywordlist_p.h
@@ -53,13 +53,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);
diff --git a/src/libs/3rdparty/syntax-highlighting/src/lib/repository.h b/src/libs/3rdparty/syntax-highlighting/src/lib/repository.h
index d24aa927030..9da44746852 100644
--- a/src/libs/3rdparty/syntax-highlighting/src/lib/repository.h
+++ b/src/libs/3rdparty/syntax-highlighting/src/lib/repository.h
@@ -11,10 +11,10 @@
 
 #include 
 #include 
+#include 
 
 QT_BEGIN_NAMESPACE
 class QString;
-template class QVector;
 QT_END_NAMESPACE
 
 /**
diff --git a/src/libs/3rdparty/syntax-highlighting/src/lib/rule.cpp b/src/libs/3rdparty/syntax-highlighting/src/lib/rule.cpp
index c5cf1919a76..22f59e02114 100644
--- a/src/libs/3rdparty/syntax-highlighting/src/lib/rule.cpp
+++ b/src/libs/3rdparty/syntax-highlighting/src/lib/rule.cpp
@@ -151,7 +151,7 @@ bool Rule::doLoad(QXmlStreamReader &reader)
     return true;
 }
 
-Rule::Ptr Rule::create(const QStringRef &name)
+Rule::Ptr Rule::create(const QStringView &name)
 {
     if (name == QLatin1String("AnyChar"))
         return std::make_shared();
@@ -414,7 +414,7 @@ bool IncludeRules::doLoad(QXmlStreamReader &reader)
 #if QT_VERSION < QT_VERSION_CHECK(5, 15, 0)
     const auto split = s.split(QLatin1String("##"), QString::KeepEmptyParts);
 #else
-    const auto split = s.split(QLatin1String("##"), Qt::KeepEmptyParts);
+    const auto split = s.split(QString::fromLatin1("##"), Qt::KeepEmptyParts);
 #endif
     if (split.isEmpty())
         return false;
@@ -478,10 +478,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;
     }
 
@@ -605,7 +606,8 @@ 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 (offset + pattern.size() <= text.size()
+        && QStringView(text).mid(offset, pattern.size()).compare(pattern, m_caseSensitivity) == 0)
         return offset + pattern.size();
     return offset;
 }
@@ -629,7 +631,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 288f66246e9..788aecdad3f 100644
--- a/src/libs/3rdparty/syntax-highlighting/src/lib/rule_p.h
+++ b/src/libs/3rdparty/syntax-highlighting/src/lib/rule_p.h
@@ -86,7 +86,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);
diff --git a/src/libs/3rdparty/syntax-highlighting/src/lib/state.cpp b/src/libs/3rdparty/syntax-highlighting/src/lib/state.cpp
index ea5bd36e4f4..f9b4f4b4ab0 100644
--- a/src/libs/3rdparty/syntax-highlighting/src/lib/state.cpp
+++ b/src/libs/3rdparty/syntax-highlighting/src/lib/state.cpp
@@ -56,7 +56,7 @@ bool StateData::pop(int popCount)
     // keep the initial context alive in any case
     Q_ASSERT(!isEmpty());
     const bool initialContextSurvived = m_contextStack.size() > popCount;
-    m_contextStack.resize(std::max(1, m_contextStack.size() - popCount));
+    m_contextStack.resize(std::max(1, int(m_contextStack.size()) - popCount));
     return initialContextSurvived;
 }
 
diff --git a/src/libs/3rdparty/syntax-highlighting/src/lib/state_p.h b/src/libs/3rdparty/syntax-highlighting/src/lib/state_p.h
index 80bf8f4b022..d76f84c93bb 100644
--- a/src/libs/3rdparty/syntax-highlighting/src/lib/state_p.h
+++ b/src/libs/3rdparty/syntax-highlighting/src/lib/state_p.h
@@ -13,10 +13,6 @@
 
 #include "definitionref_p.h"
 
-QT_BEGIN_NAMESPACE
-class QStringList;
-QT_END_NAMESPACE
-
 namespace KSyntaxHighlighting
 {
 class Context;
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 65f46a6abc2..018269c4855 100644
--- a/src/libs/3rdparty/syntax-highlighting/src/lib/xml_p.h
+++ b/src/libs/3rdparty/syntax-highlighting/src/lib/xml_p.h
@@ -15,7 +15,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