Improve raw string syntax color

This commit is contained in:
Roy Qu 2024-02-21 09:58:18 +08:00
parent 89c895837a
commit e49f815119
3 changed files with 16 additions and 17 deletions

View File

@ -963,8 +963,9 @@ void CppSyntaxer::procQuestion()
void CppSyntaxer::procRawString() void CppSyntaxer::procRawString()
{ {
mTokenId = TokenId::RawString; mTokenId = TokenId::RawString;
QString rawStringInitialDCharSeq;
if (mRange.state == RangeState::rsRawString) if (mRange.state == RangeState::rsRawString)
mRawStringInitialDCharSeq=""; mRange.extraData = std::make_shared<QVariant>("");
while (mRun<mLineSize) { while (mRun<mLineSize) {
if (mRange.state!=RangeState::rsRawStringNotEscaping && if (mRange.state!=RangeState::rsRawStringNotEscaping &&
(mLine[mRun]=='"' (mLine[mRun]=='"'
@ -981,20 +982,24 @@ void CppSyntaxer::procRawString()
case '(': case '(':
if (mRange.state==RangeState::rsRawString) { if (mRange.state==RangeState::rsRawString) {
mRange.state = RangeState::rsRawStringNotEscaping; mRange.state = RangeState::rsRawStringNotEscaping;
mRawStringInitialDCharSeq += "\""; rawStringInitialDCharSeq += "\"";
mRange.extraData = std::make_shared<QVariant>(rawStringInitialDCharSeq);
} }
break; break;
case ')': case ')':
if (mRange.state == RangeState::rsRawStringNotEscaping if (mRange.state == RangeState::rsRawStringNotEscaping) {
&& mLine.mid(mRun+1,mRawStringInitialDCharSeq.length()) == mRawStringInitialDCharSeq) { rawStringInitialDCharSeq = mRange.extraData->toString();
mRun = mRun+1+mRawStringInitialDCharSeq.length(); if ( mLine.mid(mRun+1,rawStringInitialDCharSeq.length()) == rawStringInitialDCharSeq) {
mRange.state = RangeState::rsUnknown; mRun = mRun+1+rawStringInitialDCharSeq.length();
return; mRange.state = RangeState::rsUnknown;
mRange.extraData = nullptr;
return;
}
} }
break; break;
} }
if (mRange.state == RangeState::rsRawString) if (mRange.state == RangeState::rsRawString)
mRawStringInitialDCharSeq += mLine[mRun]; rawStringInitialDCharSeq += mLine[mRun];
mRun+=1; mRun+=1;
} }
if (mRun>=mLineSize && mRange.state != RangeState::rsRawStringNotEscaping) if (mRun>=mLineSize && mRange.state != RangeState::rsRawStringNotEscaping)

View File

@ -159,8 +159,6 @@ private:
int mLeftBraces; int mLeftBraces;
int mRightBraces; int mRightBraces;
QString mRawStringInitialDCharSeq;
QSet<QString> mCustomTypeKeywords; QSet<QString> mCustomTypeKeywords;
PTokenAttribute mPreprocessorAttribute; PTokenAttribute mPreprocessorAttribute;

View File

@ -54,15 +54,11 @@ struct SyntaxState {
int parenthesisLevel; // current parenthesis embedding level (needed by rainbow color) int parenthesisLevel; // current parenthesis embedding level (needed by rainbow color)
// int leftBraces; // unpairing left braces in the current line ( needed by block folding) // int leftBraces; // unpairing left braces in the current line ( needed by block folding)
// int rightBraces; // unparing right braces in the current line (needed by block folding) // int rightBraces; // unparing right braces in the current line (needed by block folding)
QVector<IndentInfo> indents; QVector<IndentInfo> indents; // indents stack (needed by auto indent)
IndentInfo lastUnindent; IndentInfo lastUnindent;
// QVector<int> indents; // indents stack (needed by auto indent)
// int firstIndentThisLine; /* index of first indent that appended to the indents
// * stack at this line ( need by auto indent) */
// QVector<int> matchingIndents; /* the indent matched ( and removed )
// but not started at this line
// (need by auto indent) */
bool hasTrailingSpaces; bool hasTrailingSpaces;
std::shared_ptr<QVariant> extraData;
bool operator==(const SyntaxState& s2); bool operator==(const SyntaxState& s2);
IndentInfo getLastIndent(); IndentInfo getLastIndent();
IndentType getLastIndentType(); IndentType getLastIndentType();