refactor(utils): buff with c++20 to_upper/lower

This commit is contained in:
FutureRave 2022-11-25 20:44:08 +00:00
parent 4966bee83a
commit 8af9e83778
No known key found for this signature in database
GPG Key ID: 22F9079C86CFAB31
2 changed files with 10 additions and 8 deletions

View File

@ -34,24 +34,26 @@ namespace utils::string
return elems;
}
std::string to_lower(std::string text)
std::string to_lower(const std::string& text)
{
std::transform(text.begin(), text.end(), text.begin(), [](const unsigned char input)
std::string result;
std::ranges::transform(text, std::back_inserter(result), [](const unsigned char input)
{
return static_cast<char>(std::tolower(input));
});
return text;
return result;
}
std::string to_upper(std::string text)
std::string to_upper(const std::string& text)
{
std::transform(text.begin(), text.end(), text.begin(), [](const unsigned char input)
std::string result;
std::ranges::transform(text, std::back_inserter(result), [](const unsigned char input)
{
return static_cast<char>(std::toupper(input));
});
return text;
return result;
}
bool starts_with(const std::string& text, const std::string& substring)

View File

@ -82,8 +82,8 @@ namespace utils::string
std::vector<std::string> split(const std::string& s, char delim);
std::string to_lower(std::string text);
std::string to_upper(std::string text);
std::string to_lower(const std::string& text);
std::string to_upper(const std::string& text);
bool starts_with(const std::string& text, const std::string& substring);
bool ends_with(const std::string& text, const std::string& substring);