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:
parent
0e9a1e5109
commit
73c667c238
1 changed files with 13 additions and 0 deletions
|
@ -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,
|
||||
|
|
Loading…
Reference in a new issue