public override bool Equals(object obj) { if (obj == null || GetType() != obj.GetType()) { return(false); } else { SelectorToken t = (SelectorToken)obj; return(Text == t.Text && object.Equals(TokenType, t.TokenType)); } }
private IFilter ParseAttributeFilter() { IFilter selector = null; if (CurrentToken.Text == "[") { currentPosition++; SkipWhiteSpace(); SelectorNamespacePrefix ns = ParseNamespacePrefix(); string attributeType = Consume(SelectorTokenType.Ident); SkipWhiteSpace(); var filterLookup = new Dictionary <SelectorToken, Func <string, IFilter> >() { { new SelectorToken(SelectorTokenType.PrefixMatch, "^="), text => new AttributePrefixFilter(attributeType, text) }, { new SelectorToken(SelectorTokenType.SuffixMatch, "$="), text => new AttributeSuffixFilter(attributeType, text) }, { new SelectorToken(SelectorTokenType.SubstringMatch, "*="), text => new AttributeSubstringFilter(attributeType, text) }, { new SelectorToken(SelectorTokenType.Text, "="), text => new AttributeExactFilter(attributeType, text) }, { new SelectorToken(SelectorTokenType.Includes, "~="), text => new AttributeIncludesFilter(attributeType, text) }, { new SelectorToken(SelectorTokenType.DashMatch, "|="), text => new AttributeDashFilter(attributeType, text) } }; if (filterLookup.ContainsKey(CurrentToken)) { SelectorToken token = CurrentToken; currentPosition++; SkipWhiteSpace(); if (CurrentToken.TokenType == SelectorTokenType.Ident) { selector = filterLookup[token](CurrentToken.Text); } else if (CurrentToken.TokenType == SelectorTokenType.String) { selector = filterLookup[token](CurrentToken.Text.Substring(1, CurrentToken.Text.Length - 2)); } else { ParseError("Unexpected token type for attribute matcher"); } currentPosition++; SkipWhiteSpace(); } else { Expect("]"); } if (CurrentToken.Text == "]" && selector == null) { selector = new AttributeFilter(attributeType); currentPosition++; } else if (CurrentToken.Text == "]" && selector != null) { currentPosition++; } else { //parse error lolz } } return(selector); }