]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
refactor: Move Util::to_lowercase to util
authorJoel Rosdahl <joel@rosdahl.net>
Mon, 17 Jul 2023 13:27:07 +0000 (15:27 +0200)
committerJoel Rosdahl <joel@rosdahl.net>
Tue, 18 Jul 2023 19:36:59 +0000 (21:36 +0200)
src/Config.cpp
src/Util.cpp
src/Util.hpp
src/Win32Util.cpp
src/argprocessing.cpp
src/ccache.cpp
src/execute.cpp
src/util/string.cpp
src/util/string.hpp
unittest/test_Util.cpp
unittest/test_util_string.cpp

index 38fa4432d8d074ef3d2456d705a03fe51bd78067..4d947f492c124f0fc3784074f06047adb3cf3df2 100644 (file)
@@ -225,7 +225,7 @@ parse_bool(const std::string& value,
     // Previously any value meant true, but this was surprising to users, who
     // might do something like CCACHE_DISABLE=0 and expect ccache to be
     // enabled.
-    std::string lower_value = Util::to_lowercase(value);
+    std::string lower_value = util::to_lowercase(value);
     if (value == "0" || lower_value == "false" || lower_value == "disable"
         || lower_value == "no") {
       throw core::Error(
index b5c811666d74c74fc76571d6ed32ac3b637d345f..54c9fed30bf2cac73a6a148b5d66d5886b9d0e47 100644 (file)
@@ -358,7 +358,7 @@ is_ccache_executable(const std::string_view path)
 {
   std::string name(Util::base_name(path));
 #ifdef _WIN32
-  name = Util::to_lowercase(name);
+  name = util::to_lowercase(name);
 #endif
   return util::starts_with(name, "ccache");
 }
@@ -610,15 +610,6 @@ strip_ansi_csi_seqs(std::string_view string)
   return result;
 }
 
-std::string
-to_lowercase(std::string_view string)
-{
-  std::string result;
-  result.resize(string.length());
-  std::transform(string.begin(), string.end(), result.begin(), tolower);
-  return result;
-}
-
 #ifdef HAVE_DIRENT_H
 
 void
index 9a92aa055e6e5d3772cc39b454432254a611c22c..74d29c4444ec902294beb62645a48e27b8d0636a 100644 (file)
@@ -155,9 +155,6 @@ void send_to_fd(const Context& ctx, std::string_view text, int fd);
 // Returns a copy of string with the specified ANSI CSI sequences removed.
 [[nodiscard]] std::string strip_ansi_csi_seqs(std::string_view string);
 
-// Convert a string to lowercase.
-[[nodiscard]] std::string to_lowercase(std::string_view string);
-
 // Traverse `path` recursively (postorder, i.e. files are visited before their
 // parent directory).
 //
index d90cde1ab4c03e550cef4e71eb2728b7f4c69bc0..84e7c5b62dbfa068c31acffc45def00317301ce9 100644 (file)
@@ -20,6 +20,8 @@
 
 #include "Util.hpp"
 
+#include <util/string.hpp>
+
 #include <chrono>
 #include <thread>
 
@@ -48,7 +50,7 @@ namespace Win32Util {
 std::string
 add_exe_suffix(const std::string& path)
 {
-  auto ext = Util::to_lowercase(Util::get_extension(path));
+  auto ext = util::to_lowercase(Util::get_extension(path));
   if (ext == ".exe" || ext == ".bat" || ext == ".sh") {
     return path;
   } else {
index 99209fd69de471c840e03942f9b74e25ec6a96b9..cecd904f16f03963b5f65b64b5abdc498980df94 100644 (file)
@@ -119,7 +119,7 @@ color_output_possible()
 {
   const char* term_env = getenv("TERM");
   return isatty(STDERR_FILENO) && term_env
-         && Util::to_lowercase(term_env) != "dumb";
+         && util::to_lowercase(term_env) != "dumb";
 }
 
 bool
index 2292d3347935a5c747f24501793e1eb230ada6e7..6e0ace62d1e5c2b341fcfc89e27ebd04decb0b79 100644 (file)
@@ -260,7 +260,7 @@ guess_compiler(std::string_view path)
 #endif
 
   const auto name =
-    Util::to_lowercase(Util::remove_extension(Util::base_name(compiler_path)));
+    util::to_lowercase(Util::remove_extension(Util::base_name(compiler_path)));
   if (name.find("clang-cl") != std::string_view::npos) {
     return CompilerType::clang_cl;
   } else if (name.find("clang") != std::string_view::npos) {
index e2af383f4959fc9a5309dccd63500c4910f86c86..27cb24ae11a668f7f6d191233f434ce42b1e48b0 100644 (file)
@@ -82,7 +82,7 @@ win32getshell(const std::string& path)
 {
   const char* path_list = getenv("PATH");
   std::string sh;
-  if (Util::to_lowercase(Util::get_extension(path)) == ".sh" && path_list) {
+  if (util::to_lowercase(Util::get_extension(path)) == ".sh" && path_list) {
     sh = find_executable_in_path("sh.exe", path_list);
   }
   if (sh.empty() && getenv("CCACHE_DETECT_SHEBANG")) {
index a9d61d1c6a48b8339c8ee4e8f637d794b2a81be0..38e2f2603941960c792fc4b0e50c8057c8641b29 100644 (file)
@@ -441,4 +441,13 @@ strip_whitespace(const std::string_view string)
   return start < end ? std::string(start, end) : std::string();
 }
 
+std::string
+to_lowercase(std::string_view string)
+{
+  std::string result;
+  result.resize(string.length());
+  std::transform(string.begin(), string.end(), result.begin(), tolower);
+  return result;
+}
+
 } // namespace util
index 684f059e76af72a7b9b892635f5ff606bafa86da..dfa54c33e96cda1329cd2df27d2741bd044c4e23 100644 (file)
@@ -182,6 +182,9 @@ bool starts_with(std::string_view string, std::string_view prefix);
 // Strip whitespace from left and right side of a string.
 [[nodiscard]] std::string strip_whitespace(std::string_view string);
 
+// Convert a string to lowercase.
+[[nodiscard]] std::string to_lowercase(std::string_view string);
+
 // --- Inline implementations ---
 
 inline bool
index 31aa068f4a7752745cdb9473509776c857c81017..2fe814c4de36129971e6af7edee063ca1f872c4a 100644 (file)
@@ -398,14 +398,6 @@ TEST_CASE("Util::remove_extension")
   CHECK(Util::remove_extension("/foo/bar/f.abc.txt") == "/foo/bar/f.abc");
 }
 
-TEST_CASE("Util::to_lowercase")
-{
-  CHECK(Util::to_lowercase("") == "");
-  CHECK(Util::to_lowercase("x") == "x");
-  CHECK(Util::to_lowercase("X") == "x");
-  CHECK(Util::to_lowercase(" x_X@") == " x_x@");
-}
-
 TEST_CASE("Util::traverse")
 {
   TestContext test_context;
index 4b1a2cc4ef170750967ce978c7d26d4a9c2d4d0c..a36a77302c72066ef1c6b823a21af9143399c3d6 100644 (file)
@@ -583,4 +583,12 @@ TEST_CASE("util::strip_whitespace")
   CHECK(util::strip_whitespace("  x  y  ") == "x  y");
 }
 
+TEST_CASE("util::to_lowercase")
+{
+  CHECK(util::to_lowercase("") == "");
+  CHECK(util::to_lowercase("x") == "x");
+  CHECK(util::to_lowercase("X") == "x");
+  CHECK(util::to_lowercase(" x_X@") == " x_x@");
+}
+
 TEST_SUITE_END();