2007-07-19 17:01:42 +00:00
|
|
|
#ifndef ARABICA_XSLT_QNAME_HPP
|
|
|
|
#define ARABICA_XSLT_QNAME_HPP
|
|
|
|
|
2008-08-05 22:03:33 +01:00
|
|
|
#include <XML/strings.hpp>
|
|
|
|
|
2007-07-19 17:01:42 +00:00
|
|
|
namespace Arabica
|
|
|
|
{
|
|
|
|
namespace XSLT
|
|
|
|
{
|
|
|
|
|
|
|
|
struct QName
|
|
|
|
{
|
|
|
|
std::string prefix;
|
|
|
|
std::string localName;
|
|
|
|
std::string namespaceURI;
|
2009-03-31 20:00:26 +01:00
|
|
|
std::string qname;
|
|
|
|
|
|
|
|
QName(const std::string& p,
|
|
|
|
const std::string& lN,
|
|
|
|
const std::string& uri) :
|
|
|
|
prefix(p),
|
|
|
|
localName(lN),
|
|
|
|
namespaceURI(uri),
|
|
|
|
qname(p.empty() ? lN : (p + ":" + lN))
|
|
|
|
{
|
|
|
|
} // QName
|
|
|
|
|
2009-04-07 10:29:56 +01:00
|
|
|
static QName create(const XML::QualifiedName<std::string>& qName)
|
|
|
|
{
|
|
|
|
if(qName.prefix().length() && qName.namespaceUri().empty())
|
|
|
|
throw SAX::SAXException("Prefix " + qName.prefix() + " is not declared.");
|
|
|
|
return QName(qName.prefix(), qName.localName(), qName.namespaceUri());
|
|
|
|
} // create
|
|
|
|
|
2009-03-31 20:00:26 +01:00
|
|
|
static QName create(const std::string& qName)
|
|
|
|
{
|
|
|
|
return create(qName, "");
|
|
|
|
} // create
|
2007-07-19 17:01:42 +00:00
|
|
|
|
2009-03-31 20:00:26 +01:00
|
|
|
static QName create(const std::string& qName, const std::string& namespaceURI)
|
2007-07-19 17:01:42 +00:00
|
|
|
{
|
2009-02-23 19:43:20 +00:00
|
|
|
if(!Arabica::XML::is_qname<Arabica::default_string_adaptor<std::string> >(qName))
|
2010-01-02 22:20:13 +00:00
|
|
|
throw SAX::SAXException("Bad name : '" + qName + "'");
|
2008-08-05 22:03:33 +01:00
|
|
|
|
2007-11-22 22:36:47 +00:00
|
|
|
static char COLON = Arabica::text::Unicode<char>::COLON;
|
2009-03-31 20:00:26 +01:00
|
|
|
|
|
|
|
std::string prefix;
|
|
|
|
std::string localName;
|
2007-07-19 17:01:42 +00:00
|
|
|
|
2007-11-22 22:36:47 +00:00
|
|
|
size_t colon = qName.find(COLON);
|
2009-03-31 20:00:26 +01:00
|
|
|
|
2007-11-22 22:36:47 +00:00
|
|
|
if(colon == std::string::npos)
|
2009-03-31 20:00:26 +01:00
|
|
|
localName = qName;
|
2007-07-19 17:01:42 +00:00
|
|
|
else
|
|
|
|
{
|
2009-03-31 20:00:26 +01:00
|
|
|
prefix = qName.substr(0, colon);
|
|
|
|
localName = qName.substr(colon+1);
|
2007-07-19 17:01:42 +00:00
|
|
|
}
|
2009-03-31 20:00:26 +01:00
|
|
|
return QName(prefix, localName, namespaceURI);
|
|
|
|
} // create
|
2009-04-03 19:01:26 +01: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 20:00:26 +01:00
|
|
|
}; // struct QName
|
2007-07-19 17:01:42 +00:00
|
|
|
|
2009-04-03 19:01:26 +01:00
|
|
|
|
|
|
|
|
2007-07-19 17:01:42 +00:00
|
|
|
} // namespace XSLT
|
|
|
|
} // namespace Arabica
|
|
|
|
#endif
|