public XdfSection ReadSection(String xdf) { if (ValidateSection(xdf)) { String[] rows = xdf.Split(new String[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries); XdfSection rootSection = new XdfSection(GetSectionName(rows[0])); System.Diagnostics.Debug.WriteLine(rootSection.Name); do { Match beginMatch = Regex.Match(xdf, SectionBeginRegularExpression); beginMatch = beginMatch.NextMatch(); if (beginMatch.Success) { Match endMatch = Regex.Match(xdf, String.Format("{0}:End", GetSectionName(beginMatch.Value))); if (endMatch.Success) { String sectionXdf = xdf.Substring(beginMatch.Index, (endMatch.Index + endMatch.Length) - beginMatch.Index); xdf = xdf.Remove(beginMatch.Index, (endMatch.Index + endMatch.Length) - beginMatch.Index); XdfSection section = ReadSection(sectionXdf); System.Diagnostics.Debug.WriteLine(section.Name); rootSection.Sections.Add(section); } else { throw new BitFlex.IO.XdfException(String.Format("There is a missing section ending at index {0}.", endMatch.Index)); } } else { break; } } while (true); MatchCollection keyMatches = Regex.Matches(xdf, KeyRegularExpression); foreach (Match item in keyMatches) { XdfKey key = ReadKey(item.Value); rootSection.Keys.Add(key); } return rootSection; } else { throw new BitFlex.IO.XdfException("The specified xdf did not contain a valid section."); } }
public XdfKey ReadKey(String xdf) { Match keyMatch = Regex.Match(xdf, KeyRegularExpression); if (keyMatch.Success) { String name = keyMatch.Value.Substring(0, keyMatch.Value.IndexOf('=')); name = name.TrimEnd(' '); XdfKey retVal = new XdfKey(name); String value = keyMatch.Value.Remove(0, keyMatch.Value.IndexOf('=') + 1); value = value.TrimStart(' '); retVal.Value = value; return retVal; } else { throw new BitFlex.IO.XdfException("The specified xdf did not contain a valid key."); } }