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
// 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
return std::tolower(static_cast<unsigned char>(ch));
}
+inline char
+to_upper(char ch)
+{
+ return std::toupper(static_cast<unsigned char>(ch));
+}
+
} // namespace util
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();