Add method for path safe encoding of filenames etc
/*
- * Copyright 2006-2021 The MZmine Development Team
+ * Copyright 2006-2020 The MZmine Development Team
*
* This file is part of MZmine.
*
* License, or (at your option) any later version.
*
* MZmine is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
- * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
+ * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
+ * Public License for more details.
*
* You should have received a copy of the GNU General Public License along with MZmine; if not,
- * write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
+ * write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
package io.github.mzmine.util.files;
@@ -450,4 +449,25 @@ public class FileAndPathUtil {
}
return uniqueFile;
}
+
+ /**
+ * Remove all symbols not allowed in path. Replaces with _
+ *
+ * @param name source name (filename or path)
+ * @return path safe string
+ */
+ public static String safePathEncode(String name) {
+ return name.replaceAll("\\W+", "_");
+ }
+
+ /**
+ * Remove all symbols not allowed in path
+ *
+ * @param name source name (filename or path)
+ * @param replaceStr replace all restricted characters by this str
+ * @return path safe string
+ */
+ public static String safePathEncode(String name, String replaceStr) {
+ return name.replaceAll("\\W+", replaceStr);
+ }
}
