summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/pugixml.cpp162
-rw-r--r--src/pugixml.hpp149
-rw-r--r--src/pugixpath.cpp1
-rw-r--r--tests/test.cpp9
-rw-r--r--tests/test_deprecated.cpp118
5 files changed, 10 insertions, 429 deletions
diff --git a/src/pugixml.cpp b/src/pugixml.cpp
index 3238a3d..d319069 100644
--- a/src/pugixml.cpp
+++ b/src/pugixml.cpp
@@ -98,6 +98,7 @@ namespace pugi
namespace impl
{
size_t strlen(const char_t* s);
+ bool strequal(const char_t* src, const char_t* dst);
bool strequalrange(const char_t* lhs, const char_t* rhs, size_t count);
void widen_ascii(wchar_t* dest, const char* source);
}
@@ -138,89 +139,6 @@ namespace pugi
return lhs[count] == 0;
}
- // Character set pattern match.
- static bool strequalwild_cset(const char_t** src, const char_t** dst)
- {
- int find = 0, excl = 0, star = 0;
-
- if (**src == '!')
- {
- excl = 1;
- ++(*src);
- }
-
- while (**src != ']' || star == 1)
- {
- if (find == 0)
- {
- if (**src == '-' && *(*src-1) < *(*src+1) && *(*src+1) != ']' && star == 0)
- {
- if (**dst >= *(*src-1) && **dst <= *(*src+1))
- {
- find = 1;
- ++(*src);
- }
- }
- else if (**src == **dst) find = 1;
- }
- ++(*src);
- star = 0;
- }
-
- if (excl == 1) find = (1 - find);
- if (find == 1) ++(*dst);
-
- return find == 0;
- }
-
- // Wildcard pattern match.
- static bool strequalwild_astr(const char_t** src, const char_t** dst)
- {
- int find = 1;
- ++(*src);
- while ((**dst != 0 && **src == '?') || **src == '*')
- {
- if(**src == '?') ++(*dst);
- ++(*src);
- }
- while (**src == '*') ++(*src);
- if (**dst == 0 && **src != 0) return 0;
- if (**dst == 0 && **src == 0) return 1;
- else
- {
- if (!impl::strequalwild(*src,*dst))
- {
- do
- {
- ++(*dst);
- while(**src != **dst && **src != '[' && **dst != 0)
- ++(*dst);
- }
- while ((**dst != 0) ? !impl::strequalwild(*src,*dst) : 0 != (find=0));
- }
- if (**dst == 0 && **src == 0) find = 1;
- return find == 0;
- }
- }
-
- // Compare two strings, with globbing, and character sets.
- bool PUGIXML_FUNCTION strequalwild(const char_t* src, const char_t* dst)
- {
- int find = 1;
- for(; *src != 0 && find == 1 && *dst != 0; ++src)
- {
- switch (*src)
- {
- case '?': ++dst; break;
- case '[': ++src; find = !strequalwild_cset(&src,&dst); break;
- case '*': find = !strequalwild_astr(&src,&dst); --src; break;
- default : find = (int) (*src == *dst); ++dst;
- }
- }
- while (*src == '*' && find == 1) ++src;
- return (find == 1 && *dst == 0 && *src == 0);
- }
-
#ifdef PUGIXML_WCHAR_MODE
// Convert string to wide string, assuming all symbols are ASCII
void widen_ascii(wchar_t* dest, const char* source)
@@ -3493,16 +3411,6 @@ namespace pugi
return xml_node();
}
- xml_node xml_node::child_w(const char_t* name) const
- {
- if (!_root) return xml_node();
-
- for (xml_node_struct* i = _root->first_child; i; i = i->next_sibling)
- if (i->name && impl::strequalwild(name, i->name)) return xml_node(i);
-
- return xml_node();
- }
-
xml_attribute xml_node::attribute(const char_t* name) const
{
if (!_root) return xml_attribute();
@@ -3514,17 +3422,6 @@ namespace pugi
return xml_attribute();
}
- xml_attribute xml_node::attribute_w(const char_t* name) const
- {
- if (!_root) return xml_attribute();
-
- for (xml_attribute_struct* i = _root->first_attribute; i; i = i->next_attribute)
- if (i->name && impl::strequalwild(name, i->name))
- return xml_attribute(i);
-
- return xml_attribute();
- }
-
xml_node xml_node::next_sibling(const char_t* name) const
{
if (!_root) return xml_node();
@@ -3535,16 +3432,6 @@ namespace pugi
return xml_node();
}
- xml_node xml_node::next_sibling_w(const char_t* name) const
- {
- if (!_root) return xml_node();
-
- for (xml_node_struct* i = _root->next_sibling; i; i = i->next_sibling)
- if (i->name && impl::strequalwild(name, i->name)) return xml_node(i);
-
- return xml_node();
- }
-
xml_node xml_node::next_sibling() const
{
if (!_root) return xml_node();
@@ -3563,16 +3450,6 @@ namespace pugi
return xml_node();
}
- xml_node xml_node::previous_sibling_w(const char_t* name) const
- {
- if (!_root) return xml_node();
-
- for (xml_node_struct* i = _root->prev_sibling_c; i->next_sibling; i = i->prev_sibling_c)
- if (i->name && impl::strequalwild(name, i->name)) return xml_node(i);
-
- return xml_node();
- }
-
xml_node xml_node::previous_sibling() const
{
if (!_root) return xml_node();
@@ -3615,16 +3492,6 @@ namespace pugi
return child(name).child_value();
}
- const char_t* xml_node::child_value_w(const char_t* name) const
- {
- if (!_root) return PUGIXML_TEXT("");
-
- for (xml_node_struct* i = _root->first_child; i; i = i->next_sibling)
- if (i->name && impl::strequalwild(name, i->name)) return xml_node(i).child_value();
-
- return PUGIXML_TEXT("");
- }
-
xml_attribute xml_node::first_attribute() const
{
return _root ? xml_attribute(_root->first_attribute) : xml_attribute();
@@ -3918,21 +3785,6 @@ namespace pugi
return xml_node();
}
- xml_node xml_node::find_child_by_attribute_w(const char_t* name, const char_t* attr_name, const char_t* attr_value) const
- {
- if (!_root) return xml_node();
-
- for (xml_node_struct* i = _root->first_child; i; i = i->next_sibling)
- if (i->name && impl::strequalwild(name, i->name))
- {
- for (xml_attribute_struct* a = i->first_attribute; a; a = a->next_attribute)
- if (impl::strequalwild(attr_name, a->name) && impl::strequalwild(attr_value, a->value))
- return xml_node(i);
- }
-
- return xml_node();
- }
-
xml_node xml_node::find_child_by_attribute(const char_t* attr_name, const char_t* attr_value) const
{
if (!_root) return xml_node();
@@ -3945,18 +3797,6 @@ namespace pugi
return xml_node();
}
- xml_node xml_node::find_child_by_attribute_w(const char_t* attr_name, const char_t* attr_value) const
- {
- if (!_root) return xml_node();
-
- for (xml_node_struct* i = _root->first_child; i; i = i->next_sibling)
- for (xml_attribute_struct* a = i->first_attribute; a; a = a->next_attribute)
- if (impl::strequalwild(attr_name, a->name) && impl::strequalwild(attr_value, a->value))
- return xml_node(i);
-
- return xml_node();
- }
-
#ifndef PUGIXML_NO_STL
string_t xml_node::path(char_t delimiter) const
{
diff --git a/src/pugixml.hpp b/src/pugixml.hpp
index 91a3190..3c9072b 100644
--- a/src/pugixml.hpp
+++ b/src/pugixml.hpp
@@ -108,16 +108,6 @@ namespace pugi
}
#endif
-// Helpers for inline implementation
-namespace pugi
-{
- namespace impl
- {
- bool PUGIXML_FUNCTION strequal(const char_t*, const char_t*);
- bool PUGIXML_FUNCTION strequalwild(const char_t*, const char_t*);
- }
-}
-
/// The PugiXML Parser namespace.
namespace pugi
{
@@ -690,45 +680,6 @@ namespace pugi
/// \internal Initializing constructor
explicit xml_node(xml_node_struct* p);
- private:
- template <typename OutputIterator> void all_elements_by_name_helper(const char_t* name, OutputIterator it) const
- {
- if (!_root) return;
-
- for (xml_node node = first_child(); node; node = node.next_sibling())
- {
- if (node.type() == node_element)
- {
- if (impl::strequal(name, node.name()))
- {
- *it = node;
- ++it;
- }
-
- if (node.first_child()) node.all_elements_by_name_helper(name, it);
- }
- }
- }
-
- template <typename OutputIterator> void all_elements_by_name_w_helper(const char_t* name, OutputIterator it) const
- {
- if (!_root) return;
-
- for (xml_node node = first_child(); node; node = node.next_sibling())
- {
- if (node.type() == node_element)
- {
- if (impl::strequalwild(name, node.name()))
- {
- *it = node;
- ++it;
- }
-
- if (node.first_child()) node.all_elements_by_name_w_helper(name, it);
- }
- }
- }
-
public:
/**
* Default constructor. Constructs an empty node.
@@ -873,16 +824,6 @@ namespace pugi
xml_node child(const char_t* name) const;
/**
- * Get child with the name that matches specified pattern
- *
- * \param name - child name pattern
- * \return child with the name that matches pattern, if any; empty node otherwise
- *
- * \deprecated This function is deprecated
- */
- PUGIXML_DEPRECATED xml_node child_w(const char_t* name) const;
-
- /**
* Get attribute with the specified name
*
* \param name - attribute name
@@ -891,16 +832,6 @@ namespace pugi
xml_attribute attribute(const char_t* name) const;
/**
- * Get attribute with the name that matches specified pattern
- *
- * \param name - attribute name pattern
- * \return attribute with the name that matches pattern, if any; empty attribute otherwise
- *
- * \deprecated This function is deprecated
- */
- PUGIXML_DEPRECATED xml_attribute attribute_w(const char_t* name) const;
-
- /**
* Get first of following sibling nodes with the specified name
*
* \param name - sibling name
@@ -909,16 +840,6 @@ namespace pugi
xml_node next_sibling(const char_t* name) const;
/**
- * Get first of the following sibling nodes with the name that matches specified pattern
- *
- * \param name - sibling name pattern
- * \return node with the name that matches pattern, if any; empty node otherwise
- *
- * \deprecated This function is deprecated
- */
- PUGIXML_DEPRECATED xml_node next_sibling_w(const char_t* name) const;
-
- /**
* Get following sibling
*
* \return following sibling node, if any; empty node otherwise
@@ -934,16 +855,6 @@ namespace pugi
xml_node previous_sibling(const char_t* name) const;
/**
- * Get first of the preceding sibling nodes with the name that matches specified pattern
- *
- * \param name - sibling name pattern
- * \return node with the name that matches pattern, if any; empty node otherwise
- *
- * \deprecated This function is deprecated
- */
- PUGIXML_DEPRECATED xml_node previous_sibling_w(const char_t* name) const;
-
- /**
* Get preceding sibling
*
* \return preceding sibling node, if any; empty node otherwise
@@ -980,17 +891,6 @@ namespace pugi
*/
const char_t* child_value(const char_t* name) const;
- /**
- * Get child value of child with name that matches the specified pattern. \see child_value
- * node.child_value_w(name) is equivalent to node.child_w(name).child_value()
- *
- * \param name - child name pattern
- * \return child value of specified child node, if any; "" otherwise
- *
- * \deprecated This function is deprecated
- */
- PUGIXML_DEPRECATED const char_t* child_value_w(const char_t* name) const;
-
public:
/**
* Set node name to \a rhs (for PI/element nodes). \see name
@@ -1160,32 +1060,6 @@ namespace pugi
xml_attribute last_attribute() const;
/**
- * Get all elements from subtree with given name
- *
- * \param name - node name
- * \param it - output iterator (for example, std::back_insert_iterator (result of std::back_inserter))
- *
- * \deprecated This function is deprecated
- */
- template <typename OutputIterator> PUGIXML_DEPRECATED void all_elements_by_name(const char_t* name, OutputIterator it) const
- {
- all_elements_by_name_helper(name, it);
- }
-
- /**
- * Get all elements from subtree with name that matches given pattern
- *
- * \param name - node name pattern
- * \param it - output iterator (for example, std::back_insert_iterator (result of std::back_inserter))
- *
- * \deprecated This function is deprecated
- */
- template <typename OutputIterator> PUGIXML_DEPRECATED void all_elements_by_name_w(const char_t* name, OutputIterator it) const
- {
- all_elements_by_name_w_helper(name, it);
- }
-
- /**
* Get first child
*
* \return first child, if any; empty node otherwise
@@ -1273,18 +1147,6 @@ namespace pugi
xml_node find_child_by_attribute(const char_t* name, const char_t* attr_name, const char_t* attr_value) const;
/**
- * Find child node with the specified name that has specified attribute (use pattern matching for node name and attribute name/value)
- *
- * \param name - pattern for child node name
- * \param attr_name - pattern for attribute name of child node
- * \param attr_value - pattern for attribute value of child node
- * \return first matching child node, or empty node
- *
- * \deprecated This function is deprecated
- */
- PUGIXML_DEPRECATED xml_node find_child_by_attribute_w(const char_t* name, const char_t* attr_name, const char_t* attr_value) const;
-
- /**
* Find child node that has specified attribute
*
* \param attr_name - attribute name of child node
@@ -1293,17 +1155,6 @@ namespace pugi
*/
xml_node find_child_by_attribute(const char_t* attr_name, const char_t* attr_value) const;
- /**
- * Find child node that has specified attribute (use pattern matching for attribute name/value)
- *
- * \param attr_name - pattern for attribute name of child node
- * \param attr_value - pattern for attribute value of child node
- * \return first matching child node, or empty node
- *
- * \deprecated This function is deprecated
- */
- PUGIXML_DEPRECATED xml_node find_child_by_attribute_w(const char_t* attr_name, const char_t* attr_value) const;
-
#ifndef PUGIXML_NO_STL
/**
* Get the absolute node path from root as a text string.
diff --git a/src/pugixpath.cpp b/src/pugixpath.cpp
index 4040eb9..7ab466c 100644
--- a/src/pugixpath.cpp
+++ b/src/pugixpath.cpp
@@ -63,6 +63,7 @@ namespace pugi
namespace impl
{
size_t strlen(const char_t* s);
+ bool strequal(const char_t* src, const char_t* dst);
bool strequalrange(const char_t* lhs, const char_t* rhs, size_t count);
void widen_ascii(wchar_t* dest, const char* source);
}
diff --git a/tests/test.cpp b/tests/test.cpp
index 9435f1e..43c6b22 100644
--- a/tests/test.cpp
+++ b/tests/test.cpp
@@ -6,6 +6,8 @@
#include <math.h>
#include <float.h>
+#include <string.h>
+#include <wchar.h>
#include <algorithm>
#include <vector>
@@ -41,7 +43,12 @@ static void build_document_order(std::vector<pugi::xpath_node>& result, pugi::xm
bool test_string_equal(const pugi::char_t* lhs, const pugi::char_t* rhs)
{
- return (!lhs || !rhs) ? lhs == rhs : pugi::impl::strequal(lhs, rhs);
+ return (!lhs || !rhs) ? lhs == rhs :
+ #ifdef PUGIXML_WCHAR_MODE
+ wcscmp(lhs, rhs) == 0;
+ #else
+ strcmp(lhs, rhs) == 0;
+ #endif
}
bool test_node(const pugi::xml_node& node, const pugi::char_t* contents, const pugi::char_t* indent, unsigned int flags)
diff --git a/tests/test_deprecated.cpp b/tests/test_deprecated.cpp
index f28dd55..3f7ecb0 100644
--- a/tests/test_deprecated.cpp
+++ b/tests/test_deprecated.cpp
@@ -74,121 +74,3 @@ TEST(as_utf16)
#endif
}
#endif
-
-// wildcard functions
-TEST_XML(dom_node_child_w, "<node><child1/><child2/></node>")
-{
- CHECK(doc.child_w(STR("n?de")) == doc.child(STR("node")));
- CHECK(doc.child_w(STR("n[az]de")) == xml_node());
- CHECK(doc.child_w(STR("n[aoz]de")) == doc.child(STR("node")));
- CHECK(doc.child_w(STR("*e")) == doc.child(STR("node")));
- CHECK(doc.child(STR("node")).child_w(STR("*l?[23456789]*")) == doc.child(STR("node")).child(STR("child2")));
-}
-
-TEST_XML(dom_node_attribute_w, "<node attr1='0' attr2='1'/>")
-{
- xml_node node = doc.child(STR("node"));
-
- CHECK(node.attribute_w(STR("*tt?[23456789]*")) == node.attribute(STR("attr2")));
- CHECK(node.attribute_w(STR("?")) == xml_attribute());
-}
-
-TEST_XML(dom_node_next_previous_sibling_w, "<node><child1/><child2/><child3/></node>")
-{
- CHECK(xml_node().next_sibling_w(STR("n")) == xml_node());
- CHECK(xml_node().previous_sibling_w(STR("n")) == xml_node());
-
- xml_node child1 = doc.child(STR("node")).child(STR("child1"));
- xml_node child3 = doc.child(STR("node")).child(STR("child3"));
-
- CHECK(child1.next_sibling_w(STR("*[3456789]")) == child3);
- CHECK(child1.next_sibling_w(STR("?")) == xml_node());
- CHECK(child3.previous_sibling_w(STR("*[3456789]")) == xml_node());
- CHECK(child3.previous_sibling_w(STR("?")) == xml_node());
- CHECK(child3.previous_sibling_w(STR("*1")) == child1);
-}
-
-TEST_XML(dom_node_child_value_w, "<node><novalue/><child1>value1</child1><child2>value2<n/></child2><child3><![CDATA[value3]]></child3>value4</node>")
-{
- CHECK_STRING(xml_node().child_value_w(STR("n")), STR(""));
-
- xml_node node = doc.child(STR("node"));
-
- CHECK_STRING(node.child_value_w(STR("c*[23456789]")), STR("value2"));
- CHECK_STRING(node.child_value_w(STR("*")), STR("")); // child_value(name) and child_value_w(pattern) do not continue the search if a node w/out value is found first
- CHECK_STRING(node.child_value_w(STR("nothing*here")), STR(""));
-}
-
-TEST_XML(dom_node_find_child_by_attribute_w, "<node><child1 attr='value1'/><child2 attr='value2'/><child2 attr='value3'/></node>")
-{
- CHECK(xml_node().find_child_by_attribute_w(STR("name"), STR("attr"), STR("value")) == xml_node());
- CHECK(xml_node().find_child_by_attribute_w(STR("attr"), STR("value")) == xml_node());
-
- xml_node node = doc.child(STR("node"));
-
- CHECK(node.find_child_by_attribute_w(STR("*"), STR("att?"), STR("val*[0123456789]")) == node.child(STR("child1")));
- CHECK(node.find_child_by_attribute_w(STR("*"), STR("attr3"), STR("val*[0123456789]")) == xml_node());
- CHECK(node.find_child_by_attribute_w(STR("att?"), STR("val*[0123456789]")) == node.child(STR("child1")));
- CHECK(node.find_child_by_attribute_w(STR("attr3"), STR("val*[0123456789]")) == xml_node());
-}
-
-TEST_XML(dom_node_all_elements_by_name, "<node><child><child/><child/></child></node>")
-{
- std::vector<xml_node> v;
-
- v.clear();
- xml_node().all_elements_by_name(STR("node"), std::back_inserter(v));
- CHECK(v.empty());
-
- v.clear();
- doc.all_elements_by_name(STR("node"), std::back_inserter(v));
- CHECK(v.size() == 1 && v[0] == doc.child(STR("node")));
-
- v.clear();
- doc.all_elements_by_name(STR("child"), std::back_inserter(v));
- CHECK(v.size() == 3);
- CHECK(v[0] == doc.child(STR("node")).child(STR("child")));
- CHECK(v[1] == doc.child(STR("node")).child(STR("child")).first_child());
- CHECK(v[2] == doc.child(STR("node")).child(STR("child")).last_child());
-}
-
-TEST_XML(dom_node_all_elements_by_name_w, "<node><child><child/><child/></child></node>")
-{
- std::vector<xml_node> v;
-
- v.clear();
- xml_node().all_elements_by_name_w(STR("*"), std::back_inserter(v));
- CHECK(v.empty());
-
- v.clear();
- doc.all_elements_by_name_w(STR("*"), std::back_inserter(v));
- CHECK(v.size() == 4);
- CHECK(v[0] == doc.child(STR("node")));
- CHECK(v[1] == doc.child(STR("node")).child(STR("child")));
- CHECK(v[2] == doc.child(STR("node")).child(STR("child")).first_child());
- CHECK(v[3] == doc.child(STR("node")).child(STR("child")).last_child());
-}
-
-TEST_XML(dom_node_wildcard_cset, "<node c='1'/>")
-{
- xml_node node = doc.child(STR("node"));
-
- CHECK(node.attribute_w(STR("[A-Z]")).as_int() == 0);
- CHECK(node.attribute_w(STR("[a-z]")).as_int() == 1);
- CHECK(node.attribute_w(STR("[A-z]")).as_int() == 1);
- CHECK(node.attribute_w(STR("[z-a]")).as_int() == 0);
- CHECK(node.attribute_w(STR("[a-zA-Z]")).as_int() == 1);
- CHECK(node.attribute_w(STR("[!A-Z]")).as_int() == 1);
- CHECK(node.attribute_w(STR("[!A-Za-z]")).as_int() == 0);
-}
-
-TEST_XML(dom_node_wildcard_star, "<node cd='1'/>")
-{
- xml_node node = doc.child(STR("node"));
-
- CHECK(node.attribute_w(STR("*")).as_int() == 1);
- CHECK(node.attribute_w(STR("?d*")).as_int() == 1);
- CHECK(node.attribute_w(STR("?c*")).as_int() == 0);
- CHECK(node.attribute_w(STR("*?*c*")).as_int() == 0);
- CHECK(node.attribute_w(STR("*?*d*")).as_int() == 1);
-}