/// <summary> /// Creates and XDocument in which child elements map to token-pair matches. /// </summary> /// <param name="inputString">The string upon which the XDocument frame will be derived.</param> /// <returns></returns> /// <remarks> /// Given a string arguement (or a path to a text file) the function will /// produce an XDocument where the nesting of child nodes represents /// the internal context of a matching pair of tokens. Therefore the output /// will contian nodes and those nodes may contain furthere child nodes and /// so on down to an internal size that is at least the defined minimum token /// span. /// /// The string input will have all its concurrent occurances of spaces and /// tabs reduced to a single space. /// /// The result is simply a frame and does not contain any of the original string. /// </remarks> public XElement GetXDocFrame(string inputString) { if (string.IsNullOrWhiteSpace(inputString)) { throw new ItsDeadJim("The input string arg is empty."); } inputString = NfString.DistillCrLf(inputString); inputString = NfString.DistillTabs(inputString); var tokens = GetTokens(inputString); var gaps = GetGaps(tokens); var xDoc = FrameTokensXDoc(tokens); xDoc = FrameGapsXDoc(xDoc, gaps); return(xDoc); }
/// <summary> /// Applies the results of Get-XDocFrame to the original content. /// </summary> /// <param name="xDoc"></param> /// <param name="inputString"></param> /// <remarks> /// Returns the XDocument with the inter-string spans applied as text data /// of each of the XDocument frame nodes. /// /// The input is again distilled of all concurrent occurances of tab and space /// characters. /// </remarks> public void ApplyXDocFrame(XElement xDoc, string inputString) { if (string.IsNullOrWhiteSpace(inputString)) { throw new ItsDeadJim("The input string arg is empty."); } if (xDoc == null) { throw new ItsDeadJim("a XElement must be supplied, call GetXDocFrame prior to calling this member"); } //crit - the indices must match the original so process like frame f(x) did inputString = NfString.DistillCrLf(inputString); inputString = NfString.DistillTabs(inputString); XDocIter(xDoc, inputString); }