forked from qt-creator/qt-creator
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 <hjk@qt.io>
This commit is contained in:
@@ -44,7 +44,7 @@ Context *ContextSwitch::context() const
|
|||||||
return m_context;
|
return m_context;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ContextSwitch::parse(const QStringRef &contextInstr)
|
void ContextSwitch::parse(const QStringView &contextInstr)
|
||||||
{
|
{
|
||||||
if (contextInstr.isEmpty() || contextInstr == QLatin1String("#stay"))
|
if (contextInstr.isEmpty() || contextInstr == QLatin1String("#stay"))
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ public:
|
|||||||
int popCount() const;
|
int popCount() const;
|
||||||
Context *context() const;
|
Context *context() const;
|
||||||
|
|
||||||
void parse(const QStringRef &contextInstr);
|
void parse(const QStringView &contextInstr);
|
||||||
void resolve(const Definition &def);
|
void resolve(const Definition &def);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|||||||
@@ -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('.'));
|
const auto idx = verStr.indexOf(QLatin1Char('.'));
|
||||||
if (idx <= 0) {
|
if (idx <= 0) {
|
||||||
qCWarning(Log) << "Skipping" << fileName << "due to having no valid kateversion attribute:" << verStr;
|
qCWarning(Log) << "Skipping" << fileName << "due to having no valid kateversion attribute:" << verStr;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
const auto major = verStr.left(idx).toInt();
|
const auto major = verStr.left(idx).toString().toInt();
|
||||||
const auto minor = verStr.mid(idx + 1).toInt();
|
const auto minor = verStr.mid(idx + 1).toString().toInt();
|
||||||
|
|
||||||
if (major > SyntaxHighlighting_VERSION_MAJOR || (major == SyntaxHighlighting_VERSION_MAJOR && minor > SyntaxHighlighting_VERSION_MINOR)) {
|
if (major > SyntaxHighlighting_VERSION_MAJOR || (major == SyntaxHighlighting_VERSION_MAJOR && minor > SyntaxHighlighting_VERSION_MINOR)) {
|
||||||
qCWarning(Log) << "Skipping" << fileName << "due to being too new, version:" << verStr;
|
qCWarning(Log) << "Skipping" << fileName << "due to being too new, version:" << verStr;
|
||||||
|
|||||||
@@ -68,7 +68,7 @@ public:
|
|||||||
void loadComments(QXmlStreamReader &reader);
|
void loadComments(QXmlStreamReader &reader);
|
||||||
void loadFoldingIgnoreList(QXmlStreamReader &reader);
|
void loadFoldingIgnoreList(QXmlStreamReader &reader);
|
||||||
void loadSpellchecking(QXmlStreamReader &reader);
|
void loadSpellchecking(QXmlStreamReader &reader);
|
||||||
bool checkKateVersion(const QStringRef &verStr);
|
bool checkKateVersion(const QStringView &verStr);
|
||||||
|
|
||||||
void resolveIncludeKeywords();
|
void resolveIncludeKeywords();
|
||||||
|
|
||||||
|
|||||||
@@ -35,7 +35,7 @@
|
|||||||
|
|
||||||
using namespace KSyntaxHighlighting;
|
using namespace KSyntaxHighlighting;
|
||||||
|
|
||||||
static Theme::TextStyle stringToDefaultFormat(const QStringRef &str)
|
static Theme::TextStyle stringToDefaultFormat(const QStringView &str)
|
||||||
{
|
{
|
||||||
if (!str.startsWith(QLatin1String("ds")))
|
if (!str.startsWith(QLatin1String("ds")))
|
||||||
return Theme::Normal;
|
return Theme::Normal;
|
||||||
@@ -243,7 +243,7 @@ void FormatPrivate::load(QXmlStreamReader &reader)
|
|||||||
name = reader.attributes().value(QStringLiteral("name")).toString();
|
name = reader.attributes().value(QStringLiteral("name")).toString();
|
||||||
defaultStyle = stringToDefaultFormat(reader.attributes().value(QStringLiteral("defStyleNum")));
|
defaultStyle = stringToDefaultFormat(reader.attributes().value(QStringLiteral("defStyleNum")));
|
||||||
|
|
||||||
QStringRef attribute = reader.attributes().value(QStringLiteral("color"));
|
QStringView attribute = reader.attributes().value(QStringLiteral("color"));
|
||||||
if (!attribute.isEmpty()) {
|
if (!attribute.isEmpty()) {
|
||||||
style.textColor = QColor(attribute.toString()).rgba();
|
style.textColor = QColor(attribute.toString()).rgba();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,7 +32,7 @@
|
|||||||
|
|
||||||
using namespace KSyntaxHighlighting;
|
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
|
* get right vector to search in
|
||||||
@@ -42,7 +42,12 @@ bool KeywordList::contains(const QStringRef &str, Qt::CaseSensitivity caseSensit
|
|||||||
/**
|
/**
|
||||||
* search with right predicate
|
* 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)
|
void KeywordList::load(QXmlStreamReader &reader)
|
||||||
@@ -100,13 +105,17 @@ void KeywordList::initLookupForCaseSensitivity(Qt::CaseSensitivity caseSensitive
|
|||||||
*/
|
*/
|
||||||
vectorToSort.reserve(m_keywords.size());
|
vectorToSort.reserve(m_keywords.size());
|
||||||
for (const auto &keyword : qAsConst(m_keywords)) {
|
for (const auto &keyword : qAsConst(m_keywords)) {
|
||||||
vectorToSort.push_back(&keyword);
|
vectorToSort.emplace_back(keyword);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* sort with right predicate
|
* 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)
|
void KeywordList::resolveIncludeKeywords(DefinitionData &def)
|
||||||
|
|||||||
@@ -68,13 +68,10 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Checks if @p str is a keyword in this list. */
|
/** Checks if @p str is a keyword in this list. */
|
||||||
bool contains(const QStringRef &str) const
|
bool contains(const QStringView &str) const { return contains(str, m_caseSensitive); }
|
||||||
{
|
|
||||||
return contains(str, m_caseSensitive);
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Checks if @p str is a keyword in this list, overriding the global case-sensitivity setting. */
|
/** 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 load(QXmlStreamReader &reader);
|
||||||
void setCaseSensitivity(Qt::CaseSensitivity caseSensitive);
|
void setCaseSensitivity(Qt::CaseSensitivity caseSensitive);
|
||||||
@@ -105,12 +102,12 @@ private:
|
|||||||
/**
|
/**
|
||||||
* case-sensitive sorted string references to m_keywords for lookup
|
* case-sensitive sorted string references to m_keywords for lookup
|
||||||
*/
|
*/
|
||||||
std::vector<QStringRef> m_keywordsSortedCaseSensitive;
|
std::vector<QStringView> m_keywordsSortedCaseSensitive;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* case-insensitive sorted string references to m_keywords for lookup
|
* case-insensitive sorted string references to m_keywords for lookup
|
||||||
*/
|
*/
|
||||||
std::vector<QStringRef> m_keywordsSortedCaseInsensitive;
|
std::vector<QStringView> m_keywordsSortedCaseInsensitive;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -134,7 +134,7 @@ void Rule::resolveContext()
|
|||||||
m_context.resolve(m_def.definition());
|
m_context.resolve(m_def.definition());
|
||||||
|
|
||||||
// cache for DefinitionData::wordDelimiters, is accessed VERY often
|
// 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)
|
void Rule::resolveAttributeFormat(Context *lookupContext)
|
||||||
@@ -156,7 +156,7 @@ bool Rule::doLoad(QXmlStreamReader &reader)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
Rule::Ptr Rule::create(const QStringRef &name)
|
Rule::Ptr Rule::create(const QStringView &name)
|
||||||
{
|
{
|
||||||
Rule *rule = nullptr;
|
Rule *rule = nullptr;
|
||||||
if (name == QLatin1String("AnyChar"))
|
if (name == QLatin1String("AnyChar"))
|
||||||
@@ -418,7 +418,7 @@ bool IncludeRules::includeAttribute() const
|
|||||||
|
|
||||||
bool IncludeRules::doLoad(QXmlStreamReader &reader)
|
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)
|
#if QT_VERSION < QT_VERSION_CHECK(5, 15, 0)
|
||||||
const auto split = s.split(QLatin1String("##"), QString::KeepEmptyParts);
|
const auto split = s.split(QLatin1String("##"), QString::KeepEmptyParts);
|
||||||
#else
|
#else
|
||||||
@@ -426,9 +426,9 @@ bool IncludeRules::doLoad(QXmlStreamReader &reader)
|
|||||||
#endif
|
#endif
|
||||||
if (split.isEmpty())
|
if (split.isEmpty())
|
||||||
return false;
|
return false;
|
||||||
m_contextName = split.at(0).toString();
|
m_contextName = split.at(0);
|
||||||
if (split.size() > 1)
|
if (split.size() > 1)
|
||||||
m_defName = split.at(1).toString();
|
m_defName = split.at(1);
|
||||||
m_includeAttribute = Xml::attrToBool(reader.attributes().value(QLatin1String("includeAttrib")));
|
m_includeAttribute = Xml::attrToBool(reader.attributes().value(QLatin1String("includeAttrib")));
|
||||||
|
|
||||||
return !m_contextName.isEmpty() || !m_defName.isEmpty();
|
return !m_contextName.isEmpty() || !m_defName.isEmpty();
|
||||||
@@ -486,10 +486,11 @@ MatchResult KeywordListRule::doMatch(const QString &text, int offset, const QStr
|
|||||||
return offset;
|
return offset;
|
||||||
|
|
||||||
if (m_hasCaseSensitivityOverride) {
|
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;
|
return newOffset;
|
||||||
} else {
|
} else {
|
||||||
if (m_keywordList->contains(text.midRef(offset, newOffset - offset)))
|
if (m_keywordList->contains(QStringView(text).mid(offset, newOffset - offset)))
|
||||||
return newOffset;
|
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;
|
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 + pattern.size();
|
||||||
return offset;
|
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)))
|
if (offset > 0 && !isWordDelimiter(text.at(offset - 1)) && !isWordDelimiter(text.at(offset)))
|
||||||
return 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;
|
return offset;
|
||||||
|
|
||||||
if (text.size() == offset + m_word.size() || isWordDelimiter(text.at(offset + m_word.size())) || isWordDelimiter(text.at(offset + m_word.size() - 1)))
|
if (text.size() == offset + m_word.size() || isWordDelimiter(text.at(offset + m_word.size())) || isWordDelimiter(text.at(offset + m_word.size() - 1)))
|
||||||
|
|||||||
@@ -100,7 +100,7 @@ public:
|
|||||||
|
|
||||||
virtual MatchResult doMatch(const QString &text, int offset, const QStringList &captures) const = 0;
|
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:
|
protected:
|
||||||
virtual bool doLoad(QXmlStreamReader &reader);
|
virtual bool doLoad(QXmlStreamReader &reader);
|
||||||
@@ -121,7 +121,7 @@ private:
|
|||||||
bool m_lookAhead = false;
|
bool m_lookAhead = false;
|
||||||
|
|
||||||
// cache for DefinitionData::wordDelimiters, is accessed VERY often
|
// cache for DefinitionData::wordDelimiters, is accessed VERY often
|
||||||
QStringRef m_wordDelimiter;
|
QStringView m_wordDelimiter;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool m_dynamic = false;
|
bool m_dynamic = false;
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ namespace KSyntaxHighlighting
|
|||||||
namespace Xml
|
namespace Xml
|
||||||
{
|
{
|
||||||
/** Parse a xs:boolean attribute. */
|
/** 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;
|
return str == QLatin1String("1") || str.compare(QLatin1String("true"), Qt::CaseInsensitive) == 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user