Introduce CaseSensitivity enum class

The enum is a bit more verbose, but leads to more readable code:

str.Equals("foo", true)
// vs.
str.Equals("foo", CString::CaseSensitive)

Deprecate the old Equals() and leave out the length parameter
from the new version => use StartsWith() or StrCmp() instead.
This commit is contained in:
J-P Nurmi
2014-09-29 16:10:26 +02:00
parent 227f2cfb29
commit e86f43d841
3 changed files with 31 additions and 4 deletions
+15 -4
View File
@@ -57,6 +57,11 @@ static const unsigned char base64_table[256] = {
XX,XX,XX,XX, XX,XX,XX,XX, XX,XX,XX,XX, XX,XX,XX,XX,
};
enum class CaseSensitivity {
CaseInsensitive,
CaseSensitive
};
/**
* @brief String class that is used inside ZNC.
*
@@ -75,6 +80,9 @@ public:
EDEBUG
} EEscape;
static const CaseSensitivity CaseSensitive = CaseSensitivity::CaseSensitive;
static const CaseSensitivity CaseInsensitive = CaseSensitivity::CaseInsensitive;
explicit CString(bool b) : std::string(b ? "true" : "false") {}
explicit CString(char c);
explicit CString(unsigned char c);
@@ -149,12 +157,15 @@ public:
/**
* Check if this string is equal to some other string.
* @param s The string to compare to.
* @param bCaseSensitive True if you want the comparision to be case
* sensitive.
* @param uLen Number of characters to consider.
* @param cs CaseSensitive if you want the comparision to be case
* sensitive, CaseInsensitive (default) otherwise.
* @return True if the strings are equal.
*/
bool Equals(const CString& s, bool bCaseSensitive = false, CString::size_type uLen = CString::npos) const;
bool Equals(const CString& s, CaseSensitivity cs = CaseInsensitive) const;
/**
* @deprecated
*/
bool Equals(const CString& s, bool bCaseSensitive, CString::size_type uLen = CString::npos) const;
/**
* Do a wildcard comparision between two strings.
* For example, the following returns true: