[jsword-svn] r1690 - in trunk/common/src: main/java/org/crosswire/common/diff test/java/org/crosswire/common/diff
dmsmith at www.crosswire.org
dmsmith at www.crosswire.org
Thu Aug 23 14:01:26 MST 2007
Author: dmsmith
Date: 2007-08-23 14:01:26 -0700 (Thu, 23 Aug 2007)
New Revision: 1690
Modified:
trunk/common/src/main/java/org/crosswire/common/diff/DiffCleanup.java
trunk/common/src/main/java/org/crosswire/common/diff/PatchEntry.java
trunk/common/src/test/java/org/crosswire/common/diff/PatchEntryTest.java
Log:
Fixed a diff problem where the difference was a newline.
Modified: trunk/common/src/main/java/org/crosswire/common/diff/DiffCleanup.java
===================================================================
--- trunk/common/src/main/java/org/crosswire/common/diff/DiffCleanup.java 2007-08-22 15:55:59 UTC (rev 1689)
+++ trunk/common/src/main/java/org/crosswire/common/diff/DiffCleanup.java 2007-08-23 21:01:26 UTC (rev 1690)
@@ -84,7 +84,7 @@
// Replace equality with a delete.
pointer.set(new Difference(EditType.DELETE, lastEquality));
- // Insert a coresponding an insert.
+ // Insert a corresponding an insert.
pointer.add(new Difference(EditType.INSERT, lastEquality));
equalities.pop(); // Throw away the equality we just deleted;
if (!equalities.empty())
@@ -203,7 +203,7 @@
// Replace equality with a delete.
pointer.set(new Difference(EditType.DELETE, lastEquality));
- // Insert a coresponding an insert.
+ // Insert a corresponding an insert.
curDiff = new Difference(EditType.INSERT, lastEquality);
pointer.add(curDiff);
@@ -310,7 +310,7 @@
if (countDelete != 0 && countInsert != 0)
{
- // Factor out any common prefixies.
+ // Factor out any common prefixes.
commonLength = Commonality.prefix(textInsert.toString(), textDelete.toString());
if (commonLength > 0)
{
@@ -329,7 +329,7 @@
textDelete.replace(0, textDelete.length(), textDelete.substring(commonLength));
}
- // Factor out any common suffixies.
+ // Factor out any common suffixes.
commonLength = Commonality.suffix(textInsert.toString(), textDelete.toString());
if (commonLength > 0)
{
Modified: trunk/common/src/main/java/org/crosswire/common/diff/PatchEntry.java
===================================================================
--- trunk/common/src/main/java/org/crosswire/common/diff/PatchEntry.java 2007-08-22 15:55:59 UTC (rev 1689)
+++ trunk/common/src/main/java/org/crosswire/common/diff/PatchEntry.java 2007-08-23 21:01:26 UTC (rev 1690)
@@ -232,6 +232,11 @@
{
sign = text[lineCount].charAt(0);
line = text[lineCount].substring(1);
+ // Lines with zero length are the difference of a new line.
+ if (line.length() == 0)
+ {
+ line = "\n"; //$NON-NLS-1$
+ }
diffs.add(new Difference(EditType.fromSymbol(sign), line));
}
}
Modified: trunk/common/src/test/java/org/crosswire/common/diff/PatchEntryTest.java
===================================================================
--- trunk/common/src/test/java/org/crosswire/common/diff/PatchEntryTest.java 2007-08-22 15:55:59 UTC (rev 1689)
+++ trunk/common/src/test/java/org/crosswire/common/diff/PatchEntryTest.java 2007-08-23 21:01:26 UTC (rev 1690)
@@ -42,6 +42,21 @@
assertEquals("PatchEntry.fromText: #2.", "@@ -1 +1 @@\n-a\n+b\n", new PatchEntry("@@ -1 +1 @@\n-a\n+b\n").toString()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
assertEquals("PatchEntry.fromText: #3.", "@@ -1,3 +0,0 @@\n-abc\n", new PatchEntry("@@ -1,3 +0,0 @@\n-abc\n").toString()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
assertEquals("PatchEntry.fromText: #4.", "@@ -0,0 +1,3 @@\n+abc\n", new PatchEntry("@@ -0,0 +1,3 @@\n+abc\n").toString()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ assertEquals("PatchEntry.fromText: #4.", "@@ -1,7 +1,6 @@\n foo\n-\n\n bar\n", new PatchEntry("@@ -1,7 +1,6 @@\n foo\n-\n\n bar\n").toString()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ String text1 = "foo\nbar";
+ String text2 = "foobar";
+ Patch patch = new Patch(text1, text2);
+ String patchText = patch.toText();
+ //@@ -1,7 +1,6 @@
+ // foo
+ //-
+ //
+ // bar
+
+ Patch patch2 = new Patch();
+ patch2 = patch2.fromText(patchText);
+ System.out.println(patch2.apply(text1).getText());
+ // should print "foobar" but prints "bar"
}
public void testMatchAddContext()
More information about the jsword-svn
mailing list