From 484307c6dc86fcffd02c35efab21cd9016cb8f55 Mon Sep 17 00:00:00 2001 From: "peterl%netscape.com" Date: Thu, 11 Feb 1999 06:42:49 +0000 Subject: [PATCH] handle case sensitivity in attribute selector values here git-svn-id: svn://10.0.0.236/trunk@20385 18797224-902f-48f8-a5cc-f745e15eee43 --- .../html/style/src/nsCSSStyleSheet.cpp | 42 ++++++++++++------- .../layout/html/style/src/nsCSSStyleSheet.cpp | 42 ++++++++++++------- mozilla/layout/style/nsCSSStyleSheet.cpp | 42 ++++++++++++------- 3 files changed, 84 insertions(+), 42 deletions(-) diff --git a/mozilla/content/html/style/src/nsCSSStyleSheet.cpp b/mozilla/content/html/style/src/nsCSSStyleSheet.cpp index c14fc1c3afb..e056f4315e8 100644 --- a/mozilla/content/html/style/src/nsCSSStyleSheet.cpp +++ b/mozilla/content/html/style/src/nsCSSStyleSheet.cpp @@ -885,12 +885,13 @@ nsresult CSSStyleSheetImpl::QueryInterface(const nsIID& aIID, static const PRUnichar kNullCh = PRUnichar('\0'); -static PRBool ValueIncludes(const nsString& aValueList, const nsString& aValue) +static PRBool ValueIncludes(const nsString& aValueList, const nsString& aValue, PRBool aCaseSensitive) { nsAutoString valueList(aValueList); valueList.Append(kNullCh); // put an extra null at the end + PRUnichar* value = (PRUnichar*)aValue; PRUnichar* start = (PRUnichar*)valueList; PRUnichar* end = start; @@ -905,8 +906,17 @@ static PRBool ValueIncludes(const nsString& aValueList, const nsString& aValue) } *end = kNullCh; // end string here - if ((start < end) && (aValue == start)) { - return PR_TRUE; + if (start < end) { + if (aCaseSensitive) { + if (aValue.Equals(value, start)) { + return PR_TRUE; + } + } + else { + if (aValue.EqualsIgnoreCase(value, start)) { + return PR_TRUE; + } + } } start = ++end; @@ -916,12 +926,13 @@ static PRBool ValueIncludes(const nsString& aValueList, const nsString& aValue) static const PRUnichar kDashCh = PRUnichar('-'); -static PRBool ValueDashMatch(const nsString& aValueList, const nsString& aValue) +static PRBool ValueDashMatch(const nsString& aValueList, const nsString& aValue, PRBool aCaseSensitive) { nsAutoString valueList(aValueList); valueList.Append(kNullCh); // put an extra null at the end + PRUnichar* value = (PRUnichar*)aValue; PRUnichar* start = (PRUnichar*)valueList; PRUnichar* end = start; @@ -936,8 +947,17 @@ static PRBool ValueDashMatch(const nsString& aValueList, const nsString& aValue) } *end = kNullCh; // end string here - if ((start < end) && (aValue == start)) { - return PR_TRUE; + if (start < end) { + if (aCaseSensitive) { + if (aValue.Equals(value, start)) { + return PR_TRUE; + } + } + else { + if (aValue.EqualsIgnoreCase(value, start)) { + return PR_TRUE; + } + } } } return PR_FALSE; @@ -977,16 +997,10 @@ static PRBool SelectorMatches(nsIPresContext* aPresContext, } break; case NS_ATTR_FUNC_INCLUDES: - if (PR_FALSE == attr->mCaseSensitive) { - value.ToUpperCase(); - } - result = ValueIncludes(value, attr->mValue); + result = ValueIncludes(value, attr->mValue, attr->mCaseSensitive); break; case NS_ATTR_FUNC_DASHMATCH: - if (PR_FALSE == attr->mCaseSensitive) { - value.ToUpperCase(); - } - result = ValueDashMatch(value, attr->mValue); + result = ValueDashMatch(value, attr->mValue, attr->mCaseSensitive); break; } } diff --git a/mozilla/layout/html/style/src/nsCSSStyleSheet.cpp b/mozilla/layout/html/style/src/nsCSSStyleSheet.cpp index c14fc1c3afb..e056f4315e8 100644 --- a/mozilla/layout/html/style/src/nsCSSStyleSheet.cpp +++ b/mozilla/layout/html/style/src/nsCSSStyleSheet.cpp @@ -885,12 +885,13 @@ nsresult CSSStyleSheetImpl::QueryInterface(const nsIID& aIID, static const PRUnichar kNullCh = PRUnichar('\0'); -static PRBool ValueIncludes(const nsString& aValueList, const nsString& aValue) +static PRBool ValueIncludes(const nsString& aValueList, const nsString& aValue, PRBool aCaseSensitive) { nsAutoString valueList(aValueList); valueList.Append(kNullCh); // put an extra null at the end + PRUnichar* value = (PRUnichar*)aValue; PRUnichar* start = (PRUnichar*)valueList; PRUnichar* end = start; @@ -905,8 +906,17 @@ static PRBool ValueIncludes(const nsString& aValueList, const nsString& aValue) } *end = kNullCh; // end string here - if ((start < end) && (aValue == start)) { - return PR_TRUE; + if (start < end) { + if (aCaseSensitive) { + if (aValue.Equals(value, start)) { + return PR_TRUE; + } + } + else { + if (aValue.EqualsIgnoreCase(value, start)) { + return PR_TRUE; + } + } } start = ++end; @@ -916,12 +926,13 @@ static PRBool ValueIncludes(const nsString& aValueList, const nsString& aValue) static const PRUnichar kDashCh = PRUnichar('-'); -static PRBool ValueDashMatch(const nsString& aValueList, const nsString& aValue) +static PRBool ValueDashMatch(const nsString& aValueList, const nsString& aValue, PRBool aCaseSensitive) { nsAutoString valueList(aValueList); valueList.Append(kNullCh); // put an extra null at the end + PRUnichar* value = (PRUnichar*)aValue; PRUnichar* start = (PRUnichar*)valueList; PRUnichar* end = start; @@ -936,8 +947,17 @@ static PRBool ValueDashMatch(const nsString& aValueList, const nsString& aValue) } *end = kNullCh; // end string here - if ((start < end) && (aValue == start)) { - return PR_TRUE; + if (start < end) { + if (aCaseSensitive) { + if (aValue.Equals(value, start)) { + return PR_TRUE; + } + } + else { + if (aValue.EqualsIgnoreCase(value, start)) { + return PR_TRUE; + } + } } } return PR_FALSE; @@ -977,16 +997,10 @@ static PRBool SelectorMatches(nsIPresContext* aPresContext, } break; case NS_ATTR_FUNC_INCLUDES: - if (PR_FALSE == attr->mCaseSensitive) { - value.ToUpperCase(); - } - result = ValueIncludes(value, attr->mValue); + result = ValueIncludes(value, attr->mValue, attr->mCaseSensitive); break; case NS_ATTR_FUNC_DASHMATCH: - if (PR_FALSE == attr->mCaseSensitive) { - value.ToUpperCase(); - } - result = ValueDashMatch(value, attr->mValue); + result = ValueDashMatch(value, attr->mValue, attr->mCaseSensitive); break; } } diff --git a/mozilla/layout/style/nsCSSStyleSheet.cpp b/mozilla/layout/style/nsCSSStyleSheet.cpp index c14fc1c3afb..e056f4315e8 100644 --- a/mozilla/layout/style/nsCSSStyleSheet.cpp +++ b/mozilla/layout/style/nsCSSStyleSheet.cpp @@ -885,12 +885,13 @@ nsresult CSSStyleSheetImpl::QueryInterface(const nsIID& aIID, static const PRUnichar kNullCh = PRUnichar('\0'); -static PRBool ValueIncludes(const nsString& aValueList, const nsString& aValue) +static PRBool ValueIncludes(const nsString& aValueList, const nsString& aValue, PRBool aCaseSensitive) { nsAutoString valueList(aValueList); valueList.Append(kNullCh); // put an extra null at the end + PRUnichar* value = (PRUnichar*)aValue; PRUnichar* start = (PRUnichar*)valueList; PRUnichar* end = start; @@ -905,8 +906,17 @@ static PRBool ValueIncludes(const nsString& aValueList, const nsString& aValue) } *end = kNullCh; // end string here - if ((start < end) && (aValue == start)) { - return PR_TRUE; + if (start < end) { + if (aCaseSensitive) { + if (aValue.Equals(value, start)) { + return PR_TRUE; + } + } + else { + if (aValue.EqualsIgnoreCase(value, start)) { + return PR_TRUE; + } + } } start = ++end; @@ -916,12 +926,13 @@ static PRBool ValueIncludes(const nsString& aValueList, const nsString& aValue) static const PRUnichar kDashCh = PRUnichar('-'); -static PRBool ValueDashMatch(const nsString& aValueList, const nsString& aValue) +static PRBool ValueDashMatch(const nsString& aValueList, const nsString& aValue, PRBool aCaseSensitive) { nsAutoString valueList(aValueList); valueList.Append(kNullCh); // put an extra null at the end + PRUnichar* value = (PRUnichar*)aValue; PRUnichar* start = (PRUnichar*)valueList; PRUnichar* end = start; @@ -936,8 +947,17 @@ static PRBool ValueDashMatch(const nsString& aValueList, const nsString& aValue) } *end = kNullCh; // end string here - if ((start < end) && (aValue == start)) { - return PR_TRUE; + if (start < end) { + if (aCaseSensitive) { + if (aValue.Equals(value, start)) { + return PR_TRUE; + } + } + else { + if (aValue.EqualsIgnoreCase(value, start)) { + return PR_TRUE; + } + } } } return PR_FALSE; @@ -977,16 +997,10 @@ static PRBool SelectorMatches(nsIPresContext* aPresContext, } break; case NS_ATTR_FUNC_INCLUDES: - if (PR_FALSE == attr->mCaseSensitive) { - value.ToUpperCase(); - } - result = ValueIncludes(value, attr->mValue); + result = ValueIncludes(value, attr->mValue, attr->mCaseSensitive); break; case NS_ATTR_FUNC_DASHMATCH: - if (PR_FALSE == attr->mCaseSensitive) { - value.ToUpperCase(); - } - result = ValueDashMatch(value, attr->mValue); + result = ValueDashMatch(value, attr->mValue, attr->mCaseSensitive); break; } }