예제 #1
0
        private static StringBuilder appendSelector(SelectorRule objRule, bool isMinus, bool needSigns = true)
        {
            StringBuilder sb     = new StringBuilder();
            string        header = isMinus ?
                                   "---------------exists in first file, but not exists in second---------------" :
                                   "+++++++++++++++++   not exists in first file, but exists in second++++++++++++";
            string footer = isMinus ? "--------------------------" : "+++++++++++++++++++++++";

            if (needSigns)
            {
                sb.Append("\r\n/*" + header + "*/");
            }
            sb.Append("\r\n");
            if (objRule.Media != null)
            {
                sb.Append("@media " + objRule.Media + "{\r\n");
            }
            sb.Append(string.Join(",\r\n", objRule.Selector))
            .Append(" {\r\n\t")
            .Append(string.Join("\r\n\t", objRule.Rules))
            .Append("\r\n\t}\r\n");
            if (objRule.Media != null)
            {
                sb.Append("}");
            }
            if (needSigns)
            {
                sb.Append("\r\n/*" + footer + "*/" + "\r\n");
            }
            sb.Append("\r\n");
            return(sb);
        }
예제 #2
0
        private void addRules(string rulesStr, string media)
        {
            var allRules = Regex.Split(rulesStr, @"}\r?\n{0,}\t?").Where(
                s => !String.IsNullOrEmpty(s.Trim())).ToList <string>();
            var length = allRules.Count;

            for (int i = 0; i < length; i++)
            {
                var tempRule = new SelectorRule();
                var pair     = Regex.Split(allRules[i], "{\r?\n?\t?");
                tempRule.addSelectors(pair[0].Split(','), media);
                int foundIndex = CSSrules.FindIndex(x => x.selectorHASH == tempRule.selectorHASH);
                if (foundIndex < 0)
                {
                    tempRule.addRules(Regex.Split(pair[1].Trim(), "(?<=\");|;\r?\n\t?|\r?\n\t?"));
                    cssrules.Add(tempRule);
                    continue;
                }
                cssrules[foundIndex].addRules(Regex.Split(pair[1].Trim(), "(?<=\");|;\r?\n\t?|\r?\n\t?"));
            }
        }