From: Joel Rosdahl Date: Mon, 13 Jul 2020 17:49:44 +0000 (+0200) Subject: Make Util::to_lowercase work on nonstd::string_view X-Git-Tag: v4.0~329 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9d0a1dfd72a800f5a7d4ae485df9daf8d2952b6c;p=thirdparty%2Fccache.git Make Util::to_lowercase work on nonstd::string_view --- diff --git a/src/Util.cpp b/src/Util.cpp index 9218aa93f..337392fcf 100644 --- a/src/Util.cpp +++ b/src/Util.cpp @@ -819,10 +819,11 @@ strip_whitespace(const std::string& string) } std::string -to_lowercase(const std::string& string) +to_lowercase(string_view string) { - std::string result = string; - std::transform(result.begin(), result.end(), result.begin(), tolower); + std::string result; + result.resize(string.length()); + std::transform(string.begin(), string.end(), result.begin(), tolower); return result; } diff --git a/src/Util.hpp b/src/Util.hpp index c455b2fb1..dd37c0630 100644 --- a/src/Util.hpp +++ b/src/Util.hpp @@ -322,7 +322,8 @@ strip_ansi_csi_seqs(nonstd::string_view string); strip_whitespace(const std::string& string); // Convert a string to lowercase. -[[gnu::warn_unused_result]] std::string to_lowercase(const std::string& string); +[[gnu::warn_unused_result]] std::string +to_lowercase(nonstd::string_view string); // Traverse `path` recursively (postorder, i.e. files are visited before their // parent directory).