[jsword-svn] r1688 - 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
Wed Aug 22 06:34:23 MST 2007


Author: dmsmith
Date: 2007-08-22 06:34:22 -0700 (Wed, 22 Aug 2007)
New Revision: 1688

Modified:
   trunk/common/src/main/java/org/crosswire/common/diff/Patch.java
   trunk/common/src/test/java/org/crosswire/common/diff/PatchTest.java
Log:
Fixed a bug with Diff.

Modified: trunk/common/src/main/java/org/crosswire/common/diff/Patch.java
===================================================================
--- trunk/common/src/main/java/org/crosswire/common/diff/Patch.java	2007-08-16 13:27:51 UTC (rev 1687)
+++ trunk/common/src/main/java/org/crosswire/common/diff/Patch.java	2007-08-22 13:34:22 UTC (rev 1688)
@@ -420,8 +420,17 @@
     {
         patches.clear();
         String[] text = patchBoundaryPattern.split(input);
+        StringBuffer buf = new StringBuffer();
         for (int patchCount = 0; patchCount < text.length; patchCount++)
         {
+            // Splitting removed @@ from the start of patches,
+            // so it needs to be added back in.
+            if (patchCount > 0)
+            {
+                // re-use the string buffer by using replace
+                buf.replace(0, buf.length(), "@@").append(text[patchCount]); //$NON-NLS-1$
+                text[patchCount] = buf.toString();
+            }
             patches.add(new PatchEntry(text[patchCount]));
         }
         return this;
@@ -463,6 +472,8 @@
         private boolean[] results;
     }
 
+    // Ideally we'd like to have the @@ be merely a look-ahead, but it doesn't
+    // work that way with split.
     private static Pattern patchBoundaryPattern = Pattern.compile("\n@@"); //$NON-NLS-1$
 
     private List patches;

Modified: trunk/common/src/test/java/org/crosswire/common/diff/PatchTest.java
===================================================================
--- trunk/common/src/test/java/org/crosswire/common/diff/PatchTest.java	2007-08-16 13:27:51 UTC (rev 1687)
+++ trunk/common/src/test/java/org/crosswire/common/diff/PatchTest.java	2007-08-22 13:34:22 UTC (rev 1688)
@@ -25,6 +25,7 @@
         assertEquals("patch_fromText: #2.", "@@ -1 +1 @@\n-a\n+b\n", new Patch("@@ -1 +1 @@\n-a\n+b\n").toText()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
         assertEquals("patch_fromText: #3.", "@@ -1,3 +0,0 @@\n-abc\n", new Patch("@@ -1,3 +0,0 @@\n-abc\n").toText()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
         assertEquals("patch_fromText: #4.", "@@ -0,0 +1,3 @@\n+abc\n", new Patch("@@ -0,0 +1,3 @@\n+abc\n").toText()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+        assertEquals("patch_fromText: #5.", "@@ -1,9 +1,9 @@\n-f\n+F\n oo fooba\n@@ -7,9 +7,9 @@\n obar\n-,\n+.\n  tes\n", new Patch("@@ -1,9 +1,9 @@\n-f\n+F\n oo fooba\n@@ -7,9 +7,9 @@\n obar\n-,\n+.\n  tes\n").toText()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
     }
 
     public void testMatchMake()




More information about the jsword-svn mailing list