/// <summary> /// Find tagged segment within GenInfo.SearchStart and GenInfo.SearchEnd /// </summary> /// <returns></returns> /// <remarks> /// Not using EditPoint.FindPattern because it can only search from startpoint to end of doc, no way to limit to selection /// Not using DTE Find because it has to change params of current find dialog, might screw up normal find usage /// </remarks> public FoundSegment[] FindSegments(Writer info) { var regex = GetRegexByType(info.SegmentType); //Using regex in FindPattern does var text = info.GetSearchText(); var matches = regex.Matches(text); var segments = new List <FoundSegment>(); foreach (var m in matches.Cast <Match>()) { EditPoint matchStart = null; EditPoint matchEnd = null; if (m.Success) { //Convert match into start and end TextPoints matchStart = info.SearchStart.CreateEditPoint(); matchStart.CharRightExact(m.Index); matchEnd = matchStart.CreateEditPoint(); matchEnd.CharRightExact(m.Length); } var segment = new FoundSegment(this, info.GenAttribute, matchStart, matchEnd); if (segment.IsValid) { segments.Add(segment); } } return(segments.ToArray()); }
public TextPoint GetContentEndPoint() { EditPoint endP = InsertStart.CreateEditPoint(); endP.CharRightExact(Content.Length); return(endP); }
/// <summary> /// Find tagged segment within GenInfo.SearchStart and GenInfo.SearchEnd /// </summary> /// <returns></returns> /// <remarks> /// Not using EditPoint.FindPattern because it can only search from startpoint to end of doc, no way to limit to selection /// Not using DTE Find because it has to change params of current find dialog, might screw up normal find usage /// </remarks> static public GeneratedSegment[] FindSegments(Writer writer) { var regex = _regexDict[writer.TagFormat][writer.SegmentType]; //Using regex in FindPattern does var text = writer.GetSearchText(); var matches = regex.Matches(text); var segments = new List <GeneratedSegment>(); foreach (var m in matches.Cast <Match>()) { EditPoint matchStart = null; EditPoint matchEnd = null; if (m.Success) { //Convert match into start and end TextPoints matchStart = writer.SearchStart.CreateEditPoint(); matchStart.CharRightExact(m.Index); matchEnd = matchStart.CreateEditPoint(); matchEnd.CharRightExact(m.Length); } var range = new TextRange(matchStart, matchEnd); if (range.IsValid) { var tag = ParseTextRange(range, writer.Manager.TagFormat); segments.Add(tag); } } return(segments.ToArray()); }