It would be nice to have a family of substring extraction functions for situations like this:
auto extension = substring_after_last("readme.txt", ".");
REQUIRE(extension == "txt");
auto facility = substring_before_first("FACILITY/DEVICE/LOCATION/PROPERTY", "/");
REQUIRE(facility == "FACILITY");
The use cases for this functionality are frequent, and writing ad-hoc code for it is clumsy and makes the code hard to read.
To start off, I could imagine the following signatures:
std::string substring_after_first(std::string_view string, std::string_view separator);
std::string substring_after_last(std::string_view string, std::string_view separator);
std::string substring_before_first(std::string_view string, std::string_view separator);
std::string substring_before_last(std::string_view string, std::string_view separator);
We could add _sv versions returning string_view as well.
It would be nice to have a family of substring extraction functions for situations like this:
The use cases for this functionality are frequent, and writing ad-hoc code for it is clumsy and makes the code hard to read.
To start off, I could imagine the following signatures:
We could add
_svversions returningstring_viewas well.