mirror of
https://github.com/matrix-construct/construct
synced 2025-03-14 05:20:17 +01:00
ircd: Add string_view based tolower()/toupper().
This commit is contained in:
parent
9563781e35
commit
aa013ac526
2 changed files with 58 additions and 0 deletions
|
@ -91,6 +91,14 @@ namespace ircd
|
|||
string_view replace(const mutable_buffer &, const char &before, const char &after);
|
||||
string_view replace(const mutable_buffer &out, const string_view &in, const char &before, const char &after);
|
||||
|
||||
// Change a single character's case
|
||||
using std::tolower;
|
||||
using std::toupper;
|
||||
|
||||
// Change case for all characters.
|
||||
string_view tolower(const mutable_buffer &out, const string_view &in) noexcept;
|
||||
string_view toupper(const mutable_buffer &out, const string_view &in) noexcept;
|
||||
|
||||
// Truncate view at maximum length
|
||||
string_view trunc(const string_view &, const size_t &max);
|
||||
}
|
||||
|
|
|
@ -8,6 +8,56 @@
|
|||
// copyright notice and this permission notice is present in all copies. The
|
||||
// full license for this software is available in the LICENSE file.
|
||||
|
||||
ircd::string_view
|
||||
ircd::toupper(const mutable_buffer &out,
|
||||
const string_view &in)
|
||||
noexcept
|
||||
{
|
||||
const auto stop
|
||||
{
|
||||
std::next(begin(in), std::min(size(in), size(out)))
|
||||
};
|
||||
|
||||
const auto end
|
||||
{
|
||||
std::transform(begin(in), stop, begin(out), []
|
||||
(const auto &c)
|
||||
{
|
||||
return std::toupper(c);
|
||||
})
|
||||
};
|
||||
|
||||
return string_view
|
||||
{
|
||||
data(out), std::distance(begin(out), end)
|
||||
};
|
||||
}
|
||||
|
||||
ircd::string_view
|
||||
ircd::tolower(const mutable_buffer &out,
|
||||
const string_view &in)
|
||||
noexcept
|
||||
{
|
||||
const auto stop
|
||||
{
|
||||
std::next(begin(in), std::min(size(in), size(out)))
|
||||
};
|
||||
|
||||
const auto end
|
||||
{
|
||||
std::transform(begin(in), stop, begin(out), []
|
||||
(const auto &c)
|
||||
{
|
||||
return std::tolower(c);
|
||||
})
|
||||
};
|
||||
|
||||
return string_view
|
||||
{
|
||||
data(out), std::distance(begin(out), end)
|
||||
};
|
||||
}
|
||||
|
||||
std::string
|
||||
ircd::replace(const string_view &s,
|
||||
const char &before,
|
||||
|
|
Loading…
Add table
Reference in a new issue