Caching regex return in user cleanup.

(Pushing this for testing purposes).
This commit is contained in:
KHobbits 2012-02-13 19:40:33 +00:00
parent effe0d5ec5
commit bc2578b788

View File

@ -22,11 +22,17 @@ public class Util
} }
private final static Logger logger = Logger.getLogger("Minecraft"); private final static Logger logger = Logger.getLogger("Minecraft");
private final static Pattern INVALIDFILECHARS = Pattern.compile("[^a-z0-9]"); private final static Pattern INVALIDFILECHARS = Pattern.compile("[^a-z0-9]");
private final static Pattern INVALIDCHARS = Pattern.compile("[^\t\n\r\u0020-\u007E\u0085\u00A0-\uD7FF\uE000-\uFFFC]");; private final static Pattern INVALIDCHARS = Pattern.compile("[^\t\n\r\u0020-\u007E\u0085\u00A0-\uD7FF\uE000-\uFFFC]");
private static Map<String,String> sanitizedName = new HashMap<String,String>();
public static String sanitizeFileName(final String name) public static String sanitizeFileName(final String name)
{ {
return INVALIDFILECHARS.matcher(name.toLowerCase(Locale.ENGLISH)).replaceAll("_"); if (sanitizedName.containsKey(name)) {
return sanitizedName.get(name);
}
final String newName = INVALIDFILECHARS.matcher(name.toLowerCase(Locale.ENGLISH)).replaceAll("_");
sanitizedName.put(name, newName);
return newName;
} }
public static String sanitizeString(final String string) public static String sanitizeString(final String string)