Keep notes on their own line if parsed that way

This commit is contained in:
John Wiegley 2012-02-26 02:18:22 -06:00
parent 40ab813080
commit 4cf95497f9
3 changed files with 18 additions and 9 deletions

View file

@ -100,9 +100,10 @@ private:
class item_t : public supports_flags<uint_least16_t>, public scope_t
{
public:
#define ITEM_NORMAL 0x00 // no flags at all, a basic posting
#define ITEM_GENERATED 0x01 // posting was not found in a journal
#define ITEM_TEMP 0x02 // posting is a managed temporary
#define ITEM_NORMAL 0x00 // no flags at all, a basic posting
#define ITEM_GENERATED 0x01 // posting was not found in a journal
#define ITEM_TEMP 0x02 // posting is a managed temporary
#define ITEM_NOTE_ON_NEXT_LINE 0x04 // did we see a note on the next line?
enum state_t { UNCLEARED = 0, CLEARED, PENDING };
@ -117,7 +118,8 @@ public:
optional<string_map> metadata;
item_t(flags_t _flags = ITEM_NORMAL, const optional<string>& _note = none)
: supports_flags<uint_least16_t>(_flags), _state(UNCLEARED), note(_note)
: supports_flags<uint_least16_t>(_flags), _state(UNCLEARED),
note(_note)
{
TRACE_CTOR(item_t, "flags_t, const string&");
}

View file

@ -43,12 +43,15 @@ namespace ledger {
namespace {
void print_note(std::ostream& out,
const string& note,
const bool note_on_next_line,
const std::size_t columns,
const std::size_t prior_width)
{
// The 4 is for four leading spaces at the beginning of the posting, and
// the 3 is for two spaces and a semi-colon before the note.
if (columns > 0 && note.length() > columns - (prior_width + 3))
// The 3 is for two spaces and a semi-colon before the note.
if (note_on_next_line ||
(columns > 0 &&
(columns <= prior_width + 3 ||
note.length() > columns - (prior_width + 3))))
out << "\n ;";
else
out << " ;";
@ -103,7 +106,8 @@ namespace {
static_cast<std::size_t>(report.HANDLER(columns_).value.to_long()) : 80);
if (xact.note)
print_note(out, *xact.note, columns, unistring(leader).length());
print_note(out, *xact.note, xact.has_flags(ITEM_NOTE_ON_NEXT_LINE),
columns, unistring(leader).length());
out << '\n';
if (xact.metadata) {
@ -226,7 +230,8 @@ namespace {
}
if (post->note)
print_note(out, *post->note, columns, 4 + account_width);
print_note(out, *post->note, post->has_flags(ITEM_NOTE_ON_NEXT_LINE),
columns, 4 + account_width);
out << '\n';
}
}

View file

@ -577,6 +577,7 @@ void instance_t::automated_xact_directive(char * line)
// This is a trailing note, and possibly a metadata info tag
item->append_note(p + 1, context.scope, true);
item->add_flags(ITEM_NOTE_ON_NEXT_LINE);
item->pos->end_pos = curr_pos;
item->pos->end_line++;
@ -1529,6 +1530,7 @@ xact_t * instance_t::parse_xact(char * line,
if (*p == ';') {
// This is a trailing note, and possibly a metadata info tag
item->append_note(p + 1, context.scope, true);
item->add_flags(ITEM_NOTE_ON_NEXT_LINE);
item->pos->end_pos = curr_pos;
item->pos->end_line++;
}