Add tolower_char(char)->char. Avoids C4244 for char<->int conversion

This commit is contained in:
Alexander Karatarakis 2017-02-15 20:41:03 -08:00
parent d86c1ddd6c
commit 83fa6a09fb

View File

@ -9,6 +9,11 @@ namespace vcpkg::Strings::details
return std::isspace(c);
};
static char tolower_char(const char c)
{
return static_cast<char>(std::tolower(c));
}
std::string format_internal(const char* fmtstr, ...)
{
va_list lst;
@ -53,17 +58,17 @@ namespace vcpkg::Strings
std::string::const_iterator case_insensitive_ascii_find(const std::string& s, const std::string& pattern)
{
std::string pattern_as_lower_case;
std::transform(pattern.begin(), pattern.end(), back_inserter(pattern_as_lower_case), tolower);
std::transform(pattern.begin(), pattern.end(), back_inserter(pattern_as_lower_case), &details::tolower_char);
return search(s.begin(), s.end(), pattern_as_lower_case.begin(), pattern_as_lower_case.end(), [](const char a, const char b)
{
return tolower(a) == b;
return details::tolower_char(a) == b;
});
}
std::string ascii_to_lowercase(const std::string& input)
{
std::string output = input;
std::transform(output.begin(), output.end(), output.begin(), ::tolower);
std::string output(input);
std::transform(output.begin(), output.end(), output.begin(), &details::tolower_char);
return output;
}