From 83fa6a09fb0afdde99ac0b035111777de5813211 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Wed, 15 Feb 2017 20:41:03 -0800 Subject: [PATCH] Add tolower_char(char)->char. Avoids C4244 for char<->int conversion --- toolsrc/src/vcpkg_Strings.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/toolsrc/src/vcpkg_Strings.cpp b/toolsrc/src/vcpkg_Strings.cpp index 3b9d6a8598d..9cad336105f 100644 --- a/toolsrc/src/vcpkg_Strings.cpp +++ b/toolsrc/src/vcpkg_Strings.cpp @@ -9,6 +9,11 @@ namespace vcpkg::Strings::details return std::isspace(c); }; + static char tolower_char(const char c) + { + return static_cast(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; }