diff options
author | KHobbits <rob@khobbits.co.uk> | 2012-02-13 19:40:33 +0000 |
---|---|---|
committer | KHobbits <rob@khobbits.co.uk> | 2012-02-13 19:40:33 +0000 |
commit | bc2578b7887f38e8106a1d4c2ce000618c19bb23 (patch) | |
tree | 7fe03c43bcb945c464f2fdd7cc5670524254aa44 | |
parent | effe0d5ec5f6ab4ef877e8d3a417979889c63810 (diff) | |
download | Essentials-bc2578b7887f38e8106a1d4c2ce000618c19bb23.tar Essentials-bc2578b7887f38e8106a1d4c2ce000618c19bb23.tar.gz Essentials-bc2578b7887f38e8106a1d4c2ce000618c19bb23.tar.lz Essentials-bc2578b7887f38e8106a1d4c2ce000618c19bb23.tar.xz Essentials-bc2578b7887f38e8106a1d4c2ce000618c19bb23.zip |
Caching regex return in user cleanup.
(Pushing this for testing purposes).
-rw-r--r-- | Essentials/src/com/earth2me/essentials/Util.java | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/Essentials/src/com/earth2me/essentials/Util.java b/Essentials/src/com/earth2me/essentials/Util.java index 65077a7fc..c6df66165 100644 --- a/Essentials/src/com/earth2me/essentials/Util.java +++ b/Essentials/src/com/earth2me/essentials/Util.java @@ -22,11 +22,17 @@ public class Util } private final static Logger logger = Logger.getLogger("Minecraft"); 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) { - 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) |