From 428121bab4125c996d66ea330bca75ad308e3295 Mon Sep 17 00:00:00 2001 From: jez Date: Mon, 13 Jul 2009 09:13:50 +0100 Subject: [PATCH] moved string functions to use StringXPathFunction base class --- include/XSLT/impl/xslt_functions.hpp | 59 ++++++++++++---------------- 1 file changed, 26 insertions(+), 33 deletions(-) diff --git a/include/XSLT/impl/xslt_functions.hpp b/include/XSLT/impl/xslt_functions.hpp index c4453393..5a2f9d88 100644 --- a/include/XSLT/impl/xslt_functions.hpp +++ b/include/XSLT/impl/xslt_functions.hpp @@ -154,37 +154,32 @@ public: }; // CurrentFunction // string unparsed-entity-uri(string) -class UnparsedEntityUriFunction : public Arabica::XPath::XPathFunction +class UnparsedEntityUriFunction : public Arabica::XPath::StringXPathFunction { - typedef Arabica::XPath::XPathFunction baseT; - public: UnparsedEntityUriFunction(const std::vector >& args) : - Arabica::XPath::XPathFunction(1, 1, args) { } + Arabica::XPath::StringXPathFunction(1, 1, args) { } - virtual Arabica::XPath::ValueType type() const { return Arabica::XPath::STRING; } - - virtual Arabica::XPath::XPathValue_impl* evaluate(const DOM::Node& context, - const Arabica::XPath::ExecutionContext& executionContext) const +protected: + virtual std::string doEvaluate(const DOM::Node& context, + const Arabica::XPath::ExecutionContext& executionContext) const { // This is a minimal, but I think conformant, implementation - return new Arabica::XPath::StringValue(""); + return ""; } // evaluate }; // UnparsedEntityUri // string generate-id(node-set?) -class GenerateIdFunction : public Arabica::XPath::XPathFunction +class GenerateIdFunction : public Arabica::XPath::StringXPathFunction { - typedef Arabica::XPath::XPathFunction baseT; - + typedef Arabica::XPath::StringXPathFunction baseT; public: GenerateIdFunction(const std::vector >& args) : - Arabica::XPath::XPathFunction(0, 1, args) { } + Arabica::XPath::StringXPathFunction(0, 1, args) { } - virtual Arabica::XPath::ValueType type() const { return Arabica::XPath::STRING; } - - virtual Arabica::XPath::XPathValue_impl* evaluate(const DOM::Node& context, - const Arabica::XPath::ExecutionContext& executionContext) const +protected: + virtual std::string doEvaluate(const DOM::Node& context, + const Arabica::XPath::ExecutionContext& executionContext) const { DOM::Node node; if(baseT::argCount() == 0) @@ -193,39 +188,37 @@ public: { Arabica::XPath::NodeSet ns = baseT::argAsNodeSet(0, context, executionContext); if(ns.size() == 0) - return new Arabica::XPath::StringValue(""); + return ""; node = ns.top(); } // if ... std::ostringstream os; os << node.underlying_impl(); - return new Arabica::XPath::StringValue(os.str()); - } //evaluate + return os.str(); + } // doEvaluate }; // class GenerateIdFunction // object system-property(string) -class SystemPropertyFunction : public Arabica::XPath::XPathFunction +class SystemPropertyFunction : public Arabica::XPath::StringXPathFunction { - typedef Arabica::XPath::XPathFunction baseT; - + typedef Arabica::XPath::StringXPathFunction baseT; public: SystemPropertyFunction (const std::vector >& args) : - Arabica::XPath::XPathFunction(1, 1, args) { } + Arabica::XPath::StringXPathFunction(1, 1, args) { } - virtual Arabica::XPath::ValueType type() const { return Arabica::XPath::STRING; } - - virtual Arabica::XPath::XPathValue_impl* evaluate(const DOM::Node& context, - const Arabica::XPath::ExecutionContext& executionContext) const +protected: + virtual std::string doEvaluate(const DOM::Node& context, + const Arabica::XPath::ExecutionContext& executionContext) const { std::string property = baseT::argAsString(0, context, executionContext); std::string result; if(property == "xsl:version") - result = "1.0"; - else if(property == "xsl:vendor") - result = "Jez Higgins, Jez UK Ltd"; + return "1.0"; + if(property == "xsl:vendor") + return "Jez Higgins, Jez UK Ltd"; else if(property == "xsl:vendor-url") - result = "http://www.jezuk.co.uk/arabica"; - return new Arabica::XPath::StringValue(result); + return "http://www.jezuk.co.uk/arabica"; + return ""; } // evaluate }; // SystemPropertyFunction