mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-09 12:02:21 +02:00
Fixed reformatting of multiline string literals
This commit is contained in:
parent
a7ee9fde07
commit
23dd0f22e9
2 changed files with 68 additions and 2 deletions
|
@ -41,7 +41,7 @@ BfPrinter::BfPrinter(BfRootNode* rootNode, BfRootNode* sidechannelRootNode, BfRo
|
||||||
mCurTypeDecl = NULL;
|
mCurTypeDecl = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void BfPrinter::Write(const StringImpl& str)
|
void BfPrinter::Write(const StringView& str)
|
||||||
{
|
{
|
||||||
mOutString.Append(str);
|
mOutString.Append(str);
|
||||||
if (mCharMapping != NULL)
|
if (mCharMapping != NULL)
|
||||||
|
@ -867,6 +867,72 @@ void BfPrinter::Visit(BfLiteralExpression* literalExpr)
|
||||||
{
|
{
|
||||||
Visit(literalExpr->ToBase());
|
Visit(literalExpr->ToBase());
|
||||||
|
|
||||||
|
if (literalExpr->mValue.mTypeCode == BfTypeCode_CharPtr)
|
||||||
|
{
|
||||||
|
bool isMultiLine = false;
|
||||||
|
|
||||||
|
auto sourceData = literalExpr->GetSourceData();
|
||||||
|
for (int i = literalExpr->GetSrcStart(); i < (int)literalExpr->GetSrcEnd(); i++)
|
||||||
|
{
|
||||||
|
char c = sourceData->mSrc[i];
|
||||||
|
if (c == '\n')
|
||||||
|
{
|
||||||
|
isMultiLine = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (isMultiLine)
|
||||||
|
{
|
||||||
|
int srcLineStart = 0;
|
||||||
|
|
||||||
|
int checkIdx = literalExpr->GetSrcStart() - 1;
|
||||||
|
while (checkIdx >= 0)
|
||||||
|
{
|
||||||
|
char c = sourceData->mSrc[checkIdx];
|
||||||
|
if (c == '\n')
|
||||||
|
{
|
||||||
|
srcLineStart = checkIdx + 1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
checkIdx--;
|
||||||
|
}
|
||||||
|
|
||||||
|
int queuedSpaceCount = mQueuedSpaceCount;
|
||||||
|
FlushIndent();
|
||||||
|
|
||||||
|
for (int i = literalExpr->GetSrcStart(); i < (int)literalExpr->GetSrcEnd(); i++)
|
||||||
|
{
|
||||||
|
char c = sourceData->mSrc[i];
|
||||||
|
Write(c);
|
||||||
|
if (c == '\n')
|
||||||
|
{
|
||||||
|
i++;
|
||||||
|
int srcIdx = srcLineStart;
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
char srcC = sourceData->mSrc[srcIdx++];
|
||||||
|
char litC = sourceData->mSrc[i];
|
||||||
|
|
||||||
|
if (srcC != litC)
|
||||||
|
break;
|
||||||
|
if ((srcC != ' ') && (srcC != '\t'))
|
||||||
|
break;
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
|
||||||
|
mQueuedSpaceCount = queuedSpaceCount;
|
||||||
|
FlushIndent();
|
||||||
|
|
||||||
|
i--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
WriteSourceString(literalExpr);
|
WriteSourceString(literalExpr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -80,7 +80,7 @@ public:
|
||||||
public:
|
public:
|
||||||
bool CheckReplace(BfAstNode* astNode);
|
bool CheckReplace(BfAstNode* astNode);
|
||||||
void FlushIndent();
|
void FlushIndent();
|
||||||
void Write(const StringImpl& str);
|
void Write(const StringView& str);
|
||||||
void Write(BfAstNode* node, int start, int len);
|
void Write(BfAstNode* node, int start, int len);
|
||||||
void WriteSourceString(BfAstNode* node);
|
void WriteSourceString(BfAstNode* node);
|
||||||
void QueueVisitChild(BfAstNode* astNode);
|
void QueueVisitChild(BfAstNode* astNode);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue