diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2014-05-09 15:09:38 -0700 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2014-05-09 15:09:38 -0700 |
commit | 19fbbfa8ffa594690d55dce80963d2016b4ec781 (patch) | |
tree | 67a1aeb4cccc3238b12dbc80f23506c1ad50f03f | |
parent | fec681be83c91268ee4db97f34ce4e47179316dd (diff) |
Code clean up
-rw-r--r-- | xml/parser.cxx | 35 | ||||
-rw-r--r-- | xml/parser.hxx | 73 | ||||
-rw-r--r-- | xml/parser.ixx | 35 |
3 files changed, 74 insertions, 69 deletions
diff --git a/xml/parser.cxx b/xml/parser.cxx index 6d5ab23..ef5683f 100644 --- a/xml/parser.cxx +++ b/xml/parser.cxx @@ -204,6 +204,41 @@ namespace xml istream::iostate old_state_; }; + parser::event_type parser:: + next () + { + if (state_ == state_next) + return next_ (false); + else + { + // If we previously peeked at start/end_element, then adjust + // state accordingly. + // + switch (event_) + { + case end_element: + { + if (!element_state_.empty () && + element_state_.back ().depth == depth_) + pop_element (); + + depth_--; + break; + } + case start_element: + { + depth_++; + break; + } + default: + break; + } + + state_ = state_next; + return event_; + } + } + const string& parser:: attribute (const qname_type& qn) const { diff --git a/xml/parser.hxx b/xml/parser.hxx index 7c2cc45..97a6291 100644 --- a/xml/parser.hxx +++ b/xml/parser.hxx @@ -12,7 +12,6 @@ #include <string> #include <iosfwd> #include <cstddef> // std::size_t -#include <cassert> #include <xml/details/config.hxx> // LIBSTUDXML_EXTERNAL_EXPAT @@ -138,41 +137,7 @@ namespace xml }; event_type - next () - { - //@@ Move to .ixx. - - if (state_ == state_next) - return next_ (false); - else - { - // If we previously peeked at start/end_element, then adjust - // state accordingly. - // - switch (event_) - { - case end_element: - { - if (!element_state_.empty () && - element_state_.back ().depth == depth_) - pop_element (); - - depth_--; - break; - } - case start_element: - { - depth_++; - break; - } - default: - break; - } - - state_ = state_next; - return event_; - } - } + next (); // Get the next event and make sure that it's what's expected. If it // is not, then throw an appropriate parsing exception. @@ -190,19 +155,7 @@ namespace xml next_expect (event_type, const std::string& ns, const std::string& name); event_type - peek () - { - //@@ move to .ixx - - if (state_ == state_peek) - return event_; - else - { - event_type e (next_ (true)); - state_ = state_peek; // Set it after the call to next_(). - return e; - } - } + peek (); // Return the even that was last returned by the call to next() or // peek(). @@ -304,28 +257,10 @@ namespace xml // Note that you cannot get/set content while peeking. // void - content (content_type c) - { - //@@ move to .ixx - - assert (state_ == state_next); - - if (!element_state_.empty () && element_state_.back ().depth == depth_) - element_state_.back ().content = c; - else - element_state_.push_back (element_entry (depth_, c)); - } + content (content_type); content_type - content () const - { - assert (state_ == state_next); - - return - !element_state_.empty () && element_state_.back ().depth == depth_ - ? element_state_.back ().content - : mixed; - } + content () const; // Versions that also set the content. Event type must be start_element. // diff --git a/xml/parser.ixx b/xml/parser.ixx index c0fe256..49d9c89 100644 --- a/xml/parser.ixx +++ b/xml/parser.ixx @@ -29,6 +29,19 @@ namespace xml init (); } + inline parser::event_type parser:: + peek () + { + if (state_ == state_peek) + return event_; + else + { + event_type e (next_ (true)); + state_ = state_peek; // Set it after the call to next_(). + return e; + } + } + template <typename T> inline T parser:: value () const @@ -173,6 +186,28 @@ namespace xml return element<T> (qname_type (n), dv); } + inline void parser:: + content (content_type c) + { + assert (state_ == state_next); + + if (!element_state_.empty () && element_state_.back ().depth == depth_) + element_state_.back ().content = c; + else + element_state_.push_back (element_entry (depth_, c)); + } + + inline parser::content_type parser:: + content () const + { + assert (state_ == state_next); + + return + !element_state_.empty () && element_state_.back ().depth == depth_ + ? element_state_.back ().content + : mixed; + } + inline const parser::element_entry* parser:: get_element () const { |