static private Parse ( string &css, object parent, bool readOnly, string replacedStrings, CssStyleSheetType origin ) : CssRule | ||
css | string | |
parent | object | |
readOnly | bool | |
replacedStrings | string | |
origin | CssStyleSheetType | |
return | CssRule |
private CssRule TryParse(ref string css, object parent, bool readOnly, IList <string> replacedStrings, CssStyleSheetType origin) { CssRule rule; // creates and parses a CssMediaRule or return null rule = CssMediaRule.Parse(ref css, parent, readOnly, replacedStrings, origin); if (rule != null) { return(rule); } // create ImportRule rule = CssImportRule.Parse(ref css, parent, readOnly, replacedStrings, origin); if (rule != null) { return(rule); } // create CharSetRule rule = CssCharsetRule.Parse(ref css, parent, readOnly, replacedStrings, origin); if (rule != null) { return(rule); } rule = CssFontFaceRule.Parse(ref css, parent, readOnly, replacedStrings, origin); if (rule != null) { _hasFontRule = true; return(rule); } rule = CssPageRule.Parse(ref css, parent, readOnly, replacedStrings, origin); if (rule != null) { return(rule); } rule = CssUnknownRule.Parse(ref css, parent, readOnly, replacedStrings, origin); if (rule != null) { return(rule); } return(rule); }
/* can take two kind of structures: * rule{} * rule{} * or: * { * rule{} * rule{} * } * */ private void Parse(ref string css, object parent, bool readOnly, IList <string> replacedStrings, CssStyleSheetType origin) { bool withBrackets = false; css = css.Trim(); if (css.StartsWith("{", StringComparison.OrdinalIgnoreCase)) { withBrackets = true; css = css.Substring(1); } while (true) { css = css.Trim(); if (css.Length == 0) { if (withBrackets) { throw new DomException(DomExceptionType.SyntaxErr, "Style block missing ending bracket"); } break; } else if (css.StartsWith("}", StringComparison.OrdinalIgnoreCase)) { // end of block; css = css.Substring(1); break; } else if (css.StartsWith("@", StringComparison.OrdinalIgnoreCase)) { // Parse at-rules // @-rule CssRule rule; // creates and parses a CssMediaRule or return null rule = CssMediaRule.Parse(ref css, parent, readOnly, replacedStrings, origin); if (rule == null) { // create ImportRule rule = CssImportRule.Parse(ref css, parent, readOnly, replacedStrings, origin); if (rule == null) { // create CharSetRule rule = CssCharsetRule.Parse(ref css, parent, readOnly, replacedStrings, origin); if (rule == null) { rule = CssFontFaceRule.Parse(ref css, parent, readOnly, replacedStrings, origin); if (rule == null) { rule = CssPageRule.Parse(ref css, parent, readOnly, replacedStrings, origin); if (rule == null) { rule = CssUnknownRule.Parse(ref css, parent, readOnly, replacedStrings, origin); } } } } } InsertRule(rule); } else { // must be a selector or error CssRule rule = CssStyleRule.Parse(ref css, parent, readOnly, replacedStrings, origin); if (rule != null) { InsertRule(rule); } else { // this is an unknown rule format, possibly a new kind of selector. Try to find the end of it to skip it int startBracket = css.IndexOf("{", StringComparison.OrdinalIgnoreCase); int endBracket = css.IndexOf("}", StringComparison.OrdinalIgnoreCase); int endSemiColon = css.IndexOf(";", StringComparison.OrdinalIgnoreCase); int endRule; if (endSemiColon > 0 && endSemiColon < startBracket) { endRule = endSemiColon; } else { endRule = endBracket; } if (endRule > -1) { css = css.Substring(endRule + 1); } else { throw new DomException(DomExceptionType.SyntaxErr, "Can not parse the CSS file"); } } } } }