static Dictionary <string, object> match_tag(Token token) { Match match = MatchTagPrefixAndName.Match(token.ToString()); Dictionary <string, object> node = Groupdict(MatchTagPrefixAndName, match, token); int end = match.Index + match.Length; token = token.Substring(end); var attrs = new List <Dictionary <string, object> >(); node["attrs"] = attrs; foreach (Match m in MatchSingleAttribute.Matches(token.ToString())) { Dictionary <string, object> attr = Groupdict(MatchSingleAttribute, m, token); if (attr.Keys.Contains("alt_value")) { var altValue = attr["alt_value"] as Token; attr.Remove("alt_value"); if (!string.IsNullOrEmpty(altValue.ToString())) { attr["value"] = altValue; attr["quote"] = ""; } } if (attr.Keys.Contains("simple_value")) { var simpleValue = attr["simple_value"] as Token; attr.Remove("simple_value"); if (!string.IsNullOrEmpty(simpleValue.ToString())) { attr["quote"] = ""; attr["value"] = new Token(""); attr["eq"] = ""; } } attrs.Add(attr); int m_end = m.Index + m.Length; node["suffix"] = token.Substring(m_end); } return(node); }
static Dictionary <string, object> Groupdict(Regex r, Match m, Token token) { var d = new Dictionary <string, object>(); foreach (string name in r.GetGroupNames()) { Group g = m.Groups[name]; if (g != null) { int i = g.Index; int j = g.Length; d.Add(name, token.Substring(i, j)); } else { d.Add(name, null); } } return(d); }
static Dictionary<string, object> match_tag(Token token) { Match match = MatchTagPrefixAndName.Match(token.ToString()); Dictionary<string, object> node = Groupdict(MatchTagPrefixAndName, match, token); int end = match.Index + match.Length; token = token.Substring(end); var attrs = new List<Dictionary<string, object>>(); node["attrs"] = attrs; foreach (Match m in MatchSingleAttribute.Matches(token.ToString())) { Dictionary<string, object> attr = Groupdict(MatchSingleAttribute, m, token); if (attr.Keys.Contains("alt_value")) { var altValue = attr["alt_value"] as Token; attr.Remove("alt_value"); if (!string.IsNullOrEmpty(altValue.ToString())) { attr["value"] = altValue; attr["quote"] = ""; } } if (attr.Keys.Contains("simple_value")) { var simpleValue = attr["simple_value"] as Token; attr.Remove("simple_value"); if (!string.IsNullOrEmpty(simpleValue.ToString())) { attr["quote"] = ""; attr["value"] = new Token(""); attr["eq"] = ""; } } attrs.Add(attr); int m_end = m.Index + m.Length; node["suffix"] = token.Substring(m_end); } return node; }
static Dictionary<string, object> Groupdict(Regex r, Match m, Token token) { var d = new Dictionary<string, object>(); foreach (string name in r.GetGroupNames()) { Group g = m.Groups[name]; if (g != null) { int i = g.Index; int j = g.Length; d.Add(name, token.Substring(i, j)); } else { d.Add(name, null); } } return d; }