diff options
Diffstat (limited to 'src/lib/util/corestr.cpp')
-rw-r--r-- | src/lib/util/corestr.cpp | 38 |
1 files changed, 36 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). |