-
Notifications
You must be signed in to change notification settings - Fork 736
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
Add remaining std::string_view overloads #636
Add remaining std::string_view overloads #636
Conversation
Thanks! Would you mind also replicating |
I will add the clone test for |
As long as the changes are test-only it's fine to add in this PR. |
Merged, thanks a lot! |
Adding overloads for string_view to core public APIs as described in #626
The most material change is adding a helper function for checking equality between
string_view
and null terminated c-stringsimpl::stringview_equal
. Using strncmp/wsncmp directly would not work, because that stops comparison at the first null, and thestring_view
might have a null in the middle -- we do not want a string_view of "n\0pe" to be considered equal to a node named "n" for lookups.string_view
has acompare
function that has an overload for const char* (null terminated c-string) that would give the comparison we want. However, that helper works by constructing astring_view
from the const char* and then comparing to that newstring_view
, which would trigger an extra iteration over the const char*. The existing helperstrequalrange
also cannot be used: if the string_view is "n\0pe" and the test name is "n", the n and null characters will match, and then the function will attempt to read past the end of the allocation of the test name.These overloads are created by copying and pasting the original and substituting the new equality function:
Added some unit tests for
child(string_view_t)
andattribute(string_view_t)
. Also added unit tests documenting the behavior of child and attribute lookup when the node/attribute has null name -- searching does not find these nodes, even if an empty argument name is provided.These other functions also gained overloads, but they just pass the string_view_t to another overloaded function. No new unit tests were added for these functions.
Documentation will be updated to cover the new overloads after the opt-in define PUGIXML_STRING_VIEW is removed