]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
enhance: Add util::to_uppercase
authorJoel Rosdahl <joel@rosdahl.net>
Thu, 26 Mar 2026 08:42:43 +0000 (09:42 +0100)
committerJoel Rosdahl <joel@rosdahl.net>
Thu, 26 Mar 2026 11:54:05 +0000 (12:54 +0100)
src/ccache/util/string.cpp
src/ccache/util/string.hpp
unittest/test_util_string.cpp

index 9eca073d9cff88781291ee90163d78d19f6d98cf..1fde6f07f78439b2705f888838171d68af8d2efc 100644 (file)
@@ -647,4 +647,13 @@ to_lowercase(std::string_view string)
   return result;
 }
 
+std::string
+to_uppercase(std::string_view string)
+{
+  std::string result;
+  result.resize(string.length());
+  std::transform(string.begin(), string.end(), result.begin(), util::to_upper);
+  return result;
+}
+
 } // namespace util
index b9bc31bfd38b3d47cc089235ee1ab8b07f38b2c8..ce62f407c9d4d137dc4493d88507b6a68297240c 100644 (file)
@@ -229,9 +229,15 @@ std::vector<std::filesystem::path> split_path_list(std::string_view path_list);
 // Return lowercase `ch`.
 char to_lower(char ch);
 
+// Return uppercase `ch`.
+char to_upper(char ch);
+
 // Convert a string to lowercase.
 [[nodiscard]] std::string to_lowercase(std::string_view string);
 
+// Convert a string to uppercase.
+[[nodiscard]] std::string to_uppercase(std::string_view string);
+
 // --- Inline implementations ---
 
 inline bool
@@ -291,4 +297,10 @@ to_lower(char ch)
   return std::tolower(static_cast<unsigned char>(ch));
 }
 
+inline char
+to_upper(char ch)
+{
+  return std::toupper(static_cast<unsigned char>(ch));
+}
+
 } // namespace util
index 9421dd5b3bd9606a29f60c824f10180387e928e4..08af49107cd56ad78df7dc37ad3b15164c2b3e37 100644 (file)
@@ -773,4 +773,12 @@ TEST_CASE("util::to_lowercase")
   CHECK(util::to_lowercase(" x_X@") == " x_x@");
 }
 
+TEST_CASE("util::to_uppercase")
+{
+  CHECK(util::to_uppercase("") == "");
+  CHECK(util::to_uppercase("X") == "X");
+  CHECK(util::to_uppercase("x") == "X");
+  CHECK(util::to_uppercase(" x_X@") == " X_X@");
+}
+
 TEST_SUITE_END();