PathUtils { public static String removeTrailingSeparator(String path) { char lastChar; int len = path.length(); if(len>0 && ((lastChar=path.charAt(len-1))=='/' || lastChar=='\\')) return path.substring(0, len-1); return path; }  static ResolvedDestination resolveDestination(String destPath, AbstractFile baseFolder); static String removeLeadingSeparator(String path); static String removeLeadingSeparator(String path, String separator); static String removeTrailingSeparator(String path); static String removeTrailingSeparator(String path, String separator); static boolean pathEquals(String path1, String path2, String separator); static int getPathHashCode(String path, String separator); static String removeLeadingFragments(String path, String separator, int nbFragments); static int getDepth(String path, String separator);  }
@Test public void testRemoveTrailingSeparator() { assert PathUtils.removeTrailingSeparator("/home/", "/").equals("/home"); assert PathUtils.removeTrailingSeparator("/home/maxence", "/").equals("/home/maxence"); assert PathUtils.removeTrailingSeparator("/home/maxence/", "/").equals("/home/maxence"); assert PathUtils.removeTrailingSeparator("/home/", "\\").equals("/home/"); assert PathUtils.removeTrailingSeparator("/", "/").equals(""); assert PathUtils.removeTrailingSeparator("C:\\home", "\\").equals("C:\\home"); assert PathUtils.removeTrailingSeparator("C:\\home\\", "\\").equals("C:\\home"); assert PathUtils.removeTrailingSeparator("C:\\home\\maxence", "\\").equals("C:\\home\\maxence"); assert PathUtils.removeTrailingSeparator("C:\\home\\maxence", "\\").equals("C:\\home\\maxence"); assert PathUtils.removeTrailingSeparator("C:\\home\\", "/").equals("C:\\home\\"); assert PathUtils.removeTrailingSeparator("--home--", "--").equals("--home"); assert PathUtils.removeTrailingSeparator("--home--maxence", "--").equals("--home--maxence"); assert PathUtils.removeTrailingSeparator("--home--maxence--", "--").equals("--home--maxence"); assert PathUtils.removeTrailingSeparator("--home--", "/").equals("--home--"); assert PathUtils.removeTrailingSeparator("--", "--").equals(""); }