/// <summary> /// Checks the string and restores any encoded HTML Entities such as & and " to their /// standard character & and " returning the result. Resets the Buffer /// </summary> /// <param name="value"></param> /// <returns></returns> private string HTMLUnEntities(string value) { Buffer.Clear(); if (value.IndexOf(HTMLEntityStartMarker) > -1) { StringEnumerator enumerate = new StringEnumerator(value); while (enumerate.MoveNext()) { if (enumerate.Current == HTMLEntityStartMarker) { if (!enumerate.MoveNext()) { Buffer.Append(enumerate.Current); return(Buffer.ToString()); } else { char unencoded = ReadHtmlEscapedChar(enumerate); Buffer.Append(unencoded); enumerate.MovePrev(); } } else { Buffer.Append(enumerate.Current); } } value = Buffer.ToString(); } return(value); }
/// <summary> /// Based on the provided string of a style attribute. Splits each of the items up into /// </summary> /// <param name="styleitems"></param> /// <returns></returns> private Dictionary <string, string> GetSplitStyleItems(string styleitems) { if (styleitems.StartsWith("'") || styleitems.StartsWith("\"")) { styleitems = styleitems.Substring(1); } if (styleitems.EndsWith("'") || styleitems.EndsWith("\"")) { styleitems = styleitems.Substring(0, styleitems.Length - 1); } if (styleitems.Length > 0) { Buffer.Clear(); Dictionary <string, string> split = new Dictionary <string, string>(); StringEnumerator enumerate = new StringEnumerator(styleitems); bool inkey = true; string keyname = string.Empty; char stylevaluegroupchar = '\0'; while (enumerate.MoveNext()) { char cur = enumerate.Current; if (cur == HTMLStyleItemTerminator) { if (inkey == false) { if (stylevaluegroupchar != '\0') { //Still in a value grouping so ignore the terminator and just add Buffer.Append(cur); } //full value has been read - if we have a key, then set the value else if (!string.IsNullOrEmpty(keyname)) { split[keyname] = Buffer.ToString().Trim(); Buffer.Clear(); inkey = true; stylevaluegroupchar = '\0'; } else { //No key so ignore and move on Buffer.Clear(); inkey = true; stylevaluegroupchar = '\0'; } } } else if (cur == stylevaluegroupchar) { Buffer.Append(cur); stylevaluegroupchar = '\0'; } else if (cur == HTMLStyleValuePairSeparator) { if (inkey) { keyname = Buffer.ToString().Trim(); Buffer.Clear(); inkey = false; } else if (stylevaluegroupchar != '\0') { Buffer.Append(cur); } } else if (cur == '(' && Buffer.ToString() == "url") { stylevaluegroupchar = ')'; Buffer.Append(cur); } else if (cur == HTMLEntityStartMarker) { enumerate.MoveNext(); cur = ReadHtmlEscapedChar(enumerate); Buffer.Append(cur); enumerate.MovePrev(); } else { Buffer.Append(cur); } } if (inkey == false && Buffer.Length > 0 && keyname.Length > 0) { split[keyname] = Buffer.ToString().Trim(); } if (split.Count > 0) { return(split); } else { return(null); } } return(null); }