Esempio n. 1
0
        /// <summary>
        /// Creates an attribute selector using the current state.
        /// </summary>
        /// <returns>The created selector.</returns>
        SimpleSelector CreateAttrSelector()
        {
            switch (attrOp)
            {
            case "=":
                return(SimpleSelector.AttrMatch(attrName, attrValue, attrNs));

            case "~=":
                return(SimpleSelector.AttrList(attrName, attrValue, attrNs));

            case "|=":
                return(SimpleSelector.AttrHyphen(attrName, attrValue, attrNs));

            case "^=":
                return(SimpleSelector.AttrBegins(attrName, attrValue, attrNs));

            case "$=":
                return(SimpleSelector.AttrEnds(attrName, attrValue, attrNs));

            case "*=":
                return(SimpleSelector.AttrContains(attrName, attrValue, attrNs));

            case "!=":
                return(SimpleSelector.AttrNotMatch(attrName, attrValue, attrNs));

            default:
                return(SimpleSelector.AttrAvailable(attrName, attrNs));
            }
        }
        /// <summary>
        /// Creates the associated CSS attribute selector.
        /// </summary>
        /// <param name="combinator">The used CSS combinator.</param>
        /// <param name="name">The name of the attribute.</param>
        /// <param name="value">The used value, if any.</param>
        /// <param name="prefix">The given prefix, if any.</param>
        /// <returns>The associated selector.</returns>
        public ISelector Create(String combinator, String name, String value, String prefix)
        {
            var creator = default(Creator);

            if (creators.TryGetValue(combinator, out creator))
            {
                return(creator(name, value, prefix));
            }

            return(SimpleSelector.AttrAvailable(name, value));
        }
        /// <summary>
        /// Invoked once a square bracket has been found in the token enumerator.
        /// </summary>
        /// <param name="token">The token.</param>
        /// <returns>True if no error occurred, otherwise false.</returns>
        Boolean OnAttributeEnd(CssToken token)
        {
            if (token.Type == CssTokenType.Whitespace)
            {
                return(true);
            }

            state = State.Data;

            if (token.Type == CssTokenType.SquareBracketClose)
            {
                switch (attrOp)
                {
                case "=":
                    Insert(SimpleSelector.AttrMatch(attrName, attrValue));
                    break;

                case "~=":
                    Insert(SimpleSelector.AttrList(attrName, attrValue));
                    break;

                case "|=":
                    Insert(SimpleSelector.AttrHyphen(attrName, attrValue));
                    break;

                case "^=":
                    Insert(SimpleSelector.AttrBegins(attrName, attrValue));
                    break;

                case "$=":
                    Insert(SimpleSelector.AttrEnds(attrName, attrValue));
                    break;

                case "*=":
                    Insert(SimpleSelector.AttrContains(attrName, attrValue));
                    break;

                case "!=":
                    Insert(SimpleSelector.AttrNotMatch(attrName, attrValue));
                    break;

                default:
                    Insert(SimpleSelector.AttrAvailable(attrName));
                    break;
                }

                return(true);
            }

            return(false);
        }
 /// <summary>
 /// Creates the default CSS attribute selector for the given options.
 /// </summary>
 /// <param name="name">The name of the attribute.</param>
 /// <param name="value">The used value, if any.</param>
 /// <param name="prefix">The given prefix, if any.</param>
 /// <param name="insensitive">Should be evaluated insensitive.</param>
 /// <returns>The selector with the given options.</returns>
 protected virtual ISelector CreateDefault(String name, String value, String prefix, Boolean insensitive)
 {
     return(SimpleSelector.AttrAvailable(name, value));
 }
Esempio n. 5
0
        /// <summary>
        /// Gets the attribute selector for the specified sequence of tokens.
        /// </summary>
        /// <param name="tokens">The token source.</param>
        /// <returns>The created selector.</returns>
        public SimpleSelector GetAttributeSelector(IEnumerator <CssToken> tokens)
        {
            var      values = new List <string>();
            CssToken op     = null;

            while (tokens.MoveNext())
            {
                if (tokens.Current.Type == CssTokenType.SquareBracketClose)
                {
                    break;
                }
                else if (tokens.Current.Type == CssTokenType.Ident)
                {
                    values.Add(((CssKeywordToken)tokens.Current).Data);
                }
                else if (tokens.Current.Type == CssTokenType.String)
                {
                    values.Add(((CssStringToken)tokens.Current).Data);
                }
                else if (tokens.Current.Type == CssTokenType.Number)
                {
                    values.Add(((CssNumberToken)tokens.Current).Data.ToString());
                }
                else if (op == null && (tokens.Current is CssMatchToken || tokens.Current.Type == CssTokenType.Delim))
                {
                    op = tokens.Current;
                }
                else if (tokens.Current.Type != CssTokenType.Whitespace)
                {
                    if (!ignoreErrors)
                    {
                        throw new DOMException(ErrorCode.SyntaxError);
                    }
                    return(null);
                }
            }

            if ((op == null || values.Count != 2) && (op != null || values.Count != 1))
            {
                if (!ignoreErrors)
                {
                    throw new DOMException(ErrorCode.SyntaxError);
                }
                return(null);
            }

            if (op == null)
            {
                return(SimpleSelector.AttrAvailable(values[0]));
            }

            switch (op.ToValue())
            {
            case "=":
                return(SimpleSelector.AttrMatch(values[0], values[1]));

            case "~=":
                return(SimpleSelector.AttrList(values[0], values[1]));

            case "|=":
                return(SimpleSelector.AttrHyphen(values[0], values[1]));

            case "^=":
                return(SimpleSelector.AttrBegins(values[0], values[1]));

            case "$=":
                return(SimpleSelector.AttrEnds(values[0], values[1]));

            case "*=":
                return(SimpleSelector.AttrContains(values[0], values[1]));

            case "!=":
                return(SimpleSelector.AttrNotMatch(values[0], values[1]));
            }

            if (!ignoreErrors)
            {
                throw new DOMException(ErrorCode.SyntaxError);
            }
            return(null);
        }