Merge pull request #543 from diamante0018/develop

refactor(utils): buff with c++20 to_upper/lower
This commit is contained in:
Edo 2022-11-25 20:54:30 +00:00 committed by GitHub
commit 8d96e0a3ff
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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);