internal static void WriteUnified(StreamWriter stream, string[] a, string[] b, DiffItem[] items) { List<Hunk> hunkSet = new List<Hunk>(); for (int x = 0; x < items.Length; x++) { DiffItem item = items[x]; int prevDist = CONTEXT; if (x > 0) prevDist = Math.Min(CONTEXT, item.StartA - (items[x - 1].StartA + items[x - 1].deletedA)); int nextDist = CONTEXT; if (x < items.Length - 1) nextDist = Math.Min(CONTEXT, items[x + 1].StartA - item.StartA - 1); Hunk hunk = new Hunk(item, prevDist, nextDist, a.Length, b.Length); hunkSet.Add(hunk); if (nextDist == CONTEXT) { WriteHunkSet(stream, a, b, hunkSet); hunkSet.Clear(); } } WriteHunkSet(stream, a, b, hunkSet); }
internal static void WriteNewFile(StreamWriter stream, string[] b) { DiffItem item = new DiffItem(); item.StartA = 0; item.StartB = 0; item.deletedA = 0; item.insertedB = b.Length; stream.WriteLine(String.Format("@@ -0,0 +1,{0} @@", b.Length)); Hunk hunk = new Hunk(item, 0, 0, 0, b.Length); stream.Write(hunk.ToString(new string[0], b)); }