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,
|
2012-11-21 07:59:40 +01:00
|
|
|
const string_type& lN,
|
|
|
|
const string_type& uri) :
|
2009-03-31 21:00:26 +02:00
|
|
|
prefix(p),
|
|
|
|
localName(lN),
|
|
|
|
namespaceURI(uri),
|
2012-11-21 07:59:40 +01:00
|
|
|
qname()
|
2009-03-31 21:00:26 +02:00
|
|
|
{
|
2012-11-21 07:59:40 +01:00
|
|
|
if(!string_adaptor::empty(p))
|
|
|
|
{
|
|
|
|
string_adaptor::append(qname, p);
|
|
|
|
string_adaptor::append(qname, SC::COLON);
|
|
|
|
} // if ...
|
|
|
|
string_adaptor::append(qname, lN);
|
2009-03-31 21:00:26 +02:00
|
|
|
} // QName
|
|
|
|
|
2012-11-21 12:12:35 +01:00
|
|
|
static QName create(const XML::QualifiedName<string_type, string_adaptor>& qName)
|
2009-04-07 11:29:56 +02:00
|
|
|
{
|
2012-11-21 07:59:40 +01:00
|
|
|
if(string_adaptor::length(qName.prefix()) && string_adaptor::empty(qName.namespaceUri()))
|
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-21 07:59:40 +01:00
|
|
|
size_t colon = string_adaptor::find(qName, SC::COLON);
|
2009-03-31 21:00:26 +02:00
|
|
|
|
2012-11-21 07:59:40 +01:00
|
|
|
if(colon == string_adaptor::npos())
|
2009-03-31 21:00:26 +02:00
|
|
|
localName = qName;
|
2007-07-19 19:01:42 +02:00
|
|
|
else
|
|
|
|
{
|
2012-11-21 07:59:40 +01:00
|
|
|
prefix = string_adaptor::substr(qName, 0, colon);
|
|
|
|
localName = string_adaptor::substr(qName, 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
|