From 454dcbadcb1f54020e81beb600b8ff33cbe12803 Mon Sep 17 00:00:00 2001 From: Roy Qu Date: Tue, 14 May 2024 21:19:42 +0800 Subject: [PATCH] - optimization: use QString::constData() instead of QString::data() if possible - fix: Can't correctly parse template parameters that contains "->", like "std::queuevoid>>"; --- NEWS.md | 2 ++ RedPandaIDE/parser/cpptokenizer.cpp | 7 ++++--- RedPandaIDE/problems/problemcasevalidator.cpp | 2 +- RedPandaIDE/widgets/qconsole.cpp | 2 +- libs/qsynedit/qsynedit/qsynedit.cpp | 2 +- libs/qsynedit/qsynedit/syntaxer/asm.cpp | 3 ++- libs/qsynedit/qsynedit/syntaxer/asm.h | 2 +- libs/qsynedit/qsynedit/syntaxer/glsl.cpp | 3 ++- libs/qsynedit/qsynedit/syntaxer/glsl.h | 2 +- libs/qsynedit/qsynedit/syntaxer/makefile.cpp | 3 ++- libs/qsynedit/qsynedit/syntaxer/makefile.h | 2 +- libs/qsynedit/qsynedit/syntaxer/textfile.cpp | 3 ++- libs/qsynedit/qsynedit/syntaxer/textfile.h | 2 +- libs/redpanda_qt_utils/qt_utils/utils.cpp | 9 +++++++++ libs/redpanda_qt_utils/qt_utils/utils.h | 2 ++ 15 files changed, 32 insertions(+), 14 deletions(-) diff --git a/NEWS.md b/NEWS.md index 97a5fa10..eb1d7815 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,6 +1,7 @@ Red Panda C++ Version 3.1 - fix: Can't correctly select in column mode. + - fix: Can't correctly parse template parameters that contains "->", like "std::queuevoid>>"; Red Panda C++ Version 3.0 @@ -174,6 +175,7 @@ Red Panda C++ Version 3.0 - enhancement: Show full filepath in the tooltip of editor tab. Red Panda C++ Version 2.26 + - enhancement: Code suggestion for embedded std::vectors. - change: Use ctrl+mouseMove event to highlight jumpable symbols (instead of ctrl+tooltip). - enhancement: Auto adjust position of the suggestion popup window. diff --git a/RedPandaIDE/parser/cpptokenizer.cpp b/RedPandaIDE/parser/cpptokenizer.cpp index 65c01e71..5546fafa 100644 --- a/RedPandaIDE/parser/cpptokenizer.cpp +++ b/RedPandaIDE/parser/cpptokenizer.cpp @@ -49,7 +49,8 @@ void CppTokenizer::tokenize(const QStringList &buffer) mBufferStr+='\n'; mBufferStr+=mBuffer[i]; } - mBufferStr.append(QChar(0)); + //QByteArray is always '\0'-terminated unless it's created by QbyteArray::fromRawData() + //mBufferStr.append(QChar(0)); mStart = mBufferStr.constData(); mCurrent = mStart; mLineCount = mStart; @@ -695,8 +696,8 @@ bool CppTokenizer::skipAngleBracketPair() return false; case '-': if (*(mCurrent+1)=='>') { - mCurrent=backup; - return false; + mCurrent+=2; + continue; } break; case '.': diff --git a/RedPandaIDE/problems/problemcasevalidator.cpp b/RedPandaIDE/problems/problemcasevalidator.cpp index cc4b1c6f..a430fe83 100644 --- a/RedPandaIDE/problems/problemcasevalidator.cpp +++ b/RedPandaIDE/problems/problemcasevalidator.cpp @@ -89,7 +89,7 @@ bool ProblemCaseValidator::equalIgnoringSpaces(const QString &s1, const QString QStringList ProblemCaseValidator::split(const QString &s) { QStringList result; - const QChar* p = s.data(); + const QChar* p = getNullTerminatedStringData(s); const QChar* start = p; while (p->unicode()!=0) { if (p->isSpace()) { diff --git a/RedPandaIDE/widgets/qconsole.cpp b/RedPandaIDE/widgets/qconsole.cpp index ce2399eb..f06725ed 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.append(s.data(), ColTo); + result.append(s.constData(), ColTo); return result; } } diff --git a/libs/qsynedit/qsynedit/qsynedit.cpp b/libs/qsynedit/qsynedit/qsynedit.cpp index d76d3386..61f4969a 100644 --- a/libs/qsynedit/qsynedit/qsynedit.cpp +++ b/libs/qsynedit/qsynedit/qsynedit.cpp @@ -4498,7 +4498,7 @@ QString QSynEdit::selText() const result+=lineBreak(); } const QString &line = mDocument->getLine(lastLine); - result.append(line.data(), charTo-1); + result.append(line.constData(), charTo-1); return result; } } diff --git a/libs/qsynedit/qsynedit/syntaxer/asm.cpp b/libs/qsynedit/qsynedit/syntaxer/asm.cpp index a889f1d9..deee944d 100644 --- a/libs/qsynedit/qsynedit/syntaxer/asm.cpp +++ b/libs/qsynedit/qsynedit/syntaxer/asm.cpp @@ -16,6 +16,7 @@ */ #include "asm.h" #include "../constants.h" +#include #include namespace QSynedit { @@ -1706,7 +1707,7 @@ void ASMSyntaxer::next() void ASMSyntaxer::setLine(const QString &newLine, int lineNumber) { mLineString = newLine; - mLine = mLineString.data(); + mLine = getNullTerminatedStringData(mLineString); mLineNumber = lineNumber; mRun = 0; next(); diff --git a/libs/qsynedit/qsynedit/syntaxer/asm.h b/libs/qsynedit/qsynedit/syntaxer/asm.h index ab0c1ce2..626a7626 100644 --- a/libs/qsynedit/qsynedit/syntaxer/asm.h +++ b/libs/qsynedit/qsynedit/syntaxer/asm.h @@ -60,7 +60,7 @@ public: static const QSet Directives; static const QSet ATTDirectives; private: - QChar* mLine; + const QChar* mLine; QString mLineString; int mLineNumber; int mRun; diff --git a/libs/qsynedit/qsynedit/syntaxer/glsl.cpp b/libs/qsynedit/qsynedit/syntaxer/glsl.cpp index 939f7396..82f388d1 100644 --- a/libs/qsynedit/qsynedit/syntaxer/glsl.cpp +++ b/libs/qsynedit/qsynedit/syntaxer/glsl.cpp @@ -16,6 +16,7 @@ */ #include "glsl.h" #include "../constants.h" +#include #include @@ -1360,7 +1361,7 @@ void GLSLSyntaxer::next() void GLSLSyntaxer::setLine(const QString &newLine, int lineNumber) { mLineString = newLine; - mLine = mLineString.data(); + mLine = getNullTerminatedStringData(mLineString); mLineNumber = lineNumber; mRun = 0; mRange.blockStarted = 0; diff --git a/libs/qsynedit/qsynedit/syntaxer/glsl.h b/libs/qsynedit/qsynedit/syntaxer/glsl.h index e33f5aa5..b3096c9b 100644 --- a/libs/qsynedit/qsynedit/syntaxer/glsl.h +++ b/libs/qsynedit/qsynedit/syntaxer/glsl.h @@ -134,7 +134,7 @@ private: SyntaxState mRange; // SynRangeState mSpaceRange; QString mLineString; - QChar* mLine; + const QChar* mLine; int mLineSize; int mRun; int mStringLen; diff --git a/libs/qsynedit/qsynedit/syntaxer/makefile.cpp b/libs/qsynedit/qsynedit/syntaxer/makefile.cpp index c7b4e389..1980c7d6 100644 --- a/libs/qsynedit/qsynedit/syntaxer/makefile.cpp +++ b/libs/qsynedit/qsynedit/syntaxer/makefile.cpp @@ -16,6 +16,7 @@ */ #include "makefile.h" #include "../constants.h" +#include //#include namespace QSynedit { @@ -643,7 +644,7 @@ void MakefileSyntaxer::next() void MakefileSyntaxer::setLine(const QString &newLine, int lineNumber) { mLineString = newLine; - mLine = mLineString.data(); + mLine = getNullTerminatedStringData(mLineString); mLineNumber = lineNumber; mRun = 0; next(); diff --git a/libs/qsynedit/qsynedit/syntaxer/makefile.h b/libs/qsynedit/qsynedit/syntaxer/makefile.h index d78c0e8d..36a0d4ab 100644 --- a/libs/qsynedit/qsynedit/syntaxer/makefile.h +++ b/libs/qsynedit/qsynedit/syntaxer/makefile.h @@ -72,7 +72,7 @@ public: static const QSet Directives; private: - QChar* mLine; + const QChar* mLine; QString mLineString; int mLineNumber; int mRun; diff --git a/libs/qsynedit/qsynedit/syntaxer/textfile.cpp b/libs/qsynedit/qsynedit/syntaxer/textfile.cpp index 0d3ed5db..e5e0b595 100644 --- a/libs/qsynedit/qsynedit/syntaxer/textfile.cpp +++ b/libs/qsynedit/qsynedit/syntaxer/textfile.cpp @@ -16,6 +16,7 @@ */ #include "textfile.h" #include "../constants.h" +#include //#include namespace QSynedit { @@ -102,7 +103,7 @@ void TextSyntaxer::next() void TextSyntaxer::setLine(const QString &newLine, int lineNumber) { mLineString = newLine; - mLine = mLineString.data(); + mLine = getNullTerminatedStringData(mLineString); mLineNumber = lineNumber; mRun = 0; next(); diff --git a/libs/qsynedit/qsynedit/syntaxer/textfile.h b/libs/qsynedit/qsynedit/syntaxer/textfile.h index 8328522f..64e0fa92 100644 --- a/libs/qsynedit/qsynedit/syntaxer/textfile.h +++ b/libs/qsynedit/qsynedit/syntaxer/textfile.h @@ -42,7 +42,7 @@ public: static const QSet Directives; private: - QChar* mLine; + const QChar* mLine; QString mLineString; int mLineNumber; int mRun; diff --git a/libs/redpanda_qt_utils/qt_utils/utils.cpp b/libs/redpanda_qt_utils/qt_utils/utils.cpp index a183cd72..84c63e4b 100644 --- a/libs/redpanda_qt_utils/qt_utils/utils.cpp +++ b/libs/redpanda_qt_utils/qt_utils/utils.cpp @@ -756,3 +756,12 @@ QString replacePrefix(const QString &oldString, const QString &prefix, const QSt } return result; } + +const QChar *getNullTerminatedStringData(const QString &str) +{ + const QChar* result = str.constData(); + if (result[str.size()]!=QChar(0)) { + result = str.data(); + } + return result; +} diff --git a/libs/redpanda_qt_utils/qt_utils/utils.h b/libs/redpanda_qt_utils/qt_utils/utils.h index ca05b90a..cd6dcd36 100644 --- a/libs/redpanda_qt_utils/qt_utils/utils.h +++ b/libs/redpanda_qt_utils/qt_utils/utils.h @@ -69,6 +69,8 @@ public: /* text processing utils */ const QByteArray guessTextEncoding(const QByteArray& text); +const QChar *getNullTerminatedStringData(const QString& str); + bool isBinaryContent(const QByteArray& text); bool isTextAllAscii(const QByteArray& text); bool isTextAllAscii(const QString& text);