Skip to content

Commit

Permalink
Fixed a bug in streamOutAsParagraph, where the size of the first line…
Browse files Browse the repository at this point in the history
… could be wrongly calculated under some circumstances
  • Loading branch information
LostInCompilation authored and phlptp committed Sep 27, 2024
1 parent 5318408 commit 70bb437
Showing 1 changed file with 2 additions and 10 deletions.
12 changes: 2 additions & 10 deletions include/CLI/impl/StringTools_inl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -578,14 +578,6 @@ CLI11_INLINE std::ostream &streamOutAsParagraph(std::ostream &out,
std::size_t paragraphWidth,
const std::string &linePrefix,
bool skipPrefixOnFirstLine) {
// Do we even have line wrapping?
const std::size_t firstLineSize = text.size() + (skipPrefixOnFirstLine ? 0 : linePrefix.size());
if(firstLineSize <= paragraphWidth) {
// No line wraps
out << (skipPrefixOnFirstLine ? "" : linePrefix) << text;
return out;
}

if(!skipPrefixOnFirstLine)
out << linePrefix; // First line prefix

Expand All @@ -597,13 +589,13 @@ CLI11_INLINE std::ostream &streamOutAsParagraph(std::ostream &out,
std::size_t charsWritten = 0;

while(iss >> word) {
if(word.size() + charsWritten > paragraphWidth) {
if(word.length() + charsWritten > paragraphWidth) {
out << std::endl << linePrefix;
charsWritten = 0;
}

out << word << " ";
charsWritten += word.size() + 1;
charsWritten += word.length() + 1;
}

if(!lss.eof())
Expand Down

0 comments on commit 70bb437

Please sign in to comment.