From 9d0076ab91bfc3fd2514b9f0d612b4049b5bbaf7 Mon Sep 17 00:00:00 2001 From: AJR Date: Tue, 2 Aug 2022 08:21:53 -0400 Subject: Change debugger command handler parameter vector element type from std::string to std::string_view --- src/lib/util/corestr.cpp | 38 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) (limited to 'src/lib/util/corestr.cpp') diff --git a/src/lib/util/corestr.cpp b/src/lib/util/corestr.cpp index 85e7e517665..50f2469b14f 100644 --- a/src/lib/util/corestr.cpp +++ b/src/lib/util/corestr.cpp @@ -165,11 +165,11 @@ std::string strmakeupper(std::string_view str) } /** - * @fn std::string &strmakelower(std::string_view str) + * @fn std::string strmakelower(std::string_view str) * * @brief Returns a lower case version of the given string. * - * @param [in,out] str The string to make lower case + * @param [in] str The string to make lower case * * @return A new std::string having been changed to lower case */ @@ -209,6 +209,40 @@ int strreplace(std::string &str, const std::string& search, const std::string& r namespace util { +/** + * @fn bool streqlower(std::string_view str, std::string_view lcstr) + * + * @brief Tests whether a mixed-case string matches a lowercase string. + * + * @param [in] str First string to compare (may be mixed-case). + * @param [in] lcstr Second string to compare (must be all lowercase). + * + * @return True if the strings match regardless of case. + */ + +bool streqlower(std::string_view str, std::string_view lcstr) +{ + return std::equal(str.begin(), str.end(), lcstr.begin(), lcstr.end(), + [] (unsigned char c1, unsigned char c2) { return std::tolower(c1) == c2; }); +} + +/** + * @fn bool strequpper(std::string_view str, std::string_view ucstr) + * + * @brief Tests whether a mixed-case string matches an uppercase string. + * + * @param [in] str First string to compare (may be mixed-case). + * @param [in] ucstr Second string to compare (must be all uppercase). + * + * @return True if the strings match regardless of case. + */ + +bool strequpper(std::string_view str, std::string_view ucstr) +{ + return std::equal(str.begin(), str.end(), ucstr.begin(), ucstr.end(), + [] (unsigned char c1, unsigned char c2) { return std::toupper(c1) == c2; }); +} + /** * @fn double edit_distance(std::u32string_view lhs, std::u32string_view rhs) * -- cgit v1.2.3-70-g09d2