示例#1
0
        internal static bool IsMatch(this HtmlAgilityPack.HtmlNode node, ExCSS.Model.Attribute attribute)
        {
            var attr = node.Attributes[attribute.Operand];

            if (attr != null)
            {
                var value = attr.Value;
                var test  = (attribute.Value ?? "").Trim(' ', '\'', '"');
                switch (attribute.Operator)
                {
                case AttributeOperator.BeginsWith:
                    return(value.StartsWith(test));

                case AttributeOperator.Contains:
                    return(value.Contains(test));

                case AttributeOperator.EndsWith:
                    return(value.EndsWith(test));

                case AttributeOperator.Equals:
                    return(value == test);

                case AttributeOperator.Hyphenated:
                    return(value.Split('-').Contains(test));

                case AttributeOperator.InList:
                    return(value.Split(' ').Contains(test));

                case AttributeOperator.None:
                    return(true);
                }
            }

            return(false);
        }
示例#2
0
文件: Parser.cs 项目: Piedone/ExCSS
        void attrib(out Model.Attribute attribute)
        {
            attribute = new Model.Attribute { Value = "" };
            string quote;
            string ident;

            Expect(36);
            while (la.kind == 4) {
            Get();
            }
            identity(out ident);
            attribute.Operand = ident;
            while (la.kind == 4) {
            Get();
            }
            if (StartOf(15)) {
            switch (la.kind) {
            case 37: {
                Get();
                attribute.Operator = AttributeOperator.Equals;
                break;
            }
            case 38: {
                Get();
                attribute.Operator = AttributeOperator.InList;
                break;
            }
            case 39: {
                Get();
                attribute.Operator = AttributeOperator.Hyphenated;
                break;
            }
            case 40: {
                Get();
                attribute.Operator = AttributeOperator.EndsWith;
                break;
            }
            case 41: {
                Get();
                attribute.Operator = AttributeOperator.BeginsWith;
                break;
            }
            case 42: {
                Get();
                attribute.Operator = AttributeOperator.Contains;
                break;
            }
            }
            while (StartOf(16)) {
                while (la.kind == 4) {
                    Get();
                }
                if (StartOf(13)) {
                    if (la.kind == 24) {
                        Get();
                        attribute.Value += "-";
                    }
                    identity(out ident);
                    attribute.Value += ident;
                } else if (la.kind == 7 || la.kind == 8) {
                    QuotedStringPreserved(out quote);
                    attribute.Value = quote;
                } else SynErr(58);
                while (la.kind == 4) {
                    Get();
                }
            }
            }
            Expect(43);
        }