summaryrefslogtreecommitdiffstatshomepage
path: root/src/lib
diff options
context:
space:
mode:
author AJR <ajrhacker@users.noreply.github.com>2022-08-02 08:21:53 -0400
committer AJR <ajrhacker@users.noreply.github.com>2022-08-02 08:21:59 -0400
commit9d0076ab91bfc3fd2514b9f0d612b4049b5bbaf7 (patch)
treea09afdd6439afe481d985d721754a0be9cbf9fe8 /src/lib
parent786016ae25d7918bd4c3ccaa6340f2f84397d288 (diff)
Change debugger command handler parameter vector element type from std::string to std::string_view
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/util/corestr.cpp38
-rw-r--r--src/lib/util/corestr.h3
2 files changed, 39 insertions, 2 deletions
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
*/
@@ -210,6 +210,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)
*
* @brief Compares strings and returns prefix-weighted similarity score (smaller is more similar).
diff --git a/src/lib/util/corestr.h b/src/lib/util/corestr.h
index d5b79ddb5fa..b000d76731c 100644
--- a/src/lib/util/corestr.h
+++ b/src/lib/util/corestr.h
@@ -77,6 +77,9 @@ int strreplace(std::string &str, const std::string& search, const std::string& r
namespace util {
+bool strequpper(std::string_view str, std::string_view ucstr);
+bool streqlower(std::string_view str, std::string_view lcstr);
+
// based on Jaro-Winkler distance - returns value from 0.0 (totally dissimilar) to 1.0 (identical)
double edit_distance(std::u32string_view lhs, std::u32string_view rhs);