mirror of
https://github.com/matrix-construct/construct
synced 2025-01-14 00:34:18 +01:00
ircd: Add mutable_buffer inplace replace to stringops.
This commit is contained in:
parent
6379813950
commit
5c03f4e08f
1 changed files with 28 additions and 0 deletions
|
@ -101,6 +101,7 @@ namespace ircd
|
||||||
std::string replace(std::string, const string_view &before, const string_view &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);
|
std::string replace(const string_view &, const char &before, const string_view &after);
|
||||||
std::string replace(const string_view &, const string_view &before, const string_view &after);
|
std::string replace(const string_view &, const string_view &before, const string_view &after);
|
||||||
|
string_view replace(const mutable_buffer &, const char &before, const char &after);
|
||||||
|
|
||||||
// Truncate view at maximum length
|
// Truncate view at maximum length
|
||||||
string_view trunc(const string_view &, const size_t &max);
|
string_view trunc(const string_view &, const size_t &max);
|
||||||
|
@ -365,6 +366,33 @@ ircd::trunc(const string_view &s,
|
||||||
return { s.data(), std::min(s.size(), max) };
|
return { s.data(), std::min(s.size(), max) };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline ircd::string_view
|
||||||
|
ircd::replace(const mutable_buffer &out,
|
||||||
|
const string_view &in,
|
||||||
|
const char &before,
|
||||||
|
const char &after)
|
||||||
|
{
|
||||||
|
const auto &end_in
|
||||||
|
{
|
||||||
|
std::(begin(in), std::min(size(in), size(out)))
|
||||||
|
};
|
||||||
|
|
||||||
|
return
|
||||||
|
{
|
||||||
|
begin(out),
|
||||||
|
std::replace_copy(begin(in), end_in, begin(out), before, after)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
inline ircd::string_view
|
||||||
|
ircd::replace(const mutable_buffer &s,
|
||||||
|
const char &before,
|
||||||
|
const char &after)
|
||||||
|
{
|
||||||
|
std::replace(begin(s), end(s), before, after);
|
||||||
|
return { data(s), size(s) };
|
||||||
|
}
|
||||||
|
|
||||||
inline std::string
|
inline std::string
|
||||||
ircd::replace(const string_view &s,
|
ircd::replace(const string_view &s,
|
||||||
const string_view &before,
|
const string_view &before,
|
||||||
|
|
Loading…
Reference in a new issue