commit 8d1b6207c5b03a969362a558c3b5451d036f09e8 Author: Daniel Swanson Date: Mon Jun 14 10:33:59 2021 -0500 add caseless compare helper to replace (tolower(a) == tolower(b)) diff --git a/lttoolbox/string_utils.cc b/lttoolbox/string_utils.cc index fe2d2bc..411380d 100644 --- a/lttoolbox/string_utils.cc +++ b/lttoolbox/string_utils.cc @@ -233,3 +233,17 @@ StringUtils::copycase(const UString& source, const UString& target) return tolower(target); } } + +bool +StringUtils::caseequal(const UString& a, const UString& b) +{ + UErrorCode err = U_ZERO_ERROR; + int cmp = u_strCaseCompare(a.c_str(), -1, b.c_str(), -1, 0, &err); + if (U_FAILURE(err)) { + std::cerr << "Error: caseless string comparison failed on '"; + std::cerr << a << "' and '" << b << "'" << std::endl; + std::cerr << "error code: " << u_errorName(err) << std::endl; + exit(EXIT_FAILURE); + } + return (cmp == 0); +} diff --git a/lttoolbox/string_utils.h b/lttoolbox/string_utils.h index df664ab..79aeadf 100644 --- a/lttoolbox/string_utils.h +++ b/lttoolbox/string_utils.h @@ -31,6 +31,8 @@ public: static UString getcase(const UString& str); static UString copycase(const UString& source, const UString& target); + + static bool caseequal(const UString& a, const UString& b); }; #endif // __LT_STRING_UTILS_H__