mirror of
https://github.com/pocoproject/poco.git
synced 2025-10-28 19:51:58 +01:00
fixes for style, documentation and consistency, part I. More coming...
This commit is contained in:
@@ -9,70 +9,69 @@
|
||||
//
|
||||
// Definition of the XMLStreamParser class.
|
||||
//
|
||||
// Copyright (c) 2004-2015, Applied Informatics Software Engineering GmbH.
|
||||
// Copyright (c) 2015, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Based on libstudxml (http://www.codesynthesis.com/projects/libstudxml/).
|
||||
// Copyright (c) 2009-2013 Code Synthesis Tools CC.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
// copyright : Copyright (c) 2009-2013 Code Synthesis Tools CC
|
||||
// license : MIT; see accompanying LICENSE file
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/XML/XMLStreamParser.h"
|
||||
#include <new> // std::bad_alloc
|
||||
#include <new>
|
||||
#include <cassert>
|
||||
#include <cstring> // std::strchr
|
||||
#include <cstring>
|
||||
#include <istream>
|
||||
#include <ostream>
|
||||
#include <sstream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
namespace Poco
|
||||
{
|
||||
namespace XML
|
||||
{
|
||||
namespace Poco {
|
||||
namespace XML {
|
||||
|
||||
struct stream_exception_controller
|
||||
|
||||
struct StreamExceptionController
|
||||
{
|
||||
~stream_exception_controller()
|
||||
StreamExceptionController(std::istream& is):
|
||||
_istr(is),
|
||||
_oldState(_istr.exceptions())
|
||||
{
|
||||
istream::iostate s = is_.rdstate();
|
||||
s &= ~istream::failbit;
|
||||
_istr.exceptions(_oldState & ~std::istream::failbit);
|
||||
}
|
||||
|
||||
~StreamExceptionController()
|
||||
{
|
||||
std::istream::iostate s = _istr.rdstate();
|
||||
s &= ~std::istream::failbit;
|
||||
|
||||
// If our error state (sans failbit) intersects with the
|
||||
// exception state then that means we have an active
|
||||
// exception and changing error/exception state will
|
||||
// cause another to be thrown.
|
||||
//
|
||||
if (!(old_state_ & s))
|
||||
if (!(_oldState & s))
|
||||
{
|
||||
// Clear failbit if it was caused by eof.
|
||||
//
|
||||
if (is_.fail() && is_.eof())
|
||||
is_.clear(s);
|
||||
if (_istr.fail() && _istr.eof())
|
||||
_istr.clear(s);
|
||||
|
||||
is_.exceptions(old_state_);
|
||||
_istr.exceptions(_oldState);
|
||||
}
|
||||
}
|
||||
|
||||
stream_exception_controller(istream& is)
|
||||
: is_(is), old_state_(is_.exceptions())
|
||||
{
|
||||
is_.exceptions(old_state_ & ~istream::failbit);
|
||||
}
|
||||
private:
|
||||
StreamExceptionController(const StreamExceptionController&);
|
||||
StreamExceptionController& operator = (const StreamExceptionController&);
|
||||
|
||||
private:
|
||||
stream_exception_controller(const stream_exception_controller&);
|
||||
|
||||
stream_exception_controller&
|
||||
operator=(const stream_exception_controller&);
|
||||
|
||||
private:
|
||||
istream& is_;
|
||||
istream::iostate old_state_;
|
||||
std::istream& _istr;
|
||||
std::istream::iostate _oldState;
|
||||
};
|
||||
|
||||
|
||||
static const char* parser_event_str[] =
|
||||
static const char* parserEventStrings[] =
|
||||
{
|
||||
"start element",
|
||||
"end element",
|
||||
@@ -85,22 +84,26 @@ static const char* parser_event_str[] =
|
||||
};
|
||||
|
||||
|
||||
ostream& operator<<(ostream& os, XMLStreamParser::EventType e)
|
||||
std::ostream& operator << (std::ostream& os, XMLStreamParser::EventType e)
|
||||
{
|
||||
return os << parser_event_str[e];
|
||||
return os << parserEventStrings[e];
|
||||
}
|
||||
|
||||
|
||||
XMLStreamParser::XMLStreamParser(std::istream& is, const std::string& iname, FeatureType f)
|
||||
: _size(0), _inputName(iname), feature_(f)
|
||||
XMLStreamParser::XMLStreamParser(std::istream& is, const std::string& iname, FeatureType f):
|
||||
_size(0),
|
||||
_inputName(iname),
|
||||
_feature(f)
|
||||
{
|
||||
_data.is = &is;
|
||||
init();
|
||||
}
|
||||
|
||||
|
||||
XMLStreamParser::XMLStreamParser(const void* data, std::size_t size, const std::string& iname, FeatureType f)
|
||||
: _size(size), _inputName(iname), feature_(f)
|
||||
XMLStreamParser::XMLStreamParser(const void* data, std::size_t size, const std::string& iname, FeatureType f):
|
||||
_size(size),
|
||||
_inputName(iname),
|
||||
_feature(f)
|
||||
{
|
||||
assert(data != 0 && size != 0);
|
||||
|
||||
@@ -111,64 +114,63 @@ XMLStreamParser::XMLStreamParser(const void* data, std::size_t size, const std::
|
||||
|
||||
XMLStreamParser::~XMLStreamParser()
|
||||
{
|
||||
if (p_ != 0)
|
||||
XML_ParserFree(p_);
|
||||
if (_parser) XML_ParserFree(_parser);
|
||||
}
|
||||
|
||||
|
||||
void XMLStreamParser::init()
|
||||
{
|
||||
depth_ = 0;
|
||||
_depth = 0;
|
||||
_parserState = state_next;
|
||||
_currentEvent = Eof;
|
||||
queue_ = Eof;
|
||||
_queue = Eof;
|
||||
|
||||
_qualifiedName = &qname_;
|
||||
pvalue_ = &value_;
|
||||
_qualifiedName = &_qname;
|
||||
_pvalue = &_value;
|
||||
|
||||
_line = 0;
|
||||
_column = 0;
|
||||
|
||||
_currentAttributeIndex = 0;
|
||||
start_ns_i_ = 0;
|
||||
end_ns_i_ = 0;
|
||||
_startNamespaceIndex = 0;
|
||||
_endNamespaceIndex = 0;
|
||||
|
||||
if ((feature_ & RECEIVE_ATTRIBUTE_MAP) != 0 && (feature_ & RECEIVE_ATTRIBUTES_EVENT) != 0)
|
||||
feature_ &= ~RECEIVE_ATTRIBUTE_MAP;
|
||||
if ((_feature & RECEIVE_ATTRIBUTE_MAP) != 0 && (_feature & RECEIVE_ATTRIBUTES_EVENT) != 0)
|
||||
_feature &= ~RECEIVE_ATTRIBUTE_MAP;
|
||||
|
||||
// Allocate the XMLStreamParser. Make sure nothing else can throw after
|
||||
// this call since otherwise we will leak it.
|
||||
//
|
||||
p_ = XML_ParserCreateNS(0, XML_Char(' '));
|
||||
_parser = XML_ParserCreateNS(0, XML_Char(' '));
|
||||
|
||||
if (p_ == 0)
|
||||
throw bad_alloc();
|
||||
if (_parser == 0)
|
||||
throw std::bad_alloc();
|
||||
|
||||
// Get prefixes in addition to namespaces and local names.
|
||||
//
|
||||
XML_SetReturnNSTriplet(p_, true);
|
||||
XML_SetReturnNSTriplet(_parser, true);
|
||||
|
||||
// Set handlers.
|
||||
//
|
||||
XML_SetUserData(p_, this);
|
||||
XML_SetUserData(_parser, this);
|
||||
|
||||
if ((feature_ & RECEIVE_ELEMENTS) != 0)
|
||||
if ((_feature & RECEIVE_ELEMENTS) != 0)
|
||||
{
|
||||
XML_SetStartElementHandler(p_, &start_element_);
|
||||
XML_SetEndElementHandler(p_, &end_element_);
|
||||
XML_SetStartElementHandler(_parser, &start_element_);
|
||||
XML_SetEndElementHandler(_parser, &end_element_);
|
||||
}
|
||||
|
||||
if ((feature_ & RECEIVE_CHARACTERS) != 0)
|
||||
XML_SetCharacterDataHandler(p_, &characters_);
|
||||
if ((_feature & RECEIVE_CHARACTERS) != 0)
|
||||
XML_SetCharacterDataHandler(_parser, &characters_);
|
||||
|
||||
if ((feature_ & RECEIVE_NAMESPACE_DECLS) != 0)
|
||||
XML_SetNamespaceDeclHandler(p_, &start_namespace_decl_, &end_namespace_decl_);
|
||||
if ((_feature & RECEIVE_NAMESPACE_DECLS) != 0)
|
||||
XML_SetNamespaceDeclHandler(_parser, &start_namespace_decl_, &end_namespace_decl_);
|
||||
}
|
||||
|
||||
|
||||
void XMLStreamParser::handle_error()
|
||||
{
|
||||
XML_Error e(XML_GetErrorCode(p_));
|
||||
XML_Error e(XML_GetErrorCode(_parser));
|
||||
|
||||
if (e == XML_ERROR_ABORTED)
|
||||
{
|
||||
@@ -188,7 +190,7 @@ void XMLStreamParser::handle_error()
|
||||
}
|
||||
}
|
||||
else
|
||||
throw XMLStreamParserException(_inputName, XML_GetCurrentLineNumber(p_), XML_GetCurrentColumnNumber(p_), XML_ErrorString(e));
|
||||
throw XMLStreamParserException(_inputName, XML_GetCurrentLineNumber(_parser), XML_GetCurrentColumnNumber(_parser), XML_ErrorString(e));
|
||||
}
|
||||
|
||||
|
||||
@@ -205,15 +207,15 @@ XMLStreamParser::EventType XMLStreamParser::next()
|
||||
{
|
||||
case EndElement:
|
||||
{
|
||||
if (!_elementState.empty() && _elementState.back().depth == depth_)
|
||||
if (!_elementState.empty() && _elementState.back().depth == _depth)
|
||||
popElement();
|
||||
|
||||
depth_--;
|
||||
_depth--;
|
||||
break;
|
||||
}
|
||||
case StartElement:
|
||||
{
|
||||
depth_++;
|
||||
_depth++;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
@@ -226,18 +228,18 @@ XMLStreamParser::EventType XMLStreamParser::next()
|
||||
}
|
||||
|
||||
|
||||
const string& XMLStreamParser::attribute(const QName& qn) const
|
||||
const std::string& XMLStreamParser::attribute(const QName& qn) const
|
||||
{
|
||||
if (const ElementEntry* e = getElement())
|
||||
{
|
||||
AttributeMapType::const_iterator i(e->attr_map_.find(qn));
|
||||
AttributeMapType::const_iterator i(e->attributeMap.find(qn));
|
||||
|
||||
if (i != e->attr_map_.end())
|
||||
if (i != e->attributeMap.end())
|
||||
{
|
||||
if (!i->second.handled)
|
||||
{
|
||||
i->second.handled = true;
|
||||
e->attributesUnhandled_--;
|
||||
e->attributesUnhandled--;
|
||||
}
|
||||
return i->second.value;
|
||||
}
|
||||
@@ -247,18 +249,18 @@ const string& XMLStreamParser::attribute(const QName& qn) const
|
||||
}
|
||||
|
||||
|
||||
string XMLStreamParser::attribute(const QName& qn, const string& dv) const
|
||||
std::string XMLStreamParser::attribute(const QName& qn, const std::string& dv) const
|
||||
{
|
||||
if (const ElementEntry* e = getElement())
|
||||
{
|
||||
AttributeMapType::const_iterator i(e->attr_map_.find(qn));
|
||||
AttributeMapType::const_iterator i(e->attributeMap.find(qn));
|
||||
|
||||
if (i != e->attr_map_.end())
|
||||
if (i != e->attributeMap.end())
|
||||
{
|
||||
if (!i->second.handled)
|
||||
{
|
||||
i->second.handled = true;
|
||||
e->attributesUnhandled_--;
|
||||
e->attributesUnhandled--;
|
||||
}
|
||||
return i->second.value;
|
||||
}
|
||||
@@ -272,14 +274,14 @@ bool XMLStreamParser::attributePresent(const QName& qn) const
|
||||
{
|
||||
if (const ElementEntry* e = getElement())
|
||||
{
|
||||
AttributeMapType::const_iterator i(e->attr_map_.find(qn));
|
||||
AttributeMapType::const_iterator i(e->attributeMap.find(qn));
|
||||
|
||||
if (i != e->attr_map_.end())
|
||||
if (i != e->attributeMap.end())
|
||||
{
|
||||
if (!i->second.handled)
|
||||
{
|
||||
i->second.handled = true;
|
||||
e->attributesUnhandled_--;
|
||||
e->attributesUnhandled--;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -292,21 +294,21 @@ bool XMLStreamParser::attributePresent(const QName& qn) const
|
||||
void XMLStreamParser::nextExpect(EventType e)
|
||||
{
|
||||
if (next() != e)
|
||||
throw XMLStreamParserException(*this, string(parser_event_str[e]) + " expected");
|
||||
throw XMLStreamParserException(*this, std::string(parserEventStrings[e]) + " expected");
|
||||
}
|
||||
|
||||
|
||||
void XMLStreamParser::nextExpect(EventType e, const string& ns, const string& n)
|
||||
void XMLStreamParser::nextExpect(EventType e, const std::string& ns, const std::string& n)
|
||||
{
|
||||
if (next() != e || namespace_() != ns || name() != n)
|
||||
throw XMLStreamParserException(*this, string(parser_event_str[e]) + " '" + QName(ns, n).string() + "' expected");
|
||||
if (next() != e || namespaceURI() != ns || localName() != n)
|
||||
throw XMLStreamParserException(*this, std::string(parserEventStrings[e]) + " '" + QName(ns, n).string() + "' expected");
|
||||
}
|
||||
|
||||
|
||||
string XMLStreamParser::element()
|
||||
std::string XMLStreamParser::element()
|
||||
{
|
||||
content(Content::Simple);
|
||||
string r;
|
||||
std::string r;
|
||||
|
||||
// The content of the element can be empty in which case there
|
||||
// will be no characters event.
|
||||
@@ -327,7 +329,7 @@ string XMLStreamParser::element()
|
||||
}
|
||||
|
||||
|
||||
string XMLStreamParser::element(const QName& qn, const string& dv)
|
||||
std::string XMLStreamParser::element(const QName& qn, const std::string& dv)
|
||||
{
|
||||
if (peek() == StartElement && getQName() == qn)
|
||||
{
|
||||
@@ -339,7 +341,7 @@ string XMLStreamParser::element(const QName& qn, const string& dv)
|
||||
}
|
||||
|
||||
|
||||
const XMLStreamParser::ElementEntry* XMLStreamParser::get_element_() const
|
||||
const XMLStreamParser::ElementEntry* XMLStreamParser::getElementImpl() const
|
||||
{
|
||||
// The start_element_() Expat handler may have already provisioned
|
||||
// an entry in the element stack. In this case, we need to get the
|
||||
@@ -348,12 +350,12 @@ const XMLStreamParser::ElementEntry* XMLStreamParser::get_element_() const
|
||||
const ElementEntry* r(0);
|
||||
ElementState::size_type n(_elementState.size() - 1);
|
||||
|
||||
if (_elementState[n].depth == depth_)
|
||||
if (_elementState[n].depth == _depth)
|
||||
r = &_elementState[n];
|
||||
else if (n != 0 && _elementState[n].depth > depth_)
|
||||
else if (n != 0 && _elementState[n].depth > _depth)
|
||||
{
|
||||
n--;
|
||||
if (_elementState[n].depth == depth_)
|
||||
if (_elementState[n].depth == _depth)
|
||||
r = &_elementState[n];
|
||||
}
|
||||
|
||||
@@ -366,11 +368,11 @@ void XMLStreamParser::popElement()
|
||||
// Make sure there are no unhandled attributes left.
|
||||
//
|
||||
const ElementEntry& e(_elementState.back());
|
||||
if (e.attributesUnhandled_ != 0)
|
||||
if (e.attributesUnhandled != 0)
|
||||
{
|
||||
// Find the first unhandled attribute and report it.
|
||||
//
|
||||
for (AttributeMapType::const_iterator i(e.attr_map_.begin()); i != e.attr_map_.end(); ++i)
|
||||
for (AttributeMapType::const_iterator i(e.attributeMap.begin()); i != e.attributeMap.end(); ++i)
|
||||
{
|
||||
if (!i->second.handled)
|
||||
throw XMLStreamParserException(*this, "unexpected attribute '" + i->first.string() + "'");
|
||||
@@ -403,10 +405,10 @@ XMLStreamParser::EventType XMLStreamParser::next_(bool peek)
|
||||
//
|
||||
if (!peek)
|
||||
{
|
||||
if (!_elementState.empty() && _elementState.back().depth == depth_)
|
||||
if (!_elementState.empty() && _elementState.back().depth == _depth)
|
||||
popElement();
|
||||
|
||||
depth_--;
|
||||
_depth--;
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -428,7 +430,7 @@ XMLStreamParser::EventType XMLStreamParser::next_(bool peek)
|
||||
// If this is a peek, then delay adjusting the depth.
|
||||
//
|
||||
if (!peek)
|
||||
depth_++;
|
||||
_depth++;
|
||||
|
||||
break;
|
||||
}
|
||||
@@ -444,7 +446,7 @@ XMLStreamParser::EventType XMLStreamParser::next_body()
|
||||
{
|
||||
// See if we have any start namespace declarations we need to return.
|
||||
//
|
||||
if (start_ns_i_ < start_ns_.size())
|
||||
if (_startNamespaceIndex < _startNamespace.size())
|
||||
{
|
||||
// Based on the previous event determine what's the next one must be.
|
||||
//
|
||||
@@ -452,11 +454,11 @@ XMLStreamParser::EventType XMLStreamParser::next_body()
|
||||
{
|
||||
case StartNamespaceDecl:
|
||||
{
|
||||
if (++start_ns_i_ == start_ns_.size())
|
||||
if (++_startNamespaceIndex == _startNamespace.size())
|
||||
{
|
||||
start_ns_i_ = 0;
|
||||
start_ns_.clear();
|
||||
_qualifiedName = &qname_;
|
||||
_startNamespaceIndex = 0;
|
||||
_startNamespace.clear();
|
||||
_qualifiedName = &_qname;
|
||||
break; // No more declarations.
|
||||
}
|
||||
// Fall through.
|
||||
@@ -464,7 +466,7 @@ XMLStreamParser::EventType XMLStreamParser::next_body()
|
||||
case StartElement:
|
||||
{
|
||||
_currentEvent = StartNamespaceDecl;
|
||||
_qualifiedName = &start_ns_[start_ns_i_];
|
||||
_qualifiedName = &_startNamespace[_startNamespaceIndex];
|
||||
return _currentEvent;
|
||||
}
|
||||
default:
|
||||
@@ -486,7 +488,7 @@ XMLStreamParser::EventType XMLStreamParser::next_body()
|
||||
case StartAttribute:
|
||||
{
|
||||
_currentEvent = Characters;
|
||||
pvalue_ = &_attributes[_currentAttributeIndex].value;
|
||||
_pvalue = &_attributes[_currentAttributeIndex].value;
|
||||
return _currentEvent;
|
||||
}
|
||||
case Characters:
|
||||
@@ -500,8 +502,8 @@ XMLStreamParser::EventType XMLStreamParser::next_body()
|
||||
{
|
||||
_currentAttributeIndex = 0;
|
||||
_attributes.clear();
|
||||
_qualifiedName = &qname_;
|
||||
pvalue_ = &value_;
|
||||
_qualifiedName = &_qname;
|
||||
_pvalue = &_value;
|
||||
break; // No more attributes.
|
||||
}
|
||||
// Fall through.
|
||||
@@ -523,7 +525,7 @@ XMLStreamParser::EventType XMLStreamParser::next_body()
|
||||
|
||||
// See if we have any end namespace declarations we need to return.
|
||||
//
|
||||
if (end_ns_i_ < end_ns_.size())
|
||||
if (_endNamespaceIndex < _endNamespace.size())
|
||||
{
|
||||
// Based on the previous event determine what's the next one must be.
|
||||
//
|
||||
@@ -531,11 +533,11 @@ XMLStreamParser::EventType XMLStreamParser::next_body()
|
||||
{
|
||||
case EndNamespaceDecl:
|
||||
{
|
||||
if (++end_ns_i_ == end_ns_.size())
|
||||
if (++_endNamespaceIndex == _endNamespace.size())
|
||||
{
|
||||
end_ns_i_ = 0;
|
||||
end_ns_.clear();
|
||||
_qualifiedName = &qname_;
|
||||
_endNamespaceIndex = 0;
|
||||
_endNamespace.clear();
|
||||
_qualifiedName = &_qname;
|
||||
break; // No more declarations.
|
||||
}
|
||||
// Fall through.
|
||||
@@ -546,7 +548,7 @@ XMLStreamParser::EventType XMLStreamParser::next_body()
|
||||
default:
|
||||
{
|
||||
_currentEvent = EndNamespaceDecl;
|
||||
_qualifiedName = &end_ns_[end_ns_i_];
|
||||
_qualifiedName = &_endNamespace[_endNamespaceIndex];
|
||||
return _currentEvent;
|
||||
}
|
||||
}
|
||||
@@ -554,13 +556,13 @@ XMLStreamParser::EventType XMLStreamParser::next_body()
|
||||
|
||||
// Check the queue.
|
||||
//
|
||||
if (queue_ != Eof)
|
||||
if (_queue != Eof)
|
||||
{
|
||||
_currentEvent = queue_;
|
||||
queue_ = Eof;
|
||||
_currentEvent = _queue;
|
||||
_queue = Eof;
|
||||
|
||||
_line = XML_GetCurrentLineNumber(p_);
|
||||
_column = XML_GetCurrentColumnNumber(p_);
|
||||
_line = XML_GetCurrentLineNumber(_parser);
|
||||
_column = XML_GetCurrentColumnNumber(_parser);
|
||||
|
||||
return _currentEvent;
|
||||
}
|
||||
@@ -570,7 +572,7 @@ XMLStreamParser::EventType XMLStreamParser::next_body()
|
||||
_accumulateContent = false;
|
||||
|
||||
XML_ParsingStatus ps;
|
||||
XML_GetParsingStatus(p_, &ps);
|
||||
XML_GetParsingStatus(_parser, &ps);
|
||||
|
||||
switch (ps.parsing)
|
||||
{
|
||||
@@ -590,7 +592,7 @@ XMLStreamParser::EventType XMLStreamParser::next_body()
|
||||
}
|
||||
case XML_SUSPENDED:
|
||||
{
|
||||
switch (XML_ResumeParser(p_))
|
||||
switch (XML_ResumeParser(_parser))
|
||||
{
|
||||
case XML_STATUS_SUSPENDED:
|
||||
{
|
||||
@@ -627,7 +629,7 @@ XMLStreamParser::EventType XMLStreamParser::next_body()
|
||||
{
|
||||
if (_size != 0)
|
||||
{
|
||||
s = XML_Parse(p_, static_cast<const char*>(_data.buf), static_cast<int>(_size), true);
|
||||
s = XML_Parse(_parser, static_cast<const char*>(_data.buf), static_cast<int>(_size), true);
|
||||
|
||||
if (s == XML_STATUS_ERROR)
|
||||
handle_error();
|
||||
@@ -638,17 +640,17 @@ XMLStreamParser::EventType XMLStreamParser::next_body()
|
||||
{
|
||||
const size_t cap(4096);
|
||||
|
||||
char* b(static_cast<char*>(XML_GetBuffer(p_, cap)));
|
||||
char* b(static_cast<char*>(XML_GetBuffer(_parser, cap)));
|
||||
if (b == 0)
|
||||
throw bad_alloc();
|
||||
throw std::bad_alloc();
|
||||
|
||||
// Temporarily unset the exception failbit. Also clear the fail bit
|
||||
// when we reset the old state if it was caused by eof.
|
||||
//
|
||||
istream& is(*_data.is);
|
||||
std::istream& is(*_data.is);
|
||||
{
|
||||
stream_exception_controller sec(is);
|
||||
is.read(b, static_cast<streamsize>(cap));
|
||||
StreamExceptionController sec(is);
|
||||
is.read(b, static_cast<std::streamsize>(cap));
|
||||
}
|
||||
|
||||
// If the caller hasn't configured the stream to use exceptions,
|
||||
@@ -659,7 +661,7 @@ XMLStreamParser::EventType XMLStreamParser::next_body()
|
||||
|
||||
bool eof(is.eof());
|
||||
|
||||
s = XML_ParseBuffer(p_, static_cast<int>(is.gcount()), eof);
|
||||
s = XML_ParseBuffer(_parser, static_cast<int>(is.gcount()), eof);
|
||||
|
||||
if (s == XML_STATUS_ERROR)
|
||||
handle_error();
|
||||
@@ -675,9 +677,9 @@ XMLStreamParser::EventType XMLStreamParser::next_body()
|
||||
|
||||
static void splitName(const XML_Char* s, QName& qn)
|
||||
{
|
||||
string& ns(qn.namespace_());
|
||||
string& name(qn.name());
|
||||
string& prefix(qn.prefix());
|
||||
std::string& ns(qn.namespaceURI());
|
||||
std::string& name(qn.localName());
|
||||
std::string& prefix(qn.prefix());
|
||||
|
||||
const char* p(strchr(s, ' '));
|
||||
|
||||
@@ -713,7 +715,7 @@ void XMLCALL XMLStreamParser::start_element_(void* v, const XML_Char* name, cons
|
||||
XMLStreamParser& p(*static_cast<XMLStreamParser*>(v));
|
||||
|
||||
XML_ParsingStatus ps;
|
||||
XML_GetParsingStatus(p.p_, &ps);
|
||||
XML_GetParsingStatus(p._parser, &ps);
|
||||
|
||||
// Expat has a (mis)-feature of a possibily calling handlers even
|
||||
// after the non-resumable XML_StopParser call.
|
||||
@@ -734,31 +736,31 @@ void XMLCALL XMLStreamParser::start_element_(void* v, const XML_Char* name, cons
|
||||
// It would have been easier to throw the exception directly,
|
||||
// however, the Expat code is most likely not exception safe.
|
||||
//
|
||||
p._line = XML_GetCurrentLineNumber(p.p_);
|
||||
p._column = XML_GetCurrentColumnNumber(p.p_);
|
||||
XML_StopParser(p.p_, false);
|
||||
p._line = XML_GetCurrentLineNumber(p._parser);
|
||||
p._column = XML_GetCurrentColumnNumber(p._parser);
|
||||
XML_StopParser(p._parser, false);
|
||||
return;
|
||||
}
|
||||
|
||||
p._currentEvent = StartElement;
|
||||
splitName(name, p.qname_);
|
||||
splitName(name, p._qname);
|
||||
|
||||
p._line = XML_GetCurrentLineNumber(p.p_);
|
||||
p._column = XML_GetCurrentColumnNumber(p.p_);
|
||||
p._line = XML_GetCurrentLineNumber(p._parser);
|
||||
p._column = XML_GetCurrentColumnNumber(p._parser);
|
||||
|
||||
// Handle attributes.
|
||||
//
|
||||
if (*atts != 0)
|
||||
{
|
||||
bool am((p.feature_ & RECEIVE_ATTRIBUTE_MAP) != 0);
|
||||
bool ae((p.feature_ & RECEIVE_ATTRIBUTES_EVENT) != 0);
|
||||
bool am((p._feature & RECEIVE_ATTRIBUTE_MAP) != 0);
|
||||
bool ae((p._feature & RECEIVE_ATTRIBUTES_EVENT) != 0);
|
||||
|
||||
// Provision an entry for this element.
|
||||
//
|
||||
ElementEntry* pe(0);
|
||||
if (am)
|
||||
{
|
||||
p._elementState.push_back(ElementEntry(p.depth_ + 1));
|
||||
p._elementState.push_back(ElementEntry(p._depth + 1));
|
||||
pe = &p._elementState.back();
|
||||
}
|
||||
|
||||
@@ -773,7 +775,7 @@ void XMLCALL XMLStreamParser::start_element_(void* v, const XML_Char* name, cons
|
||||
AttributeMapType::value_type v(qn, AttributeValueType());
|
||||
v.second.value = *(atts + 1);
|
||||
v.second.handled = false;
|
||||
pe->attr_map_.insert(v);
|
||||
pe->attributeMap.insert(v);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -784,11 +786,11 @@ void XMLCALL XMLStreamParser::start_element_(void* v, const XML_Char* name, cons
|
||||
}
|
||||
|
||||
if (am)
|
||||
pe->attributesUnhandled_ = pe->attr_map_.size();
|
||||
pe->attributesUnhandled = pe->attributeMap.size();
|
||||
}
|
||||
}
|
||||
|
||||
XML_StopParser(p.p_, true);
|
||||
XML_StopParser(p._parser, true);
|
||||
}
|
||||
|
||||
|
||||
@@ -797,7 +799,7 @@ void XMLCALL XMLStreamParser::end_element_(void* v, const XML_Char* name)
|
||||
XMLStreamParser& p(*static_cast<XMLStreamParser*>(v));
|
||||
|
||||
XML_ParsingStatus ps;
|
||||
XML_GetParsingStatus(p.p_, &ps);
|
||||
XML_GetParsingStatus(p._parser, &ps);
|
||||
|
||||
// Expat has a (mis)-feature of a possibily calling handlers even
|
||||
// after the non-resumable XML_StopParser call.
|
||||
@@ -809,24 +811,24 @@ void XMLCALL XMLStreamParser::end_element_(void* v, const XML_Char* name)
|
||||
// case the element name is already set.
|
||||
//
|
||||
if (ps.parsing != XML_PARSING)
|
||||
p.queue_ = EndElement;
|
||||
p._queue = EndElement;
|
||||
else
|
||||
{
|
||||
splitName(name, p.qname_);
|
||||
splitName(name, p._qname);
|
||||
|
||||
// If we are accumulating characters, then queue this event.
|
||||
//
|
||||
if (p._accumulateContent)
|
||||
p.queue_ = EndElement;
|
||||
p._queue = EndElement;
|
||||
else
|
||||
{
|
||||
p._currentEvent = EndElement;
|
||||
|
||||
p._line = XML_GetCurrentLineNumber(p.p_);
|
||||
p._column = XML_GetCurrentColumnNumber(p.p_);
|
||||
p._line = XML_GetCurrentLineNumber(p._parser);
|
||||
p._column = XML_GetCurrentColumnNumber(p._parser);
|
||||
}
|
||||
|
||||
XML_StopParser(p.p_, true);
|
||||
XML_StopParser(p._parser, true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -836,7 +838,7 @@ void XMLCALL XMLStreamParser::characters_(void* v, const XML_Char* s, int n)
|
||||
XMLStreamParser& p(*static_cast<XMLStreamParser*>(v));
|
||||
|
||||
XML_ParsingStatus ps;
|
||||
XML_GetParsingStatus(p.p_, &ps);
|
||||
XML_GetParsingStatus(p._parser, &ps);
|
||||
|
||||
// Expat has a (mis)-feature of a possibily calling handlers even
|
||||
// after the non-resumable XML_StopParser call.
|
||||
@@ -862,9 +864,9 @@ void XMLCALL XMLStreamParser::characters_(void* v, const XML_Char* s, int n)
|
||||
// It would have been easier to throw the exception directly,
|
||||
// however, the Expat code is most likely not exception safe.
|
||||
//
|
||||
p._line = XML_GetCurrentLineNumber(p.p_);
|
||||
p._column = XML_GetCurrentColumnNumber(p.p_);
|
||||
XML_StopParser(p.p_, false);
|
||||
p._line = XML_GetCurrentLineNumber(p._parser);
|
||||
p._column = XML_GetCurrentColumnNumber(p._parser);
|
||||
XML_StopParser(p._parser, false);
|
||||
break;
|
||||
}
|
||||
return;
|
||||
@@ -880,15 +882,15 @@ void XMLCALL XMLStreamParser::characters_(void* v, const XML_Char* s, int n)
|
||||
if (p._accumulateContent || ps.parsing != XML_PARSING)
|
||||
{
|
||||
assert(p._currentEvent == Characters);
|
||||
p.value_.append(s, n);
|
||||
p._value.append(s, n);
|
||||
}
|
||||
else
|
||||
{
|
||||
p._currentEvent = Characters;
|
||||
p.value_.assign(s, n);
|
||||
p._value.assign(s, n);
|
||||
|
||||
p._line = XML_GetCurrentLineNumber(p.p_);
|
||||
p._column = XML_GetCurrentColumnNumber(p.p_);
|
||||
p._line = XML_GetCurrentLineNumber(p._parser);
|
||||
p._column = XML_GetCurrentColumnNumber(p._parser);
|
||||
|
||||
// In simple content we need to accumulate all the characters
|
||||
// into a single event. To do this we will let the XMLStreamParser run
|
||||
@@ -897,7 +899,7 @@ void XMLCALL XMLStreamParser::characters_(void* v, const XML_Char* s, int n)
|
||||
if (cont == Content::Simple)
|
||||
p._accumulateContent = true;
|
||||
else
|
||||
XML_StopParser(p.p_, true);
|
||||
XML_StopParser(p._parser, true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -907,7 +909,7 @@ void XMLCALL XMLStreamParser::start_namespace_decl_(void* v, const XML_Char* pre
|
||||
XMLStreamParser& p(*static_cast<XMLStreamParser*>(v));
|
||||
|
||||
XML_ParsingStatus ps;
|
||||
XML_GetParsingStatus(p.p_, &ps);
|
||||
XML_GetParsingStatus(p._parser, &ps);
|
||||
|
||||
// Expat has a (mis)-feature of a possibily calling handlers even
|
||||
// after the non-resumable XML_StopParser call.
|
||||
@@ -915,9 +917,9 @@ void XMLCALL XMLStreamParser::start_namespace_decl_(void* v, const XML_Char* pre
|
||||
if (ps.parsing == XML_FINISHED)
|
||||
return;
|
||||
|
||||
p.start_ns_.push_back(QName());
|
||||
p.start_ns_.back().prefix() = (prefix != 0 ? prefix : "");
|
||||
p.start_ns_.back().namespace_() = (ns != 0 ? ns : "");
|
||||
p._startNamespace.push_back(QName());
|
||||
p._startNamespace.back().prefix() = (prefix != 0 ? prefix : "");
|
||||
p._startNamespace.back().namespaceURI() = (ns != 0 ? ns : "");
|
||||
}
|
||||
|
||||
|
||||
@@ -926,7 +928,7 @@ void XMLCALL XMLStreamParser::end_namespace_decl_(void* v, const XML_Char* prefi
|
||||
XMLStreamParser& p(*static_cast<XMLStreamParser*>(v));
|
||||
|
||||
XML_ParsingStatus ps;
|
||||
XML_GetParsingStatus(p.p_, &ps);
|
||||
XML_GetParsingStatus(p._parser, &ps);
|
||||
|
||||
// Expat has a (mis)-feature of a possibily calling handlers even
|
||||
// after the non-resumable XML_StopParser call.
|
||||
@@ -934,10 +936,9 @@ void XMLCALL XMLStreamParser::end_namespace_decl_(void* v, const XML_Char* prefi
|
||||
if (ps.parsing == XML_FINISHED)
|
||||
return;
|
||||
|
||||
p.end_ns_.push_back(QName());
|
||||
p.end_ns_.back().prefix() = (prefix != 0 ? prefix : "");
|
||||
p._endNamespace.push_back(QName());
|
||||
p._endNamespace.back().prefix() = (prefix != 0 ? prefix : "");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
} } // namespace Poco::XML
|
||||
|
||||
Reference in New Issue
Block a user