mirror of
https://github.com/jezhiggins/arabica
synced 2025-01-17 18:12:04 +01:00
moved string functions to use StringXPathFunction base class
This commit is contained in:
parent
bbcae98bec
commit
428121bab4
1 changed files with 26 additions and 33 deletions
|
@ -154,37 +154,32 @@ public:
|
||||||
}; // CurrentFunction
|
}; // CurrentFunction
|
||||||
|
|
||||||
// string unparsed-entity-uri(string)
|
// string unparsed-entity-uri(string)
|
||||||
class UnparsedEntityUriFunction : public Arabica::XPath::XPathFunction<std::string>
|
class UnparsedEntityUriFunction : public Arabica::XPath::StringXPathFunction<std::string>
|
||||||
{
|
{
|
||||||
typedef Arabica::XPath::XPathFunction<std::string> baseT;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
UnparsedEntityUriFunction(const std::vector<Arabica::XPath::XPathExpression<std::string> >& args) :
|
UnparsedEntityUriFunction(const std::vector<Arabica::XPath::XPathExpression<std::string> >& args) :
|
||||||
Arabica::XPath::XPathFunction<std::string>(1, 1, args) { }
|
Arabica::XPath::StringXPathFunction<std::string>(1, 1, args) { }
|
||||||
|
|
||||||
virtual Arabica::XPath::ValueType type() const { return Arabica::XPath::STRING; }
|
protected:
|
||||||
|
virtual std::string doEvaluate(const DOM::Node<std::string>& context,
|
||||||
virtual Arabica::XPath::XPathValue_impl<std::string>* evaluate(const DOM::Node<std::string>& context,
|
const Arabica::XPath::ExecutionContext<std::string>& executionContext) const
|
||||||
const Arabica::XPath::ExecutionContext<std::string>& executionContext) const
|
|
||||||
{
|
{
|
||||||
// This is a minimal, but I think conformant, implementation
|
// This is a minimal, but I think conformant, implementation
|
||||||
return new Arabica::XPath::StringValue<std::string>("");
|
return "";
|
||||||
} // evaluate
|
} // evaluate
|
||||||
}; // UnparsedEntityUri
|
}; // UnparsedEntityUri
|
||||||
|
|
||||||
// string generate-id(node-set?)
|
// string generate-id(node-set?)
|
||||||
class GenerateIdFunction : public Arabica::XPath::XPathFunction<std::string>
|
class GenerateIdFunction : public Arabica::XPath::StringXPathFunction<std::string>
|
||||||
{
|
{
|
||||||
typedef Arabica::XPath::XPathFunction<std::string> baseT;
|
typedef Arabica::XPath::StringXPathFunction<std::string> baseT;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
GenerateIdFunction(const std::vector<Arabica::XPath::XPathExpression<std::string> >& args) :
|
GenerateIdFunction(const std::vector<Arabica::XPath::XPathExpression<std::string> >& args) :
|
||||||
Arabica::XPath::XPathFunction<std::string>(0, 1, args) { }
|
Arabica::XPath::StringXPathFunction<std::string>(0, 1, args) { }
|
||||||
|
|
||||||
virtual Arabica::XPath::ValueType type() const { return Arabica::XPath::STRING; }
|
protected:
|
||||||
|
virtual std::string doEvaluate(const DOM::Node<std::string>& context,
|
||||||
virtual Arabica::XPath::XPathValue_impl<std::string>* evaluate(const DOM::Node<std::string>& context,
|
const Arabica::XPath::ExecutionContext<std::string>& executionContext) const
|
||||||
const Arabica::XPath::ExecutionContext<std::string>& executionContext) const
|
|
||||||
{
|
{
|
||||||
DOM::Node<std::string> node;
|
DOM::Node<std::string> node;
|
||||||
if(baseT::argCount() == 0)
|
if(baseT::argCount() == 0)
|
||||||
|
@ -193,39 +188,37 @@ public:
|
||||||
{
|
{
|
||||||
Arabica::XPath::NodeSet<std::string> ns = baseT::argAsNodeSet(0, context, executionContext);
|
Arabica::XPath::NodeSet<std::string> ns = baseT::argAsNodeSet(0, context, executionContext);
|
||||||
if(ns.size() == 0)
|
if(ns.size() == 0)
|
||||||
return new Arabica::XPath::StringValue<std::string>("");
|
return "";
|
||||||
node = ns.top();
|
node = ns.top();
|
||||||
} // if ...
|
} // if ...
|
||||||
|
|
||||||
std::ostringstream os;
|
std::ostringstream os;
|
||||||
os << node.underlying_impl();
|
os << node.underlying_impl();
|
||||||
return new Arabica::XPath::StringValue<std::string>(os.str());
|
return os.str();
|
||||||
} //evaluate
|
} // doEvaluate
|
||||||
}; // class GenerateIdFunction
|
}; // class GenerateIdFunction
|
||||||
|
|
||||||
// object system-property(string)
|
// object system-property(string)
|
||||||
class SystemPropertyFunction : public Arabica::XPath::XPathFunction<std::string>
|
class SystemPropertyFunction : public Arabica::XPath::StringXPathFunction<std::string>
|
||||||
{
|
{
|
||||||
typedef Arabica::XPath::XPathFunction<std::string> baseT;
|
typedef Arabica::XPath::StringXPathFunction<std::string> baseT;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
SystemPropertyFunction (const std::vector<Arabica::XPath::XPathExpression<std::string> >& args) :
|
SystemPropertyFunction (const std::vector<Arabica::XPath::XPathExpression<std::string> >& args) :
|
||||||
Arabica::XPath::XPathFunction<std::string>(1, 1, args) { }
|
Arabica::XPath::StringXPathFunction<std::string>(1, 1, args) { }
|
||||||
|
|
||||||
virtual Arabica::XPath::ValueType type() const { return Arabica::XPath::STRING; }
|
protected:
|
||||||
|
virtual std::string doEvaluate(const DOM::Node<std::string>& context,
|
||||||
virtual Arabica::XPath::XPathValue_impl<std::string>* evaluate(const DOM::Node<std::string>& context,
|
const Arabica::XPath::ExecutionContext<std::string>& executionContext) const
|
||||||
const Arabica::XPath::ExecutionContext<std::string>& executionContext) const
|
|
||||||
{
|
{
|
||||||
std::string property = baseT::argAsString(0, context, executionContext);
|
std::string property = baseT::argAsString(0, context, executionContext);
|
||||||
std::string result;
|
std::string result;
|
||||||
if(property == "xsl:version")
|
if(property == "xsl:version")
|
||||||
result = "1.0";
|
return "1.0";
|
||||||
else if(property == "xsl:vendor")
|
if(property == "xsl:vendor")
|
||||||
result = "Jez Higgins, Jez UK Ltd";
|
return "Jez Higgins, Jez UK Ltd";
|
||||||
else if(property == "xsl:vendor-url")
|
else if(property == "xsl:vendor-url")
|
||||||
result = "http://www.jezuk.co.uk/arabica";
|
return "http://www.jezuk.co.uk/arabica";
|
||||||
return new Arabica::XPath::StringValue<std::string>(result);
|
return "";
|
||||||
} // evaluate
|
} // evaluate
|
||||||
}; // SystemPropertyFunction
|
}; // SystemPropertyFunction
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue