public static PatchDocument Parse(Patch patch) { if (patch == null) { return(new PatchDocument(Array.Empty <PatchEntry>(), Array.Empty <PatchLine>())); } var lines = new List <PatchLine>(); var entries = new List <PatchEntry>(); foreach (var change in patch) { var changeLines = ParseLines(change.Patch); var entryOffset = lines.Count; var entryLength = changeLines.Count; lines.AddRange(changeLines); var hunks = new List <PatchHunk>(); var hunkOffset = GetNextHunk(changeLines, -1); while (hunkOffset < changeLines.Count) { var hunkEnd = GetNextHunk(changeLines, hunkOffset) - 1; var hunkLength = hunkEnd - hunkOffset + 1; var hunkLine = changeLines[hunkOffset].Text; int oldStart; int oldLength; int newStart; int newLength; if (TryGetHunkInformation(hunkLine, out oldStart, out oldLength, out newStart, out newLength)) { var hunk = new PatchHunk(entryOffset + hunkOffset, hunkLength, oldStart, oldLength, newStart, newLength); hunks.Add(hunk); } hunkOffset = hunkEnd + 1; } var entry = new PatchEntry(entryOffset, entryLength, patch, change, hunks); entries.Add(entry); } return(new PatchDocument(entries, lines)); }
public static PatchDocument Parse(Patch patch) { if (patch == null) return new PatchDocument(Array.Empty<PatchEntry>(), Array.Empty<PatchLine>()); var lines = new List<PatchLine>(); var entries = new List<PatchEntry>(); foreach (var change in patch) { var changeLines = ParseLines(change.Patch); var entryOffset = lines.Count; var entryLength = changeLines.Count; lines.AddRange(changeLines); var hunks = new List<PatchHunk>(); var hunkOffset = GetNextHunk(changeLines, -1); while (hunkOffset < changeLines.Count) { var hunkEnd = GetNextHunk(changeLines, hunkOffset) - 1; var hunkLength = hunkEnd - hunkOffset + 1; var hunkLine = changeLines[hunkOffset].Text; int oldStart; int oldLength; int newStart; int newLength; if (TryGetHunkInformation(hunkLine, out oldStart, out oldLength, out newStart, out newLength)) { var hunk = new PatchHunk(entryOffset + hunkOffset, hunkLength, oldStart, oldLength, newStart, newLength); hunks.Add(hunk); } hunkOffset = hunkEnd + 1; } var entry = new PatchEntry(entryOffset, entryLength, patch, change, hunks); entries.Add(entry); } return new PatchDocument(entries, lines); }