From 43e795e7919273a374e5ac98d3f835202bb572fe Mon Sep 17 00:00:00 2001 From: Cyano Hao Date: Tue, 14 May 2024 08:38:22 +0800 Subject: [PATCH] migrate QStringRef -> QStringView (#425) --- RedPandaIDE/compiler/compiler.cpp | 4 ++-- RedPandaIDE/parser/cppparser.cpp | 2 +- RedPandaIDE/parser/cpppreprocessor.cpp | 2 +- RedPandaIDE/parser/cpptokenizer.cpp | 2 +- RedPandaIDE/widgets/qconsole.cpp | 2 +- libs/qsynedit/qsynedit/qsynedit.cpp | 3 ++- 6 files changed, 8 insertions(+), 7 deletions(-) diff --git a/RedPandaIDE/compiler/compiler.cpp b/RedPandaIDE/compiler/compiler.cpp index 97234fb2..2f7151fb 100644 --- a/RedPandaIDE/compiler/compiler.cpp +++ b/RedPandaIDE/compiler/compiler.cpp @@ -148,7 +148,7 @@ int Compiler::getLineNumberFromOutputLine(QString &line) pos = line.indexOf(','); } if (pos>=0) { - result = line.midRef(0,pos).toInt(); + result = QStringView(line.data(), pos).toInt(); if (result > 0) line.remove(0,pos+1); } else { @@ -168,7 +168,7 @@ int Compiler::getColunmnFromOutputLine(QString &line) pos = line.indexOf(','); } if (pos>=0) { - result = line.midRef(0,pos).toInt(); + result = QStringView(line.data(), pos).toInt(); if (result > 0) line.remove(0,pos+1); } diff --git a/RedPandaIDE/parser/cppparser.cpp b/RedPandaIDE/parser/cppparser.cpp index 887f2844..aed6dee4 100644 --- a/RedPandaIDE/parser/cppparser.cpp +++ b/RedPandaIDE/parser/cppparser.cpp @@ -3449,7 +3449,7 @@ void CppParser::handlePreprocessor() // Mention progress to user if we enter a NEW file bool ok; - int line = s.midRef(delimPos+1).toInt(&ok); + int line = QStringView(s.begin() + delimPos + 1, s.end()).toInt(&ok); if (line == 1) { mFilesScannedCount++; mFilesToScanCount++; diff --git a/RedPandaIDE/parser/cpppreprocessor.cpp b/RedPandaIDE/parser/cpppreprocessor.cpp index 2feac9d9..97c2c8e4 100644 --- a/RedPandaIDE/parser/cpppreprocessor.cpp +++ b/RedPandaIDE/parser/cpppreprocessor.cpp @@ -1037,7 +1037,7 @@ QStringList CppPreprocessor::removeComments(const QStringList &text) currentType=ContentType::Other; break; case ContentType::RawString: - if (line.midRef(0,pos).endsWith(')'+delimiter)) + if (QStringView(line.data(), pos).endsWith(')'+delimiter)) currentType = ContentType::Other; break; case ContentType::Other: diff --git a/RedPandaIDE/parser/cpptokenizer.cpp b/RedPandaIDE/parser/cpptokenizer.cpp index 9adf1284..f317ef7c 100644 --- a/RedPandaIDE/parser/cpptokenizer.cpp +++ b/RedPandaIDE/parser/cpptokenizer.cpp @@ -194,7 +194,7 @@ QString CppTokenizer::getNextToken(TokenType *pTokenType) int delimPos = result.lastIndexOf(':'); if (delimPos >= 0) { bool ok; - mCurrentLine = result.midRef(delimPos+1).toInt(&ok)-1; // fCurrLine is 0 based + mCurrentLine = QStringView(result.begin() + delimPos + 1, result.end()).toInt(&ok)-1; // fCurrLine is 0 based } } done = (result != ""); diff --git a/RedPandaIDE/widgets/qconsole.cpp b/RedPandaIDE/widgets/qconsole.cpp index 0e0a9a4f..ce2399eb 100644 --- a/RedPandaIDE/widgets/qconsole.cpp +++ b/RedPandaIDE/widgets/qconsole.cpp @@ -252,7 +252,7 @@ QString QConsole::selText() QString s = mContents.getLine(Last); if (Last == mContents.lines()) s+= this->mCommand; - result += s.leftRef(ColTo); + result.append(s.data(), ColTo); return result; } } diff --git a/libs/qsynedit/qsynedit/qsynedit.cpp b/libs/qsynedit/qsynedit/qsynedit.cpp index fbec9aa5..d76d3386 100644 --- a/libs/qsynedit/qsynedit/qsynedit.cpp +++ b/libs/qsynedit/qsynedit/qsynedit.cpp @@ -4497,7 +4497,8 @@ QString QSynEdit::selText() const result += mDocument->getLine(i); result+=lineBreak(); } - result += mDocument->getLine(lastLine).leftRef(charTo-1); + const QString &line = mDocument->getLine(lastLine); + result.append(line.data(), charTo-1); return result; } }