string: add to_upper

This commit is contained in:
Danny Robson 2019-11-26 07:49:23 +11:00
parent d7f9b12f82
commit 595d062638

View File

@ -19,6 +19,38 @@
namespace cruft {
std::string to_utf8 (const wchar_t*);
std::string to_utf8 (const std::wstring&);
/// Convert the provided string to all upper case
inline std::string
to_upper (std::string &&val)
{
std::transform (
std::begin (val),
std::end (val),
std::begin (val),
::toupper
);
return std::move (val);
}
/// Convert the provided string to all upper case
inline std::string
to_upper (std::string const &val)
{
std::string res;
res.reserve (val.size ());
std::transform (
std::begin (val),
std::end (val),
std::back_inserter (res),
::toupper
);
return res;
}
}