aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2014-05-08 12:47:35 -0700
committerBoris Kolpackov <boris@codesynthesis.com>2014-05-08 12:47:35 -0700
commitc86af7c94b9dc4e378a6f87b5cab3b7a571c9961 (patch)
tree3caeb224bad01642cdfba81c55c1961f8aef577d
parented23e3d3ca8b6780eef9ea0f04da978ccc885173 (diff)
Add parser::next_expect() version that also sets content model
-rw-r--r--tests/parser/driver.cxx11
-rw-r--r--xml/parser.hxx17
-rw-r--r--xml/parser.ixx30
3 files changed, 54 insertions, 4 deletions
diff --git a/tests/parser/driver.cxx b/tests/parser/driver.cxx
index e4ecd69..3414c0c 100644
--- a/tests/parser/driver.cxx
+++ b/tests/parser/driver.cxx
@@ -84,6 +84,17 @@ main ()
// cerr << e.what () << endl;
}
+ // Test next_expect() with content setting.
+ //
+ {
+ istringstream is ("<root> </root>");
+ parser p (is, "empty");
+
+ p.next_expect (parser::start_element, "root", parser::empty);
+ p.next_expect (parser::end_element);
+ p.next_expect (parser::eof);
+ }
+
// Test namespace declarations.
//
{
diff --git a/xml/parser.hxx b/xml/parser.hxx
index 1c9d389..c957b6d 100644
--- a/xml/parser.hxx
+++ b/xml/parser.hxx
@@ -178,10 +178,10 @@ namespace xml
next_expect (event_type);
void
- next_expect (event_type, const qname_type& qname);
+ next_expect (event_type, const std::string& name);
void
- next_expect (event_type, const std::string& name);
+ next_expect (event_type, const qname_type& qname);
void
next_expect (event_type, const std::string& ns, const std::string& name);
@@ -321,6 +321,19 @@ namespace xml
: mixed;
}
+ // Versions that also set the content. Event type must be start_element.
+ //
+ void
+ next_expect (event_type, const std::string& name, content_type);
+
+ void
+ next_expect (event_type, const qname_type& qname, content_type);
+
+ void
+ next_expect (event_type,
+ const std::string& ns, const std::string& name,
+ content_type);
+
private:
static void XMLCALL
start_element_ (void*, const XML_Char*, const XML_Char**);
diff --git a/xml/parser.ixx b/xml/parser.ixx
index 9041b0c..e58d2cf 100644
--- a/xml/parser.ixx
+++ b/xml/parser.ixx
@@ -90,13 +90,39 @@ namespace xml
inline void parser::
next_expect (event_type e, const qname_type& qn)
{
- return next_expect (e, qn.namespace_ (), qn.name ());
+ next_expect (e, qn.namespace_ (), qn.name ());
}
inline void parser::
next_expect (event_type e, const std::string& n)
{
- return next_expect (e, std::string (), n);
+ next_expect (e, std::string (), n);
+ }
+
+ inline void parser::
+ next_expect (event_type e, const qname_type& qn, content_type c)
+ {
+ next_expect (e, qn);
+ assert (e == start_element);
+ content (c);
+ }
+
+ inline void parser::
+ next_expect (event_type e, const std::string& n, content_type c)
+ {
+ next_expect (e, std::string (), n);
+ assert (e == start_element);
+ content (c);
+ }
+
+ inline void parser::
+ next_expect (event_type e,
+ const std::string& ns, const std::string& n,
+ content_type c)
+ {
+ next_expect (e, ns, n);
+ assert (e == start_element);
+ content (c);
}
inline const parser::element_entry* parser::