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