Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] The implements of some v2 concepts for discuss only #457

Draft
wants to merge 46 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
15697a7
Initial string_view for set_name, set_value
halx99 Sep 29, 2021
3a975d2
Add explicit boolean type for store as 'true' or 'false'
halx99 Sep 29, 2021
aeda2ef
Use string_view when needs store
halx99 Sep 29, 2021
b79d580
Use basic_string_view<char_t> instead of string_view
halx99 Sep 29, 2021
5f1eb20
Fix appveyor msvc120 compile error
halx99 Sep 29, 2021
4ed7a7f
Fix compile issue for compiler without cpp11
halx99 Sep 29, 2021
fd795fd
Avoid unnecessary strlen operations
halx99 Sep 29, 2021
e3af244
Fix for non-cpp11 compiler
halx99 Sep 30, 2021
bffbcfd
Fix for non-cpp11 compiler
halx99 Sep 30, 2021
dbced76
Update pugixml.hpp
halx99 Sep 30, 2021
4852708
Fix for non-cpp11 compiler
halx99 Sep 30, 2021
0d9a303
Add shallow_copy support for improve performance of literal string
halx99 Sep 30, 2021
366113e
Make logic more clearly
halx99 Sep 30, 2021
15cec5f
Fix logic
halx99 Sep 30, 2021
bd0fd02
Delete unused
halx99 Sep 30, 2021
909b3b6
Add length field for name & value
halx99 Dec 23, 2021
69e24c7
Add string_view name & value getter with suffix for compatible
halx99 Dec 23, 2021
233d7fd
Update build.yml
halx99 Dec 23, 2021
4e4af11
Fix warnings on PUGIXML_WCHAR_MODE
halx99 Dec 23, 2021
b025069
Fix for old compilers
halx99 Dec 23, 2021
9129d79
Fix ci
halx99 Dec 23, 2021
7791e7d
Store length for setters
halx99 Dec 23, 2021
b634ea5
Node copy avoid stringlen operation
halx99 Dec 23, 2021
32cccfe
Use string_view for all dom APIs
halx99 Dec 23, 2021
0d87d4f
Fix ci & add run test cost
halx99 Dec 23, 2021
46805e8
Fix warnings
halx99 Dec 23, 2021
f0259eb
Fix ci
halx99 Dec 23, 2021
d3a8b86
Add missing commit from shallow_copy branch
halx99 Dec 23, 2021
3ceb703
Update pugixml.cpp
halx99 Dec 23, 2021
c95044d
Fix for compact mode
halx99 Dec 24, 2021
3c9111d
Allow build compact mode
halx99 Dec 24, 2021
d6fac0a
More string_view
halx99 Feb 8, 2022
6c2bb13
Fix ci
halx99 Feb 8, 2022
ce19f19
Merge branch 'zeux:master' into dev
halx99 Feb 16, 2022
62e2407
Fix memory leak
TodorHryn May 16, 2022
7f2d74d
Fix memory leak during OOM in convert_buffer
zeux May 17, 2022
1c6a55f
Use more idiomatic code in this codebase
zeux May 17, 2022
4bec1e8
C++20 compiler support
halx99 Oct 5, 2022
72e3201
c++ 20 compiler support
halx99 Oct 5, 2022
377a2a9
c++20 compiler support
halx99 Oct 5, 2022
5d8dbac
Fix ci
halx99 Oct 5, 2022
aee049f
Merge 'zeux-master' into dev
halx99 Feb 4, 2023
eae27e5
Merge branch 'zeux-master' into dev
halx99 Feb 4, 2023
f79549c
1.13 ABI compatible
halx99 Feb 4, 2023
a328bb5
Fix ci
halx99 Feb 4, 2023
66e1430
Fix ci
halx99 Feb 4, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
596 changes: 325 additions & 271 deletions src/pugixml.cpp

Large diffs are not rendered by default.

244 changes: 197 additions & 47 deletions src/pugixml.hpp

Large diffs are not rendered by default.

7 changes: 5 additions & 2 deletions tests/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

#include <string>

#include <time.h>

#ifndef PUGIXML_NO_EXCEPTIONS
# include <exception>
#endif
Expand Down Expand Up @@ -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];
Expand Down Expand Up @@ -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;
}
Expand Down
10 changes: 0 additions & 10 deletions tests/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 4 additions & 1 deletion tests/test.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
6 changes: 3 additions & 3 deletions tests/test_document.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
8 changes: 4 additions & 4 deletions tests/test_dom_modify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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\"/>"));
}
Expand Down Expand Up @@ -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")));
Expand Down
8 changes: 4 additions & 4 deletions tests/test_dom_text.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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>"));
Expand All @@ -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>"));
}
Expand Down
4 changes: 2 additions & 2 deletions tests/test_dom_traverse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
};
Expand Down
2 changes: 1 addition & 1 deletion tests/test_memory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
}
Expand Down
10 changes: 5 additions & 5 deletions tests/test_parse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down Expand Up @@ -563,7 +563,7 @@ TEST(parse_escapes_unicode)
CHECK(doc.load_string(STR("<node>&#x03B3;&#x03b3;&#x24B62;</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);

Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion tests/test_unicode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand Down