fixes for style, documentation and consistency, part I. More coming...

This commit is contained in:
Guenter Obiltschnig 2015-08-27 10:18:32 +02:00
parent dbea46bbcb
commit 95818ff27f
12 changed files with 458 additions and 432 deletions

View File

@ -22,7 +22,7 @@ objects = AbstractContainerNode AbstractNode Attr AttrMap Attributes \
NamespaceSupport NodeAppender Node NodeFilter NodeIterator NodeList Notation \
ParserEngine ProcessingInstruction QName SAXException SAXParser Text \
TreeWalker WhitespaceFilter XMLException XMLFilter XMLFilterImpl XMLReader \
XMLString XMLWriter XMLStreamParser XMLStreamParserException
XMLString XMLWriter XMLStreamParser XMLStreamParserException ValueTraits
expat_objects = xmlparse xmlrole xmltok

View File

@ -9,52 +9,57 @@
//
// Definition of the Content enum.
//
// 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
//
#ifndef POCO_XML_CONTENT
#define POCO_XML_CONTENT
#ifndef XML_Content_INCLUDED
#define XML_Content_INCLUDED
namespace Poco
{
namespace XML
{
namespace Poco {
namespace XML {
/// XML content model. C++11 enum class emulated for C++98.
struct Content
/// XML content model. C++11 enum class emulated for C++98.
///
/// element characters whitespaces notes
/// Empty no no ignored
/// Simple no yes preserved content accumulated
/// Complex yes no ignored
/// Mixed yes yes preserved
{
enum value
{
// element characters whitespaces notes
Empty, // no no ignored
Simple, // no yes preserved content accumulated
Complex, // yes no ignored
Mixed // yes yes preserved
Empty,
Simple,
Complex,
Mixed
};
Content(value v)
: v_(v)
: _v(v)
{
}
operator value() const
{
return v_;
return _v;
}
private:
value v_;
value _v;
};
}
}
} } // namespace Poco::XML
#endif // XML_CONTENT
#endif // XML_Content_INCLUDED

View File

@ -9,32 +9,35 @@
//
// Definition of the QName 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
//
#ifndef XML_QName_INCLUDED
#define XML_QName_INCLUDED
#ifndef POCO_XML_QNAME_HXX
#define POCO_XML_QNAME_HXX
#include "Poco/XML/XML.h"
#include <string>
#include <iosfwd>
namespace Poco
{
namespace XML
{
namespace Poco {
namespace XML {
// Note that the optional prefix is just a "syntactic sugar". In
// particular, it is ignored by the comparison operators and the
// std::ostream insertion operator.
//
class XML_API QName
/// This class represents a qualified XML name in the stream parser.
///
/// Note that the optional prefix is just a "syntactic sugar". In
/// particular, it is ignored by the comparison operators and the
/// std::ostream insertion operator.
{
public:
QName();
@ -42,31 +45,41 @@ public:
QName(const std::string& ns, const std::string& name);
QName(const std::string& ns, const std::string& name, const std::string& prefix);
const std::string& namespace_() const;
const std::string& name() const;
const std::string& namespaceURI() const;
/// Returns the namespace URI part of the name.
const std::string& localName() const;
/// Returns the local part of the name.
const std::string& prefix() const;
std::string& namespace_();
std::string& name();
/// Returns the namespace prefix of the name.
std::string& namespaceURI();
/// Returns the namespace URI part of the name.
std::string& localName();
/// Returns the local part of the name.
std::string& prefix();
/// Returns the namespace prefix of the name.
// Printable representation in the [<namespace>#]<name> form.
//
std::string string() const;
/// Returns a printable representation in the [<namespace>#]<name> form.
// Note that comparison operators
//
public:
friend bool operator<(const QName& x, const QName& y)
friend bool operator < (const QName& x, const QName& y)
{
return x._ns < y._ns || (x._ns == y._ns && x._name < y._name);
}
friend bool operator==(const QName& x, const QName& y)
friend bool operator == (const QName& x, const QName& y)
{
return x._ns == y._ns && x._name == y._name;
}
friend bool operator!=(const QName& x, const QName& y)
friend bool operator != (const QName& x, const QName& y)
{
return !(x == y);
}
@ -78,13 +91,16 @@ private:
};
inline const std::string& QName::namespace_() const
//
// inlines
//
inline const std::string& QName::namespaceURI() const
{
return _ns;
}
inline const std::string& QName::name() const
inline const std::string& QName::localName() const
{
return _name;
}
@ -96,13 +112,13 @@ inline const std::string& QName::prefix() const
}
inline std::string& QName::namespace_()
inline std::string& QName::namespaceURI()
{
return _ns;
}
inline std::string& QName::name()
inline std::string& QName::localName()
{
return _name;
}
@ -116,7 +132,8 @@ inline std::string& QName::prefix()
XML_API std::ostream& operator<<(std::ostream&, const QName&);
}
}
#endif // CUTL_XML_QNAME_HXX
} } // namespace Poco::XML
#endif // XML_QName_INCLUDED

View File

@ -9,36 +9,37 @@
//
// Definition of the ValueTraits templates.
//
// 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
//
#ifndef POCO_XML_VALUE_TRAITS_HXX
#define POCO_XML_VALUE_TRAITS_HXX
#ifndef XML_ValueTraits_INCLUDED
#define XML_ValueTraits_INCLUDED
#include "XMLStreamParserException.h"
#include <string>
#include <cstddef> // std::size_t
#include <cstddef>
#include <iostream>
#include <sstream>
namespace Poco
{
namespace XML
{
namespace Poco {
namespace XML {
class XMLStreamParser;
class XMLStreamSerializer;
template<typename T>
struct default_value_traits
template <typename T>
struct DefaultValueTraits
{
static T
parse(std::string, const XMLStreamParser&);
@ -48,8 +49,8 @@ struct default_value_traits
};
template<>
struct XML_API default_value_traits<bool>
template <>
struct XML_API DefaultValueTraits<bool>
{
static bool
parse(std::string, const XMLStreamParser&);
@ -61,8 +62,8 @@ struct XML_API default_value_traits<bool>
};
template<>
struct XML_API default_value_traits<std::string>
template <>
struct XML_API DefaultValueTraits<std::string>
{
static std::string parse(std::string s, const XMLStreamParser&)
{
@ -76,20 +77,20 @@ struct XML_API default_value_traits<std::string>
};
template<typename T>
struct ValueTraits: default_value_traits<T>
template <typename T>
struct ValueTraits: DefaultValueTraits<T>
{
};
template<typename T, std::size_t N>
struct ValueTraits<T[N]> : default_value_traits<const T*>
template <typename T, std::size_t N>
struct ValueTraits<T[N]> : DefaultValueTraits<const T*>
{
};
template<typename T>
T default_value_traits<T>::parse(std::string s, const XMLStreamParser& p)
template <typename T>
T DefaultValueTraits<T>::parse(std::string s, const XMLStreamParser& p)
{
T r;
std::istringstream is(s);
@ -99,7 +100,7 @@ T default_value_traits<T>::parse(std::string s, const XMLStreamParser& p)
}
}
}
} } // namespace Poco::XML
#endif // CUTL_XML_VALUE_TRAITS_HXX
#endif // XML_ValueTraits_INCLUDED

View File

@ -9,25 +9,26 @@
//
// 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
//
#ifndef POCO_XML_XMLSTREAMPARSER_INCLUDED
#define POCO_XML_XMLSTREAMPARSER_INCLUDED
#ifndef XML_XMLStreamParser_INCLUDED
#define XML_XMLStreamParser_INCLUDED
// We only support UTF-8 expat.
//
#ifdef XML_UNICODE
# error UTF-16 expat (XML_UNICODE defined) is not supported
#error UTF-16 expat (XML_UNICODE defined) is not supported
#endif
#include "Poco/XML/QName.h"
#include "Poco/XML/ValueTraits.h"
#include "Poco/XML/Content.h"
@ -36,14 +37,12 @@
#include <vector>
#include <string>
#include <iosfwd>
#include <cstddef> // std::size_t
#include <cstddef>
#include <cassert>
namespace Poco
{
namespace XML
{
namespace Poco {
namespace XML {
class XML_API XMLStreamParser
@ -60,8 +59,8 @@ class XML_API XMLStreamParser
/// without the default value throws an appropriate parsing exception
/// while the version with the default value returns that value.
///
/// Note also that there is no attribute(ns,name) version since it
/// would conflict with attribute(name,dv) (qualified attributes
/// Note also that there is no attribute(ns, name) version since it
/// would conflict with attribute(name, dv) (qualified attributes
/// are not very common).
///
/// Attribute map is valid throughout at the "element level" until
@ -69,36 +68,32 @@ class XML_API XMLStreamParser
/// the map is still valid after peek() that returned end_element until
/// this end_element event is retrieved with next().
///
/// For more information see: http://www.codesynthesis.com/projects/libstudxml/doc/intro.xhtml
///
/// Using parser:
/// @code
/// XMLStreamParser p (ifs, argv[1]);
/// for (XMLStreamParser::EventType e: p)
/// {
/// switch (e)
/// {
/// case XMLStreamParser::startElement:
/// cerr << p.line () << ':' << p.column () << ": start " << p.name () << endl; break;
/// case XMLStreamParser::endElement:
/// cerr << p.line () << ':' << p.column () << ": end " << p.name () << endl; break;
/// case XMLStreamParser::startAttribute:
/// ...
/// case XMLStreamParser::endAttribute:
/// ...
/// case XMLStreamParser::characters:
/// ...
/// }
/// }
/// @endcode
///
/// XMLStreamParser p(ifs, argv[1]);
/// for (XMLStreamParser::EventType e: p)
/// {
/// switch (e)
/// {
/// case XMLStreamParser::startElement:
/// cerr << p.line () << ':' << p.column () << ": start " << p.name () << endl;
/// break;
/// case XMLStreamParser::endElement:
/// cerr << p.line () << ':' << p.column () << ": end " << p.name () << endl;
/// break;
/// case XMLStreamParser::startAttribute:
/// ...
/// case XMLStreamParser::endAttribute:
/// ...
/// case XMLStreamParser::characters:
/// ...
/// }
/// }
{
public:
/// Parsing events.
enum EventType
/// Parsing events.
{
// If adding new events, also update the stream insertion operator.
StartElement,
EndElement,
StartAttribute,
@ -110,10 +105,9 @@ public:
};
typedef unsigned short FeatureType;
/// If both receive_attributes_event and RECEIVE_ATTRIBUTE_MAP are
/// specified, then RECEIVE_ATTRIBUTES_EVENT is assumed.
// If both receive_attributes_event and receive_attributes_map are
// specified, then receive_attributes_event is assumed.
//
static const FeatureType RECEIVE_ELEMENTS = 0x0001;
static const FeatureType RECEIVE_CHARACTERS = 0x0002;
static const FeatureType RECEIVE_ATTRIBUTE_MAP = 0x0004;
@ -121,10 +115,7 @@ public:
static const FeatureType RECEIVE_NAMESPACE_DECLS = 0x0010;
static const FeatureType RECEIVE_DEFAULT = RECEIVE_ELEMENTS | RECEIVE_CHARACTERS | RECEIVE_ATTRIBUTE_MAP;
// Low-level attribute map access. Note that this API assumes
// all attributes are handled.
//
struct AttributeValueType
struct XML_API AttributeValueType
{
std::string value;
mutable bool handled;
@ -132,55 +123,55 @@ public:
typedef std::map<QName, AttributeValueType> AttributeMapType;
// C++11 range-based for support. Generally, the iterator interface
// doesn't make much sense for the XMLStreamParser so for now we have an
// implementation that is just enough to the range-based for.
//
struct Iterator
struct XML_API Iterator
// C++11 range-based for support. Generally, the iterator interface
// doesn't make much sense for the XMLStreamParser so for now we have an
// implementation that is just enough to the range-based for.
{
typedef EventType value_type;
Iterator(XMLStreamParser* p = 0, EventType e = Eof) :
p_(p),
e_(e)
_parser(p),
_e(e)
{
}
value_type operator*() const
{
return e_;
return _e;
}
Iterator& operator++()
{
e_ = p_->next();
_e = _parser->next();
return *this;
}
// Comparison only makes sense when comparing to end (eof).
//
bool operator==(Iterator y) const
bool operator == (Iterator y) const
/// Comparison only makes sense when comparing to end (eof).
{
return e_ == Eof && y.e_ == Eof;
return _e == Eof && y._e == Eof;
}
bool operator!=(Iterator y) const
/// Comparison only makes sense when comparing to end (eof).
{
return !(*this == y);
}
private:
XMLStreamParser* p_;
EventType e_;
XMLStreamParser* _parser;
EventType _e;
};
Iterator begin()
{
return Iterator(this, next());
}
Iterator end()
{
return Iterator(this, Eof);
}
XMLStreamParser(std::istream&, const std::string& input_name, FeatureType = RECEIVE_DEFAULT);
/// The parser constructor takes three arguments: the stream to parse,
/// input name that is used in diagnostics to identify the document being
@ -198,6 +189,7 @@ public:
/// is used in diagnostics to identify the document being parsed.
~XMLStreamParser();
/// Destroys the XMLStreamParser.
EventType next();
/// Call the next() function when we are ready to handle the next piece of XML.
@ -212,12 +204,12 @@ public:
EventType peek();
EventType event();
// Return the even that was last returned by the call to next() or peek().
/// Return the even that was last returned by the call to next() or peek().
const std::string& inputName() const;
const QName& getQName() const;
const std::string& namespace_() const;
const std::string& name() const;
const std::string& namespaceURI() const;
const std::string& localName() const;
const std::string& prefix() const;
std::string& value();
const std::string& value() const;
@ -238,16 +230,11 @@ public:
T attribute(const QName& qname, const T& default_value) const;
bool attributePresent(const std::string& name) const;
bool attributePresent(const QName& qname) const;
const AttributeMapType& attributeMap() const;
// Note that you cannot get/set content while peeking.
//
void content(Content);
Content content() const;
// Versions that also set the content. Event type must be startElement.
//
void nextExpect(EventType, const std::string& name, Content);
void nextExpect(EventType, const QName& qname, Content);
void nextExpect(EventType, const std::string& ns, const std::string& name, Content);
@ -301,35 +288,21 @@ private:
_data;
std::size_t _size;
const std::string _inputName;
FeatureType feature_;
XML_Parser p_;
std::size_t depth_;
FeatureType _feature;
XML_Parser _parser;
std::size_t _depth;
bool _accumulateContent; // Whether we are accumulating character content.
enum
{
state_next, state_peek
}
_parserState;
enum { state_next, state_peek } _parserState;
EventType _currentEvent;
EventType queue_;
QName qname_;
std::string value_;
// These are used to avoid copying when we are handling attributes
// and namespace decls.
//
EventType _queue;
QName _qname;
std::string _value;
const QName* _qualifiedName;
std::string* pvalue_;
std::string* _pvalue;
Poco::UInt64 _line;
Poco::UInt64 _column;
// Attributes as events.
//
struct attribute_type
{
QName qname;
@ -337,95 +310,93 @@ private:
};
typedef std::vector<attribute_type> attributes;
attributes _attributes;
attributes::size_type _currentAttributeIndex; // Index of the current attribute.
// Namespace declarations.
//
typedef std::vector<QName> namespace_decls;
typedef std::vector<QName> NamespaceDecls;
NamespaceDecls _startNamespace;
NamespaceDecls::size_type _startNamespaceIndex;// Index of the current decl.
NamespaceDecls _endNamespace;
NamespaceDecls::size_type _endNamespaceIndex;// Index of the current decl.
namespace_decls start_ns_;
namespace_decls::size_type start_ns_i_;// Index of the current decl.
namespace_decls end_ns_;
namespace_decls::size_type end_ns_i_;// Index of the current decl.
// Element state consisting of the content model and attribute map.
//
struct ElementEntry
{
ElementEntry(std::size_t d, Content c = Content::Mixed) :
depth(d),
content(c),
attributesUnhandled_(0)
attributesUnhandled(0)
{
}
std::size_t depth;
Content content;
AttributeMapType attr_map_;
mutable AttributeMapType::size_type attributesUnhandled_;
AttributeMapType attributeMap;
mutable AttributeMapType::size_type attributesUnhandled;
};
typedef std::vector<ElementEntry> ElementState;
std::vector<ElementEntry> _elementState;
// Empty attribute map to return when an element has no attributes.
//
const AttributeMapType _emptyAttrMap;
// Return the element entry corresponding to the current depth, if
// exists, and NULL otherwise.
//
const ElementEntry* getElement() const;
const ElementEntry* get_element_() const;
const ElementEntry* getElementImpl() const;
void popElement();
};
XML_API std::ostream& operator<<(std::ostream&, XMLStreamParser::EventType);
XML_API std::ostream& operator << (std::ostream&, XMLStreamParser::EventType);
//
// inlines
//
inline XMLStreamParser::EventType XMLStreamParser::event()
// Return the even that was last returned by the call to next() or peek().
{
return _currentEvent;
}
inline const std::string& XMLStreamParser::inputName() const
{
return _inputName;
}
inline const QName& XMLStreamParser::getQName() const
{
return *_qualifiedName;
}
inline const std::string& XMLStreamParser::namespace_() const
inline const std::string& XMLStreamParser::namespaceURI() const
{
return _qualifiedName->namespace_();
return _qualifiedName->namespaceURI();
}
inline const std::string& XMLStreamParser::name() const
inline const std::string& XMLStreamParser::localName() const
{
return _qualifiedName->name();
return _qualifiedName->localName();
}
inline const std::string& XMLStreamParser::prefix() const
{
return _qualifiedName->prefix();
}
inline std::string& XMLStreamParser::value()
{
return *pvalue_;
return *_pvalue;
}
inline const std::string& XMLStreamParser::value() const
{
return *pvalue_;
return *_pvalue;
}
@ -434,11 +405,13 @@ inline Poco::UInt64 XMLStreamParser::line() const
return _line;
}
inline Poco::UInt64 XMLStreamParser::column() const
{
return _column;
}
inline XMLStreamParser::EventType XMLStreamParser::peek()
{
if (_parserState == state_peek)
@ -451,66 +424,77 @@ inline XMLStreamParser::EventType XMLStreamParser::peek()
}
}
template<typename T>
inline T XMLStreamParser::value() const
{
return ValueTraits < T > ::parse(value(), *this);
}
inline const std::string& XMLStreamParser::attribute(const std::string& n) const
{
return attribute(QName(n));
}
template<typename T>
inline T XMLStreamParser::attribute(const std::string& n) const
{
return attribute < T > (QName(n));
}
inline std::string XMLStreamParser::attribute(const std::string& n, const std::string& dv) const
{
return attribute(QName(n), dv);
}
template<typename T>
inline T XMLStreamParser::attribute(const std::string& n, const T& dv) const
{
return attribute < T > (QName(n), dv);
}
template<typename T>
inline T XMLStreamParser::attribute(const QName& qn) const
{
return ValueTraits < T > ::parse(attribute(qn), *this);
}
inline bool XMLStreamParser::attributePresent(const std::string& n) const
{
return attributePresent(QName(n));
}
inline const XMLStreamParser::AttributeMapType& XMLStreamParser::attributeMap() const
{
if (const ElementEntry* e = getElement())
{
e->attributesUnhandled_ = 0; // Assume all handled.
return e->attr_map_;
e->attributesUnhandled = 0; // Assume all handled.
return e->attributeMap;
}
return _emptyAttrMap;
}
inline void XMLStreamParser::nextExpect(EventType e, const QName& qn)
{
nextExpect(e, qn.namespace_(), qn.name());
nextExpect(e, qn.namespaceURI(), qn.localName());
}
inline void XMLStreamParser::nextExpect(EventType e, const std::string& n)
{
nextExpect(e, std::string(), n);
}
inline void XMLStreamParser::nextExpect(EventType e, const QName& qn, Content c)
{
nextExpect(e, qn);
@ -518,6 +502,7 @@ inline void XMLStreamParser::nextExpect(EventType e, const QName& qn, Content c)
content(c);
}
inline void XMLStreamParser::nextExpect(EventType e, const std::string& n, Content c)
{
nextExpect(e, std::string(), n);
@ -525,6 +510,7 @@ inline void XMLStreamParser::nextExpect(EventType e, const std::string& n, Conte
content(c);
}
inline void XMLStreamParser::nextExpect(EventType e, const std::string& ns, const std::string& n, Content c)
{
nextExpect(e, ns, n);
@ -532,82 +518,93 @@ inline void XMLStreamParser::nextExpect(EventType e, const std::string& ns, cons
content(c);
}
template<typename T>
inline T XMLStreamParser::element()
{
return ValueTraits < T > ::parse(element(), *this);
}
inline std::string XMLStreamParser::element(const std::string& n)
{
nextExpect(StartElement, n);
return element();
}
inline std::string XMLStreamParser::element(const QName& qn)
{
nextExpect(StartElement, qn);
return element();
}
template<typename T>
inline T XMLStreamParser::element(const std::string& n)
{
return ValueTraits < T > ::parse(element(n), *this);
}
template<typename T>
inline T XMLStreamParser::element(const QName& qn)
{
return ValueTraits < T > ::parse(element(qn), *this);
}
inline std::string XMLStreamParser::element(const std::string& n, const std::string& dv)
{
return element(QName(n), dv);
}
template<typename T>
inline T XMLStreamParser::element(const std::string& n, const T& dv)
{
return element < T > (QName(n), dv);
}
inline void XMLStreamParser::content(Content c)
{
assert(_parserState == state_next);
if (!_elementState.empty() && _elementState.back().depth == depth_)
if (!_elementState.empty() && _elementState.back().depth == _depth)
_elementState.back().content = c;
else
_elementState.push_back(ElementEntry(depth_, c));
_elementState.push_back(ElementEntry(_depth, c));
}
inline Content XMLStreamParser::content() const
{
assert(_parserState == state_next);
return !_elementState.empty() && _elementState.back().depth == depth_ ? _elementState.back().content : Content(Content::Mixed);
return !_elementState.empty() && _elementState.back().depth == _depth ? _elementState.back().content : Content(Content::Mixed);
}
inline const XMLStreamParser::ElementEntry* XMLStreamParser::getElement() const
{
return _elementState.empty() ? 0 : get_element_();
return _elementState.empty() ? 0 : getElementImpl();
}
template<typename T>
T XMLStreamParser::attribute(const QName& qn, const T& 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 ValueTraits < T > ::parse(i->second.value, *this);
}
@ -616,6 +613,7 @@ T XMLStreamParser::attribute(const QName& qn, const T& dv) const
return dv;
}
template<typename T>
T XMLStreamParser::element(const QName& qn, const T& dv)
{
@ -629,8 +627,7 @@ T XMLStreamParser::element(const QName& qn, const T& dv)
}
}
}
} } // namespace Poco::XML
#endif // CUTL_XML_PARSER_HXX
#endif // XML_XMLStreamParser_INCLUDED

View File

@ -9,27 +9,28 @@
//
// Definition of the XMLStreamParserException class.
//
// Copyright (c) 2004-2015, Applied Informatics Software Engineering GmbH.
// Copyright (c) 2015, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// SPDX-License-Identifier: BSL-1.0
// copyright : Copyright (c) 2013-2014 Code Synthesis Tools CC
// license : MIT; see accompanying LICENSE file
//
#ifndef POCO_XML_XMLSTREAMPARSEREXCEPTION_H_
#define POCO_XML_XMLSTREAMPARSEREXCEPTION_H_
#ifndef XML_XMLStreamParserException_INCLUDED
#define XML_XMLStreamParserException_INCLUDED
#include <Poco/XML/XMLException.h>
namespace Poco {
namespace XML {
#include <Poco/DOM/DOMException.h>
namespace Poco
{
namespace XML
{
class XMLStreamParser;
class XML_API XMLStreamParserException :
public Poco::XML::XMLException
class XML_API XMLStreamParserException: public Poco::XML::XMLException
{
public:
XMLStreamParserException(const std::string& name, Poco::UInt64 line, Poco::UInt64 column, const std::string& description);
@ -52,7 +53,8 @@ private:
std::string _what;
};
}
/* namespace XML */
} /* namespace Poco */
#endif /* POCO_XML_XMLSTREAMPARSEREXCEPTION_H_ */
} } // namespace Poco::XML
#endif // XML_XMLStreamParserException_INCLUDED

View File

@ -9,22 +9,23 @@
//
// Definition of the QName 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/QName.h"
#include <ostream>
using namespace std;
namespace Poco
{
namespace XML
{
namespace Poco {
namespace XML {
QName::QName()
{
@ -52,7 +53,7 @@ QName::QName(const std::string& ns, const std::string& name, const std::string&
}
string QName::string() const
std::string QName::string() const
{
std::string r;
if (!_ns.empty())
@ -65,10 +66,11 @@ string QName::string() const
return r;
}
ostream& operator<<(ostream& os, const QName& qn)
std::ostream& operator<<(std::ostream& os, const QName& qn)
{
return os << qn.string();
}
}
}
} } // namespace Poco::XML

View File

@ -9,28 +9,25 @@
//
// Definition of the ValueTraits templates.
//
// 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 "Poco/XML/XMLStreamParserException.h"
using namespace std;
namespace Poco {
namespace XML {
namespace Poco
{
namespace XML
{
bool default_value_traits<bool>::parse(string s, const XMLStreamParser& p)
bool DefaultValueTraits<bool>::parse(std::string s, const XMLStreamParser& p)
{
if (s == "true" || s == "1" || s == "True" || s == "TRUE")
return true;
@ -41,5 +38,4 @@ bool default_value_traits<bool>::parse(string s, const XMLStreamParser& p)
}
}
}
} } // namespace Poco::XML

View File

@ -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

View File

@ -9,23 +9,19 @@
//
// Definition of the XMLStreamParserException class.
//
// Copyright (c) 2004-2015, Applied Informatics Software Engineering GmbH.
// Copyright (c) 2015, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// SPDX-License-Identifier: BSL-1.0
// copyright : Copyright (c) 2013-2014 Code Synthesis Tools CC
// license : MIT; see accompanying LICENSE file
//
#include "Poco/XML/XMLStreamParserException.h"
#include "Poco/XML/XMLStreamParser.h"
using namespace std;
namespace Poco
{
namespace XML
{
namespace Poco {
namespace XML {
XMLStreamParserException::~XMLStreamParserException() throw ()
@ -33,15 +29,21 @@ XMLStreamParserException::~XMLStreamParserException() throw ()
}
XMLStreamParserException::XMLStreamParserException(const string& n, Poco::UInt64 l, Poco::UInt64 c, const string& d)
: _name(n), _line(l), _column(c), _description(d)
XMLStreamParserException::XMLStreamParserException(const std::string& n, Poco::UInt64 l, Poco::UInt64 c, const std::string& d):
_name(n),
_line(l),
_column(c),
_description(d)
{
init();
}
XMLStreamParserException::XMLStreamParserException(const XMLStreamParser& p, const std::string& d)
: _name(p.inputName()), _line(p.line()), _column(p.column()), _description(d)
XMLStreamParserException::XMLStreamParserException(const XMLStreamParser& p, const std::string& d):
_name(p.inputName()),
_line(p.line()),
_column(p.column()),
_description(d)
{
init();
}
@ -62,26 +64,29 @@ const char* XMLStreamParserException::name() const throw()
return _name.c_str();
}
Poco::UInt64 XMLStreamParserException::line() const
{
return _line;
}
Poco::UInt64 XMLStreamParserException::column() const
{
return _column;
}
const std::string& XMLStreamParserException::description() const
{
return _description;
}
char const* XMLStreamParserException::what() const throw ()
{
return _what.c_str();
}
} /* namespace XML */
} /* namespace Poco */
} } // namespace Poco::XML

View File

@ -12,7 +12,7 @@ objects = AttributesImplTest ChildNodesTest DOMTestSuite DocumentTest \
DocumentTypeTest Driver ElementTest EventTest NamePoolTest NameTest \
NamespaceSupportTest NodeIteratorTest NodeTest ParserWriterTest \
SAXParserTest SAXTestSuite TextTest TreeWalkerTest \
XMLTestSuite XMLWriterTest NodeAppenderTest XMLStreamSerializerTestSuite \
XMLTestSuite XMLWriterTest NodeAppenderTest \
XMLStreamParserTestSuite
target = testrunner

View File

@ -153,7 +153,7 @@ void XMLStreamParserTestSuite::testParser()
XMLStreamParser p(is, "test");
p.nextExpect(XMLStreamParser::StartElement, "root");
poco_assert(p.attribute("a") == "a");
poco_assert(p.peek() == XMLStreamParser::StartElement && p.name() == "nested");
poco_assert(p.peek() == XMLStreamParser::StartElement && p.localName() == "nested");
poco_assert(p.attribute("a") == "a");
p.nextExpect(XMLStreamParser::StartElement, "nested");
poco_assert(p.attribute("a") == "A");