0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-12-26 15:33:54 +01:00

ircd: Add substring replacement stringop.

This commit is contained in:
Jason Volk 2018-02-28 00:18:47 -08:00
parent 0e9a1e5109
commit 73c667c238

View file

@ -95,6 +95,7 @@ namespace ircd
std::string unquote(std::string &&);
std::string replace(std::string, const char &before, const char &after);
std::string replace(std::string, const string_view &before, const string_view &after);
std::string replace(const string_view &, const char &before, const string_view &after);
// Truncate view at maximum length
@ -108,6 +109,18 @@ ircd::trunc(const string_view &s,
return { s.data(), std::min(s.size(), max) };
}
inline std::string
ircd::replace(std::string s,
const string_view &before,
const string_view &after)
{
size_t p(s.find(data(before), 0, size(before)));
for(; p != s.npos; p = s.find(data(before), p + size(after), size(before)))
s.replace(p, size(before), data(after), size(after));
return s;
}
inline std::string
ircd::replace(std::string s,
const char &before,