Exemplo n.º 1
0
        public CssSpecificity CalculateSpecificity(string selector)
        {
            if (string.IsNullOrWhiteSpace(selector) || selector == "*")
            {
                return(CssSpecificity.None);
            }

            var cssSelector = new CssSelector(selector);

            var result = CssSpecificity.None;

            if (cssSelector.HasNotPseudoClass)
            {
                result += CalculateSpecificity(cssSelector.NotPseudoClassContent);
            }

            var buffer = cssSelector.StripNotPseudoClassContent().ToString();

            var ids            = MatchCountAndStrip(IdMatcher, buffer, out buffer);
            var attributes     = MatchCountAndStrip(AttribMatcher, buffer, out buffer);
            var classes        = MatchCountAndStrip(ClassMatcher, buffer, out buffer);
            var pseudoClasses  = MatchCountAndStrip(PseudoClassMatcher, buffer, out buffer);
            var elementNames   = MatchCountAndStrip(ElemMatcher, buffer, out buffer);
            var pseudoElements = MatchCountAndStrip(PseudoElemMatcher, buffer, out buffer);

            var specificity = new CssSpecificity(ids, (classes + attributes + pseudoClasses), (elementNames + pseudoElements));

            return(result + specificity);
        }
		public CssSpecificity CalculateSpecificity(string selector)
		{
			if (string.IsNullOrWhiteSpace(selector) || selector == "*")
				return CssSpecificity.None;

			var cssSelector = new CssSelector(selector);

			var result = CssSpecificity.None;
			if (cssSelector.HasNotPseudoClass)
			{
				result += CalculateSpecificity(cssSelector.NotPseudoClassContent);
			}

			var buffer = cssSelector.StripNotPseudoClassContent().ToString();

			var ids = MatchCountAndStrip(_idMatcher, buffer, out buffer);
			var attributes = MatchCountAndStrip(_attribMatcher, buffer, out buffer);
			var classes = MatchCountAndStrip(_classMatcher, buffer, out buffer);
			var pseudoClasses = MatchCountAndStrip(_pseudoClassMatcher, buffer, out buffer);
			var elementNames = MatchCountAndStrip(_elemMatcher, buffer, out buffer);
			var pseudoElements = MatchCountAndStrip(_pseudoElemMatcher, buffer, out buffer);

			var specificity = new CssSpecificity(ids, (classes + attributes + pseudoClasses), (elementNames + pseudoElements));
			return result + specificity;
		}