public void LoadText(string cssText) { Debug.Assert(cssText != null); this.Sections.Clear(); ///去掉输入字符串的首尾空格 cssText = cssText.Trim(); ///用正则解析字符串 MatchCollection mc = _regexParseCssPage.Matches(cssText); int index = -1; foreach (Match m in mc) { ///两次Match中间的部分用CssOtherSection保存起来 int lastNextIndex = index + 1; if (m.Index > lastNextIndex) { CssOtherSection otherSection = new CssOtherSection(cssText.Substring(lastNextIndex, m.Index - lastNextIndex)); this.Sections.Add(otherSection); } index = m.Index + m.Length; ///保存匹配到的CssSection CssSection section = CssSection.Parse(m.Value); this.Sections.Add(section); } }
public void SetStyle(string width, string height) { string styleStr = this.GetAttribute("style"); CssSection section = CssSection.Parse(styleStr); section.Properties["width"] = width; section.Properties["height"] = height; this.SetAttribute("style", section.ToString()); }