示例#1
0
 public override bool Equals(object obj)
 {
     if (obj == null || GetType() != obj.GetType())
     {
         return(false);
     }
     else
     {
         LangFilter t = (LangFilter)obj;
         return(lang.Equals(t.lang));
     }
 }
示例#2
0
        private IFilter ParsePseudoFilter()
        {
            IFilter selector = null;
            if (CurrentToken.Text == ":")
            {
                currentPosition++;
                ParseErrorIfEnd();
                if (CurrentToken.Text == ":")
                {
                    ParseError(":: selectors do not apply to static html, so were not implemented.");
                }
                else if (CurrentToken.TokenType == SelectorTokenType.Ident)
                {
                    var filterLookup = new Dictionary<string, IFilter>()
                    {
                        { "root", new RootFilter() },
                        { "first-child", new FirstChildFilter() },
                        { "last-child", new LastChildFilter() },
                        { "first-of-type", new FirstOfTypeFilter() },
                        { "last-of-type", new LastOfTypeFilter() },
                        { "only-child", new OnlyChildFilter() },
                        { "only-of-type", new OnlyOfTypeFilter() },
                        { "empty", new EmptyFilter() },
                        { "enabled", new EnabledFilter() },
                        { "disabled", new DisabledFilter() },
                        { "checked", new CheckedFilter() }
                    };

                    if (filterLookup.ContainsKey(CurrentToken.Text))
                    {
                        selector = filterLookup[CurrentToken.Text];
                        currentPosition++;
                    }
                    else
                    {
                        ParseError("Unsupported or invalid pseudo selector :" + filterLookup);
                    }
                }
                else if (CurrentToken.TokenType == SelectorTokenType.Function)
                {
                    var filterLookup = new Dictionary<string, Func<Expression, IFilter>>()
                    {
                        { "nth-child(", e => new NthChildFilter(e) },
                        { "nth-last-child(", e => new NthLastChildFilter(e) },
                        { "nth-of-type(", e => new NthOfTypeFilter(e) },
                        { "nth-last-of-type(", e => new NthLastOfTypeFilter(e) }
                    };

                    if (filterLookup.ContainsKey(CurrentToken.Text))
                    {
                        string text = CurrentToken.Text;
                        currentPosition++;
                        ParseErrorIfEnd();
                        SkipWhiteSpace();
                        ParseErrorIfEnd();
                        Expression expression = ParseExpression();
                        if (expression == null)
                        {
                            ParseError("Unable to parse expression");
                        }
                        selector = filterLookup[text](expression);
                    }
                    else if (CurrentToken.Text == "lang(")
                    {
                        currentPosition++;
                        ParseErrorIfEnd();
                        SkipWhiteSpace();
                        ParseErrorIfEnd();
                        if (CurrentToken.TokenType == SelectorTokenType.Ident)
                        {
                            selector = new LangFilter(CurrentToken.Text);
                        }
                        else if (CurrentToken.TokenType == SelectorTokenType.String)
                        {
                            selector = new LangFilter(CurrentToken.Text.Substring(1, CurrentToken.Text.Length - 2));
                        }

                    }
                    else
                    {
                        ParseError("Unrecognized pseudo function");
                    }
                    currentPosition++;
                    Consume(")");
                }
            }
            return selector;
        }
        private IFilter ParsePseudoFilter()
        {
            IFilter selector = null;

            if (CurrentToken.Text == ":")
            {
                currentPosition++;
                ParseErrorIfEnd();
                if (CurrentToken.Text == ":")
                {
                    ParseError(":: selectors do not apply to static html, so were not implemented.");
                }
                else if (CurrentToken.TokenType == SelectorTokenType.Ident)
                {
                    var filterLookup = new Dictionary <string, IFilter>()
                    {
                        { "root", new RootFilter() },
                        { "first-child", new FirstChildFilter() },
                        { "last-child", new LastChildFilter() },
                        { "first-of-type", new FirstOfTypeFilter() },
                        { "last-of-type", new LastOfTypeFilter() },
                        { "only-child", new OnlyChildFilter() },
                        { "only-of-type", new OnlyOfTypeFilter() },
                        { "empty", new EmptyFilter() },
                        { "enabled", new EnabledFilter() },
                        { "disabled", new DisabledFilter() },
                        { "checked", new CheckedFilter() }
                    };

                    if (filterLookup.ContainsKey(CurrentToken.Text))
                    {
                        selector = filterLookup[CurrentToken.Text];
                        currentPosition++;
                    }
                    else
                    {
                        ParseError("Unsupported or invalid pseudo selector :" + filterLookup);
                    }
                }
                else if (CurrentToken.TokenType == SelectorTokenType.Function)
                {
                    var filterLookup = new Dictionary <string, Func <Expression, IFilter> >()
                    {
                        { "nth-child(", e => new NthChildFilter(e) },
                        { "nth-last-child(", e => new NthLastChildFilter(e) },
                        { "nth-of-type(", e => new NthOfTypeFilter(e) },
                        { "nth-last-of-type(", e => new NthLastOfTypeFilter(e) }
                    };

                    if (filterLookup.ContainsKey(CurrentToken.Text))
                    {
                        string text = CurrentToken.Text;
                        currentPosition++;
                        ParseErrorIfEnd();
                        SkipWhiteSpace();
                        ParseErrorIfEnd();
                        Expression expression = ParseExpression();
                        if (expression == null)
                        {
                            ParseError("Unable to parse expression");
                        }
                        selector = filterLookup[text](expression);
                    }
                    else if (CurrentToken.Text == "lang(")
                    {
                        currentPosition++;
                        ParseErrorIfEnd();
                        SkipWhiteSpace();
                        ParseErrorIfEnd();
                        if (CurrentToken.TokenType == SelectorTokenType.Ident)
                        {
                            selector = new LangFilter(CurrentToken.Text);
                        }
                        else if (CurrentToken.TokenType == SelectorTokenType.String)
                        {
                            selector = new LangFilter(CurrentToken.Text.Substring(1, CurrentToken.Text.Length - 2));
                        }
                    }
                    else
                    {
                        ParseError("Unrecognized pseudo function");
                    }
                    currentPosition++;
                    Consume(")");
                }
            }
            return(selector);
        }