mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-10 20:42:21 +02:00
Made comment wrapping smarter
This commit is contained in:
parent
aed9fb5d36
commit
b0f69ae37d
1 changed files with 44 additions and 0 deletions
|
@ -374,6 +374,50 @@ void BfPrinter::WriteIgnoredNode(BfAstNode* node)
|
|||
{
|
||||
Visit((BfAstNode*)node);
|
||||
startIdx = node->mSrcStart;
|
||||
|
||||
if (doWrap)
|
||||
{
|
||||
bool wantWrap = false;
|
||||
|
||||
int spacedWordCount = 0;
|
||||
bool inQuotes = false;
|
||||
auto src = astNodeSrc->mSrc;
|
||||
bool isDefinitelyCode = false;
|
||||
bool hadNonSlash = false;
|
||||
|
||||
for (int i = node->mSrcStart + 1; i < node->mSrcEnd - 1; i++)
|
||||
{
|
||||
char c = src[i];
|
||||
if (c != '/')
|
||||
hadNonSlash = true;
|
||||
if (inQuotes)
|
||||
{
|
||||
if (c == '\\')
|
||||
{
|
||||
i++;
|
||||
}
|
||||
else if (c == '\"')
|
||||
{
|
||||
inQuotes = false;
|
||||
}
|
||||
}
|
||||
else if (c == '"')
|
||||
{
|
||||
inQuotes = true;
|
||||
}
|
||||
else if (c == ' ')
|
||||
{
|
||||
if ((isalpha(src[i - 1])) && (isalpha(src[i + 1])))
|
||||
spacedWordCount++;
|
||||
}
|
||||
else if ((c == '/') && (src[i - 1] == '/') && (hadNonSlash))
|
||||
isDefinitelyCode = true;
|
||||
}
|
||||
|
||||
// If this doesn't look like a sentence then don't try to word wrap
|
||||
if ((isDefinitelyCode) || (spacedWordCount < 4))
|
||||
doWrap = false;
|
||||
}
|
||||
}
|
||||
|
||||
int lineEmittedChars = 0;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue