Beispiel #1
0
        public simpleSelector Parse()
        {
            // first check whether this is a combinartor or not.
            if (IsCombinatorSelector(_selectorText))
            {
                parseCombinartor();
                return(simple);
            }

            //TODO: to be checked.
            if (_selectorText.Contains("::"))
            {
                parsePseudoElement();

                return(simple);
            }
            if (_selectorText.Contains(":"))
            {
                parsePseudoClass();
                return(simple);
            }

            while (true)
            {
                char currentChar = ReadNext();
                if (stop)
                {
                    break;
                }

                /// An ID selector contains a "number sign" (U+0023, #) immediately followed by the ID value
                if (currentChar == '\u0023')
                {
                    parseIdSelector();
                    return(simple);
                }

                /// The universal selector, written as a CSS qualified name [CSS3NAMESPACE] with an asterisk (* U+002A) as the local name
                else if (currentChar == '\u002A')
                {
                    if (_selectorText.Trim() != '\u002A'.ToString())
                    {
                        _buffer.Append(currentChar);
                        continue;
                    }
                    else
                    {
                        return(new universalSelector());
                    }
                }
                ///Working with HTML, authors may use the "period" notation (also known as "full stop", U+002E, .) as an alternative to the ~= notation when representing the class attribute.
                else if (currentChar == '\u002E')
                {
                    parseClassSelector();
                    return(simple);
                }
                else if (currentChar == '[')
                {
                    parseAttributeSelecotr();
                    return(simple);
                }
                else if (currentChar == ':')
                {
                    if (LookupNext() == ':')
                    {
                        parsePseudoElement();
                    }
                    else
                    {
                        parsePseudoClass();
                    }
                    return(simple);
                }

                else
                {
                    _buffer.Append(currentChar);
                }
            }


            if (simple == null || simple.Type == enumSimpleSelectorType.unknown)
            {
                // nothing mathc, this is a type selector.
                typeSelector typeselector = new typeSelector();
                typeselector.elementE  = AppendCleanBuffer(_buffer);
                typeselector.wholeText = typeselector.elementE;

                simple = typeselector;
            }
            return(simple);
        }
Beispiel #2
0
 private static bool matchType(Element element, typeSelector typeselector)
 {
     return(element.tagName == typeselector.elementE.ToLower());
 }