public TagAttributeParser(Dictionary <string, string> tagattrdict) { if (tagattrdict == null || tagattrdict.Count == 0) { throw new InvalidOperationException("Parameter 'tagattrdict' cannot be empty."); } foreach (var keypair in tagattrdict) { var tagattr = new TagAttr(keypair.Key, keypair.Value + Postfix); TagAttrs.Add(tagattr); } }
private string[] Parse(string html, TagAttr tagattr) { var attrLen = tagattr.LcAttr.Length; var tagLen = tagattr.LcTag.Length; var list = new List <string>(); var index = -1; var startIndex = -1; var tagActivated = false; for (var i = 0; i < html.Length; i++) { if (i < html.Length - tagLen - 2 && html[i] == '<') { for (var j = 0; j < tagLen && index == -1; j++) { if (html[i + j + 1] == tagattr.LcTag[j] || html[i + j + 1] == tagattr.UcTag[j]) { if (j == tagLen - 1) { tagActivated = true; i += tagLen; } } else { break; } } } for (var j = 0; j < attrLen && index == -1 && tagActivated; j++) { if (html[i + j] == tagattr.LcAttr[j] || html[i + j] == tagattr.UcAttr[j]) { if (j == attrLen - 1) { index = i; startIndex = index + attrLen; i = startIndex; } } else { break; } } if (html[i] == '"' && index != -1 && tagActivated) { var end = i - startIndex; var attrValue = html.Substring(startIndex, end); list.Add(attrValue); index = -1; tagActivated = false; } } return(list.Distinct().ToArray()); }