mirror of
https://github.com/jezhiggins/arabica
synced 2025-01-18 22:26:32 +01:00
working towards excising all std::string-isms, so that Arabica can be used with any string type
This commit is contained in:
parent
4c18001197
commit
f354817b66
18 changed files with 181 additions and 68 deletions
|
@ -44,6 +44,10 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "example_xgrep", "examples\X
|
|||
ProjectSection(ProjectDependencies) = postProject
|
||||
EndProjectSection
|
||||
EndProject
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "test_xpath_silly", "test\XPath_silly\xpathic_silly.vcproj", "{B3C75B3A-BB0A-4B23-87F9-FB9CD98FF8CE}"
|
||||
ProjectSection(ProjectDependencies) = postProject
|
||||
EndProjectSection
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfiguration) = preSolution
|
||||
Debug = Debug
|
||||
|
@ -90,6 +94,10 @@ Global
|
|||
{5F7B038E-5148-4EF4-AB43-5035F666D00D}.Debug.Build.0 = Debug|Win32
|
||||
{5F7B038E-5148-4EF4-AB43-5035F666D00D}.Release.ActiveCfg = Release|Win32
|
||||
{5F7B038E-5148-4EF4-AB43-5035F666D00D}.Release.Build.0 = Release|Win32
|
||||
{B3C75B3A-BB0A-4B23-87F9-FB9CD98FF8CE}.Debug.ActiveCfg = Debug|Win32
|
||||
{B3C75B3A-BB0A-4B23-87F9-FB9CD98FF8CE}.Debug.Build.0 = Debug|Win32
|
||||
{B3C75B3A-BB0A-4B23-87F9-FB9CD98FF8CE}.Release.ActiveCfg = Release|Win32
|
||||
{B3C75B3A-BB0A-4B23-87F9-FB9CD98FF8CE}.Release.Build.0 = Release|Win32
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
EndGlobalSection
|
||||
|
|
|
@ -83,7 +83,7 @@ class AttrImpl : public DOM::Attr_impl<stringT>,
|
|||
{
|
||||
stringT value;
|
||||
for(DOM::Node_impl<stringT>* c = NodeT::getFirstChild(); c != 0; c = c->getNextSibling())
|
||||
value += c->getNodeValue();
|
||||
string_adaptorT::append(value, c->getNodeValue());
|
||||
return value;
|
||||
} // getNodeValue
|
||||
|
||||
|
|
|
@ -70,7 +70,11 @@ class AttrMap : public NamedNodeMapImpl<stringT, string_adaptorT>
|
|||
|
||||
void setAttributeNS(const stringT& namespaceURI, const stringT& qualifiedName, const stringT& value)
|
||||
{
|
||||
AttrNSImpl<stringT, string_adaptorT>* a = new AttrNSImpl<stringT, string_adaptorT>(MapT::ownerDoc_, namespaceURI, !namespaceURI.empty(), qualifiedName);
|
||||
AttrNSImpl<stringT, string_adaptorT>* a =
|
||||
new AttrNSImpl<stringT, string_adaptorT>(MapT::ownerDoc_,
|
||||
namespaceURI,
|
||||
!string_adaptorT::empty(namespaceURI),
|
||||
qualifiedName);
|
||||
a->setValue(value);
|
||||
a->setOwnerElement(ownerElement_);
|
||||
MapT::setNamedItemNS(a);
|
||||
|
|
|
@ -10,7 +10,7 @@ namespace SimpleDOM
|
|||
template<class stringT, class string_adaptorT>
|
||||
class AttrNSImpl : public AttrImpl<stringT, string_adaptorT>
|
||||
{
|
||||
typedef typename stringT::size_type size_type;
|
||||
typedef typename string_adaptorT::size_type size_type;
|
||||
typedef AttrImpl<stringT, string_adaptorT> AttrT;
|
||||
|
||||
public:
|
||||
|
@ -24,9 +24,9 @@ class AttrNSImpl : public AttrImpl<stringT, string_adaptorT>
|
|||
string_adaptorT SA;
|
||||
bool hasPrefix = false;
|
||||
stringT prefix;
|
||||
size_type index = qualifiedName.find(SA.makeStringT(":"));
|
||||
size_type index = string_adaptorT::find(qualifiedName, SA.makeStringT(":"));
|
||||
|
||||
if(index == stringT::npos)
|
||||
if(index == string_adaptorT::npos)
|
||||
{ //qualifiedName contains no ':'
|
||||
localName_ = qualifiedName;
|
||||
if(localName_ == SA.makeStringT("xmlns"))
|
||||
|
@ -38,8 +38,8 @@ class AttrNSImpl : public AttrImpl<stringT, string_adaptorT>
|
|||
else
|
||||
{
|
||||
hasPrefix = true;
|
||||
prefix = qualifiedName.substr(0, index);
|
||||
localName_ = qualifiedName.substr(index+1);
|
||||
prefix = string_adaptorT::substr(qualifiedName, 0, index);
|
||||
localName_ = string_adaptorT::substr(qualifiedName, index+1);
|
||||
}
|
||||
|
||||
std::pair<bool, stringT> mappedURI =
|
||||
|
@ -69,8 +69,8 @@ class AttrNSImpl : public AttrImpl<stringT, string_adaptorT>
|
|||
virtual stringT getPrefix() const
|
||||
{
|
||||
string_adaptorT SA;
|
||||
size_type index = AttrT::name_.find(SA.makeStringT(":"));
|
||||
return (index != stringT::npos) ? AttrT::name_.substr(0, index) : stringT();
|
||||
size_type index = string_adaptorT::find(AttrT::name_, SA.makeStringT(":"));
|
||||
return (index != string_adaptorT::npos) ? string_adaptorT::substr(AttrT::name_, 0, index) : stringT();
|
||||
} // getPrefix
|
||||
|
||||
virtual void setPrefix(const stringT& prefix)
|
||||
|
@ -78,7 +78,7 @@ class AttrNSImpl : public AttrImpl<stringT, string_adaptorT>
|
|||
if(hasNamespaceURI_ == false)
|
||||
throw DOM::DOMException(DOM::DOMException::NAMESPACE_ERR);
|
||||
|
||||
if(prefix.empty())
|
||||
if(string_adaptorT::empty(prefix))
|
||||
{
|
||||
AttrT::name_ = localName_;
|
||||
return;
|
||||
|
@ -86,8 +86,9 @@ class AttrNSImpl : public AttrImpl<stringT, string_adaptorT>
|
|||
|
||||
checkPrefixAndNamespace<stringT, string_adaptorT>(true, prefix, true, namespaceURI_, DOM::Node<stringT>::ATTRIBUTE_NODE);
|
||||
|
||||
string_adaptorT SA;
|
||||
AttrT::name_ = prefix + SA.makeStringT(":") + localName_;
|
||||
AttrT::name_ = prefix;
|
||||
string_adaptorT::append(AttrT::name_, string_adaptorT().makeStringT(":"));
|
||||
string_adaptorT::append(AttrT::name_, localName_);
|
||||
} // setPrefix
|
||||
|
||||
virtual stringT getLocalName() const
|
||||
|
@ -108,8 +109,7 @@ class AttrNSImpl : public AttrImpl<stringT, string_adaptorT>
|
|||
|
||||
virtual bool hasPrefix() const
|
||||
{
|
||||
string_adaptorT SA;
|
||||
return (AttrT::name_.find(SA.makeStringT(":")) != stringT::npos);
|
||||
return (string_adaptorT::find(AttrT::name_, string_adaptorT().makeStringT(":")) != string_adaptorT::npos);
|
||||
} // hasPrefix
|
||||
|
||||
private:
|
||||
|
|
|
@ -36,42 +36,47 @@ class CharacterDataImpl : virtual public DOM::CharacterData_impl<stringT>,
|
|||
|
||||
virtual int getLength() const
|
||||
{
|
||||
return static_cast<int>(data_.length());
|
||||
return static_cast<int>(string_adaptorT::length(data_));
|
||||
} // getLength
|
||||
|
||||
virtual stringT substringData(int offset, int count) const
|
||||
{
|
||||
return data_.substr(offset, count);
|
||||
return string_adaptorT::substr(data_, offset, count);
|
||||
} // substringData
|
||||
|
||||
virtual void appendData(const stringT& arg)
|
||||
{
|
||||
NodeT::throwIfReadOnly();
|
||||
data_.append(arg);
|
||||
string_adaptorT::append(data_, arg);
|
||||
} // appendData
|
||||
|
||||
virtual void insertData(int offset, const stringT& arg)
|
||||
{
|
||||
NodeT::throwIfReadOnly();
|
||||
if(offset > static_cast<int>(data_.length()))
|
||||
if(offset > static_cast<int>(string_adaptorT::length(data_)))
|
||||
throw DOM::DOMException(DOM::DOMException::INDEX_SIZE_ERR);
|
||||
data_.insert(offset, arg);
|
||||
|
||||
string_adaptorT::insert(data_, offset, arg);
|
||||
} // insertData
|
||||
|
||||
virtual void deleteData(int offset, int count)
|
||||
{
|
||||
NodeT::throwIfReadOnly();
|
||||
if(offset > static_cast<int>(data_.length()))
|
||||
|
||||
if(offset > static_cast<int>(string_adaptorT::length(data_)))
|
||||
throw DOM::DOMException(DOM::DOMException::INDEX_SIZE_ERR);
|
||||
data_.replace(offset, count, stringT());
|
||||
|
||||
string_adaptorT::replace(data_, offset, count, stringT());
|
||||
} // deleteData
|
||||
|
||||
virtual void replaceData(int offset, int count, const stringT& arg)
|
||||
{
|
||||
NodeT::throwIfReadOnly();
|
||||
if(offset > static_cast<int>(data_.length()))
|
||||
|
||||
if(offset > static_cast<int>(string_adaptorT::length(data_)))
|
||||
throw DOM::DOMException(DOM::DOMException::INDEX_SIZE_ERR);
|
||||
data_.replace(offset, count, arg);
|
||||
|
||||
string_adaptorT::replace(data_, offset, count, arg);
|
||||
} // replaceData
|
||||
|
||||
///////////////////////////////////////////////////////
|
||||
|
|
|
@ -43,7 +43,7 @@ class DOMImplementationImpl : public DOM::DOMImplementation_impl<stringT>
|
|||
for(int n = 0; names[n] != 0; ++n)
|
||||
{
|
||||
if((feature == SA.makeStringT(names[n])) &&
|
||||
(version.empty() || version == SA.makeStringT("1.0") || version == SA.makeStringT("2.0")))
|
||||
(string_adaptorT::empty(version) || version == SA.makeStringT("1.0") || version == SA.makeStringT("2.0")))
|
||||
return true;
|
||||
} // while
|
||||
|
||||
|
@ -65,7 +65,7 @@ class DOMImplementationImpl : public DOM::DOMImplementation_impl<stringT>
|
|||
{
|
||||
DocumentImpl<stringT, string_adaptorT>* doc = new DocumentImpl<stringT, string_adaptorT>(namespaceURI, qualifiedName, docType, this);
|
||||
|
||||
if(!qualifiedName.empty())
|
||||
if(!string_adaptorT::empty(qualifiedName))
|
||||
doc->appendChild(doc->createElementNS(namespaceURI, qualifiedName));
|
||||
|
||||
return doc;
|
||||
|
|
|
@ -204,7 +204,7 @@ class DocumentImpl : public DOM::Document_impl<stringT>,
|
|||
switch(importedNode->getNodeType())
|
||||
{
|
||||
case DOM::Node<stringT>::ATTRIBUTE_NODE:
|
||||
if(importedNode->getLocalName().empty())
|
||||
if(string_adaptorT::empty(importedNode->getLocalName()))
|
||||
newNode = createAttribute(importedNode->getNodeName());
|
||||
else
|
||||
newNode = createAttributeNS(importedNode->getNamespaceURI(), importedNode->getNodeName());
|
||||
|
@ -220,7 +220,7 @@ class DocumentImpl : public DOM::Document_impl<stringT>,
|
|||
case DOM::Node<stringT>::ELEMENT_NODE:
|
||||
{
|
||||
DOM::Element_impl<stringT>* elem;
|
||||
if(importedNode->getLocalName().empty())
|
||||
if(string_adaptorT::empty(importedNode->getLocalName()))
|
||||
elem = createElement(importedNode->getNodeName());
|
||||
else
|
||||
elem = createElementNS(importedNode->getNamespaceURI(), importedNode->getNodeName());
|
||||
|
@ -233,7 +233,7 @@ class DocumentImpl : public DOM::Document_impl<stringT>,
|
|||
if(a->getSpecified())
|
||||
{
|
||||
DOM::Attr_impl<stringT>* newA = dynamic_cast<DOM::Attr_impl<stringT>*>(importNode(a, true));
|
||||
if(a->getLocalName().empty())
|
||||
if(string_adaptorT::empty(a->getLocalName()))
|
||||
elem->setAttributeNode(newA);
|
||||
else
|
||||
elem->setAttributeNodeNS(newA);
|
||||
|
@ -296,14 +296,14 @@ class DocumentImpl : public DOM::Document_impl<stringT>,
|
|||
|
||||
virtual DOM::Element_impl<stringT>* createElementNS(const stringT& namespaceURI, const stringT& qualifiedName) const
|
||||
{
|
||||
ElementNSImpl<stringT, string_adaptorT>* n = new ElementNSImpl<stringT, string_adaptorT>(const_cast<DocumentImpl*>(this), namespaceURI, !namespaceURI.empty(), qualifiedName);
|
||||
ElementNSImpl<stringT, string_adaptorT>* n = new ElementNSImpl<stringT, string_adaptorT>(const_cast<DocumentImpl*>(this), namespaceURI, !string_adaptorT::empty(namespaceURI), qualifiedName);
|
||||
orphaned(n);
|
||||
return n;
|
||||
} // createElementNS
|
||||
|
||||
virtual DOM::Attr_impl<stringT>* createAttributeNS(const stringT& namespaceURI, const stringT& qualifiedName) const
|
||||
{
|
||||
AttrNSImpl<stringT, string_adaptorT>* n = new AttrNSImpl<stringT, string_adaptorT>(const_cast<DocumentImpl*>(this), namespaceURI, !namespaceURI.empty(), qualifiedName);
|
||||
AttrNSImpl<stringT, string_adaptorT>* n = new AttrNSImpl<stringT, string_adaptorT>(const_cast<DocumentImpl*>(this), namespaceURI, !string_adaptorT::empty(namespaceURI), qualifiedName);
|
||||
orphaned(n);
|
||||
return n;
|
||||
} // createAttrNS
|
||||
|
|
|
@ -163,7 +163,7 @@ class ElementImpl : public DOM::Element_impl<stringT>,
|
|||
if(a->getSpecified())
|
||||
{
|
||||
DOM::Attr_impl<stringT>* newA = dynamic_cast<DOM::Attr_impl<stringT>*>(a->cloneNode(true));
|
||||
if(a->getLocalName().empty())
|
||||
if(string_adaptorT::empty(a->getLocalName()))
|
||||
clone->setAttributeNode(newA);
|
||||
else
|
||||
clone->setAttributeNodeNS(newA);
|
||||
|
|
|
@ -10,7 +10,7 @@ namespace SimpleDOM
|
|||
template<class stringT, class string_adaptorT>
|
||||
class ElementNSImpl : public ElementImpl<stringT, string_adaptorT>
|
||||
{
|
||||
typedef typename stringT::size_type size_type;
|
||||
typedef typename string_adaptorT::size_type size_type;
|
||||
typedef ElementImpl<stringT, string_adaptorT> ElementImplT;
|
||||
public:
|
||||
ElementNSImpl(DocumentImpl<stringT, string_adaptorT>* ownerDoc,
|
||||
|
@ -23,17 +23,17 @@ class ElementNSImpl : public ElementImpl<stringT, string_adaptorT>
|
|||
string_adaptorT SA;
|
||||
bool hasPrefix = false;
|
||||
stringT prefix;
|
||||
size_type index = qualifiedName.find(SA.makeStringT(":"));
|
||||
size_type index = string_adaptorT::find(qualifiedName, SA.makeStringT(":"));
|
||||
|
||||
if(index == stringT::npos)
|
||||
if(index == string_adaptorT::npos)
|
||||
{ //qualifiedName contains no ':'
|
||||
localName_ = qualifiedName;
|
||||
}
|
||||
else
|
||||
{
|
||||
hasPrefix = true;
|
||||
prefix = qualifiedName.substr(0, index);
|
||||
localName_ = qualifiedName.substr(index+1);
|
||||
prefix = string_adaptorT::substr(qualifiedName, 0, index);
|
||||
localName_ = string_adaptorT::substr(qualifiedName, index+1);
|
||||
}
|
||||
|
||||
std::pair<bool, stringT> mappedURI =
|
||||
|
@ -62,8 +62,8 @@ class ElementNSImpl : public ElementImpl<stringT, string_adaptorT>
|
|||
virtual stringT getPrefix() const
|
||||
{
|
||||
string_adaptorT SA;
|
||||
size_type index = ElementImplT::tagName_.find(SA.makeStringT(":"));
|
||||
return (index != stringT::npos) ? ElementImplT::tagName_.substr(0, index) : stringT();
|
||||
size_type index = string_adaptorT::find(ElementImplT::tagName_, SA.makeStringT(":"));
|
||||
return (index != string_adaptorT::npos) ? string_adaptorT::substr(ElementImplT::tagName_, 0, index) : stringT();
|
||||
} // getPrefix
|
||||
|
||||
virtual void setPrefix(const stringT& prefix)
|
||||
|
@ -73,7 +73,7 @@ class ElementNSImpl : public ElementImpl<stringT, string_adaptorT>
|
|||
if(hasNamespaceURI_ == false)
|
||||
throw DOM::DOMException(DOM::DOMException::NAMESPACE_ERR);
|
||||
|
||||
if(prefix.empty())
|
||||
if(string_adaptorT::empty(prefix))
|
||||
{
|
||||
ElementImplT::tagName_ = localName_;
|
||||
return;
|
||||
|
@ -81,8 +81,9 @@ class ElementNSImpl : public ElementImpl<stringT, string_adaptorT>
|
|||
|
||||
checkPrefixAndNamespace<stringT, string_adaptorT>(true, prefix, true, namespaceURI_, DOM::Node<stringT>::ELEMENT_NODE);
|
||||
|
||||
string_adaptorT SA;
|
||||
ElementImplT::tagName_ = prefix + SA.makeStringT(":") + localName_;
|
||||
string_adaptorT::append(ElementImplT::tagName_, prefix);
|
||||
string_adaptorT::append(ElementImplT::tagName_, string_adaptorT().makeStringT(":"));
|
||||
string_adaptorT::append(ElementImplT::tagName_, localName_);
|
||||
} // setPrefix
|
||||
|
||||
virtual stringT getLocalName() const
|
||||
|
@ -103,8 +104,7 @@ class ElementNSImpl : public ElementImpl<stringT, string_adaptorT>
|
|||
|
||||
virtual bool hasPrefix() const
|
||||
{
|
||||
string_adaptorT SA;
|
||||
return (ElementImplT::tagName_.find(SA.makeStringT(":")) != stringT::npos);
|
||||
return (string_adaptorT::find(ElementImplT::tagName_, string_adaptorT().makeStringT(":")) != string_adaptorT::npos);
|
||||
} // hasPrefix
|
||||
|
||||
private:
|
||||
|
|
|
@ -23,7 +23,7 @@ std::pair<bool, stringT> checkPrefixAndNamespace(bool hasPrefix,
|
|||
if(!hasPrefix)
|
||||
return std::make_pair(hasNamespaceURI, namespaceURI);
|
||||
|
||||
if(prefix.find(SA.makeStringT(":")) != stringT::npos)
|
||||
if(string_adaptorT::find(prefix, SA.makeStringT(":")) != string_adaptorT::npos)
|
||||
throw DOM::DOMException(DOM::DOMException::NAMESPACE_ERR);
|
||||
|
||||
if(prefix == xml)
|
||||
|
@ -37,12 +37,12 @@ std::pair<bool, stringT> checkPrefixAndNamespace(bool hasPrefix,
|
|||
{
|
||||
// DOM mandates xmlns: be bound to a namespace URI, XML Namespace rec
|
||||
// says not - allow for both here
|
||||
if((namespaceURI == xmlnsURI) || (namespaceURI.empty()))
|
||||
if((namespaceURI == xmlnsURI) || (string_adaptorT::empty(namespaceURI)))
|
||||
return std::make_pair(true, xmlnsURI);
|
||||
throw DOM::DOMException(DOM::DOMException::NAMESPACE_ERR);
|
||||
} // if(nodeType == DOM::Node<stringT>::ATTRIBUTE_NODE && prefix == xmlns)
|
||||
|
||||
if(hasNamespaceURI == false || namespaceURI.length() == 0)
|
||||
if(hasNamespaceURI == false || string_adaptorT::empty(namespaceURI))
|
||||
throw DOM::DOMException(DOM::DOMException::NAMESPACE_ERR);
|
||||
|
||||
return std::make_pair(true, namespaceURI);
|
||||
|
|
|
@ -34,11 +34,11 @@ class namespaceAndNameIs : public std::unary_function<NodeImpl<stringT, string_a
|
|||
|
||||
bool operator()(const NodeImpl<stringT, string_adaptorT>* node) const
|
||||
{
|
||||
if(namespaceURI_.empty())
|
||||
if(string_adaptorT::empty(namespaceURI_))
|
||||
{
|
||||
if((node->hasNamespaceURI() == false) &&
|
||||
((node->getLocalName() == localName_) ||
|
||||
(node->getLocalName().empty() && node->getNodeName() == localName_)
|
||||
(string_adaptorT::empty(node->getLocalName()) && node->getNodeName() == localName_)
|
||||
)
|
||||
)
|
||||
return true;
|
||||
|
|
|
@ -101,7 +101,7 @@ class NodeImpl : virtual public DOM::Node_impl<stringT>
|
|||
removeChild(next);
|
||||
next = textNode->getNextSibling();
|
||||
} // while
|
||||
if(textNode->getData().empty())
|
||||
if(string_adaptorT::empty(textNode->getData()))
|
||||
removeChild(textNode);
|
||||
}
|
||||
else
|
||||
|
|
|
@ -18,6 +18,8 @@ class default_string_adaptor
|
|||
public:
|
||||
typedef string_type stringT;
|
||||
typedef typename stringT::value_type value_type;
|
||||
typedef typename stringT::size_type size_type;
|
||||
static const size_type npos;
|
||||
|
||||
value_type makeValueT(char c) const;
|
||||
stringT makeStringT(const char* str) const;
|
||||
|
@ -27,6 +29,15 @@ public:
|
|||
stringT makeStringT(const wchar_t* str, int length) const;
|
||||
#endif
|
||||
|
||||
static bool empty(const string_type& str); // as std::string::empty
|
||||
static size_type find(const string_type& str, const string_type& what); // return npos if not found, otherwise index
|
||||
static string_type substr(const string_type& str, const size_type& offset);
|
||||
static string_type substr(const string_type& str, const size_type& offset, const size_type& count);
|
||||
static size_type length(const string_type& str);
|
||||
static void append(string_type& str, const string_type& a);
|
||||
static void insert(string_type& str, size_type offset, const string_type& a);
|
||||
static void replace(string_type& str, size_type offser, size_type count, const string_type& a);
|
||||
|
||||
// only used to constuct error strings - don't have to be highly efficient!
|
||||
std::string asStdString(const stringT& str) const;
|
||||
#ifndef ARABICA_NO_WCHAR_T
|
||||
|
@ -41,6 +52,8 @@ class default_string_adaptor<std::string>
|
|||
public:
|
||||
typedef std::string stringT;
|
||||
typedef std::string::value_type value_type;
|
||||
typedef std::string::size_type size_type;
|
||||
static const size_type npos = static_cast<size_type>(-1);
|
||||
|
||||
char makeValueT(char c) const { return c; }
|
||||
|
||||
|
@ -83,6 +96,46 @@ public:
|
|||
} // toStdWString
|
||||
#endif
|
||||
|
||||
static bool empty(const std::string& str)
|
||||
{
|
||||
return str.empty();
|
||||
} // empty
|
||||
|
||||
static size_type find(const std::string& str, const std::string& what)
|
||||
{
|
||||
return str.find(what);
|
||||
} // find
|
||||
|
||||
static std::string substr(const std::string& str, const size_type& offset)
|
||||
{
|
||||
return str.substr(offset);
|
||||
} // substr
|
||||
|
||||
static std::string substr(const std::string& str, const size_type& offset, const size_type& count)
|
||||
{
|
||||
return str.substr(offset, count);
|
||||
} // substr
|
||||
|
||||
static size_type length(const std::string& str)
|
||||
{
|
||||
return str.length(); // TODO - fix me for utf8
|
||||
} // length
|
||||
|
||||
static void append(std::string& str, const std::string& a)
|
||||
{
|
||||
str.append(a);
|
||||
} // append
|
||||
|
||||
static void insert(std::string& str, size_type offset, const std::string& a)
|
||||
{
|
||||
str.insert(offset, a);
|
||||
} // insert
|
||||
|
||||
static void replace(std::string& str, size_type offset, size_type count, const std::string& a)
|
||||
{
|
||||
str.replace(offset, count, a);
|
||||
} // replace
|
||||
|
||||
#ifndef ARABICA_NO_WCHAR_T
|
||||
default_string_adaptor() :
|
||||
#ifndef ARABICA_VS6_WORKAROUND
|
||||
|
@ -117,6 +170,8 @@ class default_string_adaptor<std::wstring>
|
|||
public:
|
||||
typedef std::wstring stringT;
|
||||
typedef std::wstring::value_type value_type;
|
||||
typedef std::wstring::size_type size_type;
|
||||
static const size_type npos = static_cast<size_type>(-1);
|
||||
|
||||
wchar_t makeValueT(char c) const
|
||||
{
|
||||
|
@ -155,6 +210,46 @@ public:
|
|||
return str;
|
||||
} // toStdWString
|
||||
|
||||
static bool empty(const std::wstring& str)
|
||||
{
|
||||
return str.empty();
|
||||
} // empty
|
||||
|
||||
static size_type find(const std::wstring& str, const std::wstring& what)
|
||||
{
|
||||
return str.find(what);
|
||||
} // find
|
||||
|
||||
static std::wstring substr(const std::wstring& str, const size_type& offset)
|
||||
{
|
||||
return str.substr(offset);
|
||||
} // substr
|
||||
|
||||
static std::wstring substr(const std::wstring& str, const size_type& offset, const size_type& count)
|
||||
{
|
||||
return str.substr(offset, count);
|
||||
} // substr
|
||||
|
||||
static size_type length(const std::string& str)
|
||||
{
|
||||
return str.length(); // TODO - fix me for utf8
|
||||
} // length
|
||||
|
||||
static void append(std::wstring& str, const std::wstring& a)
|
||||
{
|
||||
str.append(a);
|
||||
} // append
|
||||
|
||||
static void insert(std::wstring& str, size_type offset, const std::wstring& a)
|
||||
{
|
||||
str.insert(offset, a);
|
||||
} // insert
|
||||
|
||||
static void replace(std::wstring& str, size_type offset, size_type count, const std::wstring& a)
|
||||
{
|
||||
str.replace(offset, count, a);
|
||||
} // replace
|
||||
|
||||
default_string_adaptor() :
|
||||
#ifndef ARABICA_VS6_WORKAROUND
|
||||
loc_(std::locale(), new Arabica::convert::utf8ucs2codecvt()),
|
||||
|
|
|
@ -194,7 +194,7 @@ private:
|
|||
AncestorOrSelfAxisWalker(const AncestorOrSelfAxisWalker& rhs) : AxisWalker<string_type>(rhs) { }
|
||||
}; // class AncestorOrSelfAxisWalker
|
||||
|
||||
template<class string_type>
|
||||
template<class string_type, class string_adaptor>
|
||||
class AttributeAxisWalker : public AxisWalker<string_type>
|
||||
{
|
||||
public:
|
||||
|
@ -241,7 +241,7 @@ private:
|
|||
do
|
||||
{
|
||||
a = attrs_.item(index_++);
|
||||
} while ((a != 0) && (a.getNamespaceURI() == "http://www.w3.org/2000/xmlns/"));
|
||||
} while ((a != 0) && (a.getNamespaceURI() == string_adaptor().makeStringT("http://www.w3.org/2000/xmlns/")));
|
||||
|
||||
AxisWalker<string_type>::set(a);
|
||||
} // set_next
|
||||
|
@ -407,8 +407,8 @@ public:
|
|||
DOM::Node<string_type> attr = current.getAttributes().item(a);
|
||||
if(attr.getPrefix() == xmlns_prefix_)
|
||||
list_.push_back(DOM::Node<string_type>(
|
||||
new NamespaceNodeImpl<string_type>(attr.getLocalName(),
|
||||
attr.getNodeValue())
|
||||
new NamespaceNodeImpl<string_type, string_adaptor>(attr.getLocalName(),
|
||||
attr.getNodeValue())
|
||||
)
|
||||
);
|
||||
} // for ...
|
||||
|
@ -555,7 +555,7 @@ AxisEnumerator<string_type, string_adaptor>::AxisLookupTable[] =
|
|||
{
|
||||
{ ANCESTOR, impl::CreateAxis<impl::AncestorAxisWalker<string_type>, string_type> },
|
||||
{ ANCESTOR_OR_SELF, impl::CreateAxis<impl::AncestorOrSelfAxisWalker<string_type>, string_type> },
|
||||
{ ATTRIBUTE, impl::CreateAxis<impl::AttributeAxisWalker<string_type>, string_type> },
|
||||
{ ATTRIBUTE, impl::CreateAxis<impl::AttributeAxisWalker<string_type, string_adaptor>, string_type> },
|
||||
{ CHILD, impl::CreateAxis<impl::ChildAxisWalker<string_type>, string_type> },
|
||||
{ DESCENDANT, impl::CreateAxis<impl::DescendantAxisWalker<string_type>, string_type> },
|
||||
{ DESCENDANT_OR_SELF, impl::CreateAxis<impl::DescendantOrSelfAxisWalker<string_type>, string_type> },
|
||||
|
|
|
@ -37,7 +37,7 @@ public:
|
|||
} // matches
|
||||
}; // class AnyNodeTest
|
||||
|
||||
template<class string_type>
|
||||
template<class string_type, class string_adaptor>
|
||||
class NameNodeTest : public NodeTest<string_type>
|
||||
{
|
||||
public:
|
||||
|
@ -46,7 +46,7 @@ public:
|
|||
virtual bool operator()(const DOM::Node<string_type>& node) const
|
||||
{
|
||||
return (name_ == node.getNodeName()) &&
|
||||
(node.getPrefix().empty());
|
||||
(string_adaptor::empty(node.getPrefix()));
|
||||
} // test
|
||||
|
||||
private:
|
||||
|
@ -120,7 +120,7 @@ public:
|
|||
} // operator()
|
||||
}; // CommentNodeTest
|
||||
|
||||
template<class string_type>
|
||||
template<class string_type, class string_adaptor>
|
||||
class ProcessingInstructionNodeTest : public NodeTest<string_type>
|
||||
{
|
||||
public:
|
||||
|
@ -132,7 +132,7 @@ public:
|
|||
if(node.getNodeType() != DOM::Node<string_type>::PROCESSING_INSTRUCTION_NODE)
|
||||
return false;
|
||||
|
||||
if(target_.empty())
|
||||
if(string_adaptor::empty(target_))
|
||||
return true;
|
||||
|
||||
return node.getNodeName() == target_;
|
||||
|
|
|
@ -313,7 +313,7 @@ string_type nodeStringValue(const DOM::Node<string_type>& node)
|
|||
os << ae->getNodeValue();
|
||||
++ae;
|
||||
} // while
|
||||
return os.str();
|
||||
return string_adaptor().makeStringT(os.str().c_str());
|
||||
} // case
|
||||
|
||||
case DOM::Node_base::ATTRIBUTE_NODE:
|
||||
|
@ -324,7 +324,8 @@ string_type nodeStringValue(const DOM::Node<string_type>& node)
|
|||
return node.getNodeValue();
|
||||
|
||||
default:
|
||||
throw std::runtime_error("Don't know how to calculate string-value of " + node.getNodeName());
|
||||
throw std::runtime_error("Don't know how to calculate string-value of " +
|
||||
string_adaptor().asStdString(node.getNodeName()));
|
||||
} // switch
|
||||
} // nodeStringValue
|
||||
|
||||
|
|
|
@ -315,7 +315,7 @@ private:
|
|||
{
|
||||
string_type name(node->value.begin(), node->value.end());
|
||||
++node;
|
||||
return new NameNodeTest<string_type>(name);
|
||||
return new NameNodeTest<string_type, string_adaptor>(name);
|
||||
} // case NameNodeTest
|
||||
|
||||
case impl::Comment_id:
|
||||
|
@ -334,11 +334,11 @@ private:
|
|||
{
|
||||
++node;
|
||||
if(getNodeId<string_type>(node) != impl::Literal_id) // not sure if this is always safe
|
||||
return new ProcessingInstructionNodeTest<string_type>();
|
||||
return new ProcessingInstructionNodeTest<string_type, string_adaptor>();
|
||||
|
||||
string_type target(node->value.begin(), node->value.end());
|
||||
++node;
|
||||
return new ProcessingInstructionNodeTest<string_type>(target);
|
||||
return new ProcessingInstructionNodeTest<string_type, string_adaptor>(target);
|
||||
} // case ProcessingInstruction_id
|
||||
|
||||
case impl::SlashSlash_id:
|
||||
|
|
|
@ -30,8 +30,8 @@ public:
|
|||
} // evaluate
|
||||
virtual bool evaluateAsBool(const DOM::Node<string_type>& context) { return asBool(); }
|
||||
virtual double evaluateAsNumber(const DOM::Node<string_type>& context) { return asNumber(); }
|
||||
virtual std::string evaluateAsString(const DOM::Node<string_type>& context) { return asString(); }
|
||||
virtual NodeSet<std::string> evaluateAsNodeSet(const DOM::Node<string_type>& context) { return asNodeSet(); }
|
||||
virtual string_type evaluateAsString(const DOM::Node<string_type>& context) { return asString(); }
|
||||
virtual NodeSet<string_type> evaluateAsNodeSet(const DOM::Node<string_type>& context) { return asNodeSet(); }
|
||||
|
||||
virtual bool asBool() const { return value_; }
|
||||
virtual double asNumber() const { return value_ ? 1 : 0; }
|
||||
|
@ -73,7 +73,7 @@ public:
|
|||
return string_adaptor().makeStringT("Infinity");
|
||||
if(isNegativeInfinity(value_))
|
||||
return string_adaptor().makeStringT("-Infinity");
|
||||
return boost::lexical_cast<string_type>(value_);
|
||||
return string_adaptor().makeStringT(boost::lexical_cast<std::string>(value_).c_str());
|
||||
} // asString
|
||||
virtual const NodeSet<string_type>& asNodeSet() const { static NodeSet<string_type> empty; return empty; }
|
||||
|
||||
|
@ -88,7 +88,7 @@ class StringValue : public XPathValue<string_type>, public XPathExpression<strin
|
|||
{
|
||||
public:
|
||||
StringValue(const char* value) :
|
||||
value_(value) { }
|
||||
value_(string_adaptor().makeStringT(value)) { }
|
||||
StringValue(const string_type& value) :
|
||||
value_(value) { }
|
||||
|
||||
|
@ -102,7 +102,7 @@ public:
|
|||
virtual string_type evaluateAsString(const DOM::Node<string_type>& context) { return asString(); }
|
||||
virtual NodeSet<string_type> evaluateAsNodeSet() const { return asNodeSet(); }
|
||||
|
||||
virtual bool asBool() const { return !value_.empty(); }
|
||||
virtual bool asBool() const { return !string_adaptor::empty(value_); }
|
||||
virtual double asNumber() const
|
||||
{
|
||||
return impl::stringAsNumber(value_);
|
||||
|
|
Loading…
Reference in a new issue