00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 package com.realtime.crossfire.jxclient.util;
00023
00024 import java.util.regex.Pattern;
00025 import org.jetbrains.annotations.NotNull;
00026
00031 public class FilenameUtils {
00032
00037 @NotNull
00038 private static final String REPLACEMENT_CHARACTER = "_";
00039
00044 @NotNull
00045 private static final Pattern UNSAFE_FILENAME_CHARACTERS = Pattern.compile("[^a-zA-Z0-9_.]");
00046
00050 private FilenameUtils() {
00051 }
00052
00060 @NotNull
00061 public static String quoteName(@NotNull final String name) {
00062 final CharSequence trimmedName = name.endsWith(".png") ? name.substring(0, name.length()-4) : name;
00063 final String replacedName = UNSAFE_FILENAME_CHARACTERS.matcher(trimmedName).replaceAll(REPLACEMENT_CHARACTER);
00064 return replacedName.length() > 0 ? replacedName : REPLACEMENT_CHARACTER;
00065 }
00066
00067 }