Merge 66e143022e into 8a679cfe78
This commit is contained in:
commit
077de86f99
618
src/pugixml.cpp
618
src/pugixml.cpp
File diff suppressed because it is too large
Load Diff
244
src/pugixml.hpp
244
src/pugixml.hpp
@ -38,6 +38,31 @@
|
||||
# include <string>
|
||||
#endif
|
||||
|
||||
// Tests whether compiler has c++17 support
|
||||
#if (defined(__cplusplus) && __cplusplus >= 201703L) || \
|
||||
(defined(_MSC_VER) && _MSC_VER > 1900 && \
|
||||
((defined(_HAS_CXX17) && _HAS_CXX17 == 1) || \
|
||||
(defined(_MSVC_LANG) && (_MSVC_LANG > 201402L))))
|
||||
# ifndef PUGI_CXX_STD
|
||||
# define PUGI_CXX_STD 17
|
||||
# endif // C++17 features macro
|
||||
#endif // C++17 features check
|
||||
|
||||
// Tests whether compiler has c++20 support
|
||||
#if (defined(__cplusplus) && __cplusplus > 201703L) || \
|
||||
(defined(_MSC_VER) && _MSC_VER > 1900 && \
|
||||
((defined(_HAS_CXX20) && _HAS_CXX20 == 1) || \
|
||||
(defined(_MSVC_LANG) && (_MSVC_LANG > 201703L))))
|
||||
# ifdef PUGI_CXX_STD
|
||||
# undef PUGI_CXX_STD
|
||||
# endif
|
||||
# define PUGI_CXX_STD 20
|
||||
#endif // C++20 features check
|
||||
|
||||
#if !defined(PUGI_CXX_STD)
|
||||
# define PUGI_CXX_STD 11
|
||||
#endif
|
||||
|
||||
// Macro for deprecated features
|
||||
#ifndef PUGIXML_DEPRECATED
|
||||
# if defined(__GNUC__)
|
||||
@ -131,6 +156,126 @@
|
||||
# define PUGIXML_CHAR char
|
||||
#endif
|
||||
|
||||
|
||||
// The string_view
|
||||
namespace pugi {
|
||||
#if PUGI_CXX_STD >= 17
|
||||
template <typename C, typename T = std::char_traits<C> >
|
||||
using basic_string_view = std::basic_string_view<C, T>;
|
||||
typedef std::string_view string_view;
|
||||
typedef std::wstring_view wstring_view;
|
||||
#else
|
||||
template <typename Char, typename Traits = std::char_traits<Char> >
|
||||
struct basic_string_view {
|
||||
const Char* p;
|
||||
std::size_t s;
|
||||
|
||||
basic_string_view(const std::basic_string<Char, Traits>& r)
|
||||
: p(r.c_str()), s(r.size()) {
|
||||
}
|
||||
basic_string_view(const Char* ptr)
|
||||
: p(ptr), s(Traits::length(ptr)) {
|
||||
}
|
||||
basic_string_view(const Char* ptr, std::size_t sz)
|
||||
: p(ptr), s(sz) {
|
||||
}
|
||||
|
||||
static int compare(const Char* lhs_p, std::size_t lhs_sz, const Char* rhs_p, std::size_t rhs_sz) {
|
||||
int result = Traits::compare(lhs_p, rhs_p, lhs_sz < rhs_sz ? lhs_sz : rhs_sz);
|
||||
if (result != 0)
|
||||
return result;
|
||||
if (lhs_sz < rhs_sz)
|
||||
return -1;
|
||||
if (lhs_sz > rhs_sz)
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
const Char* begin() const {
|
||||
return p;
|
||||
}
|
||||
|
||||
const Char* end() const {
|
||||
return p + s;
|
||||
}
|
||||
|
||||
const Char* cbegin() const {
|
||||
return p;
|
||||
}
|
||||
|
||||
const Char* cend() const {
|
||||
return p + s;
|
||||
}
|
||||
|
||||
const Char* data() const {
|
||||
return p;
|
||||
}
|
||||
|
||||
std::size_t size() const {
|
||||
return s;
|
||||
}
|
||||
|
||||
std::size_t length() const {
|
||||
return size();
|
||||
}
|
||||
|
||||
bool empty() const {
|
||||
return 0 == s;
|
||||
}
|
||||
|
||||
const Char& operator[](size_t index) const {
|
||||
return p[index];
|
||||
}
|
||||
|
||||
operator std::basic_string<Char, Traits>() const {
|
||||
return std::basic_string<Char, Traits>(data(), size());
|
||||
}
|
||||
|
||||
bool operator==(const basic_string_view& r) const {
|
||||
return compare(p, s, r.data(), r.size()) == 0;
|
||||
}
|
||||
|
||||
bool operator==(const Char* r) const {
|
||||
return compare(r, Traits::length(r), p, s) == 0;
|
||||
}
|
||||
|
||||
bool operator==(const std::basic_string<Char, Traits>& r) const {
|
||||
return compare(r.data(), r.size(), p, s) == 0;
|
||||
}
|
||||
|
||||
bool operator!=(const basic_string_view& r) const {
|
||||
return !(*this == r);
|
||||
}
|
||||
|
||||
bool operator!=(const char* r) const {
|
||||
return !(*this == r);
|
||||
}
|
||||
|
||||
bool operator!=(const std::basic_string<Char, Traits>& r) const {
|
||||
return !(*this == r);
|
||||
}
|
||||
};
|
||||
} // namespace pugi
|
||||
|
||||
namespace pugi {
|
||||
typedef basic_string_view<char> string_view;
|
||||
typedef basic_string_view<wchar_t> wstring_view;
|
||||
#endif
|
||||
} // namespace pugi
|
||||
|
||||
// The explicit boolean type to avoid compiler ambiguous match const char_t* as scalar type 'bool',
|
||||
// because we preferred compiler match const char_t* as string_view_t
|
||||
namespace pugi {
|
||||
struct boolean {
|
||||
boolean() : value(false) {}
|
||||
explicit boolean(bool bval) : value(bval) {}
|
||||
bool value;
|
||||
operator bool() const { return value; }
|
||||
};
|
||||
static const boolean (true_value)(true);
|
||||
static const boolean (false_value)(false);
|
||||
} // namespace pugi
|
||||
|
||||
namespace pugi
|
||||
{
|
||||
// Character type used for all internal storage and operations; depends on PUGIXML_WCHAR_MODE
|
||||
@ -140,8 +285,13 @@ namespace pugi
|
||||
// String type used for operations that work with STL string; depends on PUGIXML_WCHAR_MODE
|
||||
typedef std::basic_string<PUGIXML_CHAR, std::char_traits<PUGIXML_CHAR>, std::allocator<PUGIXML_CHAR> > string_t;
|
||||
#endif
|
||||
|
||||
// string_view type used for operations that work with pugi::string_view, depends on PUGIXML_WCHAR_MODE
|
||||
typedef pugi::basic_string_view<char_t, std::char_traits<char_t> > string_view_t;
|
||||
}
|
||||
|
||||
#define PUGIXML_EMPTY_SV pugi::string_view_t(PUGIXML_TEXT(""), 0)
|
||||
|
||||
// The PugiXML namespace
|
||||
namespace pugi
|
||||
{
|
||||
@ -396,11 +546,12 @@ namespace pugi
|
||||
bool empty() const;
|
||||
|
||||
// Get attribute name/value, or "" if attribute is empty
|
||||
const char_t* name() const;
|
||||
const char_t* value() const;
|
||||
string_view_t name() const;
|
||||
|
||||
string_view_t value() const;
|
||||
|
||||
// Get attribute value, or the default value if attribute is empty
|
||||
const char_t* as_string(const char_t* def = PUGIXML_TEXT("")) const;
|
||||
string_view_t as_string(string_view_t def = PUGIXML_EMPTY_SV) const;
|
||||
|
||||
// Get attribute value as a number, or the default value if conversion did not succeed or attribute is empty
|
||||
int as_int(int def = 0) const;
|
||||
@ -417,9 +568,9 @@ namespace pugi
|
||||
bool as_bool(bool def = false) const;
|
||||
|
||||
// Set attribute name/value (returns false if attribute is empty or there is not enough memory)
|
||||
bool set_name(const char_t* rhs);
|
||||
bool set_value(const char_t* rhs, size_t sz);
|
||||
bool set_value(const char_t* rhs);
|
||||
bool set_name(string_view_t rhs, boolean shallow_copy = pugi::false_value);
|
||||
bool set_value(string_view_t rhs, boolean shallow_copy = pugi::false_value);
|
||||
bool set_value(const char_t*, size_t sz); // 1.13 ABI compatible
|
||||
|
||||
// Set attribute value with type conversion (numbers are converted to strings, boolean is converted to "true"/"false")
|
||||
bool set_value(int rhs);
|
||||
@ -430,7 +581,7 @@ namespace pugi
|
||||
bool set_value(double rhs, int precision);
|
||||
bool set_value(float rhs);
|
||||
bool set_value(float rhs, int precision);
|
||||
bool set_value(bool rhs);
|
||||
bool set_value(boolean rhs);
|
||||
|
||||
#ifdef PUGIXML_HAS_LONG_LONG
|
||||
bool set_value(long long rhs);
|
||||
@ -438,14 +589,14 @@ namespace pugi
|
||||
#endif
|
||||
|
||||
// Set attribute value (equivalent to set_value without error checking)
|
||||
xml_attribute& operator=(const char_t* rhs);
|
||||
xml_attribute& operator=(string_view_t rhs);
|
||||
xml_attribute& operator=(int rhs);
|
||||
xml_attribute& operator=(unsigned int rhs);
|
||||
xml_attribute& operator=(long rhs);
|
||||
xml_attribute& operator=(unsigned long rhs);
|
||||
xml_attribute& operator=(double rhs);
|
||||
xml_attribute& operator=(float rhs);
|
||||
xml_attribute& operator=(bool rhs);
|
||||
xml_attribute& operator=(boolean rhs);
|
||||
|
||||
#ifdef PUGIXML_HAS_LONG_LONG
|
||||
xml_attribute& operator=(long long rhs);
|
||||
@ -509,11 +660,11 @@ namespace pugi
|
||||
xml_node_type type() const;
|
||||
|
||||
// Get node name, or "" if node is empty or it has no name
|
||||
const char_t* name() const;
|
||||
string_view_t name() const;
|
||||
|
||||
// Get node value, or "" if node is empty or it has no value
|
||||
// Note: For <node>text</node> node.value() does not return "text"! Use child_value() or text() methods to access text inside nodes.
|
||||
const char_t* value() const;
|
||||
string_view_t value() const;
|
||||
|
||||
// Get attribute list
|
||||
xml_attribute first_attribute() const;
|
||||
@ -537,30 +688,30 @@ namespace pugi
|
||||
xml_text text() const;
|
||||
|
||||
// Get child, attribute or next/previous sibling with the specified name
|
||||
xml_node child(const char_t* name) const;
|
||||
xml_attribute attribute(const char_t* name) const;
|
||||
xml_node next_sibling(const char_t* name) const;
|
||||
xml_node previous_sibling(const char_t* name) const;
|
||||
xml_node child(string_view_t name) const;
|
||||
xml_attribute attribute(string_view_t name) const;
|
||||
xml_node next_sibling(string_view_t name) const;
|
||||
xml_node previous_sibling(string_view_t name) const;
|
||||
|
||||
// Get attribute, starting the search from a hint (and updating hint so that searching for a sequence of attributes is fast)
|
||||
xml_attribute attribute(const char_t* name, xml_attribute& hint) const;
|
||||
xml_attribute attribute(string_view_t name, xml_attribute& hint) const;
|
||||
|
||||
// Get child value of current node; that is, value of the first child node of type PCDATA/CDATA
|
||||
const char_t* child_value() const;
|
||||
string_view_t child_value() const;
|
||||
|
||||
// Get child value of child with specified name. Equivalent to child(name).child_value().
|
||||
const char_t* child_value(const char_t* name) const;
|
||||
string_view_t child_value(string_view_t name) const;
|
||||
|
||||
// Set node name/value (returns false if node is empty, there is not enough memory, or node can not have name/value)
|
||||
bool set_name(const char_t* rhs);
|
||||
bool set_value(const char_t* rhs, size_t sz);
|
||||
bool set_value(const char_t* rhs);
|
||||
bool set_name(string_view_t rhs, boolean shallow_copy = pugi::false_value);
|
||||
bool set_value(string_view_t rhs, boolean shallow_copy = pugi::false_value);
|
||||
bool set_value(const char_t* rhs, size_t sz); // 1.13 ABI compatible
|
||||
|
||||
// Add attribute with specified name. Returns added attribute, or empty attribute on errors.
|
||||
xml_attribute append_attribute(const char_t* name);
|
||||
xml_attribute prepend_attribute(const char_t* name);
|
||||
xml_attribute insert_attribute_after(const char_t* name, const xml_attribute& attr);
|
||||
xml_attribute insert_attribute_before(const char_t* name, const xml_attribute& attr);
|
||||
xml_attribute append_attribute(string_view_t name, boolean shallow_copy = pugi::false_value);
|
||||
xml_attribute prepend_attribute(string_view_t name, boolean shallow_copy = pugi::false_value);
|
||||
xml_attribute insert_attribute_after(string_view_t name, const xml_attribute& attr, boolean shallow_copy = pugi::false_value);
|
||||
xml_attribute insert_attribute_before(string_view_t name, const xml_attribute& attr, boolean shallow_copy = pugi::false_value);
|
||||
|
||||
// Add a copy of the specified attribute. Returns added attribute, or empty attribute on errors.
|
||||
xml_attribute append_copy(const xml_attribute& proto);
|
||||
@ -575,10 +726,10 @@ namespace pugi
|
||||
xml_node insert_child_before(xml_node_type type, const xml_node& node);
|
||||
|
||||
// Add child element with specified name. Returns added node, or empty node on errors.
|
||||
xml_node append_child(const char_t* name);
|
||||
xml_node prepend_child(const char_t* name);
|
||||
xml_node insert_child_after(const char_t* name, const xml_node& node);
|
||||
xml_node insert_child_before(const char_t* name, const xml_node& node);
|
||||
xml_node append_child(string_view_t name, boolean shallow_copy = pugi::false_value);
|
||||
xml_node prepend_child(string_view_t name, boolean shallow_copy = pugi::false_value);
|
||||
xml_node insert_child_after(string_view_t name, const xml_node& node, boolean shallow_copy = pugi::false_value);
|
||||
xml_node insert_child_before(string_view_t name, const xml_node& node, boolean shallow_copy = pugi::false_value);
|
||||
|
||||
// Add a copy of the specified node as a child. Returns added node, or empty node on errors.
|
||||
xml_node append_copy(const xml_node& proto);
|
||||
@ -594,14 +745,14 @@ namespace pugi
|
||||
|
||||
// Remove specified attribute
|
||||
bool remove_attribute(const xml_attribute& a);
|
||||
bool remove_attribute(const char_t* name);
|
||||
bool remove_attribute(string_view_t name);
|
||||
|
||||
// Remove all attributes
|
||||
bool remove_attributes();
|
||||
|
||||
// Remove specified child
|
||||
bool remove_child(const xml_node& n);
|
||||
bool remove_child(const char_t* name);
|
||||
bool remove_child(string_view_t name);
|
||||
|
||||
// Remove all children
|
||||
bool remove_children();
|
||||
@ -660,8 +811,8 @@ namespace pugi
|
||||
}
|
||||
|
||||
// Find child node by attribute name/value
|
||||
xml_node find_child_by_attribute(const char_t* name, const char_t* attr_name, const char_t* attr_value) const;
|
||||
xml_node find_child_by_attribute(const char_t* attr_name, const char_t* attr_value) const;
|
||||
xml_node find_child_by_attribute(string_view_t name, string_view_t attr_name, string_view_t attr_value) const;
|
||||
xml_node find_child_by_attribute(string_view_t attr_name, string_view_t attr_value) const;
|
||||
|
||||
#ifndef PUGIXML_NO_STL
|
||||
// Get the absolute node path from root as a text string.
|
||||
@ -716,7 +867,7 @@ namespace pugi
|
||||
|
||||
// Range-based for support for all children with the specified name
|
||||
// Note: name pointer must have a longer lifetime than the returned object; be careful with passing temporaries!
|
||||
xml_object_range<xml_named_node_iterator> children(const char_t* name) const;
|
||||
xml_object_range<xml_named_node_iterator> children(string_view_t name) const;
|
||||
|
||||
// Get node offset in parsed file/string (in char_t units) for debugging purposes
|
||||
ptrdiff_t offset_debug() const;
|
||||
@ -762,10 +913,10 @@ namespace pugi
|
||||
bool empty() const;
|
||||
|
||||
// Get text, or "" if object is empty
|
||||
const char_t* get() const;
|
||||
string_view_t get() const;
|
||||
|
||||
// Get text, or the default value if object is empty
|
||||
const char_t* as_string(const char_t* def = PUGIXML_TEXT("")) const;
|
||||
string_view_t as_string(string_view_t def = PUGIXML_EMPTY_SV) const;
|
||||
|
||||
// Get text as a number, or the default value if conversion did not succeed or object is empty
|
||||
int as_int(int def = 0) const;
|
||||
@ -782,8 +933,8 @@ namespace pugi
|
||||
bool as_bool(bool def = false) const;
|
||||
|
||||
// Set text (returns false if object is empty or there is not enough memory)
|
||||
bool set(const char_t* rhs, size_t sz);
|
||||
bool set(const char_t* rhs);
|
||||
bool set(string_view_t rhs, boolean shallow_copy = pugi::false_value);
|
||||
bool set(const char_t* rhs, size_t sz); // 1.13 ABI compatible
|
||||
|
||||
// Set text with type conversion (numbers are converted to strings, boolean is converted to "true"/"false")
|
||||
bool set(int rhs);
|
||||
@ -794,7 +945,7 @@ namespace pugi
|
||||
bool set(double rhs, int precision);
|
||||
bool set(float rhs);
|
||||
bool set(float rhs, int precision);
|
||||
bool set(bool rhs);
|
||||
bool set(boolean rhs);
|
||||
|
||||
#ifdef PUGIXML_HAS_LONG_LONG
|
||||
bool set(long long rhs);
|
||||
@ -802,14 +953,14 @@ namespace pugi
|
||||
#endif
|
||||
|
||||
// Set text (equivalent to set without error checking)
|
||||
xml_text& operator=(const char_t* rhs);
|
||||
xml_text& operator=(string_view_t rhs);
|
||||
xml_text& operator=(int rhs);
|
||||
xml_text& operator=(unsigned int rhs);
|
||||
xml_text& operator=(long rhs);
|
||||
xml_text& operator=(unsigned long rhs);
|
||||
xml_text& operator=(double rhs);
|
||||
xml_text& operator=(float rhs);
|
||||
xml_text& operator=(bool rhs);
|
||||
xml_text& operator=(boolean rhs);
|
||||
|
||||
#ifdef PUGIXML_HAS_LONG_LONG
|
||||
xml_text& operator=(long long rhs);
|
||||
@ -931,7 +1082,7 @@ namespace pugi
|
||||
|
||||
// Construct an iterator which points to the specified node
|
||||
// Note: name pointer is stored in the iterator and must have a longer lifetime than iterator itself
|
||||
xml_named_node_iterator(const xml_node& node, const char_t* name);
|
||||
xml_named_node_iterator(const xml_node& node, string_view_t name);
|
||||
|
||||
// Iterator operators
|
||||
bool operator==(const xml_named_node_iterator& rhs) const;
|
||||
@ -950,8 +1101,9 @@ namespace pugi
|
||||
mutable xml_node _wrap;
|
||||
xml_node _parent;
|
||||
const char_t* _name;
|
||||
int _name_len;
|
||||
|
||||
xml_named_node_iterator(xml_node_struct* ref, xml_node_struct* parent, const char_t* name);
|
||||
xml_named_node_iterator(xml_node_struct* ref, xml_node_struct* parent, string_view_t name);
|
||||
};
|
||||
|
||||
// Abstract tree walker class (see xml_node::traverse)
|
||||
@ -1433,12 +1585,10 @@ namespace pugi
|
||||
|
||||
#ifndef PUGIXML_NO_STL
|
||||
// Convert wide string to UTF8
|
||||
std::basic_string<char, std::char_traits<char>, std::allocator<char> > PUGIXML_FUNCTION as_utf8(const wchar_t* str);
|
||||
std::basic_string<char, std::char_traits<char>, std::allocator<char> > PUGIXML_FUNCTION as_utf8(const std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> >& str);
|
||||
std::string PUGIXML_FUNCTION as_utf8(const pugi::wstring_view& str);
|
||||
|
||||
// Convert UTF8 to wide string
|
||||
std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > PUGIXML_FUNCTION as_wide(const char* str);
|
||||
std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > PUGIXML_FUNCTION as_wide(const std::basic_string<char, std::char_traits<char>, std::allocator<char> >& str);
|
||||
std::wstring PUGIXML_FUNCTION as_wide(const pugi::string_view& str);
|
||||
#endif
|
||||
|
||||
// Memory allocation function interface; returns pointer to allocated memory or NULL on failure
|
||||
|
||||
@ -8,6 +8,8 @@
|
||||
|
||||
#include <string>
|
||||
|
||||
#include <time.h>
|
||||
|
||||
#ifndef PUGIXML_NO_EXCEPTIONS
|
||||
# include <exception>
|
||||
#endif
|
||||
@ -170,6 +172,7 @@ int main(int, char** argv)
|
||||
#ifdef __BORLANDC__
|
||||
_control87(MCW_EM | PC_53, MCW_EM | MCW_PC);
|
||||
#endif
|
||||
clock_t start = clock();
|
||||
|
||||
// setup temp path as the executable folder
|
||||
std::string temp = argv[0];
|
||||
@ -203,9 +206,9 @@ int main(int, char** argv)
|
||||
unsigned int failed = total - passed;
|
||||
|
||||
if (failed != 0)
|
||||
printf("FAILURE: %u out of %u tests failed.\n", failed, total);
|
||||
printf("FAILURE: %u out of %u tests failed, cost %g(s).\n", failed, total, (clock() - start) / static_cast<double>(CLOCKS_PER_SEC));
|
||||
else
|
||||
printf("Success: %u tests passed.\n", total);
|
||||
printf("Success: %u tests passed, cost %g(s).\n", total, (clock() - start) / static_cast<double>(CLOCKS_PER_SEC));
|
||||
|
||||
return failed;
|
||||
}
|
||||
|
||||
@ -42,16 +42,6 @@ static void build_document_order(std::vector<pugi::xpath_node>& result, pugi::xm
|
||||
}
|
||||
#endif
|
||||
|
||||
bool test_string_equal(const pugi::char_t* lhs, const pugi::char_t* 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)
|
||||
{
|
||||
xml_writer_string writer;
|
||||
|
||||
@ -34,7 +34,10 @@ struct test_runner
|
||||
static const char* _temp_path;
|
||||
};
|
||||
|
||||
bool test_string_equal(const pugi::char_t* lhs, const pugi::char_t* rhs);
|
||||
inline bool test_string_equal(pugi::string_view_t lhs, const pugi::char_t* rhs)
|
||||
{
|
||||
return lhs == rhs;
|
||||
}
|
||||
|
||||
template <typename Node> inline bool test_node_name_value(const Node& node, const pugi::char_t* name, const pugi::char_t* value)
|
||||
{
|
||||
|
||||
@ -910,7 +910,7 @@ inline void check_utftest_document(const xml_document& doc)
|
||||
CHECK(static_cast<unsigned int>(doc.last_child().last_child().name()[0]) >= 0x80);
|
||||
|
||||
// check magic string
|
||||
const char_t* v = doc.last_child().child(STR("Heavy")).previous_sibling().child_value();
|
||||
string_view_t v = doc.last_child().child(STR("Heavy")).previous_sibling().child_value();
|
||||
|
||||
#ifdef PUGIXML_WCHAR_MODE
|
||||
CHECK(v[0] == 0x4e16 && v[1] == 0x754c && v[2] == 0x6709 && v[3] == 0x5f88 && v[4] == 0x591a && v[5] == wchar_cast(0x8bed) && v[6] == wchar_cast(0x8a00));
|
||||
@ -1520,7 +1520,7 @@ TEST(document_load_buffer_utf_truncated)
|
||||
{
|
||||
CHECK(res);
|
||||
|
||||
const char_t* name = doc.first_child().name();
|
||||
string_view_t name = doc.first_child().name();
|
||||
|
||||
#ifdef PUGIXML_WCHAR_MODE
|
||||
CHECK(name[0] == 0x20ac && name[1] == 0);
|
||||
@ -1565,7 +1565,7 @@ TEST(document_load_stream_truncated)
|
||||
}
|
||||
else
|
||||
{
|
||||
const char_t* name = doc.first_child().name();
|
||||
string_view_t name = doc.first_child().name();
|
||||
|
||||
#ifdef PUGIXML_WCHAR_MODE
|
||||
CHECK(name[0] == 0x20ac && name[1] == 0);
|
||||
|
||||
@ -30,8 +30,8 @@ TEST_XML(dom_attr_assign, "<node/>")
|
||||
node.append_attribute(STR("attr7")) = 0.25f;
|
||||
xml_attribute() = 0.25f;
|
||||
|
||||
node.append_attribute(STR("attr8")) = true;
|
||||
xml_attribute() = true;
|
||||
node.append_attribute(STR("attr8")) = true_value;
|
||||
xml_attribute() = true_value;
|
||||
|
||||
CHECK_NODE(node, STR("<node attr1=\"v1\" attr2=\"-2147483647\" attr3=\"-2147483648\" attr4=\"4294967295\" attr5=\"4294967294\" attr6=\"0.5\" attr7=\"0.25\" attr8=\"true\"/>"));
|
||||
}
|
||||
@ -67,8 +67,8 @@ TEST_XML(dom_attr_set_value, "<node/>")
|
||||
CHECK(node.append_attribute(STR("attr7")).set_value(0.25f));
|
||||
CHECK(!xml_attribute().set_value(0.25f));
|
||||
|
||||
CHECK(node.append_attribute(STR("attr8")).set_value(true));
|
||||
CHECK(!xml_attribute().set_value(true));
|
||||
CHECK(node.append_attribute(STR("attr8")).set_value(true_value));
|
||||
CHECK(!xml_attribute().set_value(true_value));
|
||||
|
||||
CHECK(node.append_attribute(STR("attr9")).set_value(STR("v2"), 2));
|
||||
CHECK(!xml_attribute().set_value(STR("v2")));
|
||||
|
||||
@ -215,7 +215,7 @@ TEST_XML(dom_text_get_no_state, "<node/>")
|
||||
xml_text t = node.text();
|
||||
|
||||
CHECK(!t);
|
||||
CHECK(t.get() && *t.get() == 0);
|
||||
CHECK(t.get().data() && *t.get().data() == 0);
|
||||
CHECK(!node.first_child());
|
||||
|
||||
node.append_child(node_pcdata);
|
||||
@ -310,7 +310,7 @@ TEST_XML(dom_text_assign, "<node/>")
|
||||
node.append_child(STR("text7")).text() = 0.25f;
|
||||
xml_text() = 0.25f;
|
||||
|
||||
node.append_child(STR("text8")).text() = true;
|
||||
node.append_child(STR("text8")).text() = true_value;
|
||||
xml_text() = true;
|
||||
|
||||
CHECK_NODE(node, STR("<node><text1>v1</text1><text2>-2147483647</text2><text3>-2147483648</text3><text4>4294967295</text4><text5>4294967294</text5><text6>0.5</text6><text7>0.25</text7><text8>true</text8></node>"));
|
||||
@ -337,8 +337,8 @@ TEST_XML(dom_text_set_value, "<node/>")
|
||||
CHECK(node.append_child(STR("text7")).text().set(0.25f));
|
||||
CHECK(!xml_text().set(0.25f));
|
||||
|
||||
CHECK(node.append_child(STR("text8")).text().set(true));
|
||||
CHECK(!xml_text().set(true));
|
||||
CHECK(node.append_child(STR("text8")).text().set(true_value));
|
||||
CHECK(!xml_text().set(true_value));
|
||||
|
||||
CHECK_NODE(node, STR("<node><text1>v1</text1><text2>-2147483647</text2><text3>-2147483648</text3><text4>4294967295</text4><text5>4294967294</text5><text6>0.5</text6><text7>0.25</text7><text8>true</text8></node>"));
|
||||
}
|
||||
|
||||
@ -681,9 +681,9 @@ struct find_predicate_prefix
|
||||
{
|
||||
#ifdef PUGIXML_WCHAR_MODE
|
||||
// can't use wcsncmp here because of a bug in DMC
|
||||
return std::basic_string<char_t>(obj.name()).compare(0, wcslen(prefix), prefix) == 0;
|
||||
return std::basic_string<char_t>(obj.name().data()).compare(0, wcslen(prefix), prefix) == 0;
|
||||
#else
|
||||
return strncmp(obj.name(), prefix, strlen(prefix)) == 0;
|
||||
return strncmp(obj.name().data(), prefix, strlen(prefix)) == 0;
|
||||
#endif
|
||||
}
|
||||
};
|
||||
|
||||
@ -110,7 +110,7 @@ TEST(memory_large_allocations)
|
||||
// grow
|
||||
for (node = doc.first_child(); node; node = node.next_sibling())
|
||||
{
|
||||
std::basic_string<char_t> s = node.value();
|
||||
std::basic_string<char_t> s(node.value());
|
||||
|
||||
CHECK(node.set_value((s + s).c_str()));
|
||||
}
|
||||
|
||||
@ -474,7 +474,7 @@ TEST(parse_pcdata_trim)
|
||||
xml_document doc;
|
||||
CHECK(doc.load_string(td.source, td.flags | parse_trim_pcdata));
|
||||
|
||||
const char_t* value = doc.child(STR("node")) ? doc.child_value(STR("node")) : doc.text().get();
|
||||
string_view_t value = doc.child(STR("node")) ? doc.child_value(STR("node")) : doc.text().get();
|
||||
CHECK_STRING(value, td.result);
|
||||
}
|
||||
}
|
||||
@ -563,7 +563,7 @@ TEST(parse_escapes_unicode)
|
||||
CHECK(doc.load_string(STR("<node>γγ𤭢</node>"), parse_minimal | parse_escapes));
|
||||
|
||||
#ifdef PUGIXML_WCHAR_MODE
|
||||
const char_t* v = doc.child_value(STR("node"));
|
||||
string_view_t v = doc.child_value(STR("node"));
|
||||
|
||||
size_t wcharsize = sizeof(wchar_t);
|
||||
|
||||
@ -1100,7 +1100,7 @@ TEST(parse_bom_fragment_invalid_utf8)
|
||||
|
||||
CHECK(doc.load_buffer("\xef\xbb\xbb", 3, parse_fragment, encoding_utf8));
|
||||
|
||||
const char_t* value = doc.text().get();
|
||||
string_view_t value = doc.text().get();
|
||||
|
||||
#ifdef PUGIXML_WCHAR_MODE
|
||||
CHECK(value[0] == wchar_cast(0xfefb) && value[1] == 0);
|
||||
@ -1115,7 +1115,7 @@ TEST(parse_bom_fragment_invalid_utf16)
|
||||
|
||||
CHECK(doc.load_buffer("\xff\xfe", 2, parse_fragment, encoding_utf16_be));
|
||||
|
||||
const char_t* value = doc.text().get();
|
||||
string_view_t value = doc.text().get();
|
||||
|
||||
#ifdef PUGIXML_WCHAR_MODE
|
||||
CHECK(value[0] == wchar_cast(0xfffe) && value[1] == 0);
|
||||
@ -1130,7 +1130,7 @@ TEST(parse_bom_fragment_invalid_utf32)
|
||||
|
||||
CHECK(doc.load_buffer("\xff\xff\x00\x00", 4, parse_fragment, encoding_utf32_le));
|
||||
|
||||
const char_t* value = doc.text().get();
|
||||
string_view_t value = doc.text().get();
|
||||
|
||||
#ifdef PUGIXML_WCHAR_MODE
|
||||
CHECK(value[0] == wchar_cast(0xffff) && value[1] == 0);
|
||||
|
||||
@ -146,7 +146,7 @@ TEST(as_utf8_invalid)
|
||||
|
||||
TEST(as_utf8_string)
|
||||
{
|
||||
std::basic_string<wchar_t> s = L"abcd";
|
||||
std::wstring s = L"abcd";
|
||||
|
||||
CHECK(as_utf8(s) == "abcd");
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user