mirror of
https://github.com/jezhiggins/arabica
synced 2025-01-30 08:38:15 +01:00
simplified parseQName so you can pass in a std::map if you fancy
This commit is contained in:
parent
cbc3f6e8d6
commit
3557ec2d37
1 changed files with 37 additions and 0 deletions
|
@ -4,6 +4,7 @@
|
||||||
#include <SAX/ArabicaConfig.hpp>
|
#include <SAX/ArabicaConfig.hpp>
|
||||||
#include <Arabica/StringAdaptor.hpp>
|
#include <Arabica/StringAdaptor.hpp>
|
||||||
#include <XML/strings.hpp>
|
#include <XML/strings.hpp>
|
||||||
|
#include <map>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
|
||||||
template<class string_type, class string_adaptor> class QualifiedNameTest;
|
template<class string_type, class string_adaptor> class QualifiedNameTest;
|
||||||
|
@ -12,6 +13,34 @@ namespace Arabica
|
||||||
{
|
{
|
||||||
namespace XML
|
namespace XML
|
||||||
{
|
{
|
||||||
|
namespace impl
|
||||||
|
{
|
||||||
|
|
||||||
|
template<class string_type, class string_adaptor>
|
||||||
|
class MapMapper
|
||||||
|
{
|
||||||
|
typedef typename std::map<string_type, string_type> string_map;
|
||||||
|
typedef typename std::map<string_type, string_type>::const_iterator string_map_iterator;
|
||||||
|
public:
|
||||||
|
MapMapper(const std::map<string_type, string_type>& namespaces) : namespaces_(namespaces) { }
|
||||||
|
MapMapper(const MapMapper& rhs) : namespaces_(rhs.namespaces_) { }
|
||||||
|
|
||||||
|
string_type operator()(const string_type& prefix) const
|
||||||
|
{
|
||||||
|
string_map_iterator ns = namespaces_.find(prefix);
|
||||||
|
if(ns == namespaces_.end())
|
||||||
|
return string_adaptor::empty_string();
|
||||||
|
return ns->second;
|
||||||
|
} //operator()
|
||||||
|
|
||||||
|
private:
|
||||||
|
const string_map& namespaces_;
|
||||||
|
|
||||||
|
bool operator==(const MapMapper&) const;
|
||||||
|
MapMapper& operator=(const MapMapper&);
|
||||||
|
}; // class MapMapper
|
||||||
|
|
||||||
|
} // namespace impl
|
||||||
|
|
||||||
template<class string_type, class string_adaptor = Arabica::default_string_adaptor<string_type> >
|
template<class string_type, class string_adaptor = Arabica::default_string_adaptor<string_type> >
|
||||||
class QualifiedName
|
class QualifiedName
|
||||||
|
@ -56,6 +85,14 @@ public:
|
||||||
return QualifiedName(prefix, localName, uri, rawname);
|
return QualifiedName(prefix, localName, uri, rawname);
|
||||||
} // parseQName
|
} // parseQName
|
||||||
|
|
||||||
|
static QualifiedName parseQName(const string_type& rawname,
|
||||||
|
bool is_attribute,
|
||||||
|
const std::map<string_type, string_type>& namespaces)
|
||||||
|
{
|
||||||
|
return parseQName(rawname, is_attribute, impl::MapMapper<string_type, string_adaptor>(namespaces));
|
||||||
|
} // parseQName
|
||||||
|
|
||||||
|
public:
|
||||||
QualifiedName(const QualifiedName& rhs) :
|
QualifiedName(const QualifiedName& rhs) :
|
||||||
prefix_(rhs.prefix_),
|
prefix_(rhs.prefix_),
|
||||||
localName_(rhs.localName_),
|
localName_(rhs.localName_),
|
||||||
|
|
Loading…
Add table
Reference in a new issue