JAL-3244 renamed Platform method for clarity bug/JAL-3244jmolWindows
authorgmungoc <g.m.carstairs@dundee.ac.uk>
Thu, 2 May 2019 11:34:40 +0000 (12:34 +0100)
committergmungoc <g.m.carstairs@dundee.ac.uk>
Thu, 2 May 2019 11:34:40 +0000 (12:34 +0100)
src/jalview/gui/AppJmol.java
src/jalview/gui/ChimeraViewFrame.java
src/jalview/project/Jalview2XML.java
src/jalview/util/Platform.java
test/jalview/util/PlatformTest.java

index 319ba06..ea7fb6b 100644 (file)
@@ -326,7 +326,7 @@ public class AppJmol extends StructureViewerBase
     for (String s : files)
     {
       fileList.append(SPACE).append(QUOTE)
-              .append(Platform.escapeString(s)).append(QUOTE);
+              .append(Platform.escapeBackslashes(s)).append(QUOTE);
     }
     String filesString = fileList.toString();
 
index d07a7c2..a7349b8 100644 (file)
@@ -480,7 +480,7 @@ public class ChimeraViewFrame extends StructureViewerBase
         {
           filePDB.add(thePdbEntry);
           filePDBpos.add(Integer.valueOf(pi));
-          files.append(" \"" + Platform.escapeString(file) + "\"");
+          files.append(" \"" + Platform.escapeBackslashes(file) + "\"");
         }
       }
     } catch (OutOfMemoryError oomerror)
index 2aefd81..0d2ec68 100644 (file)
@@ -4520,7 +4520,7 @@ public class Jalview2XML
           String reformatedOldFilename = oldfilenam.replaceAll("/", "\\\\");
           filedat = oldFiles.get(new File(reformatedOldFilename));
         }
-        newFileLoc.append(Platform.escapeString(filedat.getFilePath()));
+        newFileLoc.append(Platform.escapeBackslashes(filedat.getFilePath()));
         pdbfilenames.add(filedat.getFilePath());
         pdbids.add(filedat.getPdbId());
         seqmaps.add(filedat.getSeqList().toArray(new SequenceI[0]));
index 2c2c081..c1d8228 100644 (file)
@@ -87,23 +87,15 @@ public class Platform
   }
 
   /**
-   * escape a string according to the local platform's escape character
+   * Answers the input with every backslash replaced with a double backslash (an
+   * 'escaped' single backslash)
    * 
-   * @param file
-   * @return escaped file
+   * @param s
+   * @return
    */
-  public static String escapeString(String file)
+  public static String escapeBackslashes(String s)
   {
-    StringBuffer f = new StringBuffer();
-    int p = 0, lastp = 0;
-    while ((p = file.indexOf('\\', lastp)) > -1)
-    {
-      f.append(file.subSequence(lastp, p));
-      f.append("\\\\");
-      lastp = p + 1;
-    }
-    f.append(file.substring(lastp));
-    return f.toString();
+    return s == null ? null : s.replace("\\", "\\\\");
   }
 
   /**
index 28d0924..d2c48f1 100644 (file)
@@ -20,7 +20,9 @@
  */
 package jalview.util;
 
+import static org.testng.Assert.assertEquals;
 import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertNull;
 import static org.testng.Assert.assertTrue;
 
 import jalview.gui.JvOptionPane;
@@ -131,4 +133,12 @@ public class PlatformTest
     assertTrue(Platform.pathEquals("apath", "apath"));
     assertTrue(Platform.pathEquals("apath/a/b", "apath\\a\\b"));
   }
+
+  @Test(groups = "Functional")
+  public void testEscapeBackslashes()
+  {
+    assertNull(Platform.escapeBackslashes(null));
+    assertEquals(Platform.escapeBackslashes("hello world"), "hello world");
+    assertEquals(Platform.escapeBackslashes("hello\\world"), "hello\\\\world");
+  }
 }