Editor: Qt6 compile fixes for KSyntaxHighlighter

Change-Id: I5f00cb8e948762da8f855059dcf90b7857d57482
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
David Schulz
2020-11-04 13:43:46 +01:00
parent d4c4f8c007
commit 9129dffe55
17 changed files with 39 additions and 36 deletions

View File

@@ -10,10 +10,6 @@
#include "definition.h"
#include "theme.h"
QT_BEGIN_NAMESPACE
class QStringList;
QT_END_NAMESPACE
namespace KSyntaxHighlighting
{
class ContextSwitch;

View File

@@ -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;

View File

@@ -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:

View File

@@ -626,7 +626,8 @@ void DefinitionData::loadGeneral(QXmlStreamReader &reader)
wordDelimiters.remove(reader.attributes().value(QLatin1String("weakDeliminator")));
// adapt WordWrapDelimiters
QStringRef wordWrapDeliminatorAttr = reader.attributes().value(QLatin1String("wordWrapDeliminator"));
auto wordWrapDeliminatorAttr = reader.attributes().value(
QLatin1String("wordWrapDeliminator"));
if (wordWrapDeliminatorAttr.isEmpty())
wordWrapDelimiters = wordDelimiters;
else {
@@ -764,15 +765,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;

View File

@@ -17,8 +17,6 @@
QT_BEGIN_NAMESPACE
class QChar;
class QString;
class QStringList;
template<typename T> class QVector;
QT_END_NAMESPACE
namespace KSyntaxHighlighting

View File

@@ -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();

View File

@@ -166,7 +166,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);

View File

@@ -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;
@@ -236,7 +236,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();
}

View File

@@ -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)
@@ -122,7 +130,11 @@ void HtmlHighlighter::highlightData(QIODevice *dev, const QString &title)
*d->out << "\"><pre>\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);

View File

@@ -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

View File

@@ -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);

View File

@@ -11,10 +11,10 @@
#include <memory>
#include <qglobal.h>
#include <qvector.h>
QT_BEGIN_NAMESPACE
class QString;
template<typename T> class QVector;
class QPalette;
QT_END_NAMESPACE

View File

@@ -182,7 +182,7 @@ void Rule::loadAdditionalWordDelimiters(QXmlStreamReader &reader)
m_weakDeliminator = reader.attributes().value(QLatin1String("weakDeliminator")).toString();
}
Rule::Ptr Rule::create(const QStringRef &name)
Rule::Ptr Rule::create(const QStringView &name)
{
if (name == QLatin1String("AnyChar"))
return std::make_shared<AnyChar>();
@@ -460,7 +460,7 @@ bool IncludeRules::includeAttribute() const
bool IncludeRules::doLoad(QXmlStreamReader &reader)
{
const auto s = reader.attributes().value(QLatin1String("context"));
const auto split = s.split(QLatin1String("##"), Qt::KeepEmptyParts);
const auto split = s.split(QString::fromLatin1("##"), Qt::KeepEmptyParts);
if (split.isEmpty())
return false;
m_contextName = split.at(0).toString();
@@ -531,10 +531,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;
}
@@ -689,7 +690,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;
}
@@ -714,7 +716,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)))

View File

@@ -89,7 +89,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);

View File

@@ -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;
}

View File

@@ -13,10 +13,6 @@
#include "definitionref_p.h"
QT_BEGIN_NAMESPACE
class QStringList;
QT_END_NAMESPACE
namespace KSyntaxHighlighting
{
class Context;

View File

@@ -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;
}