Bug 825191 - Remove nsContentUtils::EqualsLiteralIgnoreASCIICase. r=mounir

This commit is contained in:
Mohit Gahlot 2013-01-12 15:47:45 -05:00
parent 7b64bbb332
commit 58a2c20c33
3 changed files with 3 additions and 77 deletions

View File

@ -1558,42 +1558,6 @@ public:
static bool EqualsIgnoreASCIICase(const nsAString& aStr1,
const nsAString& aStr2);
/**
* Case insensitive comparison between a string and an ASCII literal.
* This must ONLY be applied to an actual literal string. Do not attempt
* to use it with a regular char* pointer, or with a char array variable.
* The template trick to acquire the array length at compile time without
* using a macro is due to Corey Kosak, which much thanks.
*/
static bool EqualsLiteralIgnoreASCIICase(const nsAString& aStr1,
const char* aStr2,
const uint32_t len);
#ifdef NS_DISABLE_LITERAL_TEMPLATE
static inline bool
EqualsLiteralIgnoreASCIICase(const nsAString& aStr1,
const char* aStr2)
{
uint32_t len = strlen(aStr2);
return EqualsLiteralIgnoreASCIICase(aStr1, aStr2, len);
}
#else
template<int N>
static inline bool
EqualsLiteralIgnoreASCIICase(const nsAString& aStr1,
const char (&aStr2)[N])
{
return EqualsLiteralIgnoreASCIICase(aStr1, aStr2, N-1);
}
template<int N>
static inline bool
EqualsLiteralIgnoreASCIICase(const nsAString& aStr1,
char (&aStr2)[N])
{
const char* s = aStr2;
return EqualsLiteralIgnoreASCIICase(aStr1, s, N-1);
}
#endif
/**
* Convert ASCII A-Z to a-z.
* @return NS_OK on success, or NS_ERROR_OUT_OF_MEMORY if making the string

View File

@ -5521,44 +5521,6 @@ nsContentUtils::EqualsIgnoreASCIICase(const nsAString& aStr1,
return true;
}
/* static */
bool
nsContentUtils::EqualsLiteralIgnoreASCIICase(const nsAString& aStr1,
const char* aStr2,
const uint32_t len)
{
if (aStr1.Length() != len) {
return false;
}
const PRUnichar* str1 = aStr1.BeginReading();
const char* str2 = aStr2;
const PRUnichar* end = str1 + len;
while (str1 < end) {
PRUnichar c1 = *str1++;
PRUnichar c2 = *str2++;
// First check if any bits other than the 0x0020 differs
if ((c1 ^ c2) & 0xffdf) {
return false;
}
// We know they can only differ in the 0x0020 bit.
// Likely the two chars are the same, so check that first
if (c1 != c2) {
// They do differ, but since it's only in the 0x0020 bit, check if it's
// the same ascii char, but just differing in case
PRUnichar c1Upper = c1 & 0xffdf;
if (!('A' <= c1Upper && c1Upper <= 'Z')) {
return false;
}
}
}
return true;
}
/* static */
bool
nsContentUtils::StringContainsASCIIUpper(const nsAString& aStr)

View File

@ -197,11 +197,11 @@ public:
void SetContentEditable(const nsAString& aContentEditable,
mozilla::ErrorResult& aError)
{
if (nsContentUtils::EqualsLiteralIgnoreASCIICase(aContentEditable, "inherit")) {
if (aContentEditable.LowerCaseEqualsLiteral("inherit")) {
UnsetHTMLAttr(nsGkAtoms::contenteditable, aError);
} else if (nsContentUtils::EqualsLiteralIgnoreASCIICase(aContentEditable, "true")) {
} else if (aContentEditable.LowerCaseEqualsLiteral("true")) {
SetHTMLAttr(nsGkAtoms::contenteditable, NS_LITERAL_STRING("true"), aError);
} else if (nsContentUtils::EqualsLiteralIgnoreASCIICase(aContentEditable, "false")) {
} else if (aContentEditable.LowerCaseEqualsLiteral("false")) {
SetHTMLAttr(nsGkAtoms::contenteditable, NS_LITERAL_STRING("false"), aError);
} else {
aError.Throw(NS_ERROR_DOM_SYNTAX_ERR);