From: David ‘Bombe’ Roden Date: Mon, 20 Jan 2014 13:04:52 +0000 (+0100) Subject: Use regular expressions to match filenames. X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=e4882fefb159ba6de40048796c943cc2115fc193;p=xudocci.git Use regular expressions to match filenames. --- diff --git a/src/main/java/net/pterodactylus/xdcc/ui/stdin/SearchCommand.java b/src/main/java/net/pterodactylus/xdcc/ui/stdin/SearchCommand.java index ad1d9d7..170365a 100644 --- a/src/main/java/net/pterodactylus/xdcc/ui/stdin/SearchCommand.java +++ b/src/main/java/net/pterodactylus/xdcc/ui/stdin/SearchCommand.java @@ -19,12 +19,16 @@ package net.pterodactylus.xdcc.ui.stdin; import static com.google.common.collect.Lists.newArrayList; import static java.util.Arrays.asList; +import static java.util.regex.Pattern.CASE_INSENSITIVE; +import static java.util.regex.Pattern.UNICODE_CASE; +import static java.util.regex.Pattern.compile; import java.io.IOException; import java.io.Writer; import java.util.Collection; import java.util.Collections; import java.util.List; +import java.util.regex.Pattern; import net.pterodactylus.xdcc.core.Core; import net.pterodactylus.xdcc.data.Bot; @@ -88,21 +92,20 @@ public class SearchCommand implements Command { private static class SearchParameter { private final boolean exclude; - private final String pattern; + private final Pattern pattern; - private SearchParameter(boolean exclude, String pattern) { + private SearchParameter(boolean exclude, Pattern pattern) { this.exclude = exclude; this.pattern = pattern; } public boolean matches(String filename) { - boolean matches = filename.toLowerCase().contains(pattern.toLowerCase()); - return matches && !exclude; + return pattern.matcher(filename).find() && !exclude; } public static SearchParameter from(String parameter) { boolean exclude = parameter.startsWith("-"); - String pattern = exclude ? parameter.substring(1) : parameter; + Pattern pattern = compile(exclude ? parameter.substring(1) : parameter, CASE_INSENSITIVE | UNICODE_CASE); return new SearchParameter(exclude, pattern); }