mirror of
https://github.com/pocoproject/poco.git
synced 2025-10-24 17:30:44 +02:00
merge some changes from develop branch; modernize and clean-up code; remove support for compiling without POCO_WIN32_UTF8
This commit is contained in:
@@ -19,24 +19,35 @@ namespace Poco {
|
||||
namespace XML {
|
||||
|
||||
|
||||
AttributesImpl::EmptyAttribute::EmptyAttribute()
|
||||
{
|
||||
specified = false;
|
||||
type = XML_LIT("CDATA");
|
||||
}
|
||||
|
||||
|
||||
AttributesImpl::EmptyAttribute AttributesImpl::_empty;
|
||||
|
||||
|
||||
AttributesImpl::AttributesImpl()
|
||||
{
|
||||
_empty.specified = false;
|
||||
_empty.type = XML_LIT("CDATA");
|
||||
}
|
||||
|
||||
|
||||
AttributesImpl::AttributesImpl(const Attributes& attributes)
|
||||
{
|
||||
_empty.specified = false;
|
||||
_empty.type = XML_LIT("CDATA");
|
||||
setAttributes(attributes);
|
||||
}
|
||||
|
||||
|
||||
AttributesImpl::AttributesImpl(const AttributesImpl& attributes):
|
||||
_attributes(attributes._attributes),
|
||||
_empty(attributes._empty)
|
||||
_attributes(attributes._attributes)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
AttributesImpl::AttributesImpl(AttributesImpl&& attributes) noexcept:
|
||||
_attributes(std::move(attributes._attributes))
|
||||
{
|
||||
}
|
||||
|
||||
@@ -56,6 +67,14 @@ AttributesImpl& AttributesImpl::operator = (const AttributesImpl& attributes)
|
||||
}
|
||||
|
||||
|
||||
AttributesImpl& AttributesImpl::operator = (AttributesImpl&& attributes) noexcept
|
||||
{
|
||||
_attributes = std::move(attributes._attributes);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
int AttributesImpl::getIndex(const XMLString& qname) const
|
||||
{
|
||||
int i = 0;
|
||||
|
||||
@@ -192,9 +192,9 @@ void DOMBuilder::startElement(const XMLString& uri, const XMLString& localName,
|
||||
|
||||
const AttributesImpl& attrs = dynamic_cast<const AttributesImpl&>(attributes);
|
||||
Attr* pPrevAttr = 0;
|
||||
for (AttributesImpl::iterator it = attrs.begin(); it != attrs.end(); ++it)
|
||||
for (const auto& attr: attrs)
|
||||
{
|
||||
AutoPtr<Attr> pAttr = new Attr(_pDocument, 0, it->namespaceURI, it->localName, it->qname, it->value, it->specified);
|
||||
AutoPtr<Attr> pAttr = new Attr(_pDocument, 0, attr.namespaceURI, attr.localName, attr.qname, attr.value, attr.specified);
|
||||
pPrevAttr = pElem->addAttributeNodeNP(pPrevAttr, pAttr);
|
||||
}
|
||||
appendNode(pElem);
|
||||
|
||||
@@ -55,7 +55,7 @@ DOMException::DOMException(const DOMException& exc):
|
||||
}
|
||||
|
||||
|
||||
DOMException::~DOMException() throw()
|
||||
DOMException::~DOMException() noexcept
|
||||
{
|
||||
}
|
||||
|
||||
@@ -71,13 +71,13 @@ DOMException& DOMException::operator = (const DOMException& exc)
|
||||
}
|
||||
|
||||
|
||||
const char* DOMException::name() const throw()
|
||||
const char* DOMException::name() const noexcept
|
||||
{
|
||||
return "DOMException";
|
||||
}
|
||||
|
||||
|
||||
const char* DOMException::className() const throw()
|
||||
const char* DOMException::className() const noexcept
|
||||
{
|
||||
return typeid(*this).name();
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ EventException::EventException(const EventException& exc):
|
||||
}
|
||||
|
||||
|
||||
EventException::~EventException() throw()
|
||||
EventException::~EventException() noexcept
|
||||
{
|
||||
}
|
||||
|
||||
@@ -44,13 +44,13 @@ EventException& EventException::operator = (const EventException& exc)
|
||||
}
|
||||
|
||||
|
||||
const char* EventException::name() const throw()
|
||||
const char* EventException::name() const noexcept
|
||||
{
|
||||
return "EventException";
|
||||
}
|
||||
|
||||
|
||||
const char* EventException::className() const throw()
|
||||
const char* EventException::className() const noexcept
|
||||
{
|
||||
return typeid(*this).name();
|
||||
}
|
||||
|
||||
@@ -57,6 +57,14 @@ Name::Name(const Name& name):
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
Name::Name(Name&& name) noexcept:
|
||||
_qname(std::move(name._qname)),
|
||||
_namespaceURI(std::move(name._namespaceURI)),
|
||||
_localName(std::move(name._localName))
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
Name::~Name()
|
||||
{
|
||||
@@ -75,6 +83,16 @@ Name& Name::operator = (const Name& name)
|
||||
}
|
||||
|
||||
|
||||
Name& Name::operator = (Name&& name) noexcept
|
||||
{
|
||||
_qname = std::move(name._qname);
|
||||
_namespaceURI = std::move(name._namespaceURI);
|
||||
_localName = std::move(name._localName);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
void Name::swap(Name& name)
|
||||
{
|
||||
std::swap(_qname, name._qname);
|
||||
|
||||
@@ -71,8 +71,8 @@ void NamespaceSupport::getDeclaredPrefixes(PrefixSet& prefixes) const
|
||||
{
|
||||
prefixes.clear();
|
||||
const Context& ctx = _contexts.back();
|
||||
for (Context::const_iterator it = ctx.begin(); it != ctx.end(); ++it)
|
||||
prefixes.insert(it->first);
|
||||
for (const auto& p: ctx)
|
||||
prefixes.insert(p.first);
|
||||
}
|
||||
|
||||
|
||||
@@ -148,7 +148,7 @@ const XMLString& NamespaceSupport::getURI(const XMLString& prefix) const
|
||||
|
||||
void NamespaceSupport::pushContext()
|
||||
{
|
||||
_contexts.push_back(Context());
|
||||
_contexts.emplace_back();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -603,9 +603,9 @@ void ParserEngine::popContext()
|
||||
|
||||
void ParserEngine::resetContext()
|
||||
{
|
||||
for (ContextStack::iterator it = _context.begin(); it != _context.end(); ++it)
|
||||
for (auto p: _context)
|
||||
{
|
||||
delete *it;
|
||||
delete p;
|
||||
}
|
||||
_context.clear();
|
||||
}
|
||||
|
||||
@@ -49,6 +49,48 @@ QName::QName(const std::string& ns, const std::string& name, const std::string&
|
||||
}
|
||||
|
||||
|
||||
QName::QName(const QName& qname):
|
||||
_ns(qname._ns),
|
||||
_name(qname._name),
|
||||
_prefix(qname._prefix)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
QName::QName(QName&& qname) noexcept:
|
||||
_ns(std::move(qname._ns)),
|
||||
_name(std::move(qname._name)),
|
||||
_prefix(std::move(qname._prefix))
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
QName& QName::operator = (const QName& qname)
|
||||
{
|
||||
QName tmp(qname);
|
||||
swap(tmp);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
QName& QName::operator = (QName&& qname) noexcept
|
||||
{
|
||||
_ns = std::move(qname._ns);
|
||||
_name = std::move(qname._name);
|
||||
_prefix = std::move(qname._prefix);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
void QName::swap(QName& qname)
|
||||
{
|
||||
std::swap(_ns, qname._ns);
|
||||
std::swap(_name, qname._name);
|
||||
std::swap(_prefix, qname._prefix);
|
||||
}
|
||||
|
||||
|
||||
std::string QName::toString() const
|
||||
{
|
||||
std::string r;
|
||||
|
||||
@@ -77,7 +77,7 @@ SAXParseException::SAXParseException(const SAXParseException& exc):
|
||||
}
|
||||
|
||||
|
||||
SAXParseException::~SAXParseException() throw()
|
||||
SAXParseException::~SAXParseException() noexcept
|
||||
{
|
||||
}
|
||||
|
||||
@@ -96,13 +96,13 @@ SAXParseException& SAXParseException::operator = (const SAXParseException& exc)
|
||||
}
|
||||
|
||||
|
||||
const char* SAXParseException::name() const throw()
|
||||
const char* SAXParseException::name() const noexcept
|
||||
{
|
||||
return "SAXParseException";
|
||||
}
|
||||
|
||||
|
||||
const char* SAXParseException::className() const throw()
|
||||
const char* SAXParseException::className() const noexcept
|
||||
{
|
||||
return typeid(*this).name();
|
||||
}
|
||||
|
||||
@@ -367,10 +367,10 @@ void XMLStreamParser::popElement()
|
||||
{
|
||||
// Find the first unhandled attribute and report it.
|
||||
//
|
||||
for (AttributeMapType::const_iterator i(e.attributeMap.begin()); i != e.attributeMap.end(); ++i)
|
||||
for (const auto& p: e.attributeMap)
|
||||
{
|
||||
if (!i->second.handled)
|
||||
throw XMLStreamParserException(*this, "unexpected attribute '" + i->first.toString() + "'");
|
||||
if (!p.second.handled)
|
||||
throw XMLStreamParserException(*this, "unexpected attribute '" + p.first.toString() + "'");
|
||||
}
|
||||
poco_assert(false);
|
||||
}
|
||||
@@ -755,7 +755,7 @@ void XMLCALL XMLStreamParser::handleStartElement(void* v, const XML_Char* name,
|
||||
ElementEntry* pe(0);
|
||||
if (am)
|
||||
{
|
||||
p._elementState.push_back(ElementEntry(p._depth + 1));
|
||||
p._elementState.emplace_back(p._depth + 1);
|
||||
pe = &p._elementState.back();
|
||||
}
|
||||
|
||||
@@ -774,7 +774,7 @@ void XMLCALL XMLStreamParser::handleStartElement(void* v, const XML_Char* name,
|
||||
}
|
||||
else
|
||||
{
|
||||
p._attributes.push_back(AttributeType());
|
||||
p._attributes.emplace_back();
|
||||
splitName(*atts, p._attributes.back().qname);
|
||||
p._attributes.back().value = *(atts + 1);
|
||||
}
|
||||
@@ -912,7 +912,7 @@ void XMLCALL XMLStreamParser::handleStartNamespaceDecl(void* v, const XML_Char*
|
||||
if (ps.parsing == XML_FINISHED)
|
||||
return;
|
||||
|
||||
p._startNamespace.push_back(QName());
|
||||
p._startNamespace.emplace_back();
|
||||
p._startNamespace.back().prefix() = (prefix != 0 ? prefix : "");
|
||||
p._startNamespace.back().namespaceURI() = (ns != 0 ? ns : "");
|
||||
}
|
||||
@@ -931,7 +931,7 @@ void XMLCALL XMLStreamParser::handleEndNamespaceDecl(void* v, const XML_Char* pr
|
||||
if (ps.parsing == XML_FINISHED)
|
||||
return;
|
||||
|
||||
p._endNamespace.push_back(QName());
|
||||
p._endNamespace.emplace_back();
|
||||
p._endNamespace.back().prefix() = (prefix != 0 ? prefix : "");
|
||||
}
|
||||
|
||||
|
||||
@@ -55,7 +55,7 @@ void XMLStreamParserException::init()
|
||||
}
|
||||
|
||||
|
||||
const char* XMLStreamParserException::name() const throw()
|
||||
const char* XMLStreamParserException::name() const noexcept
|
||||
{
|
||||
return _name.c_str();
|
||||
}
|
||||
|
||||
@@ -32,10 +32,10 @@ std::string fromXMLString(const XMLString& str)
|
||||
std::string result;
|
||||
result.reserve(str.size());
|
||||
|
||||
for (XMLString::const_iterator it = str.begin(); it != str.end(); ++it)
|
||||
for (auto xc: str)
|
||||
{
|
||||
char c;
|
||||
wctomb(&c, *it);
|
||||
wctomb(&c, xc);
|
||||
result += c;
|
||||
}
|
||||
return result;
|
||||
|
||||
@@ -259,7 +259,7 @@ void XMLWriter::startElement(const XMLString& namespaceURI, const XMLString& loc
|
||||
writeCanonicalStartElement(namespaceURI, localName, qname, attributes);
|
||||
else
|
||||
writeStartElement(namespaceURI, localName, qname, attributes);
|
||||
_elementStack.push_back(Name(qname, namespaceURI, localName));
|
||||
_elementStack.emplace_back(qname, namespaceURI, localName);
|
||||
_contentWritten = false;
|
||||
++_depth;
|
||||
}
|
||||
@@ -706,7 +706,7 @@ void XMLWriter::closeStartTag()
|
||||
|
||||
void XMLWriter::declareNamespaces(const XMLString& namespaceURI, const XMLString& localName, const XMLString& qname, const Attributes& attributes)
|
||||
{
|
||||
std::map<XMLString, std::set<XMLString> > usedNamespaces;
|
||||
std::map<XMLString, std::set<XMLString>> usedNamespaces;
|
||||
bool defaultNameSpaceUsed = false;
|
||||
XMLString defaultNamespaceURI = _namespaces.getURI(XMLString());
|
||||
XMLString local;
|
||||
@@ -738,32 +738,32 @@ void XMLWriter::declareNamespaces(const XMLString& namespaceURI, const XMLString
|
||||
defaultNameSpaceUsed = defaultNameSpaceUsed || (!defaultNamespaceURI.empty() && attributeNamespaceURI == defaultNamespaceURI);
|
||||
}
|
||||
}
|
||||
for (std::map<XMLString, std::set<XMLString> >::const_iterator it = usedNamespaces.begin(); it != usedNamespaces.end(); ++it)
|
||||
for (const auto& p: usedNamespaces)
|
||||
{
|
||||
const std::set<XMLString> namespaceURIs = it->second;
|
||||
for (std::set<XMLString>::const_iterator itURI = namespaceURIs.begin(); itURI != namespaceURIs.end(); ++itURI)
|
||||
const std::set<XMLString> namespaceURIs = p.second;
|
||||
for (const auto& nsURI: namespaceURIs)
|
||||
{
|
||||
XMLString prefix = it->first;
|
||||
XMLString prefix = p.first;
|
||||
if (prefix.empty())
|
||||
prefix = _namespaces.getPrefix(*itURI);
|
||||
if (prefix.empty() && !_namespaces.isMapped(*itURI))
|
||||
prefix = _namespaces.getPrefix(nsURI);
|
||||
if (prefix.empty() && !_namespaces.isMapped(nsURI))
|
||||
{
|
||||
if (defaultNameSpaceUsed)
|
||||
{
|
||||
if (*itURI != defaultNamespaceURI)
|
||||
if (nsURI != defaultNamespaceURI)
|
||||
prefix = uniquePrefix();
|
||||
}
|
||||
else
|
||||
{
|
||||
defaultNamespaceURI = *itURI;
|
||||
defaultNamespaceURI = nsURI;
|
||||
defaultNameSpaceUsed = true;
|
||||
}
|
||||
|
||||
}
|
||||
const XMLString& uri = _namespaces.getURI(prefix);
|
||||
if ((uri.empty() || uri != *itURI) && !itURI->empty())
|
||||
if ((uri.empty() || uri != nsURI) && !nsURI.empty())
|
||||
{
|
||||
_namespaces.declarePrefix(prefix, *itURI);
|
||||
_namespaces.declarePrefix(prefix, nsURI);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -803,11 +803,10 @@ void XMLWriter::addNamespaceAttributes(AttributeMap& attributeMap)
|
||||
{
|
||||
NamespaceSupport::PrefixSet prefixes;
|
||||
_namespaces.getDeclaredPrefixes(prefixes);
|
||||
for (NamespaceSupport::PrefixSet::const_iterator it = prefixes.begin(); it != prefixes.end(); ++it)
|
||||
for (const auto& prefix: prefixes)
|
||||
{
|
||||
XMLString prefix = *it;
|
||||
XMLString uri = _namespaces.getURI(prefix);
|
||||
XMLString qname = NamespaceSupport::XMLNS_NAMESPACE_PREFIX;
|
||||
XMLString uri = _namespaces.getURI(prefix);
|
||||
XMLString qname = NamespaceSupport::XMLNS_NAMESPACE_PREFIX;
|
||||
|
||||
if (!prefix.empty())
|
||||
{
|
||||
@@ -823,11 +822,10 @@ void XMLWriter::addNamespaceAttributes(CanonicalAttributeMap& attributeMap)
|
||||
{
|
||||
NamespaceSupport::PrefixSet prefixes;
|
||||
_namespaces.getDeclaredPrefixes(prefixes);
|
||||
for (NamespaceSupport::PrefixSet::const_iterator it = prefixes.begin(); it != prefixes.end(); ++it)
|
||||
for (const auto& prefix: prefixes)
|
||||
{
|
||||
XMLString prefix = *it;
|
||||
XMLString uri = _namespaces.getURI(prefix);
|
||||
XMLString qname = NamespaceSupport::XMLNS_NAMESPACE_PREFIX;
|
||||
XMLString uri = _namespaces.getURI(prefix);
|
||||
XMLString qname = NamespaceSupport::XMLNS_NAMESPACE_PREFIX;
|
||||
|
||||
if (!prefix.empty())
|
||||
{
|
||||
@@ -898,7 +896,7 @@ void XMLWriter::addAttributes(CanonicalAttributeMap& attributeMap, const Attribu
|
||||
|
||||
void XMLWriter::writeAttributes(const AttributeMap& attributeMap)
|
||||
{
|
||||
for (AttributeMap::const_iterator it = attributeMap.begin(); it != attributeMap.end(); ++it)
|
||||
for (const auto& ap: attributeMap)
|
||||
{
|
||||
if ((_options & PRETTY_PRINT) && (_options & PRETTY_PRINT_ATTRIBUTES))
|
||||
{
|
||||
@@ -909,11 +907,10 @@ void XMLWriter::writeAttributes(const AttributeMap& attributeMap)
|
||||
{
|
||||
writeMarkup(MARKUP_SPACE);
|
||||
}
|
||||
writeXML(it->first);
|
||||
writeXML(ap.first);
|
||||
writeMarkup(MARKUP_EQQUOT);
|
||||
for (XMLString::const_iterator itc = it->second.begin(); itc != it->second.end(); ++itc)
|
||||
for (auto c: ap.second)
|
||||
{
|
||||
XMLChar c = *itc;
|
||||
switch (c)
|
||||
{
|
||||
case '"': writeMarkup(MARKUP_QUOTENC); break;
|
||||
@@ -937,7 +934,7 @@ void XMLWriter::writeAttributes(const AttributeMap& attributeMap)
|
||||
|
||||
void XMLWriter::writeAttributes(const CanonicalAttributeMap& attributeMap)
|
||||
{
|
||||
for (CanonicalAttributeMap::const_iterator it = attributeMap.begin(); it != attributeMap.end(); ++it)
|
||||
for (const auto& ap: attributeMap)
|
||||
{
|
||||
if ((_options & PRETTY_PRINT) && (_options & PRETTY_PRINT_ATTRIBUTES))
|
||||
{
|
||||
@@ -948,11 +945,10 @@ void XMLWriter::writeAttributes(const CanonicalAttributeMap& attributeMap)
|
||||
{
|
||||
writeMarkup(MARKUP_SPACE);
|
||||
}
|
||||
writeXML(it->second.first);
|
||||
writeXML(ap.second.first);
|
||||
writeMarkup(MARKUP_EQQUOT);
|
||||
for (XMLString::const_iterator itc = it->second.second.begin(); itc != it->second.second.end(); ++itc)
|
||||
for (auto c: ap.second.second)
|
||||
{
|
||||
XMLChar c = *itc;
|
||||
switch (c)
|
||||
{
|
||||
case '"': writeMarkup(MARKUP_QUOTENC); break;
|
||||
|
||||
Reference in New Issue
Block a user