Don't leave open parentheses hanging at line breaks

This commit is contained in:
Randy Heit 2013-07-17 23:36:10 -05:00
parent c733e4229a
commit 9cf9226e86

View file

@ -34,6 +34,7 @@ public:
NestDepth = Column = 0;
WrapWidth = 72;
NeedSpace = false;
ConsecOpens = 0;
}
void Open(const char *label)
@ -43,8 +44,10 @@ public:
if (NeedSpace)
{
Str << ' ';
ConsecOpens = 0;
}
Str << '(';
ConsecOpens++;
if (label != NULL)
{
Str.AppendCStrPart(label, labellen);
@ -66,6 +69,15 @@ public:
// Don't break if not needed.
if (Column != NestDepth)
{
if (NeedSpace)
{
ConsecOpens = 0;
}
else
{ // Move hanging ( characters to the new line
Str.Truncate(long(Str.Len() - ConsecOpens));
NestDepth -= ConsecOpens;
}
Str << '\n';
Column = NestDepth;
NeedSpace = false;
@ -73,6 +85,14 @@ public:
{
Str.AppendFormat("%*s", NestDepth, "");
}
if (ConsecOpens > 0)
{
for (size_t i = 0; i < ConsecOpens; ++i)
{
Str << '(';
}
NestDepth += ConsecOpens;
}
}
}
bool CheckWrap(size_t len)
@ -143,6 +163,7 @@ private:
size_t NestDepth;
size_t Column;
size_t WrapWidth;
size_t ConsecOpens;
bool NeedSpace;
};