]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
Make Util::to_lowercase work on nonstd::string_view
authorJoel Rosdahl <joel@rosdahl.net>
Mon, 13 Jul 2020 17:49:44 +0000 (19:49 +0200)
committerJoel Rosdahl <joel@rosdahl.net>
Mon, 13 Jul 2020 17:49:44 +0000 (19:49 +0200)
src/Util.cpp
src/Util.hpp

index 9218aa93fde727aaa49519af0afb70baaceb7e01..337392fcf240613dc38b2b254bacfc643b2b592e 100644 (file)
@@ -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;
 }
 
index c455b2fb11dbde68e1f1849472c80fc7eac07593..dd37c06303e86c1c31a0bdbb5fe58b609abedbce 100644 (file)
@@ -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).