From e4882fefb159ba6de40048796c943cc2115fc193 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Mon, 20 Jan 2014 14:04:52 +0100 Subject: [PATCH] Use regular expressions to match filenames. --- .../java/net/pterodactylus/xdcc/ui/stdin/SearchCommand.java | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) 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); } -- 2.7.4