forked from qt-creator/qt-creator
		
	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:
		| @@ -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 | ||||
|   | ||||
| @@ -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; | ||||
|  | ||||
|   | ||||
| @@ -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; | ||||
|   | ||||
| @@ -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)) | ||||
|   | ||||
| @@ -528,7 +528,7 @@ void CodeFormatter::recalculateStateAfter(const QTextBlock &block) | ||||
|                 } | ||||
|             } | ||||
|  | ||||
|             QStringRef tokenText = currentTokenText(); | ||||
|             QStringView tokenText = currentTokenText(); | ||||
|             if (tokenText == QLatin1String("ifdef") | ||||
|                     || tokenText == QLatin1String("if") | ||||
|                     || tokenText == QLatin1String("ifndef")) { | ||||
| @@ -854,7 +854,7 @@ bool CodeFormatter::tryDeclaration() | ||||
|         return true; | ||||
|     case T_IDENTIFIER: | ||||
|         if (m_tokenIndex == 0) { | ||||
|             const QStringRef tokenText = currentTokenText(); | ||||
|             const QStringView tokenText = currentTokenText(); | ||||
|             if (tokenText.startsWith(QLatin1String("Q_")) | ||||
|                     || tokenText.startsWith(QLatin1String("QT_")) | ||||
|                     || tokenText.startsWith(QLatin1String("QML_")) | ||||
| @@ -1009,9 +1009,11 @@ int CodeFormatter::column(int index) const | ||||
|     return col; | ||||
| } | ||||
|  | ||||
| QStringRef CodeFormatter::currentTokenText() const | ||||
| QStringView CodeFormatter::currentTokenText() const | ||||
| { | ||||
|     return m_currentLine.midRef(m_currentToken.utf16charsBegin(), m_currentToken.utf16chars()); | ||||
|     if (m_currentToken.utf16charsEnd() > m_currentLine.size()) | ||||
|         return QStringView(m_currentLine).mid(m_currentToken.utf16charsBegin()); | ||||
|     return QStringView(m_currentLine).mid(m_currentToken.utf16charsBegin(), m_currentToken.utf16chars()); | ||||
| } | ||||
|  | ||||
| void CodeFormatter::turnInto(int newState) | ||||
|   | ||||
| @@ -216,7 +216,7 @@ private: | ||||
|     void saveCurrentState(const QTextBlock &block); | ||||
|     void restoreCurrentState(const QTextBlock &block); | ||||
|  | ||||
|     QStringRef currentTokenText() const; | ||||
|     QStringView currentTokenText() const; | ||||
|  | ||||
|     int tokenizeBlock(const QTextBlock &block, bool *endedJoined = nullptr); | ||||
|  | ||||
|   | ||||
| @@ -880,9 +880,12 @@ bool InternalCppCompletionAssistProcessor::accepts() const | ||||
|                                && tokens.at(1).kind() == T_IDENTIFIER) { | ||||
|                         const QString &line = tc.block().text(); | ||||
|                         const Token &idToken = tokens.at(1); | ||||
|                         const QStringRef &identifier = | ||||
|                                 line.midRef(idToken.utf16charsBegin(), | ||||
|                                             idToken.utf16charsEnd() - idToken.utf16charsBegin()); | ||||
|                         const QStringView &identifier = idToken.utf16charsEnd() > line.size() | ||||
|                                                             ? QStringView(line).mid( | ||||
|                                                                 idToken.utf16charsBegin()) | ||||
|                                                             : QStringView(line) | ||||
|                                                                   .mid(idToken.utf16charsBegin(), | ||||
|                                                                        idToken.utf16chars()); | ||||
|                         if (identifier == QLatin1String("include") | ||||
|                                 || identifier == QLatin1String("include_next") | ||||
|                                 || (m_interface->languageFeatures().objCEnabled && identifier == QLatin1String("import"))) { | ||||
|   | ||||
| @@ -101,7 +101,7 @@ QList<Core::LocatorFilterEntry> CppLocatorFilter::matchesFor( | ||||
|  | ||||
|                 // Highlight the matched characters, therefore it may be necessary | ||||
|                 // to update the match if the displayName is different from matchString | ||||
|                 if (matchString.midRef(matchOffset) != filterEntry.displayName) { | ||||
|                 if (QStringView(matchString).mid(matchOffset) != filterEntry.displayName) { | ||||
|                     match = shortRegexp.match(filterEntry.displayName); | ||||
|                     matchOffset = 0; | ||||
|                 } | ||||
|   | ||||
| @@ -132,7 +132,7 @@ QVariant SymbolItem::data(int /*column*/, int role) const | ||||
|  | ||||
| bool OverviewModel::hasDocument() const | ||||
| { | ||||
|     return _cppDocument; | ||||
|     return !_cppDocument.isNull(); | ||||
| } | ||||
|  | ||||
| int OverviewModel::globalSymbolCount() const | ||||
|   | ||||
| @@ -55,7 +55,7 @@ CppTools::ProjectPart::Ptr projectPartForFile(const QString &filePath) | ||||
| bool isProjectPartValid(const CppTools::ProjectPart::Ptr projectPart) | ||||
| { | ||||
|     if (projectPart) | ||||
|         return CppTools::CppModelManager::instance()->projectPartForId(projectPart->id()); | ||||
|         return !CppTools::CppModelManager::instance()->projectPartForId(projectPart->id()).isNull(); | ||||
|  | ||||
|     return false; | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user