Example #1
0
        /// <summary>
        /// Computes the differences between two strings and highlights them with a custom formatting.
        /// </summary>
        /// <param name="before">The old string.</param>
        /// <param name="after">The new string.</param>
        /// <param name="removed">Formatting for removed strings.</param>
        /// <param name="added">Formatting for added strings.</param>
        public static void Compute(ref string before, ref string after, TextDifference.Format removed, TextDifference.Format added)
        {
            var Before = new TextDifference.Info(before, removed);
            var After  = new TextDifference.Info(after, added);

            while (Before.Words.Count > 0 && After.Words.Count > 0)
            {
                if (Before.Words[0] == After.Words[0])
                {
                    Before.RemoveFirstWord();
                    After.RemoveFirstWord();
                }
                else
                {
                    After.Format(Before.Words);
                    Before.Format(After.Words);
                }

                if (After.Words.Count <= 0)
                {
                    Before.FormatEnding();
                }

                if (Before.Words.Count <= 0)
                {
                    After.FormatEnding();
                }
            }

            before = Before.Text;
            after  = After.Text;
        }
Example #2
0
 public Info(string text, TextDifference.Format format)
 {
     Text        = text;
     FormatStart = format.Start;
     FormatEnd   = format.End;
 }