private static void processCommon(ref commonOrDifferentThing common, List <commonOrDifferentThing> result) { if (common.common.Count > 0) { common.common.Reverse(); result.Add(common); common = new commonOrDifferentThing(); } }
public static List <commonOrDifferentThing> diff_comm(string[] file1, string[] file2) { // We apply the LCS to build a "comm"-style picture of the // differences between file1 and file2. var result = new List <commonOrDifferentThing>(); int tail1 = file1.Length; int tail2 = file2.Length; commonOrDifferentThing common = new commonOrDifferentThing { common = new List <string>() }; for (var candidate = TextDiff.longest_common_subsequence(file1, file2); candidate != null; candidate = candidate.chain) { commonOrDifferentThing different = new commonOrDifferentThing { file1 = new List <string>(), file2 = new List <string>() }; while (--tail1 > candidate.file1index) { different.file1.Add(file1[tail1]); } while (--tail2 > candidate.file2index) { different.file2.Add(file2[tail2]); } if (different.file1.Count > 0 || different.file2.Count > 0) { processCommon(ref common, result); different.file1.Reverse(); different.file2.Reverse(); result.Add(different); } if (tail1 >= 0) { common.common.Add(file1[tail1]); } } processCommon(ref common, result); result.Reverse(); return(result); }