public TestTextSection(TestText testText, string label, TestTextPosition start, TestTextPosition end = null) { _testText = testText; Label = label; Start = start; End = end; }
public string GetText(TestTextPosition start, TestTextPosition end) { if (start.Line == end.Line) { return(_lines[start.Line].Substring(start.Column, end.Column - start.Column)); } var result = new StringBuilder(); result.AppendLine(_lines[start.Line].Substring(start.Column)); for (int i = start.Line + 1; i <= end.Line - 1; i++) { result.AppendLine(_lines[i]); } result.Append(_lines[end.Line].Substring(0, end.Column)); return(result.ToString()); }
private string[] ProcessValue(string value) { var result = value.Split(new[] { Environment.NewLine }, StringSplitOptions.None); for (int lineIndex = 0; lineIndex < result.Length; lineIndex++) { var markerMatches = Regex.Matches(result[lineIndex], @"{\/?(?<label>\w+)}").Cast <Match>(); int removedChars = 0; foreach (var markerMatch in markerMatches) { bool isClose = markerMatch.Value.StartsWith("{/"); var label = markerMatch.Groups["label"].Value; TestTextPosition position = new TestTextPosition(lineIndex, markerMatch.Index - removedChars); if (isClose) { var section = Sections.LastOrDefault(s => s.Label == label); if (section == null) { section = new TestTextSection(this, label, position); Sections.Add(section); } section.End = position; //section.Text = GetText(section.Start, section.End); } else { var section = new TestTextSection(this, label, position); Sections.Add(section); } result[lineIndex] = result[lineIndex].Remove(position.Column, markerMatch.Length); removedChars += markerMatch.Length; } } return(result); }