From: gmungoc Date: Thu, 2 May 2019 11:34:40 +0000 (+0100) Subject: JAL-3244 renamed Platform method for clarity X-Git-Tag: Release_2_11_0~15^2~5^2 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=6853a22b51420bcea0fe12932d8850ffb30d9844;p=jalview.git JAL-3244 renamed Platform method for clarity --- diff --git a/src/jalview/gui/AppJmol.java b/src/jalview/gui/AppJmol.java index 319ba06..ea7fb6b 100644 --- a/src/jalview/gui/AppJmol.java +++ b/src/jalview/gui/AppJmol.java @@ -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(); diff --git a/src/jalview/gui/ChimeraViewFrame.java b/src/jalview/gui/ChimeraViewFrame.java index d07a7c2..a7349b8 100644 --- a/src/jalview/gui/ChimeraViewFrame.java +++ b/src/jalview/gui/ChimeraViewFrame.java @@ -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) diff --git a/src/jalview/project/Jalview2XML.java b/src/jalview/project/Jalview2XML.java index 2aefd81..0d2ec68 100644 --- a/src/jalview/project/Jalview2XML.java +++ b/src/jalview/project/Jalview2XML.java @@ -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])); diff --git a/src/jalview/util/Platform.java b/src/jalview/util/Platform.java index 2c2c081..c1d8228 100644 --- a/src/jalview/util/Platform.java +++ b/src/jalview/util/Platform.java @@ -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("\\", "\\\\"); } /** diff --git a/test/jalview/util/PlatformTest.java b/test/jalview/util/PlatformTest.java index 28d0924..d2c48f1 100644 --- a/test/jalview/util/PlatformTest.java +++ b/test/jalview/util/PlatformTest.java @@ -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"); + } }