Skip to content

Commit

Permalink
Remove slashes from filenames (#1057)
Browse files Browse the repository at this point in the history
Co-authored-by: KochTobi <[email protected]>
  • Loading branch information
KochTobi and KochTobi authored Mar 6, 2025
1 parent 48f0c76 commit 32d5dfd
Showing 1 changed file with 13 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ public class FileNameFormatter {
private static final String PART_JOINER = "_";

private static final DateTimeFormatter DATE_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd");
private static final String SLASH_REPLACEMENT = "_";

private FileNameFormatter() {

Expand All @@ -19,18 +20,26 @@ public static String formatWithTimestampedContext(LocalDate timestamp, String pr
String experimentPart, String type, String extension) {
return DATE_FORMATTER.format(timestamp)
+ PART_JOINER
+ replaceSpaces(projectPart)
+ replaceForbiddenCharacters(projectPart)
+ PART_JOINER
+ replaceSpaces(experimentPart)
+ replaceForbiddenCharacters(experimentPart)
+ PART_JOINER
+ replaceSpaces(type)
+ "." + replaceSpaces(extension);
+ replaceForbiddenCharacters(type)
+ "." + replaceForbiddenCharacters(extension);
}

private static String replaceForbiddenCharacters(String input) {
return replaceSlashes(replaceSpaces(input));
}

private static String replaceSpaces(String projectPart) {
return projectPart.replaceAll("\\s", SPACE_REPLACEMENT);
}

private static String replaceSlashes(String input) {
return input.replace("/", SLASH_REPLACEMENT);
}

public static String formatWithVersion(String filename, int version,
String extension) {
return replaceSpaces(filename) + "_" + "v" + version + "." + replaceSpaces(extension);
Expand Down

0 comments on commit 32d5dfd

Please sign in to comment.