document_builder_t is now working.
This commit is contained in:
parent
59fc3d1bdb
commit
687ee1a7c3
4 changed files with 21 additions and 17 deletions
|
|
@ -124,7 +124,6 @@ pkginclude_HEADERS = \
|
||||||
src/tuples.hpp \
|
src/tuples.hpp \
|
||||||
src/utils.h \
|
src/utils.h \
|
||||||
src/value.h \
|
src/value.h \
|
||||||
src/xml.h \
|
|
||||||
src/xpath.h
|
src/xpath.h
|
||||||
|
|
||||||
###############################################################################
|
###############################################################################
|
||||||
|
|
|
||||||
17
src/node.cc
17
src/node.cc
|
|
@ -60,17 +60,22 @@ void output_xml_string(std::ostream& out, const string& str)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void parent_node_t::print(std::ostream& out) const
|
void node_t::print_attributes(std::ostream& out) const
|
||||||
{
|
{
|
||||||
out << '<' << name();
|
|
||||||
if (attributes) {
|
if (attributes) {
|
||||||
typedef attributes_t::nth_index<0>::type attributes_by_order;
|
typedef attributes_t::nth_index<0>::type attributes_by_order;
|
||||||
foreach (const attr_pair& attr, attributes->get<0>())
|
foreach (const attr_pair& attr, attributes->get<0>())
|
||||||
out << ' ' << document().lookup_name(attr.first)
|
out << ' ' << *document().lookup_name(attr.first)
|
||||||
<< "=\"" << attr.second << "\"";
|
<< "=\"" << attr.second << "\"";
|
||||||
}
|
}
|
||||||
IF_VERIFY()
|
IF_VERIFY()
|
||||||
out << " type=\"parent_node_t\"";
|
out << " type=\"parent_node_t\"";
|
||||||
|
}
|
||||||
|
|
||||||
|
void parent_node_t::print(std::ostream& out) const
|
||||||
|
{
|
||||||
|
out << '<' << name();
|
||||||
|
print_attributes(out);
|
||||||
out << '>';
|
out << '>';
|
||||||
|
|
||||||
foreach (node_t * child, *this)
|
foreach (node_t * child, *this)
|
||||||
|
|
@ -83,13 +88,11 @@ void terminal_node_t::print(std::ostream& out) const
|
||||||
{
|
{
|
||||||
if (data.empty()) {
|
if (data.empty()) {
|
||||||
out << '<' << name();
|
out << '<' << name();
|
||||||
IF_VERIFY()
|
print_attributes(out);
|
||||||
out << " type=\"terminal_node_t\"";
|
|
||||||
out << " />";
|
out << " />";
|
||||||
} else {
|
} else {
|
||||||
out << '<' << name();
|
out << '<' << name();
|
||||||
IF_VERIFY()
|
print_attributes(out);
|
||||||
out << " type=\"terminal_node_t\"";
|
|
||||||
out << '>';
|
out << '>';
|
||||||
output_xml_string(out, text());
|
output_xml_string(out, text());
|
||||||
out << "</" << name() << '>';
|
out << "</" << name() << '>';
|
||||||
|
|
|
||||||
|
|
@ -104,6 +104,7 @@ public:
|
||||||
|
|
||||||
virtual value_t to_value() const = 0;
|
virtual value_t to_value() const = 0;
|
||||||
virtual void print(std::ostream& out) const = 0;
|
virtual void print(std::ostream& out) const = 0;
|
||||||
|
virtual void print_attributes(std::ostream& out) const;
|
||||||
|
|
||||||
const char * name() const;
|
const char * name() const;
|
||||||
nameid_t name_id() const {
|
nameid_t name_id() const {
|
||||||
|
|
@ -168,6 +169,7 @@ public:
|
||||||
T * create_child(nameid_t _name_id) {
|
T * create_child(nameid_t _name_id) {
|
||||||
T * child = new T(_name_id, document(), *this);
|
T * child = new T(_name_id, document(), *this);
|
||||||
children.push_back(child);
|
children.push_back(child);
|
||||||
|
return child;
|
||||||
}
|
}
|
||||||
|
|
||||||
void delete_child(node_t * child) {
|
void delete_child(node_t * child) {
|
||||||
|
|
|
||||||
|
|
@ -104,14 +104,14 @@ void parse_transaction(builder_t& builder,
|
||||||
*e = '\0';
|
*e = '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
builder.begin_node(ACCOUNT_PATH_NODE);
|
builder.begin_node(ACCOUNT_PATH_NODE, true);
|
||||||
builder.append_text(account_path);
|
builder.append_text(account_path);
|
||||||
builder.end_node(ACCOUNT_PATH_NODE);
|
builder.end_node(ACCOUNT_PATH_NODE);
|
||||||
|
|
||||||
// Parse the optional amount
|
// Parse the optional amount
|
||||||
|
|
||||||
if (amount) {
|
if (amount) {
|
||||||
builder.begin_node(AMOUNT_EXPR_NODE);
|
builder.begin_node(AMOUNT_EXPR_NODE, true);
|
||||||
builder.append_text(amount);
|
builder.append_text(amount);
|
||||||
builder.end_node(AMOUNT_EXPR_NODE);
|
builder.end_node(AMOUNT_EXPR_NODE);
|
||||||
}
|
}
|
||||||
|
|
@ -119,7 +119,7 @@ void parse_transaction(builder_t& builder,
|
||||||
// Parse the optional note
|
// Parse the optional note
|
||||||
|
|
||||||
if (note) {
|
if (note) {
|
||||||
builder.begin_node(NOTE_NODE);
|
builder.begin_node(NOTE_NODE, true);
|
||||||
builder.append_text(note);
|
builder.append_text(note);
|
||||||
builder.end_node(NOTE_NODE);
|
builder.end_node(NOTE_NODE);
|
||||||
}
|
}
|
||||||
|
|
@ -246,7 +246,7 @@ void parse_entry(std::istream& in,
|
||||||
|
|
||||||
builder.begin_node(ENTRY_NODE);
|
builder.begin_node(ENTRY_NODE);
|
||||||
|
|
||||||
builder.begin_node(PAYEE_NODE);
|
builder.begin_node(PAYEE_NODE, true);
|
||||||
assert(payee);
|
assert(payee);
|
||||||
builder.append_text(*payee != '\0' ? payee : "<Unspecified payee>");
|
builder.append_text(*payee != '\0' ? payee : "<Unspecified payee>");
|
||||||
builder.end_node(PAYEE_NODE, end_of_line);
|
builder.end_node(PAYEE_NODE, end_of_line);
|
||||||
|
|
@ -319,7 +319,7 @@ void textual_parser_t::parse(std::istream& in,
|
||||||
|
|
||||||
builder.push_attr(TIME_ATTR, date);
|
builder.push_attr(TIME_ATTR, date);
|
||||||
builder.push_attr(ACCOUNT_ATTR, p);
|
builder.push_attr(ACCOUNT_ATTR, p);
|
||||||
builder.begin_node(CHECKIN_NODE);
|
builder.begin_node(CHECKIN_NODE, true);
|
||||||
builder.append_text(n);
|
builder.append_text(n);
|
||||||
builder.end_node(CHECKIN_NODE, end_of_line);
|
builder.end_node(CHECKIN_NODE, end_of_line);
|
||||||
break;
|
break;
|
||||||
|
|
@ -334,7 +334,7 @@ void textual_parser_t::parse(std::istream& in,
|
||||||
|
|
||||||
builder.push_attr(TIME_ATTR, date);
|
builder.push_attr(TIME_ATTR, date);
|
||||||
builder.push_attr(ACCOUNT_ATTR, p);
|
builder.push_attr(ACCOUNT_ATTR, p);
|
||||||
builder.begin_node(CHECKIN_NODE);
|
builder.begin_node(CHECKIN_NODE, true);
|
||||||
builder.append_text(n);
|
builder.append_text(n);
|
||||||
builder.end_node(CHECKIN_NODE, end_of_line);
|
builder.end_node(CHECKIN_NODE, end_of_line);
|
||||||
break;
|
break;
|
||||||
|
|
@ -430,7 +430,7 @@ void textual_parser_t::parse(std::istream& in,
|
||||||
|
|
||||||
case '=': { // automated entry
|
case '=': { // automated entry
|
||||||
builder.begin_node(AUTO_ENTRY_NODE);
|
builder.begin_node(AUTO_ENTRY_NODE);
|
||||||
builder.begin_node(RULE_NODE);
|
builder.begin_node(RULE_NODE, true);
|
||||||
builder.append_text(skip_ws(line + 1));
|
builder.append_text(skip_ws(line + 1));
|
||||||
builder.end_node(RULE_NODE);
|
builder.end_node(RULE_NODE);
|
||||||
|
|
||||||
|
|
@ -445,7 +445,7 @@ void textual_parser_t::parse(std::istream& in,
|
||||||
|
|
||||||
case '~': // period entry
|
case '~': // period entry
|
||||||
builder.begin_node(PERIOD_ENTRY_NODE);
|
builder.begin_node(PERIOD_ENTRY_NODE);
|
||||||
builder.begin_node(PERIOD_NODE);
|
builder.begin_node(PERIOD_NODE, true);
|
||||||
builder.append_text(skip_ws(line + 1));
|
builder.append_text(skip_ws(line + 1));
|
||||||
builder.end_node(PERIOD_NODE);
|
builder.end_node(PERIOD_NODE);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue