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();
{
filePDB.add(thePdbEntry);
filePDBpos.add(Integer.valueOf(pi));
- files.append(" \"" + Platform.escapeString(file) + "\"");
+ files.append(" \"" + Platform.escapeBackslashes(file) + "\"");
}
}
} catch (OutOfMemoryError oomerror)
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]));
}
/**
- * 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("\\", "\\\\");
}
/**
*/
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;
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");
+ }
}