Example #1
0
 public void AddDeclaration(LinkedList<CSSSelector> selectors, CSSRuleSet rules)
 {
     AddDeclaration(new CSSDeclaration(selectors, rules));
 }
Example #2
0
 public CSSDeclaration(LinkedList<CSSSelector> selectors, CSSRuleSet ruleset)
 {
     p_Selectors = selectors;
     p_Ruleset = ruleset;
 }
Example #3
0
 public CSSDeclaration(CSSRuleSet ruleset)
 {
     p_Selectors = new LinkedList<CSSSelector>();
     p_Ruleset = ruleset;
 }
Example #4
0
 public CSSDeclaration(LinkedList<CSSSelector> selectors)
 {
     p_Selectors = selectors;
     p_Ruleset = new CSSRuleSet();
 }
Example #5
0
 public CSSDeclaration()
 {
     p_Ruleset = new CSSRuleSet();
     p_Selectors = new LinkedList<CSSSelector>();
 }
Example #6
0
        public static CSSRuleSet Parse(ref byte* data, byte* dataEnd, Encoding encoder)
        {
            //define the rule set we add everything to
            CSSRuleSet buffer = new CSSRuleSet();

            //read the data
            while (data < dataEnd) {
                #region skip comments
                //block comment? (/**/)
                if (*data == '/' && data < dataEnd - 2 && *(data + 1) == '*') {
                    //skip to the end of the block comment
                    while (data < dataEnd - 2) {
                        if (*data == '*' && *(data + 1) == '/') { data += 2; break; }
                        data++;
                    }
                }
                #endregion

                //we hit the end of a scope?
                if (*data == '}') { break; }

                //have we hit an alphadecimal character?
                if (isNameValueCharacter(*data)) {
                    #region read the name
                    byte* nameStart = data;
                    byte* nameEnd = dataEnd - 1;
                    while (data < dataEnd) {
                        if (!isNameValueCharacter(*data) || *data == ':') {
                            nameEnd = data - 1;
                            break;
                        }
                        data++;
                    }
                    #endregion

                    //find the ":" character which seperates the name and value
                    while (data < dataEnd && *data++ != ':') ;

                    //skip to the beginning of the value
                    while (data < dataEnd && !isNameValueCharacter(*data)) { data++; }

                    #region read the value
                    byte* valueStart = data;
                    byte* valueEnd = dataEnd - 1;
                    bool important = false;
                    while (data < dataEnd) {
                        if (*data == ';' || *data == '}') { valueEnd = data - 1; break; }

                        #region !important?
                        if (*data == '!' && data < dataEnd - IMPORTANT_STRING_LENGTH) {
                            //read and compare the upcoming data with the "important" string
                            byte* dataCopy = data + 1;
                            byte* dataCopyEnd = data + IMPORTANT_STRING_LENGTH;
                            byte* impCopy = IMPORTANT_STRING;
                            bool match = true;
                            while (dataCopy < dataCopyEnd) {
                                if (toLower(*dataCopy++) != *impCopy++) {
                                    match = false;
                                    break;
                                }
                            }

                            //match? if so, we do not have the !important inside the value
                            //so we finish reading the value here.
                            if (match) {
                                important = true;
                                valueEnd = data - 1;
                                break;
                            }
                        }
                        #endregion

                        //string open?
                        if (*data == '"' || *data == '\'') {
                            //skip over it
                            byte closeStr = *data++;
                            while (data < dataEnd) {
                                if (*data == '\\') { data += 2; continue; }
                                if (*data == closeStr) { break; }
                                data++;
                            }
                        }

                        data++;
                    }

                    //trim the value (remove the whitespaces at the end of the value)
                    while (!isNameValueCharacter(*valueEnd)) { valueEnd--; }
                    #endregion

                    //skip to the rule seperate (;)
                    while (data < dataEnd && *data != ';' && *data != '}') { data++; }

                    //create the rule
                    buffer.AddRule(
                        Helpers.ReadString(nameStart, nameEnd, encoder),
                        Helpers.ReadString(valueStart, valueEnd, encoder),
                        important);

                    //hit the end of this ruleset?
                    if (*data == '}') { break; }
                }

                //skip to the next character
                data++;
            }

            //clean up
            return buffer;
        }