string GetSegmentContent(StringBuilder content, OwlANSISection section) { if (!content.StartsWith(section.Name)) { return(string.Empty); } // If the content doesn't start with the section name break the process int intEndSegment = content.IndexOf(Properties.SegmentSeparator); if (intEndSegment == -1) { return(string.Empty); } // if the index is 0 the segment terminator wasn't found string segment = content.Substring(0, intEndSegment); int intElementSeparator = segment.IndexOf(Properties.ElementSeparator); if (intElementSeparator == -1) { intElementSeparator = intEndSegment; } // Some segments doesn't have elements if (segment.GetSafeSubstring(0, intElementSeparator) == section.Name) { return(string.Concat(segment, Properties.SegmentSeparator)); } return(string.Empty); }
void InitializeProperties() { Segments = new List <ANSISegmentBase>(); if (Properties == null) { Properties = new ANSISegmentProperties(); } _currentPos = 1; _lastValidSegment = null; }
List <ANSISegmentBase> Load(List <OwlANSISection> sections, StringBuilder content) { List <ANSISegmentBase> listSegments = new List <ANSISegmentBase>(); foreach (OwlANSISection section in sections) { if (content.Length == 0) { break; } string segmentContent = string.Empty; do { segmentContent = GetSegmentContent(content, section); if (!string.IsNullOrEmpty(segmentContent)) { // Create segment ANSISegmentBase iSegment = GetSegmentInstance(segmentContent, section.Name); listSegments.Add(iSegment); content.Remove(0, segmentContent.Length); // Log validators _currentPos += segmentContent.Length; _lastValidSegment = section; if (section.Sections != null && section.Sections.Count != 0) { var internalSegments = Load(section.Sections, content); if (internalSegments.Count != 0) { iSegment.Segments = new List <ANSISegmentBase>(); iSegment.Segments.AddRange(internalSegments); } } } } while (!string.IsNullOrEmpty(segmentContent)); // The while is for the segments that have repetitions } return(listSegments); }