XPath: Introduced new evaluate_string API (without STL), enabled XPath without STL
git-svn-id: http://pugixml.googlecode.com/svn/trunk@659 99668b35-9821-0410-8761-19e4c4f06640
This commit is contained in:
parent
0c5b9341bc
commit
053a4c0ea7
@ -56,11 +56,6 @@ namespace std
|
|||||||
# endif
|
# endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// No XPath without STL
|
|
||||||
#if !defined(PUGIXML_NO_XPATH) && defined(PUGIXML_NO_STL)
|
|
||||||
# define PUGIXML_NO_XPATH
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// Include exception header for XPath
|
// Include exception header for XPath
|
||||||
#if !defined(PUGIXML_NO_XPATH) && !defined(PUGIXML_NO_EXCEPTIONS)
|
#if !defined(PUGIXML_NO_XPATH) && !defined(PUGIXML_NO_EXCEPTIONS)
|
||||||
# include <exception>
|
# include <exception>
|
||||||
@ -2017,6 +2012,7 @@ namespace pugi
|
|||||||
*/
|
*/
|
||||||
double evaluate_number(const xml_node& n) const;
|
double evaluate_number(const xml_node& n) const;
|
||||||
|
|
||||||
|
#ifndef PUGIXML_NO_STL
|
||||||
/**
|
/**
|
||||||
* Evaluate expression as string value for the context node \a n.
|
* Evaluate expression as string value for the context node \a n.
|
||||||
* If expression does not directly evaluate to string, the expression result is converted
|
* If expression does not directly evaluate to string, the expression result is converted
|
||||||
@ -2027,6 +2023,18 @@ namespace pugi
|
|||||||
* \return evaluation result
|
* \return evaluation result
|
||||||
*/
|
*/
|
||||||
string_t evaluate_string(const xml_node& n) const;
|
string_t evaluate_string(const xml_node& n) const;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Evaluate expression as string value for the context node \a n.
|
||||||
|
* If expression does not directly evaluate to string, the expression result is converted
|
||||||
|
* as through string() XPath function call.
|
||||||
|
* Throws std::bad_alloc on out of memory error.
|
||||||
|
*
|
||||||
|
* \param n - context node
|
||||||
|
* \return evaluation result
|
||||||
|
*/
|
||||||
|
size_t evaluate_string(char_t* buffer, size_t capacity, const xml_node& n) const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Evaluate expression as node set for the context node \a n.
|
* Evaluate expression as node set for the context node \a n.
|
||||||
|
|||||||
@ -28,6 +28,12 @@
|
|||||||
# include <wchar.h>
|
# include <wchar.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include <new>
|
||||||
|
|
||||||
|
#ifndef PUGIXML_NO_STL
|
||||||
|
# include <string>
|
||||||
|
#endif
|
||||||
|
|
||||||
// int32_t
|
// int32_t
|
||||||
#if !defined(_MSC_VER) || _MSC_VER >= 1600
|
#if !defined(_MSC_VER) || _MSC_VER >= 1600
|
||||||
# include <stdint.h>
|
# include <stdint.h>
|
||||||
@ -50,8 +56,6 @@ typedef __int32 int32_t;
|
|||||||
# pragma diag_suppress=237 // controlling expression is constant
|
# pragma diag_suppress=237 // controlling expression is constant
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
// String utilities prototypes
|
// String utilities prototypes
|
||||||
namespace pugi
|
namespace pugi
|
||||||
{
|
{
|
||||||
@ -3762,6 +3766,7 @@ namespace pugi
|
|||||||
return _root->eval_number(c);
|
return _root->eval_number(c);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifndef PUGIXML_NO_STL
|
||||||
string_t xpath_query::evaluate_string(const xml_node& n) const
|
string_t xpath_query::evaluate_string(const xml_node& n) const
|
||||||
{
|
{
|
||||||
if (!_root) return string_t();
|
if (!_root) return string_t();
|
||||||
@ -3770,6 +3775,20 @@ namespace pugi
|
|||||||
|
|
||||||
return _root->eval_string(c).c_str();
|
return _root->eval_string(c).c_str();
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
size_t xpath_query::evaluate_string(char_t* buffer, size_t capacity, const xml_node& n) const
|
||||||
|
{
|
||||||
|
xpath_context c(n, 1, 1);
|
||||||
|
xpath_string r = _root ? _root->eval_string(c) : xpath_string();
|
||||||
|
|
||||||
|
size_t size = r.length() + 1;
|
||||||
|
|
||||||
|
// $$ zero-terminate?
|
||||||
|
if (capacity > 0) memcpy(buffer, r.c_str(), size < capacity ? size : capacity);
|
||||||
|
|
||||||
|
return size;
|
||||||
|
}
|
||||||
|
|
||||||
xpath_node_set xpath_query::evaluate_node_set(const xml_node& n) const
|
xpath_node_set xpath_query::evaluate_node_set(const xml_node& n) const
|
||||||
{
|
{
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user