Пример #1
0
        public static DiffReport Get(string a, string b, params char[] separators)
        {
            //StringBuilder returnText = new StringBuilder();
            //returnText.Append("<table>");
            DiffReport r = new DiffReport();

            Diff.Item[] f      = Diff.DiffText(a, b, true, true, false, separators);
            string[]    aLines = a.Split(separators);
            string[]    bLines = b.Split(separators);

            int n = 1;

            for (int fdx = 0; fdx < f.Length; fdx++)
            {
                Diff.Item aItem = f[fdx];

                // write unchanged lines
                while ((n - 1 < aItem.StartB) && (n - 1 < bLines.Length))
                {
                    r.AddLine <DiffReportToken>(n, bLines[n - 1]);//WriteLine(n, DiffType.None, bLines[n], returnText);
                    n++;
                } // while

                // write deleted lines
                for (int m = 0; m < aItem.deletedA; m++)
                {
                    r.AddLine <DeletedDiffReportToken>(-1, aLines[aItem.StartA + m]);//WriteLine(-1, DiffType.Deleted, aLines[aItem.StartA + m], returnText);
                } // for

                // write inserted lines
                while (n - 1 < aItem.StartB + aItem.insertedB)
                {
                    r.AddLine <InsertedDiffReportToken>(n, bLines[n - 1]);//WriteLine(n, DiffType.Inserted, bLines[n], returnText);
                    n++;
                } // while
            } // while

            // write rest of unchanged lines
            while (n - 1 < bLines.Length)
            {
                r.AddLine <DiffReportToken>(n, bLines[n - 1]);//WriteLine(n, DiffType.None, bLines[n], returnText);
                n++;
            } // while

            //returnText.Append("</table>");
            return(r);// returnText.ToString();
        }
Пример #2
0
        public static string GetHtmlTable(string a, string b)
        {
            DiffReport dr = Get(a, b);

            return(dr.ToHtmlTable());
        }