summaryrefslogtreecommitdiff
path: root/src/format.cc
diff options
context:
space:
mode:
authorJohn Wiegley <johnw@newartisans.com>2009-06-21 19:06:07 +0100
committerJohn Wiegley <johnw@newartisans.com>2009-06-21 19:06:07 +0100
commit8cb80185d515fe158a1858dd832ff9bc0f96e4a0 (patch)
tree51a29c09cb0b928bde19e389ec5cada3c83e753d /src/format.cc
parentc1307445c1ca691ef2d4df53d8b36c6ba6639d45 (diff)
downloadfork-ledger-8cb80185d515fe158a1858dd832ff9bc0f96e4a0.tar.gz
fork-ledger-8cb80185d515fe158a1858dd832ff9bc0f96e4a0.tar.bz2
fork-ledger-8cb80185d515fe158a1858dd832ff9bc0f96e4a0.zip
Restored the --truncate option, added baseline test
Diffstat (limited to 'src/format.cc')
-rw-r--r--src/format.cc15
1 files changed, 9 insertions, 6 deletions
diff --git a/src/format.cc b/src/format.cc
index 4066cabd..6620e5a4 100644
--- a/src/format.cc
+++ b/src/format.cc
@@ -38,6 +38,9 @@
namespace ledger {
+format_t::elision_style_t format_t::default_style = TRUNCATE_TRAILING;
+bool format_t::default_style_changed = false;
+
void format_t::element_t::dump(std::ostream& out) const
{
out << "Element: ";
@@ -386,22 +389,22 @@ string format_t::truncate(const unistring& ustr, std::size_t width,
std::ostringstream buf;
- elision_style_t style = TRUNCATE_TRAILING;
- if (account_abbrev_length > 0)
+ elision_style_t style = default_style;
+ if (account_abbrev_length > 0 && ! default_style_changed)
style = ABBREVIATE;
switch (style) {
case TRUNCATE_LEADING:
// This method truncates at the beginning.
- buf << ".." << ustr.extract(len - width, width);
+ buf << ".." << ustr.extract(len - (width - 2), width - 2);
break;
case TRUNCATE_MIDDLE:
// This method truncates in the middle.
- buf << ustr.extract(0, width / 2)
+ buf << ustr.extract(0, (width - 2) / 2)
<< ".."
- << ustr.extract(len - (width / 2 + width % 2),
- width / 2 + width % 2);
+ << ustr.extract(len - ((width - 2) / 2 + (width - 2) % 2),
+ (width - 2) / 2 + (width - 2) % 2);
break;
case ABBREVIATE: