2007-07-19 19:01:42 +02:00
|
|
|
#ifndef ARABICA_XSLT_QNAME_HPP
|
|
|
|
#define ARABICA_XSLT_QNAME_HPP
|
|
|
|
|
2008-08-05 23:03:33 +02:00
|
|
|
#include <XML/strings.hpp>
|
2012-11-12 22:46:08 +01:00
|
|
|
#include "handler/xslt_constants.hpp"
|
2008-08-05 23:03:33 +02:00
|
|
|
|
2007-07-19 19:01:42 +02:00
|
|
|
namespace Arabica
|
|
|
|
{
|
|
|
|
namespace XSLT
|
|
|
|
{
|
|
|
|
|
2012-11-06 21:15:35 +01:00
|
|
|
template<class string_type, class string_adaptor>
|
2007-07-19 19:01:42 +02:00
|
|
|
struct QName
|
|
|
|
{
|
2012-11-12 22:46:08 +01:00
|
|
|
typedef StylesheetConstant<string_type, string_adaptor> SC;
|
|
|
|
|
2012-11-06 21:15:35 +01:00
|
|
|
string_type prefix;
|
|
|
|
string_type localName;
|
|
|
|
string_type namespaceURI;
|
|
|
|
string_type qname;
|
2009-03-31 21:00:26 +02:00
|
|
|
|
2012-11-06 21:15:35 +01:00
|
|
|
QName(const string_type& p,
|
|
|
|
const string_type& lN,
|
|
|
|
const string_type& uri) :
|
2009-03-31 21:00:26 +02:00
|
|
|
prefix(p),
|
|
|
|
localName(lN),
|
|
|
|
namespaceURI(uri),
|
2012-11-12 22:46:08 +01:00
|
|
|
qname(p.empty() ? lN : (p + SC::COLON + lN))
|
2009-03-31 21:00:26 +02:00
|
|
|
{
|
|
|
|
} // QName
|
|
|
|
|
2012-11-06 21:15:35 +01:00
|
|
|
static QName create(const XML::QualifiedName<string_type>& qName)
|
2009-04-07 11:29:56 +02:00
|
|
|
{
|
|
|
|
if(qName.prefix().length() && qName.namespaceUri().empty())
|
2012-11-12 22:46:08 +01:00
|
|
|
throw SAX::SAXException("Prefix " + string_adaptor::asStdString(qName.prefix()) + " is not declared.");
|
2009-04-07 11:29:56 +02:00
|
|
|
return QName(qName.prefix(), qName.localName(), qName.namespaceUri());
|
|
|
|
} // create
|
|
|
|
|
2012-11-06 21:15:35 +01:00
|
|
|
static QName create(const string_type& qName)
|
2009-03-31 21:00:26 +02:00
|
|
|
{
|
2012-11-12 22:46:08 +01:00
|
|
|
return create(qName, string_adaptor::empty_string());
|
2009-03-31 21:00:26 +02:00
|
|
|
} // create
|
2007-07-19 19:01:42 +02:00
|
|
|
|
2012-11-06 21:15:35 +01:00
|
|
|
static QName create(const string_type& qName, const string_type& namespaceURI)
|
2007-07-19 19:01:42 +02:00
|
|
|
{
|
2012-11-06 21:15:35 +01:00
|
|
|
if(!Arabica::XML::is_qname<string_adaptor>(qName))
|
2012-11-12 22:46:08 +01:00
|
|
|
throw SAX::SAXException("Bad name : '" + string_adaptor::asStdString(qName) + "'");
|
2009-03-31 21:00:26 +02:00
|
|
|
|
2012-11-06 21:15:35 +01:00
|
|
|
string_type prefix;
|
|
|
|
string_type localName;
|
2007-07-19 19:01:42 +02:00
|
|
|
|
2012-11-12 22:46:08 +01:00
|
|
|
size_t colon = qName.find(SC::COLON);
|
2009-03-31 21:00:26 +02:00
|
|
|
|
2012-11-06 21:15:35 +01:00
|
|
|
if(colon == string_type::npos)
|
2009-03-31 21:00:26 +02:00
|
|
|
localName = qName;
|
2007-07-19 19:01:42 +02:00
|
|
|
else
|
|
|
|
{
|
2009-03-31 21:00:26 +02:00
|
|
|
prefix = qName.substr(0, colon);
|
|
|
|
localName = qName.substr(colon+1);
|
2007-07-19 19:01:42 +02:00
|
|
|
}
|
2009-03-31 21:00:26 +02:00
|
|
|
return QName(prefix, localName, namespaceURI);
|
|
|
|
} // create
|
2009-04-03 20:01:26 +02:00
|
|
|
|
|
|
|
bool operator==(const QName& rhs) const
|
|
|
|
{
|
|
|
|
return (namespaceURI == rhs.namespaceURI) &&
|
|
|
|
(localName == rhs.localName);
|
|
|
|
} // operator==
|
|
|
|
|
|
|
|
bool operator<(const QName& rhs) const
|
|
|
|
{
|
|
|
|
if(namespaceURI == rhs.namespaceURI)
|
|
|
|
return localName < rhs.localName;
|
|
|
|
return namespaceURI < rhs.namespaceURI;
|
|
|
|
} // operator<
|
2009-03-31 21:00:26 +02:00
|
|
|
}; // struct QName
|
2007-07-19 19:01:42 +02:00
|
|
|
|
2009-04-03 20:01:26 +02:00
|
|
|
|
|
|
|
|
2007-07-19 19:01:42 +02:00
|
|
|
} // namespace XSLT
|
|
|
|
} // namespace Arabica
|
|
|
|
#endif
|