return true;
}
+int StringUtils::CompareNoCase(const std::string &str1, const std::string &str2)
+{
+ return CompareNoCase(str1.c_str(), str2.c_str());
+}
+
+int StringUtils::CompareNoCase(const char *s1, const char *s2)
+{
+ char c2; // we need only one char outside the loop
+ do
+ {
+ const char c1 = *s1++; // const local variable should help compiler to optimize
+ c2 = *s2++;
+ if (c1 != c2 && ::tolower(c1) != ::tolower(c2)) // This includes the possibility that one of the characters is the null-terminator, which implies a string mismatch.
+ return ::tolower(c1) < ::tolower(c2);
+ } while (c2 != '\0'); // At this point, we know c1 == c2, so there's no need to test them both.
+ return 0;
+}
+
string StringUtils::Left(const string &str, size_t count)
{
count = max((size_t)0, min(count, str.size()));
static bool EqualsNoCase(const std::string &str1, const std::string &str2);
static bool EqualsNoCase(const std::string &str1, const char *s2);
static bool EqualsNoCase(const char *s1, const char *s2);
+ static int CompareNoCase(const std::string &str1, const std::string &str2);
+ static int CompareNoCase(const char *s1, const char *s2);
static std::string Left(const std::string &str, size_t count);
static std::string Mid(const std::string &str, size_t first, size_t count = std::string::npos);
static std::string Right(const std::string &str, size_t count);