From 630585599786427e25d9758638ff3b7d74680b4f Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Fri, 16 Mar 2012 05:30:34 -0500 Subject: Don't allow trailing ws in abbrev. account segments Fixes #358 --- src/format.cc | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'src/format.cc') diff --git a/src/format.cc b/src/format.cc index 79f94869..8c3cbc14 100644 --- a/src/format.cc +++ b/src/format.cc @@ -599,6 +599,7 @@ string format_t::truncate(const unistring& ustr, index = 0; #endif std::size_t counter = lens.size(); + std::list::iterator x = parts.begin(); for (std::list::iterator i = lens.begin(); i != lens.end(); i++) { @@ -628,12 +629,21 @@ string format_t::truncate(const unistring& ustr, if (adjust > 0) { DEBUG("format.abbrev", "Reducing segment " << ++index << " by " << adjust << " chars"); + while (std::isspace((*x)[*i - adjust - 1]) && adjust < *i) { + DEBUG("format.abbrev", + "Segment ends in whitespace, adjusting down"); + ++adjust; + } (*i) -= adjust; DEBUG("format.abbrev", "Segment " << index << " is now " << *i << " chars wide"); - overflow -= adjust; + if (adjust > overflow) + overflow = 0; + else + overflow -= adjust; DEBUG("format.abbrev", "Overflow is now " << overflow << " chars"); } + ++x; } DEBUG("format.abbrev", "Overflow ending this time at " << overflow << " chars"); -- cgit v1.2.3