Skip to content

Commit

Permalink
fixed pattern match
Browse files Browse the repository at this point in the history
  • Loading branch information
Claudenw committed Jan 14, 2025
1 parent a46a244 commit 103d9db
Show file tree
Hide file tree
Showing 4 changed files with 370 additions and 66 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -255,10 +255,10 @@ public DocumentNameMatcher getNameMatcher(final DocumentName basedir) {
.addTo(new ArrayList<>());

if (!incl.isEmpty()) {
inclMatchers.add(new DocumentNameMatcher("included patterns", MatchPatterns.from(incl), basedir));
inclMatchers.add(new DocumentNameMatcher("included patterns", MatchPatterns.from("/", incl), basedir));
}
if (!excl.isEmpty()) {
exclMatchers.add(new DocumentNameMatcher("excluded patterns", MatchPatterns.from(excl), basedir));
exclMatchers.add(new DocumentNameMatcher("excluded patterns", MatchPatterns.from("/", excl), basedir));
}

if (!includedPaths.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public final class MatchPattern {

private final char[][] tokenizedChar;

private MatchPattern(final String source, final String separator) {
MatchPattern(final String source, final String separator) {
regexPattern = SelectorUtils.isRegexPrefixedPattern(source)
? source.substring(
SelectorUtils.REGEX_HANDLER_PREFIX.length(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@

import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.function.Predicate;
import java.util.stream.Collectors;

@SuppressWarnings({"checkstyle:RegexpSingleLine", "checkstyle:JavadocVariable"})
/**
Expand All @@ -41,15 +42,15 @@ private MatchPatterns(final MatchPattern[] patterns) {

@Override
public String toString() {
return source();
return Arrays.stream(patterns).map(MatchPattern::toString).collect(Collectors.toList()).toString();
}

public String source() {
List<String> sources = new ArrayList<>();
for (MatchPattern pattern : patterns) {
sources.add(pattern.source());
}
return "[" + String.join(", ", sources) + "]";
return Arrays.stream(patterns).map(MatchPattern::source).collect(Collectors.toList()).toString();
}

public Iterable<MatchPattern> patterns() {
return Arrays.asList(patterns);
}

/**
Expand Down Expand Up @@ -83,36 +84,23 @@ public boolean matches(final String name, final char[][] tokenizedNameChar, fina
return false;
}

public Predicate<String> asPredicate(final boolean isCaseSensitive) {
return name -> matches(name, isCaseSensitive);
}

public boolean matchesPatternStart(final String name, final boolean isCaseSensitive) {
for (MatchPattern includesPattern : patterns) {
if (includesPattern.matchPatternStart(name, isCaseSensitive)) {
return true;
}
}
return false;
}

public static MatchPatterns from(final String... sources) {
public static MatchPatterns from(final String separator, final String... sources) {
final int length = sources.length;
MatchPattern[] result = new MatchPattern[length];
for (int i = 0; i < length; i++) {
result[i] = MatchPattern.fromString(sources[i]);
result[i] = new MatchPattern(sources[i], separator);
}
return new MatchPatterns(result);
}

public static MatchPatterns from(final Iterable<String> strings) {
return new MatchPatterns(getMatchPatterns(strings));
public static MatchPatterns from(final String separator, final Iterable<String> strings) {
return new MatchPatterns(getMatchPatterns(separator, strings));
}

private static MatchPattern[] getMatchPatterns(final Iterable<String> items) {
private static MatchPattern[] getMatchPatterns(final String separator, final Iterable<String> items) {
List<MatchPattern> result = new ArrayList<>();
for (String string : items) {
result.add(MatchPattern.fromString(string));
result.add(new MatchPattern(string, separator));
}
return result.toArray(new MatchPattern[0]);
}
Expand Down
Loading

0 comments on commit 103d9db

Please sign in to comment.