aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit/src/org/eclipse/jgit/ignore/internal/WildCardMatcher.java
blob: d976f6ea5b4d671e7ee56c6791ba43feedb7aee5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/*
 * Copyright (C) 2014, Andrey Loskutov <loskutov@gmx.de> and others
 *
 * This program and the accompanying materials are made available under the
 * terms of the Eclipse Distribution License v. 1.0 which is available at
 * https://www.eclipse.org/org/documents/edl-v10.php.
 *
 * SPDX-License-Identifier: BSD-3-Clause
 */
package org.eclipse.jgit.ignore.internal;

import static org.eclipse.jgit.ignore.internal.Strings.convertGlob;

import java.util.regex.Pattern;

import org.eclipse.jgit.errors.InvalidPatternException;

/**
 * Matcher built from path segments containing wildcards. This matcher converts
 * glob wildcards to Java {@link java.util.regex.Pattern}'s.
 * <p>
 * This class is immutable and thread safe.
 */
public class WildCardMatcher extends NameMatcher {

	final Pattern p;

	WildCardMatcher(String pattern, Character pathSeparator, boolean dirOnly)
			throws InvalidPatternException {
		super(pattern, pathSeparator, dirOnly, false);
		p = convertGlob(subPattern);
	}

	@Override
	public boolean matches(String segment, int startIncl, int endExcl) {
		return p.matcher(segment.substring(startIncl, endExcl)).matches();
	}
}