forked from qt-creator/qt-creator
Make QmlJS(Tools) build with Qt5 & Qt6
Port from QStringRef to QStringView Change-Id: I472d16f20e40ca52b8e5d481850a6bd8a1a38f3b Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
@@ -27,6 +27,8 @@
|
||||
|
||||
#include <qmljs/qmljsscanner.h>
|
||||
|
||||
#include <utils/porting.h>
|
||||
|
||||
#include <QChar>
|
||||
#include <QLatin1Char>
|
||||
#include <QTextDocument>
|
||||
@@ -119,7 +121,7 @@ static bool shouldInsertNewline(const QTextCursor &tc)
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool isCompleteStringLiteral(const QStringRef &text)
|
||||
static bool isCompleteStringLiteral(const QStringView &text)
|
||||
{
|
||||
if (text.length() < 2)
|
||||
return false;
|
||||
@@ -173,7 +175,7 @@ bool AutoCompleter::contextAllowsAutoBrackets(const QTextCursor &cursor,
|
||||
|
||||
case Token::String: {
|
||||
const QString blockText = cursor.block().text();
|
||||
const QStringRef tokenText = blockText.midRef(token.offset, token.length);
|
||||
const QStringView tokenText = Utils::midView(blockText, token.offset, token.length);
|
||||
QChar quote = tokenText.at(0);
|
||||
// if a string literal doesn't start with a quote, it must be multiline
|
||||
if (quote != QLatin1Char('"') && quote != QLatin1Char('\'')) {
|
||||
@@ -217,7 +219,7 @@ bool AutoCompleter::contextAllowsAutoQuotes(const QTextCursor &cursor,
|
||||
|
||||
case Token::String: {
|
||||
const QString blockText = cursor.block().text();
|
||||
const QStringRef tokenText = blockText.midRef(token.offset, token.length);
|
||||
const QStringView tokenText = Utils::midView(blockText, token.offset, token.length);
|
||||
QChar quote = tokenText.at(0);
|
||||
// if a string literal doesn't start with a quote, it must be multiline
|
||||
if (quote != QLatin1Char('"') && quote != QLatin1Char('\'')) {
|
||||
|
||||
@@ -411,7 +411,7 @@ protected:
|
||||
{
|
||||
UiQualifiedId *id = qualifiedTypeNameId(member);
|
||||
if (id) {
|
||||
const QStringRef &name = id->name;
|
||||
const QStringView &name = id->name;
|
||||
if (!name.isEmpty() && name.at(0).isUpper())
|
||||
return true;
|
||||
}
|
||||
@@ -429,7 +429,7 @@ protected:
|
||||
else if (script->qualifiedId->next)
|
||||
return false;
|
||||
|
||||
const QStringRef &propertyName = script->qualifiedId->name;
|
||||
const QStringView &propertyName = script->qualifiedId->name;
|
||||
|
||||
if (propertyName == QLatin1String("id"))
|
||||
return true;
|
||||
|
||||
@@ -89,7 +89,7 @@ protected:
|
||||
QString text;
|
||||
for (; id; id = id->next) {
|
||||
if (!id->name.isEmpty())
|
||||
text += id->name;
|
||||
text += id->name.toString();
|
||||
else
|
||||
text += QLatin1Char('?');
|
||||
|
||||
@@ -174,7 +174,7 @@ protected:
|
||||
QString text;
|
||||
for (; id; id = id->next) {
|
||||
if (!id->name.isEmpty())
|
||||
text += id->name;
|
||||
text += id->name.toString();
|
||||
else
|
||||
text += QLatin1Char('?');
|
||||
|
||||
@@ -294,12 +294,12 @@ protected:
|
||||
init(&decl, ast);
|
||||
|
||||
decl.text.fill(QLatin1Char(' '), _depth);
|
||||
decl.text += ast->name;
|
||||
decl.text += ast->name.toString();
|
||||
|
||||
decl.text += QLatin1Char('(');
|
||||
for (FormalParameterList *it = ast->formals; it; it = it->next) {
|
||||
if (!it->element->bindingIdentifier.isEmpty())
|
||||
decl.text += it->element->bindingIdentifier;
|
||||
decl.text += it->element->bindingIdentifier.toString();
|
||||
|
||||
if (it->next)
|
||||
decl.text += QLatin1String(", ");
|
||||
@@ -319,7 +319,7 @@ protected:
|
||||
|
||||
Declaration decl;
|
||||
decl.text.fill(QLatin1Char(' '), _depth);
|
||||
decl.text += ast->bindingIdentifier;
|
||||
decl.text += ast->bindingIdentifier.toString();
|
||||
|
||||
const SourceLocation first = ast->identifierToken;
|
||||
decl.startLine = first.startLine;
|
||||
@@ -342,12 +342,12 @@ protected:
|
||||
init(&decl, ast);
|
||||
|
||||
decl.text.fill(QLatin1Char(' '), _depth);
|
||||
decl.text += field->name;
|
||||
decl.text += field->name.toString();
|
||||
|
||||
decl.text += QLatin1Char('(');
|
||||
for (FormalParameterList *it = funcExpr->formals; it; it = it->next) {
|
||||
if (!it->element->bindingIdentifier.isEmpty())
|
||||
decl.text += it->element->bindingIdentifier;
|
||||
decl.text += it->element->bindingIdentifier.toString();
|
||||
|
||||
if (it->next)
|
||||
decl.text += QLatin1String(", ");
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
|
||||
#include <QSet>
|
||||
|
||||
#include <utils/porting.h>
|
||||
#include <utils/qtcassert.h>
|
||||
|
||||
using namespace QmlJS;
|
||||
@@ -75,7 +76,8 @@ void QmlJSHighlighter::highlightBlock(const QString &text)
|
||||
break;
|
||||
|
||||
case Token::Comment:
|
||||
if (m_inMultilineComment && text.midRef(token.end() - 2, 2) == QLatin1String("*/")) {
|
||||
if (m_inMultilineComment
|
||||
&& Utils::midView(text, token.end() - 2, 2) == QLatin1String("*/")) {
|
||||
onClosingParenthesis(QLatin1Char('-'), token.end() - 1, index == tokens.size()-1);
|
||||
m_inMultilineComment = false;
|
||||
} else if (!m_inMultilineComment
|
||||
@@ -119,7 +121,7 @@ void QmlJSHighlighter::highlightBlock(const QString &text)
|
||||
if (!m_qmlEnabled)
|
||||
break;
|
||||
|
||||
const QStringRef spell = text.midRef(token.offset, token.length);
|
||||
const QStringView spell = Utils::midView(text, token.offset, token.length);
|
||||
|
||||
if (maybeQmlKeyword(spell)) {
|
||||
// check the previous token
|
||||
@@ -129,25 +131,25 @@ void QmlJSHighlighter::highlightBlock(const QString &text)
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (text.midRef(token.offset, token.length) == QLatin1String("enum")) {
|
||||
if (Utils::midView(text, token.offset, token.length) == QLatin1String("enum")) {
|
||||
setFormat(token.offset, token.length, formatForCategory(C_KEYWORD));
|
||||
break;
|
||||
}
|
||||
} else if (index > 0 && maybeQmlBuiltinType(spell)) {
|
||||
const Token &previousToken = tokens.at(index - 1);
|
||||
if (previousToken.is(Token::Identifier)
|
||||
&& text.at(previousToken.offset) == QLatin1Char('p')
|
||||
&& text.midRef(previousToken.offset, previousToken.length)
|
||||
== QLatin1String("property")) {
|
||||
&& text.at(previousToken.offset) == QLatin1Char('p')
|
||||
&& Utils::midView(text, previousToken.offset, previousToken.length)
|
||||
== QLatin1String("property")) {
|
||||
setFormat(token.offset, token.length, formatForCategory(C_KEYWORD));
|
||||
break;
|
||||
}
|
||||
} else if (index == 1) {
|
||||
const Token &previousToken = tokens.at(0);
|
||||
if (previousToken.is(Token::Identifier)
|
||||
&& text.at(previousToken.offset) == QLatin1Char('e')
|
||||
&& text.midRef(previousToken.offset, previousToken.length)
|
||||
== QLatin1String("enum")) {
|
||||
&& text.at(previousToken.offset) == QLatin1Char('e')
|
||||
&& Utils::midView(text, previousToken.offset, previousToken.length)
|
||||
== QLatin1String("enum")) {
|
||||
setFormat(token.offset, token.length, formatForCategory(C_ENUMERATION));
|
||||
break;
|
||||
}
|
||||
@@ -200,7 +202,7 @@ void QmlJSHighlighter::highlightBlock(const QString &text)
|
||||
onBlockEnd(m_scanner.state());
|
||||
}
|
||||
|
||||
bool QmlJSHighlighter::maybeQmlKeyword(const QStringRef &text) const
|
||||
bool QmlJSHighlighter::maybeQmlKeyword(const QStringView &text) const
|
||||
{
|
||||
if (text.isEmpty())
|
||||
return false;
|
||||
@@ -226,7 +228,7 @@ bool QmlJSHighlighter::maybeQmlKeyword(const QStringRef &text) const
|
||||
return false;
|
||||
}
|
||||
|
||||
bool QmlJSHighlighter::maybeQmlBuiltinType(const QStringRef &text) const
|
||||
bool QmlJSHighlighter::maybeQmlBuiltinType(const QStringView &text) const
|
||||
{
|
||||
if (text.isEmpty())
|
||||
return false;
|
||||
|
||||
@@ -56,8 +56,8 @@ protected:
|
||||
void onOpeningParenthesis(QChar parenthesis, int pos, bool atStart);
|
||||
void onClosingParenthesis(QChar parenthesis, int pos, bool atEnd);
|
||||
|
||||
bool maybeQmlKeyword(const QStringRef &text) const;
|
||||
bool maybeQmlBuiltinType(const QStringRef &text) const;
|
||||
bool maybeQmlKeyword(const QStringView &text) const;
|
||||
bool maybeQmlBuiltinType(const QStringView &text) const;
|
||||
|
||||
private:
|
||||
bool m_qmlEnabled;
|
||||
|
||||
@@ -235,7 +235,7 @@ protected:
|
||||
m_scopeBuilder.pop();
|
||||
}
|
||||
|
||||
void processName(const QStringRef &name, SourceLocation location)
|
||||
void processName(const QStringView &name, SourceLocation location)
|
||||
{
|
||||
if (name.isEmpty())
|
||||
return;
|
||||
|
||||
@@ -599,7 +599,7 @@ void QmlOutlineModel::leavePublicMember()
|
||||
leaveNode();
|
||||
}
|
||||
|
||||
static QString functionDisplayName(QStringRef name, AST::FormalParameterList *formals)
|
||||
static QString functionDisplayName(QStringView name, AST::FormalParameterList *formals)
|
||||
{
|
||||
QString display;
|
||||
|
||||
@@ -1002,7 +1002,7 @@ QString QmlOutlineModel::asString(AST::UiQualifiedId *id)
|
||||
QString text;
|
||||
for (; id; id = id->next) {
|
||||
if (!id->name.isEmpty())
|
||||
text += id->name;
|
||||
text += id->name.toString();
|
||||
else
|
||||
text += QLatin1Char('?');
|
||||
|
||||
|
||||
Reference in New Issue
Block a user