Add remaining std::string_view overloads #634
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Completing the std::string_view support work defined in #626
The key new functionality is adding a helper function for checking equality between string_view and null terminated c-strings
impl::stringview_equal
. Using strncmp/wsncmp directly would not work, because that stops comparison at the first null, and the string_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 name "n" for lookups. string_view has a comparison 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 a string_view from the const char* and then comparing to the new string_view, which would trigger an extra iteration over the const char*.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