# # # patch "commands.cc" # from [483ee28f4a155cf3bff85b6db3f77f1d85083eae] # to [83c0ca592e23b9cf6a61fb553f2abf10bd80abc4] # # patch "simplestring_xform.cc" # from [c365ced7930603fa9ac400b7d32eaf305ef31c3d] # to [cd4834f8b565f622d0a10d75904f5cb196e29d76] # ============================================================ --- commands.cc 483ee28f4a155cf3bff85b6db3f77f1d85083eae +++ commands.cc 83c0ca592e23b9cf6a61fb553f2abf10bd80abc4 @@ -309,19 +309,46 @@ namespace commands split_into_words(abstract, words); const size_t maxcol = terminal_width(); - for (vector::const_iterator i = words.begin(); - i != words.end(); i++) { + vector::const_iterator i = words.begin(); + while (i != words.end()) { string const & word = *i; if (col + word.length() + 1 >= maxcol) { out << std::endl; col = 0; + + // Skip empty words at the beginning of the line so that they do + // not mess with indentation. These "words" appear because we + // put two spaces between sentences, and one of these is + // transformed into a word. + // + // Another approach could be to simply omit these words (by + // modifying split_into_words) and then add this formatting (two + // spaces between sentences) from this algorithm. But then, + // other kinds of formatting could not be allowed in the original + // strings... (i.e., they'd disappear after we mangled them). + if (word == "") + { + do + i++; + while (i != words.end() && (*i) == ""); + if (i == words.end()) + break; + else + { + while (col++ < colabstract - 1) + out << ' '; + continue; + } + } + while (col++ < colabstract - 1) out << ' '; } out << ' ' << word; col += word.length() + 1; + i++; } out << std::endl; } ============================================================ --- simplestring_xform.cc c365ced7930603fa9ac400b7d32eaf305ef31c3d +++ simplestring_xform.cc cd4834f8b565f622d0a10d75904f5cb196e29d76 @@ -268,6 +268,15 @@ UNIT_TEST(simplestring_xform, split_into BOOST_CHECK(words.size() == 2); BOOST_CHECK(words[0] == "foo"); BOOST_CHECK(words[1] == "bar"); + + // describe() in commands.cc assumes this behavior. If it ever changes, + // remember to modify that function accordingly! + words.clear(); + split_into_words("foo bar", words); + BOOST_CHECK(words.size() == 3); + BOOST_CHECK(words[0] == "foo"); + BOOST_CHECK(words[1] == ""); + BOOST_CHECK(words[2] == "bar"); } UNIT_TEST(simplestring_xform, strip_ws)