public static List<DiffChunk> Parse(string unidiffResult) { List<DiffChunk> chunks = new List<DiffChunk>(); unidiffResult = unidiffResult.Replace("\r", ""); string[] lines = unidiffResult.Split(new char[] {'\n'}); DiffChunk currentChunk = null; int i = 0; while (i < lines.Length) { Match chunkBeginMatches = beginChunkPatern.Match(lines[i]); if (chunkBeginMatches.Success) { if (currentChunk != null) chunks.Add(currentChunk); currentChunk = new DiffChunk(); currentChunk.FirstBegin = Int32.Parse(chunkBeginMatches.Groups["g1"].Value); currentChunk.FirstEnd = Int32.Parse(chunkBeginMatches.Groups["g2"].Value); currentChunk.SecondBegin = Int32.Parse(chunkBeginMatches.Groups["g3"].Value); currentChunk.SecondEnd = Int32.Parse(chunkBeginMatches.Groups["g4"].Value); } else if (currentChunk != null) { currentChunk.AddLine(lines[i]); } i++; } if (currentChunk != null) chunks.Add(currentChunk); return chunks; }
public static List <DiffChunk> Parse(string unidiffResult) { List <DiffChunk> chunks = new List <DiffChunk>(); unidiffResult = unidiffResult.Replace("\r", ""); string[] lines = unidiffResult.Split(new char[] { '\n' }); DiffChunk currentChunk = null; int i = 0; while (i < lines.Length) { Match chunkBeginMatches = beginChunkPatern.Match(lines[i]); if (chunkBeginMatches.Success) { if (currentChunk != null) { chunks.Add(currentChunk); } currentChunk = new DiffChunk(); currentChunk.FirstBegin = Int32.Parse(chunkBeginMatches.Groups["g1"].Value); currentChunk.FirstEnd = Int32.Parse(chunkBeginMatches.Groups["g2"].Value); currentChunk.SecondBegin = Int32.Parse(chunkBeginMatches.Groups["g3"].Value); currentChunk.SecondEnd = Int32.Parse(chunkBeginMatches.Groups["g4"].Value); } else if (currentChunk != null) { currentChunk.AddLine(lines[i]); } i++; } if (currentChunk != null) { chunks.Add(currentChunk); } return(chunks); }