public DiffText ( string TextA, string TextB ) : System.Item[] | ||
TextA | string | A-version of the text (usualy the old one) |
TextB | string | B-version of the text (usualy the new one) |
Résultat | System.Item[] |
public void Parse2(string baseSources, string diffSource) { Diff.Item[] diff = Diff.DiffText(baseSources, diffSource, true, true, false); baseSources = baseSources.Replace("\r", ""); diffSource = diffSource.Replace("\r", ""); string[] aLines = baseSources.Split('\n'); string[] bLines = diffSource.Split('\n'); int n = 0; int leftLineNumber = 0; int rightLineNumber = 0; for (int diffItem = 0; diffItem < diff.Length; diffItem++) { Diff.Item aItem = diff[diffItem]; // write unchanged lines while ((n < aItem.StartB) && (n < bLines.Length)) { leftPan.Add(new DiffLineData(bLines[n], DiffActionType.None, leftLineNumber)); rightPan.Add(new DiffLineData(bLines[n], DiffActionType.None, rightLineNumber)); n++; leftLineNumber++; rightLineNumber++; } // while for (int m = 0; m < aItem.deletedA; m++) { leftPan.Add(new DiffLineData(aLines[aItem.StartA + m], DiffActionType.Deleted, leftLineNumber)); rightPan.Add(new DiffLineData("", DiffActionType.None, -1)); leftLineNumber++; } // for // write inserted lines while (n < aItem.StartB + aItem.insertedB) { rightPan.Add(new DiffLineData(bLines[n], DiffActionType.Added, rightLineNumber)); leftPan.Add(new DiffLineData("", DiffActionType.None, -1)); n++; rightLineNumber++; } // while } // while // write rest of unchanged lines while (n < bLines.Length) { leftPan.Add(new DiffLineData(bLines[n], DiffActionType.None, leftLineNumber)); rightPan.Add(new DiffLineData(bLines[n], DiffActionType.None, rightLineNumber)); leftLineNumber++; rightLineNumber++; n++; } // while PostProcessPans(); }
/// <summary> /// start a self- / box-test for some diff cases and report to the debug output. /// </summary> /// <param name="args">not used</param> /// <returns>always 0</returns> public static int Main(string[] args) { StringBuilder ret = new StringBuilder(); string a, b; System.Diagnostics.ConsoleTraceListener ctl = new System.Diagnostics.ConsoleTraceListener(false); System.Diagnostics.Debug.Listeners.Add(ctl); System.Console.WriteLine("Diff Self Test..."); // test all changes a = "a,b,c,d,e,f,g,h,i,j,k,l".Replace(',', '\n'); b = "0,1,2,3,4,5,6,7,8,9".Replace(',', '\n'); System.Diagnostics.Debug.Assert(TestHelper(Diff.DiffText(a, b, false, false, false)) == "12.10.0.0*", "all-changes test failed."); System.Diagnostics.Debug.WriteLine("all-changes test passed."); // test all same a = "a,b,c,d,e,f,g,h,i,j,k,l".Replace(',', '\n'); b = a; System.Diagnostics.Debug.Assert(TestHelper(Diff.DiffText(a, b, false, false, false)) == "", "all-same test failed."); System.Diagnostics.Debug.WriteLine("all-same test passed."); // test snake a = "a,b,c,d,e,f".Replace(',', '\n'); b = "b,c,d,e,f,x".Replace(',', '\n'); System.Diagnostics.Debug.Assert(TestHelper(Diff.DiffText(a, b, false, false, false)) == "1.0.0.0*0.1.6.5*", "snake test failed."); System.Diagnostics.Debug.WriteLine("snake test passed."); // 2002.09.20 - repro a = "c1,a,c2,b,c,d,e,g,h,i,j,c3,k,l".Replace(',', '\n'); b = "C1,a,C2,b,c,d,e,I1,e,g,h,i,j,C3,k,I2,l".Replace(',', '\n'); System.Diagnostics.Debug.Assert(TestHelper(Diff.DiffText(a, b, false, false, false)) == "1.1.0.0*1.1.2.2*0.2.7.7*1.1.11.13*0.1.13.15*", "repro20020920 test failed."); System.Diagnostics.Debug.WriteLine("repro20020920 test passed."); // 2003.02.07 - repro a = "F".Replace(',', '\n'); b = "0,F,1,2,3,4,5,6,7".Replace(',', '\n'); System.Diagnostics.Debug.Assert(TestHelper(Diff.DiffText(a, b, false, false, false)) == "0.1.0.0*0.7.1.2*", "repro20030207 test failed."); System.Diagnostics.Debug.WriteLine("repro20030207 test passed."); // Muegel - repro a = "HELLO\nWORLD"; b = "\n\nhello\n\n\n\nworld\n"; System.Diagnostics.Debug.Assert(TestHelper(Diff.DiffText(a, b, false, false, false)) == "2.8.0.0*", "repro20030409 test failed."); System.Diagnostics.Debug.WriteLine("repro20030409 test passed."); // test some differences a = "a,b,-,c,d,e,f,f".Replace(',', '\n'); b = "a,b,x,c,e,f".Replace(',', '\n'); System.Diagnostics.Debug.Assert(TestHelper(Diff.DiffText(a, b, false, false, false)) == "1.1.2.2*1.0.4.4*1.0.6.5*", "some-changes test failed."); System.Diagnostics.Debug.WriteLine("some-changes test passed."); System.Diagnostics.Debug.WriteLine("End."); System.Diagnostics.Debug.Flush(); return(0); }