aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2014-05-09 16:24:44 -0700
committerBoris Kolpackov <boris@codesynthesis.com>2014-05-09 16:24:44 -0700
commit41569646f9b5e70e53769e24d5e8efe45c2d24b4 (patch)
treeac973b8eedc7341793675746c67381d742b7cf36
parent850aca7f66a32f3301795c207926beef5165c45a (diff)
Move content model enum out of parser and into xml namespace
-rw-r--r--tests/parser/driver.cxx26
-rw-r--r--xml/content.hxx35
-rw-r--r--xml/parser.cxx18
-rw-r--r--xml/parser.hxx14
-rw-r--r--xml/parser.ixx2
5 files changed, 62 insertions, 33 deletions
diff --git a/tests/parser/driver.cxx b/tests/parser/driver.cxx
index 84ab2fa..2afe522 100644
--- a/tests/parser/driver.cxx
+++ b/tests/parser/driver.cxx
@@ -91,7 +91,7 @@ main ()
istringstream is ("<root> </root>");
parser p (is, "empty");
- p.next_expect (parser::start_element, "root", parser::empty);
+ p.next_expect (parser::start_element, "root", content::empty);
p.next_expect (parser::end_element);
p.next_expect (parser::eof);
}
@@ -247,7 +247,7 @@ main ()
parser::receive_default | parser::receive_attributes_event);
assert (p.next () == parser::start_element);
- p.content (parser::empty);
+ p.content (content::empty);
assert (p.next () == parser::start_attribute);
assert (p.next () == parser::characters && p.value () == " x ");
assert (p.next () == parser::end_attribute);
@@ -261,7 +261,7 @@ main ()
parser p (is, "empty");
assert (p.next () == parser::start_element);
- p.content (parser::empty);
+ p.content (content::empty);
p.next ();
assert (false);
}
@@ -277,7 +277,7 @@ main ()
parser p (is, "simple");
assert (p.next () == parser::start_element);
- p.content (parser::simple);
+ p.content (content::simple);
assert (p.next () == parser::characters && p.value () == " X ");
assert (p.next () == parser::end_element);
assert (p.next () == parser::eof);
@@ -289,7 +289,7 @@ main ()
parser p (is, "simple");
assert (p.next () == parser::start_element);
- p.content (parser::simple);
+ p.content (content::simple);
assert (p.next () == parser::characters && p.value () == " ? ");
p.next ();
assert (false);
@@ -310,7 +310,7 @@ main ()
assert (p.next () == parser::start_element);
p.next_expect (parser::start_namespace_decl);
- p.content (parser::simple);
+ p.content (content::simple);
assert (p.next () == parser::characters && p.value () == "123");
p.next_expect (parser::end_namespace_decl);
assert (p.next () == parser::end_element);
@@ -329,7 +329,7 @@ main ()
assert (p.next () == parser::start_element);
p.next_expect (parser::start_namespace_decl);
- p.content (parser::simple);
+ p.content (content::simple);
p.next ();
assert (false);
}
@@ -351,21 +351,21 @@ main ()
parser::receive_default | parser::receive_attributes_event);
assert (p.next () == parser::start_element); // root
- p.content (parser::complex);
+ p.content (content::complex);
assert (p.next () == parser::start_attribute);
assert (p.next () == parser::characters && p.value () == " x ");
assert (p.next () == parser::end_attribute);
assert (p.next () == parser::start_element); // nested
- p.content (parser::complex);
+ p.content (content::complex);
assert (p.next () == parser::start_element); // inner
- p.content (parser::empty);
+ p.content (content::empty);
assert (p.next () == parser::end_element); // inner
assert (p.next () == parser::start_element); // inner
- p.content (parser::simple);
+ p.content (content::simple);
assert (p.next () == parser::characters && p.value () == " X ");
assert (p.next () == parser::end_element); // inner
@@ -380,7 +380,7 @@ main ()
parser p (is, "complex");
assert (p.next () == parser::start_element);
- p.content (parser::complex);
+ p.content (content::complex);
assert (p.next () == parser::start_element);
assert (p.next () == parser::end_element);
p.next ();
@@ -413,7 +413,7 @@ main ()
"</root>");
parser p (is, "element");
- p.next_expect (parser::start_element, "root", parser::complex);
+ p.next_expect (parser::start_element, "root", content::complex);
p.next_expect (parser::start_element, "nested");
assert (p.element () == "X");
diff --git a/xml/content.hxx b/xml/content.hxx
new file mode 100644
index 0000000..575ef1d
--- /dev/null
+++ b/xml/content.hxx
@@ -0,0 +1,35 @@
+// file : xml/content.hxx
+// copyright : Copyright (c) 2013-2014 Code Synthesis Tools CC
+// license : MIT; see accompanying LICENSE file
+
+#ifndef XML_CONTENT_HXX
+#define XML_CONTENT_HXX
+
+#include <xml/details/pre.hxx>
+
+namespace xml
+{
+ // XML content model. C++11 enum class emulated for C++98.
+ //
+ struct content
+ {
+ enum value
+ {
+ // element characters whitespaces notes
+ empty, // no no ignored
+ simple, // no yes preserved content accumulated
+ complex, // yes no ignored
+ mixed // yes yes preserved
+ };
+
+ content (value v): v_ (v) {};
+ operator value () const {return v_;}
+
+ private:
+ value v_;
+ };
+}
+
+#include <xml/details/post.hxx>
+
+#endif // XML_CONTENT_HXX
diff --git a/xml/parser.cxx b/xml/parser.cxx
index ef5683f..28a17ce 100644
--- a/xml/parser.cxx
+++ b/xml/parser.cxx
@@ -147,11 +147,11 @@ namespace xml
//
switch (content ())
{
- case empty:
+ case content_type::empty:
throw parsing (*this, "character in empty content");
- case simple:
+ case content_type::simple:
throw parsing (*this, "element in simple content");
- case complex:
+ case content_type::complex:
throw parsing (*this, "character in complex content");
default:
assert (false);
@@ -321,7 +321,7 @@ namespace xml
string parser::
element ()
{
- content (simple);
+ content (content_type::simple);
string r;
// The content of the element can be empty in which case there
@@ -435,9 +435,9 @@ namespace xml
{
switch (e->content)
{
- case empty:
+ case content_type::empty:
throw parsing (*this, "element in empty content");
- case simple:
+ case content_type::simple:
throw parsing (*this, "element in simple content");
default:
break;
@@ -865,8 +865,8 @@ namespace xml
//
switch (cont)
{
- case empty:
- case complex:
+ case content_type::empty:
+ case content_type::complex:
{
for (int i (0); i != n; ++i)
{
@@ -909,7 +909,7 @@ namespace xml
// into a single event. To do this we will let the parser run
// until we reach the end of the element.
//
- if (cont == simple)
+ if (cont == content_type::simple)
p.accumulate_ = true;
else
XML_StopParser (p.p_, true);
diff --git a/xml/parser.hxx b/xml/parser.hxx
index cd33588..1d45e8c 100644
--- a/xml/parser.hxx
+++ b/xml/parser.hxx
@@ -29,6 +29,7 @@
#include <xml/forward.hxx>
#include <xml/qname.hxx>
+#include <xml/content.hxx>
#include <xml/exception.hxx>
#include <xml/details/export.hxx>
@@ -80,6 +81,8 @@ namespace xml
{
public:
typedef xml::qname qname_type;
+ typedef xml::content content_type;
+
typedef unsigned short feature_type;
// If both receive_attributes_event and receive_attributes_map are
@@ -246,15 +249,6 @@ namespace xml
// Optional content processing.
//
public:
- enum content_type
- {
- // element characters whitespaces notes
- empty, // no no ignored
- simple, // no yes preserved content accumulated
- complex, // yes no ignored
- mixed // yes yes preserved
- };
-
// Note that you cannot get/set content while peeking.
//
void
@@ -434,7 +428,7 @@ namespace xml
//
struct element_entry
{
- element_entry (std::size_t d, content_type c = mixed)
+ element_entry (std::size_t d, content_type c = content_type::mixed)
: depth (d), content (c), attr_unhandled_ (0) {}
std::size_t depth;
diff --git a/xml/parser.ixx b/xml/parser.ixx
index 49d9c89..e5656d4 100644
--- a/xml/parser.ixx
+++ b/xml/parser.ixx
@@ -205,7 +205,7 @@ namespace xml
return
!element_state_.empty () && element_state_.back ().depth == depth_
? element_state_.back ().content
- : mixed;
+ : content_type (content_type::mixed);
}
inline const parser::element_entry* parser::