Ejemplo n.º 1
0
        public void WordTests()
        {
            Word w1;
            Word w2;

            w1 = new Word("", "");
            w2 = new Word("", " ");
            Assert.AreEqual("", w1.TheWord);
            Assert.AreEqual("", w1.Whitespace);
            Assert.AreEqual("", w1.ToString());
            Assert.AreEqual("", w2.TheWord);
            Assert.AreEqual(" ", w2.Whitespace);
            Assert.AreEqual(" ", w2.ToString());
            Assert.AreEqual(w1, w2);
            Assert.AreEqual(w1.GetHashCode(), w2.GetHashCode());

            w1 = new Word("foo", "  ");
            w2 = new Word("foo", "");
            Assert.AreEqual("foo", w1.TheWord);
            Assert.AreEqual("foo  ", w1.ToString());
            Assert.AreEqual("foo", w2.ToString());
            Assert.AreEqual(w1, w2);
            Assert.AreEqual(w1.GetHashCode(), w2.GetHashCode());

            w2 = new Word("Foo", "");
            Assert.AreNotEqual(w1, w2);
            Assert.AreNotEqual(w1.GetHashCode(), w2.GetHashCode());
        }
Ejemplo n.º 2
0
        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>");
                    }
                }
            }
        }
Ejemplo n.º 3
0
        private void LineChanged(int leftLine, int rightLine)
        {
            // some kind of glitch with the diff engine
            if (LeftLines[leftLine] == RightLines[rightLine])
            {
                ContextLine(rightLine);
                return;
            }

            StringBuilder left  = new StringBuilder();
            StringBuilder right = new StringBuilder();

            List <Word> leftList  = Word.SplitString(LeftLines[leftLine]);
            List <Word> rightList = Word.SplitString(RightLines[rightLine]);

            diff = new Diff(leftList, rightList, Word.Comparer);

            foreach (Diff.Hunk h in diff)
            {
                if (h.Same)
                {
                    for (int i = 0; i < h.Left.Count; i++)
                    {
                        WhitespaceDiff(left, rightList[h.Right.Start + i], leftList[h.Left.Start + i]);
                        WhitespaceDiff(right, leftList[h.Left.Start + i], rightList[h.Right.Start + i]);
                    }
                }
                else
                {
                    WordDiff(left, h.Left, h.Right, leftList, rightList);

                    WordDiff(right, h.Right, h.Left, rightList, leftList);
                }
            }

            if (Variables.RTL)
            {
                Result.AppendFormat(@"<tr onclick='window.external.GoTo({1})' ondblclick='window.external.UndoChange({0},{1})'>
  <td>+</td>
  <td class='diff-addedline'>", rightLine, leftLine);
                Result.Append(right);
                Result.Append(@"  </td>
  <td>-</td>
  <td class='diff-deletedline'>");
                Result.Append(left);
                Result.Append(@"  </td>
		</tr>"        );
            }
            else
            {
                Result.AppendFormat(@"<tr onclick='window.external.GoTo({1})' ondblclick='window.external.UndoChange({0},{1})'>
  <td>-</td>
  <td class='diff-deletedline'>", leftLine, rightLine);
                Result.Append(left);
                Result.Append(@"  </td>
  <td>+</td>
  <td class='diff-addedline'>");
                Result.Append(right);
                Result.Append(@"  </td>
		</tr>"        );
            }
        }