bool SchemeInList(nsAString& scheme, const char** schemes) { for (; *schemes; schemes++) { if (scheme.LowerCaseEqualsASCII(*schemes)) { return true; } } return false; };
/* static */ bool FeaturePolicyUtils::IsSupportedFeature(const nsAString& aFeatureName) { uint32_t numFeatures = (sizeof(sSupportedFeatures) / sizeof(sSupportedFeatures[0])); for (uint32_t i = 0; i < numFeatures; ++i) { if (aFeatureName.LowerCaseEqualsASCII(sSupportedFeatures[i].mFeatureName)) { return true; } } return false; }
bool CSP_IsValidDirective(const nsAString& aDir) { uint32_t numDirs = (sizeof(CSPStrDirectives) / sizeof(CSPStrDirectives[0])); for (uint32_t i = 0; i < numDirs; i++) { if (aDir.LowerCaseEqualsASCII(CSPStrDirectives[i])) { return true; } } return false; }
BluetoothAdapterAttribute BluetoothAdapter::ConvertStringToAdapterAttribute(const nsAString& aString) { using namespace mozilla::dom::BluetoothAdapterAttributeValues; for (size_t index = 0; index < ArrayLength(strings) - 1; index++) { if (aString.LowerCaseEqualsASCII(strings[index].value, strings[index].length)) { return static_cast<BluetoothAdapterAttribute>(index); } } return BluetoothAdapterAttribute::Unknown; }
bool CSP_IsValidDirective(const nsAString& aDir) { static_assert(CSP_LAST_DIRECTIVE_VALUE == (sizeof(CSPStrDirectives) / sizeof(CSPStrDirectives[0])), "CSP_LAST_DIRECTIVE_VALUE does not match length of CSPStrDirectives"); for (uint32_t i = 0; i < CSP_LAST_DIRECTIVE_VALUE; i++) { if (aDir.LowerCaseEqualsASCII(CSPStrDirectives[i])) { return true; } } return false; }
PRBool nsAttrValue::ParseEnumValue(const nsAString& aValue, const EnumTable* aTable, PRBool aCaseSensitive, const EnumTable* aDefaultValue) { ResetIfSet(); const EnumTable* tableEntry = aTable; while (tableEntry->tag) { if (aCaseSensitive ? aValue.EqualsASCII(tableEntry->tag) : aValue.LowerCaseEqualsASCII(tableEntry->tag)) { PRInt32 value = EnumTableEntryToValue(aTable, tableEntry); PRBool equals = aCaseSensitive || aValue.EqualsASCII(tableEntry->tag); if (!equals) { nsAutoString tag; tag.AssignASCII(tableEntry->tag); ToUpperCase(tag); if ((equals = tag.Equals(aValue))) { value |= NS_ATTRVALUE_ENUMTABLE_VALUE_NEEDS_TO_UPPER; } } SetIntValueAndType(value, eEnum, equals ? nsnull : &aValue); NS_ASSERTION(GetEnumValue() == tableEntry->value, "failed to store enum properly"); return PR_TRUE; } tableEntry++; } if (aDefaultValue) { NS_PRECONDITION(aTable <= aDefaultValue && aDefaultValue < tableEntry, "aDefaultValue not inside aTable?"); SetIntValueAndType(EnumTableEntryToValue(aTable, aDefaultValue), eEnum, &aValue); return PR_TRUE; } return PR_FALSE; }
bool nsDOMTokenList::Supports(const nsAString& aToken, ErrorResult& aError) { if (!mSupportedTokens) { aError.ThrowTypeError<MSG_TOKENLIST_NO_SUPPORTED_TOKENS>( mElement->LocalName(), nsDependentAtomString(mAttrAtom)); return false; } for (DOMTokenListSupportedToken* supportedToken = mSupportedTokens; *supportedToken; ++supportedToken) { if (aToken.LowerCaseEqualsASCII(*supportedToken)) { return true; } } return false; }
/* static */ bool FeaturePolicyUtils::AllowDefaultFeature(const nsAString& aFeatureName, const nsAString& aDefaultOrigin, const nsAString& aOrigin) { uint32_t numFeatures = (sizeof(sSupportedFeatures) / sizeof(sSupportedFeatures[0])); for (uint32_t i = 0; i < numFeatures; ++i) { if (aFeatureName.LowerCaseEqualsASCII(sSupportedFeatures[i].mFeatureName)) { switch (sSupportedFeatures[i].mDefaultAllowList) { case FeatureMap::eAll: return true; case FeatureMap::eSelf: return aDefaultOrigin == aOrigin; default: MOZ_CRASH("Unknown default value"); } return true; } } return false; }
PRBool nsAttrValue::ParseEnumValue(const nsAString& aValue, const EnumTable* aTable, PRBool aCaseSensitive) { ResetIfSet(); const EnumTable* tableEntry = aTable; while (tableEntry->tag) { if (aCaseSensitive ? aValue.EqualsASCII(tableEntry->tag) : aValue.LowerCaseEqualsASCII(tableEntry->tag)) { PRInt16 index; if (!GetEnumTableIndex(aTable, index)) { return PR_FALSE; } PRInt32 value = (tableEntry->value << NS_ATTRVALUE_ENUMTABLEINDEX_BITS) + index; PRBool equals = aCaseSensitive || aValue.EqualsASCII(tableEntry->tag); if (!equals) { nsAutoString tag; tag.AssignASCII(tableEntry->tag); ToUpperCase(tag); if ((equals = tag.Equals(aValue))) { value |= NS_ATTRVALUE_ENUMTABLE_VALUE_NEEDS_TO_UPPER; } } SetIntValueAndType(value, eEnum, equals ? nsnull : &aValue); NS_ASSERTION(GetEnumValue() == tableEntry->value, "failed to store enum properly"); return PR_TRUE; } tableEntry++; } return PR_FALSE; }
/* static */ void FeaturePolicyUtils::DefaultAllowListFeature(const nsAString& aFeatureName, const nsAString& aDefaultOrigin, nsAString& aDefaultAllowList) { uint32_t numFeatures = (sizeof(sSupportedFeatures) / sizeof(sSupportedFeatures[0])); for (uint32_t i = 0; i < numFeatures; ++i) { if (aFeatureName.LowerCaseEqualsASCII(sSupportedFeatures[i].mFeatureName)) { switch (sSupportedFeatures[i].mDefaultAllowList) { case FeatureMap::eAll: aDefaultAllowList.AppendASCII("*"); return; case FeatureMap::eSelf: aDefaultAllowList = aDefaultOrigin; return; default: MOZ_CRASH("Unknown default value"); } } } }
PRBool nsAttrValue::ParseEnumValue(const nsAString& aValue, const EnumTable* aTable, PRBool aCaseSensitive) { ResetIfSet(); while (aTable->tag) { if (aCaseSensitive ? aValue.EqualsASCII(aTable->tag) : aValue.LowerCaseEqualsASCII(aTable->tag)) { // Find index of EnumTable PRInt16 index = sEnumTableArray->IndexOf(aTable); if (index < 0) { index = sEnumTableArray->Length(); NS_ASSERTION(index <= NS_ATTRVALUE_ENUMTABLEINDEX_MAXVALUE, "too many enum tables"); if (!sEnumTableArray->AppendElement(aTable)) { return PR_FALSE; } } PRInt32 value = (aTable->value << NS_ATTRVALUE_ENUMTABLEINDEX_BITS) + index; SetIntValueAndType(value, eEnum); NS_ASSERTION(GetEnumValue() == aTable->value, "failed to store enum properly"); return PR_TRUE; } aTable++; } return PR_FALSE; }
bool CSP_IsKeyword(const nsAString& aValue, enum CSPKeyword aKey) { return aValue.LowerCaseEqualsASCII(CSP_EnumToKeyword(aKey)); }
bool CSP_IsDirective(const nsAString& aValue, enum CSPDirective aDir) { return aValue.LowerCaseEqualsASCII(CSP_EnumToDirective(aDir)); }
bool CSP_IsDirective(const nsAString& aValue, CSPDirective aDir) { return aValue.LowerCaseEqualsASCII(CSP_CSPDirectiveToString(aDir)); }