Skip to content

Commit

Permalink
chore: fix refactoring regression
Browse files Browse the repository at this point in the history
  • Loading branch information
CarstenWickner committed Nov 15, 2023
1 parent 0a94ae4 commit c88c9c4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Predicate;
import java.util.regex.Pattern;
import java.util.stream.IntStream;

/**
* Conversion logic from globs to regular expressions.
Expand All @@ -33,12 +34,12 @@ public class GlobHandler {
private static final char EXCLAMATION_SIGN_CHAR = '!';
private static final char COMMA_CHAR = ',';

private static final List<Character> GLOB_IDENTIFIERS = Arrays.asList(
private static final int[] GLOB_IDENTIFIERS = {
ESCAPE_CHAR, ASTERISK_CHAR, QUESTION_MARK_CHAR, '/', '+', '[', '{'
);
private static final List<Character> INPUT_CHARS_REQUIRING_ESCAPE = Arrays.asList(
};
private static final int[] INPUT_CHARS_REQUIRING_ESCAPE = {
'.', '(', ')', '+', '|', '^', '$', '@', '%'
);
};

/**
* Generate predicate to check the given input for filtering classes on the classpath.
Expand Down Expand Up @@ -68,7 +69,7 @@ public static Pattern createClassOrPackageNamePattern(String input, boolean forP
}

private static String convertInputToRegex(String input) {
if (input.chars().anyMatch(GLOB_IDENTIFIERS::contains)) {
if (IntStream.of(GLOB_IDENTIFIERS).anyMatch(identifier -> input.chars().anyMatch(inputChar -> inputChar == identifier))) {
// convert glob pattern into regular expression
return GlobHandler.convertGlobToRegex(input);
}
Expand Down Expand Up @@ -124,7 +125,7 @@ private static String convertGlobToRegex(String pattern) {
handleCommaChar(sb, inGroup);
break;
default:
boolean shouldBeEscaped = INPUT_CHARS_REQUIRING_ESCAPE.contains(ch)
boolean shouldBeEscaped = IntStream.of(INPUT_CHARS_REQUIRING_ESCAPE).anyMatch(specialChar -> specialChar == ch)
&& (inClass.get() == 0 || (ch == '^' && firstIndexInClass.get() == index.get()));
if (shouldBeEscaped) {
sb.append(ESCAPE_CHAR);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class GlobHandlerTest {

static Stream<Arguments> parametersForTestBasicPattern() {
return Stream.of(
Arguments.of("single star becomes all-but-shlash star", "gl*b", "gl[^/]*b"),
Arguments.of("single star becomes all-but-slash star", "gl*b", "gl[^/]*b"),
Arguments.of("double star becomes dot star", "gl**b", "gl.*b"),
Arguments.of("escaped star is unchanged", "gl\\*b", "gl\\*b"),
Arguments.of("question mark becomes all-but-shlash", "gl?b", "gl[^/]b"),
Expand Down

0 comments on commit c88c9c4

Please sign in to comment.