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

Initial support for std::string_view #633

Merged
merged 2 commits into from
Oct 22, 2024
Merged
Changes from 1 commit
Commits
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
Prev Previous commit
Rename PUGI_HAS_STRING_VIEW to PUGIXML_HAS_STRING_VIEW
Dan Ignatoff committed Oct 22, 2024

Verified

This commit was signed with the committer’s verified signature.
chcmedeiros Carlos Medeiros
commit 1514a3d4c95133714d03241531469aeb7b07daa5
10 changes: 5 additions & 5 deletions src/pugixml.cpp
Original file line number Diff line number Diff line change
@@ -5441,7 +5441,7 @@ namespace pugi
return impl::strcpy_insitu(_attr->name, _attr->header, impl::xml_memory_page_name_allocated_mask, rhs, size);
}

#ifdef PUGI_HAS_STRING_VIEW
#ifdef PUGIXML_HAS_STRING_VIEW
PUGI_IMPL_FN bool xml_attribute::set_name(string_view_t rhs)
{
if (!_attr) return false;
@@ -5464,7 +5464,7 @@ namespace pugi
return impl::strcpy_insitu(_attr->value, _attr->header, impl::xml_memory_page_value_allocated_mask, rhs, size);
}

#ifdef PUGI_HAS_STRING_VIEW
#ifdef PUGIXML_HAS_STRING_VIEW
PUGI_IMPL_FN bool xml_attribute::set_value(string_view_t rhs)
{
if (!_attr) return false;
@@ -5866,7 +5866,7 @@ namespace pugi
return impl::strcpy_insitu(_root->name, _root->header, impl::xml_memory_page_name_allocated_mask, rhs, size);
}

#ifdef PUGI_HAS_STRING_VIEW
#ifdef PUGIXML_HAS_STRING_VIEW
PUGI_IMPL_FN bool xml_node::set_name(string_view_t rhs)
{
xml_node_type type_ = _root ? PUGI_IMPL_NODETYPE(_root) : node_null;
@@ -5898,7 +5898,7 @@ namespace pugi
return impl::strcpy_insitu(_root->value, _root->header, impl::xml_memory_page_value_allocated_mask, rhs, size);
}

#ifdef PUGI_HAS_STRING_VIEW
#ifdef PUGIXML_HAS_STRING_VIEW
PUGI_IMPL_FN bool xml_node::set_value(string_view_t rhs)
{
xml_node_type type_ = _root ? PUGI_IMPL_NODETYPE(_root) : node_null;
@@ -6799,7 +6799,7 @@ namespace pugi
return dn ? impl::strcpy_insitu(dn->value, dn->header, impl::xml_memory_page_value_allocated_mask, rhs, size) : false;
}

#ifdef PUGI_HAS_STRING_VIEW
#ifdef PUGIXML_HAS_STRING_VIEW
PUGI_IMPL_FN bool xml_text::set(string_view_t rhs)
{
xml_node_struct* dn = _data_new();
18 changes: 9 additions & 9 deletions src/pugixml.hpp
Original file line number Diff line number Diff line change
@@ -41,14 +41,14 @@
// Check if std::string_view is both requested and available
#if defined(PUGIXML_STRING_VIEW) && !defined(PUGIXML_NO_STL)
# if __cplusplus >= 201703L
# define PUGI_HAS_STRING_VIEW
# define PUGIXML_HAS_STRING_VIEW
# elif defined(_MSVC_LANG) && _MSVC_LANG >= 201703L
# define PUGI_HAS_STRING_VIEW
# define PUGIXML_HAS_STRING_VIEW
# endif
#endif

// Include string_view if appropriate
#ifdef PUGI_HAS_STRING_VIEW
#ifdef PUGIXML_HAS_STRING_VIEW
# include <string_view>
#endif

@@ -155,7 +155,7 @@ namespace pugi
typedef std::basic_string<PUGIXML_CHAR> string_t;
#endif

#ifdef PUGI_HAS_STRING_VIEW
#ifdef PUGIXML_HAS_STRING_VIEW
// String view type used for operations that can work with a length delimited string; depends on PUGIXML_WCHAR_MODE
typedef std::basic_string_view<PUGIXML_CHAR> string_view_t;
#endif
@@ -442,12 +442,12 @@ namespace pugi
// 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_name(const char_t* rhs, size_t size);
#ifdef PUGI_HAS_STRING_VIEW
#ifdef PUGIXML_HAS_STRING_VIEW
bool set_name(string_view_t rhs);
#endif
bool set_value(const char_t* rhs);
bool set_value(const char_t* rhs, size_t size);
#ifdef PUGI_HAS_STRING_VIEW
#ifdef PUGIXML_HAS_STRING_VIEW
bool set_value(string_view_t rhs);
#endif

@@ -584,12 +584,12 @@ namespace pugi
// 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_name(const char_t* rhs, size_t size);
#ifdef PUGI_HAS_STRING_VIEW
#ifdef PUGIXML_HAS_STRING_VIEW
bool set_name(string_view_t rhs);
#endif
bool set_value(const char_t* rhs);
bool set_value(const char_t* rhs, size_t size);
#ifdef PUGI_HAS_STRING_VIEW
#ifdef PUGIXML_HAS_STRING_VIEW
bool set_value(string_view_t rhs);
#endif

@@ -821,7 +821,7 @@ namespace pugi
// Set text (returns false if object is empty or there is not enough memory)
bool set(const char_t* rhs);
bool set(const char_t* rhs, size_t size);
#ifdef PUGI_HAS_STRING_VIEW
#ifdef PUGIXML_HAS_STRING_VIEW
bool set(string_view_t rhs);
#endif

6 changes: 3 additions & 3 deletions tests/test_dom_modify.cpp
Original file line number Diff line number Diff line change
@@ -56,7 +56,7 @@ TEST_XML(dom_attr_set_name_with_size, "<node attr='value' />")
CHECK_NODE(doc, STR("<node n=\"value\"/>"));
}

#ifdef PUGI_HAS_STRING_VIEW
#ifdef PUGIXML_HAS_STRING_VIEW
TEST_XML(dom_attr_set_name_with_string_view, "<node attr='value' />")
{
xml_attribute attr = doc.child(STR("node")).attribute(STR("attr"));
@@ -242,7 +242,7 @@ TEST_XML(dom_node_set_name_with_size, "<node>text</node>")
CHECK_NODE(doc, STR("<n>text</n>"));
}

#ifdef PUGI_HAS_STRING_VIEW
#ifdef PUGIXML_HAS_STRING_VIEW
TEST_XML(dom_node_set_name_with_string_view, "<node>text</node>")
{
xml_node node = doc.child(STR("node"));
@@ -288,7 +288,7 @@ TEST_XML(dom_node_set_value_with_size, "<node>text</node>")
CHECK_NODE(doc, STR("<node>no text</node>"));
}

#ifdef PUGI_HAS_STRING_VIEW
#ifdef PUGIXML_HAS_STRING_VIEW
TEST_XML(dom_node_set_value_partially_with_string_view, "<node>text</node>")
{
CHECK(doc.child(STR("node")).first_child().set_value(string_view_t(STR("no text"), 2)));
6 changes: 3 additions & 3 deletions tests/test_dom_text.cpp
Original file line number Diff line number Diff line change
@@ -301,7 +301,7 @@ TEST_XML(dom_text_set_partially_with_size, "<node/>")
CHECK_NODE(node, STR("<node></node>"));
}

#ifdef PUGI_HAS_STRING_VIEW
#ifdef PUGIXML_HAS_STRING_VIEW
TEST_XML(dom_text_set_with_string_view, "<node/>")
{
xml_node node = doc.child(STR("node"));
@@ -398,7 +398,7 @@ TEST_XML(dom_text_set_value, "<node/>")
CHECK(node.append_child(STR("text1")).text().set(STR("v1")));
CHECK(!xml_text().set(STR("v1")));
CHECK(!xml_text().set(STR("v1"), 2));
#ifdef PUGI_HAS_STRING_VIEW
#ifdef PUGIXML_HAS_STRING_VIEW
CHECK(!xml_text().set(string_view_t(STR("v1"))));
#endif

@@ -537,7 +537,7 @@ TEST_XML(dom_text_middle, "<node><c1>notthisone</c1>text<c2/></node>")
CHECK(t.data() == node.last_child());
}

#ifdef PUGI_HAS_STRING_VIEW
#ifdef PUGIXML_HAS_STRING_VIEW
TEST_XML(dom_text_middle_string_view, "<node><c1>notthisone</c1>text<c2/></node>")
{
xml_node node = doc.child(STR("node"));