0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2025-02-16 16:50:12 +01:00

ircd: Add stringops rsplit().

This commit is contained in:
Jason Volk 2016-10-25 20:16:28 -07:00
parent fedeab2ddd
commit b44eb91437

View file

@ -42,6 +42,7 @@ std::string token_last(const std::string &str, const char *const &sep);
std::string chomp(const std::string &str, const std::string &c = " "s);
std::pair<std::string, std::string> split(const std::string &str, const std::string &delim = " "s);
std::pair<std::string, std::string> rsplit(const std::string &str, const std::string &delim = " "s);
std::string between(const std::string &str, const std::string &a = "("s, const std::string &b = ")"s);
bool endswith(const std::string &str, const char *const &val);
bool endswith(const std::string &str, const std::string &val);
@ -126,6 +127,15 @@ ircd::between(const std::string &str,
}
inline std::pair<std::string, std::string>
ircd::rsplit(const std::string &str,
const std::string &delim)
{
const auto pos(str.find_last_of(delim));
return pos == std::string::npos? std::make_pair(std::string{}, str):
std::make_pair(str.substr(0, pos), str.substr(pos+delim.size()));
}
inline std::pair<std::string, std::string>
ircd::split(const std::string &str,
const std::string &delim)