CppTools: Fix QStringRef and QSharedPointer related issues with Qt6

Task-number: QTCREATORBUG-24098
Change-Id: I97347ac3fb397fea8eee655e3cc4ee252c511885
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
Eike Ziller
2020-09-15 15:27:32 +02:00
parent 432247357e
commit 242579099a
10 changed files with 26 additions and 16 deletions

View File

@@ -113,10 +113,12 @@ QString BackwardsScanner::text(int index) const
return _text.mid(firstToken.utf16charsBegin(), firstToken.utf16chars());
}
QStringRef BackwardsScanner::textRef(int index) const
QStringView BackwardsScanner::textRef(int index) const
{
const Token &firstToken = _tokens.at(index + _offset);
return _text.midRef(firstToken.utf16charsBegin(), firstToken.utf16chars());
if (firstToken.utf16charsEnd() > _text.size())
return QStringView(_text).mid(firstToken.utf16charsBegin());
return QStringView(_text).mid(firstToken.utf16charsBegin(), firstToken.utf16chars());
}
int BackwardsScanner::size() const

View File

@@ -27,6 +27,7 @@
#include "SimpleLexer.h"
#include <QStringView>
#include <QTextBlock>
QT_FORWARD_DECLARE_CLASS(QTextCursor)
@@ -52,7 +53,7 @@ public:
QString mid(int index) const;
QString text(int index) const;
QStringRef textRef(int index) const;
QStringView textRef(int index) const;
// 1-based
Token LA(int index) const;

View File

@@ -54,7 +54,7 @@ static bool shouldOverrideChar(QChar ch)
static bool isCompleteStringLiteral(const BackwardsScanner &tk, int index)
{
const QStringRef text = tk.textRef(index);
const QStringView text = tk.textRef(index);
if (text.length() < 2)
return false;

View File

@@ -87,7 +87,9 @@ Tokens SimpleLexer::operator()(const QString &text, int state)
break;
}
QStringRef spell = text.midRef(tk.bytesBegin(), tk.bytes());
const QStringView spell = tk.bytesBegin() + tk.bytes() > text.size()
? QStringView(text).mid(tk.bytesBegin())
: QStringView(text).mid(tk.bytesBegin(), tk.bytes());
lex.setScanAngleStringLiteralTokens(false);
if (tk.newline() && tk.is(T_POUND))