From: Petr Machata Date: Fri, 1 Oct 2010 11:51:08 +0000 (+0200) Subject: dwarflint: Fix wrapping long words on indented lines X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=297d52f221a830aed5e6a457aefd61c6d3e67172;p=thirdparty%2Felfutils.git dwarflint: Fix wrapping long words on indented lines --- diff --git a/dwarflint/wrap.cc b/dwarflint/wrap.cc index 736091de9..37f47f6ed 100644 --- a/dwarflint/wrap.cc +++ b/dwarflint/wrap.cc @@ -98,8 +98,9 @@ wrap_str::wrap_str (std::string const &str, unsigned width) // While skipping back, we might end at the very beginning. If // that's the case, we have a word that doesn't fit user limit. - // Include it whole anyway. - if (space == last) + // Include it whole anyway. For newline, account for + // freshly-introduced indent. + if (space <= last + (newline ? indent : 0)) { space = pos; while (space < str.size () && !isspace (str[space])) @@ -131,10 +132,16 @@ wrap_str::join () const { std::string ret; for (const_iterator it = begin (); it != end (); ++it) - ret += it->build (_m_image) + "\n"; + ret += build (it) + "\n"; return ret; } +std::string +wrap_str::build (wrap_str::const_iterator it) const +{ + return it->build (_m_image); +} + namespace { class tests @@ -164,6 +171,9 @@ namespace assert (wrap ("\n\n", 5) == "\n\n"); assert (wrap ("\n\n", 0) == "\n\n"); assert (wrap ("ab\ncd ef gh ij", 5) == "ab\ncd ef\ngh ij\n"); + assert (wrap (" - abcd abbb accc", 3) == " - abcd\n abbb\n accc\n"); + assert (wrap (" -abcd abbb accc", 3) == " -abcd\n abbb\n accc\n"); + assert (wrap (" abcd abbb accc", 3) == " abcd\n abbb\n accc\n"); } } _; } diff --git a/dwarflint/wrap.hh b/dwarflint/wrap.hh index 50826b668..1c009f526 100644 --- a/dwarflint/wrap.hh +++ b/dwarflint/wrap.hh @@ -58,6 +58,7 @@ public: wrap_str (std::string const &str, unsigned width); std::string join () const; + std::string build (const_iterator it) const; }; #endif//DWARFLINT_WRAP_HH