diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/node.h | 2 | ||||
-rw-r--r-- | src/value.cc | 3 | ||||
-rw-r--r-- | src/xpath.cc | 2 | ||||
-rw-r--r-- | src/xpath.h | 46 |
4 files changed, 48 insertions, 5 deletions
@@ -259,7 +259,7 @@ public: } virtual value_t to_value() const { - return text(); + return value_t(text(), true); } void print(std::ostream& out) const; diff --git a/src/value.cc b/src/value.cc index 3965dfbd..b3578ae9 100644 --- a/src/value.cc +++ b/src/value.cc @@ -1565,6 +1565,9 @@ void value_t::print(std::ostream& out, const int first_width, case AMOUNT: case STRING: case POINTER: + // jww (2007-05-14): I need a version of this print just for XPath + // expression, since amounts and strings need to be output with + // special syntax. out << *this; break; diff --git a/src/xpath.cc b/src/xpath.cc index 6efa214a..4a20e402 100644 --- a/src/xpath.cc +++ b/src/xpath.cc @@ -2150,8 +2150,6 @@ void xpath_t::op_t::dump(std::ostream& out, const int depth) const } else { assert(! right()); } - } else { - assert(! left()); } } diff --git a/src/xpath.h b/src/xpath.h index f17d3ee8..f1fc0dcf 100644 --- a/src/xpath.h +++ b/src/xpath.h @@ -231,7 +231,7 @@ public: typedef std::list<element_t>::const_iterator element_iterator; - struct node_appender_t { + struct value_node_appender_t { value_t::sequence_t& sequence; node_appender_t(value_t::sequence_t& _sequence) : sequence(_sequence) {} @@ -245,7 +245,7 @@ public: void find_all(value_t::sequence_t& result, node_t& start, scope_t * scope) { - visit(start, scope, node_appender_t(result)); + visit(start, scope, value_node_appender_t(result)); } void visit(node_t& start, scope_t * scope, @@ -261,6 +261,36 @@ public: scope_t * scope, const function<void (node_t&)>& func); }; + class path_iterator_t + { + path_t path; + std::vector<node_t *> sequence; + + struct node_appender_t { + std::vector<node_t *>& sequence; + node_appender_t(std::vector<node_t *>& _sequence) + : sequence(_sequence) {} + void operator()(node_t& node) { + sequence.push_back(&node); + } + }; + + public: + typedef std::vector<node_t *>::iterator iterator; + typedef std::vector<node_t *>::const_iterator const_iterator; + + path_iterator_t(const xpath_t& path_expr, node_t& start, scope_t * scope) + : path(path_expr) { + path.visit(start, scope, node_appender_t(sequence)); + } + + iterator begin() { return sequence.begin(); } + const_iterator begin() const { return sequence.begin(); } + + iterator end() { return sequence.end(); } + const_iterator end() const { return sequence.end(); } + }; + struct op_t : public noncopyable { enum kind_t { @@ -704,6 +734,18 @@ public: return temp.calc(top, scope); } + void find_all(value_t::sequence_t& result, + node_t& start, scope_t * scope) { + path_t path(*this); + path.find_all(result, start, scope); + } + + void visit(node_t& start, scope_t * scope, + const function<void (node_t&)>& func) { + path_t path(*this); + path.visit(start, scope, func); + } + void print(std::ostream& out, xml::document_t& document) const { print(out, document, true, NULL, NULL, NULL); } |