changes for unicode

This commit is contained in:
Wolfgang Gahr 2019-12-05 00:10:08 +01:00
parent 2e84218655
commit cd580bc3f5

View File

@ -1524,7 +1524,7 @@ namespace cxxopts
( (
const HelpOptionDetails& o, const HelpOptionDetails& o,
size_t start, size_t start,
size_t width, size_t allowed,
bool m_tab_expansion bool m_tab_expansion
) )
{ {
@ -1558,7 +1558,7 @@ namespace cxxopts
else if (*c == '\t') else if (*c == '\t')
{ {
auto skip = 8 - size % 8; auto skip = 8 - size % 8;
desc2.append(skip, ' '); stringAppend(desc2, skip, ' ');
size += skip; size += skip;
} }
else else
@ -1573,56 +1573,78 @@ namespace cxxopts
desc += " "; desc += " ";
auto current = std::begin(desc); auto current = std::begin(desc);
auto previous = current;
auto startLine = current; auto startLine = current;
auto lastSpace = current; auto lastSpace = current;
auto size = size_t{};
bool appendNewLine;
bool onlyWhiteSpace = true;
while (current != std::end(desc)) while (current != std::end(desc))
{ {
size_t addNewLine = 0; appendNewLine = false;
if (std::isblank(*previous))
{
lastSpace = current;
}
if (!std::isblank(*current))
{
onlyWhiteSpace = false;
}
while (*current == '\n') while (*current == '\n')
{ {
*current = ' '; previous = current;
++current; ++current;
++addNewLine; appendNewLine = true;
} }
if (addNewLine == 0 && current >= startLine + width)
if (!appendNewLine && size >= allowed)
{ {
if (lastSpace != startLine) if (lastSpace != startLine)
{ {
current = lastSpace; current = lastSpace;
previous = current;
} }
if (current + 1 != std::end(desc)) appendNewLine = true;
{
++addNewLine;
}
} }
if (addNewLine > 0)
if (appendNewLine)
{ {
stringAppend(result, startLine, current); stringAppend(result, startLine, current);
startLine = current; startLine = current;
lastSpace = current; lastSpace = current;
while (addNewLine-- > 0) if (*previous != '\n')
{ {
stringAppend(result, "\n"); stringAppend(result, "\n");
} }
if (current + 1 != std::end(desc)) stringAppend(result, start, ' ');
if (*previous != '\n')
{ {
stringAppend(result, start, ' '); stringAppend(result, lastSpace, current);
} }
onlyWhiteSpace = true;
size = 0;
} }
if (std::isblank(*current)) previous = current;
{
lastSpace = current + 1;
}
++current; ++current;
++size;
} }
//append whatever is left //append whatever is left but ignore whitespace
stringAppend(result, startLine, std::end(desc) - 1); if (!onlyWhiteSpace)
{
stringAppend(result, startLine, previous);
}
return result; return result;
} }