Пример #1
0
        private void ByAttribute()
        {
            TokenQueue cq = new TokenQueue(tq.ChompBalanced('[', ']'));
            // content queue
            String key = cq.ConsumeToAny(AttributeEvals);

            // eq, not, start, end, contain, match, (no val)
            Validate.NotEmpty(key);
            cq.ConsumeWhitespace();
            if (cq.IsEmpty())
            {
                if (key.StartsWith("^"))
                {
                    evals.Add(new Evaluator.AttributeStarting(key.Substring(1)));
                }
                else
                {
                    evals.Add(new Evaluator.Attribute(key));
                }
            }
            else
            {
                if (cq.MatchChomp("="))
                {
                    evals.Add(new Evaluator.AttributeWithValue(key, cq.Remainder()));
                }
                else
                {
                    if (cq.MatchChomp("!="))
                    {
                        evals.Add(new Evaluator.AttributeWithValueNot(key, cq.Remainder()));
                    }
                    else
                    {
                        if (cq.MatchChomp("^="))
                        {
                            evals.Add(new Evaluator.AttributeWithValueStarting(key, cq.Remainder()));
                        }
                        else
                        {
                            if (cq.MatchChomp("$="))
                            {
                                evals.Add(new Evaluator.AttributeWithValueEnding(key, cq.Remainder()));
                            }
                            else
                            {
                                if (cq.MatchChomp("*="))
                                {
                                    evals.Add(new Evaluator.AttributeWithValueContaining(key, cq.Remainder()));
                                }
                                else
                                {
                                    if (cq.MatchChomp("~="))
                                    {
                                        evals.Add(new Evaluator.AttributeWithValueMatching(key, iText.IO.Util.StringUtil.RegexCompile(cq.Remainder
                                                                                                                                          ())));
                                    }
                                    else
                                    {
                                        throw new Selector.SelectorParseException("Could not parse attribute query " + PortUtil.EscapedSingleBracket
                                                                                  + "{0}" + PortUtil.EscapedSingleBracket + ": unexpected token at " + PortUtil.EscapedSingleBracket +
                                                                                  "{1}" + PortUtil.EscapedSingleBracket, query, cq.Remainder());
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }