Add string_view utility functions, strict string->numeric parser#14719
Draft
dbaston wants to merge 19 commits into
Draft
Add string_view utility functions, strict string->numeric parser#14719dbaston wants to merge 19 commits into
dbaston wants to merge 19 commits into
Conversation
rouault
reviewed
Jun 4, 2026
|
|
||
| ifdef GDAL_CONFIG | ||
| override CXXFLAGS += -std=c++11 -g -Wall -Werror $(shell $(GDAL_CONFIG) --cflags) | ||
| override CXXFLAGS += -std=c++17 -g -Wall -Werror $(shell $(GDAL_CONFIG) --cflags) |
Member
There was a problem hiding this comment.
do we formally give up on C++11 public header compatibility ? I'm not against it, but that should be done more formally than in a PR
| str.compare(str.size() - suffixLen, suffixLen, suffix, | ||
| suffixLen) == 0; | ||
| } | ||
| std::string_view CPL_DLL trim(std::string_view str); |
Member
There was a problem hiding this comment.
there's a risk such API could be mis-used if the argument is a tempory like in
auto t = trim(a_str + "x");
I'd suggest we double them with something like :
inline std::string trim(const std::string &str)
{
return std::string(trim(std::string_view(str)));
}
inline std::string_view trim(std::string &str)
{
return trim(std::string_view(str));
}
Applies to all those that return std::string_view
Member
Author
There was a problem hiding this comment.
Good point! Here is a possible alternative, in which trim always returns a consistent type:
inline std::string_view trim(const char* s) {
return trim(std::string_view(s));
}
std::string_view trim(std::string&&) = delete;
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
References #10130, #9953
Primary new feature is
cpl::strict_parse<T>, which intends to make it easier to check string arguments for invalid values instead of silently converting to zero. The final commits show some example applications of this.