WikiFunctions.WikiDiff.WhitespaceDiff C# (CSharp) Method

WhitespaceDiff() private static method

private static WhitespaceDiff ( StringBuilder res, Word left, Word right ) : void
res StringBuilder
left Word
right Word
return void
        private static void WhitespaceDiff(StringBuilder res, Word left, Word right)
        {
            if (left.Whitespace == right.Whitespace) res.Append(HttpUtility.HtmlEncode(right.ToString()));
            else
            {
                res.Append(HttpUtility.HtmlEncode(right.TheWord));
                char[] leftChars = left.Whitespace.ToCharArray();
                char[] rightChars = right.Whitespace.ToCharArray();

                Diff diff = new Diff(leftChars, rightChars, Word.Comparer);
                foreach (Diff.Hunk h in diff)
                {
                    if (h.Same)
                    {
                        res.Append(rightChars, h.Right.Start, h.Right.Count);
                    }
                    else
                    {
                        res.Append("<span class='diffchange'>");
                        res.Append('\x00A0', h.Right.Count); // replace spaces with NBSPs to make 'em visible
                        res.Append("</span>");
                    }
                }
            }
        }