1
2
3
4
5
6
7
8
9
10 package org.eclipse.jgit.ignore.internal;
11
12
13
14
15 public class LeadingAsteriskMatcher extends NameMatcher {
16
17 LeadingAsteriskMatcher(String pattern, Character pathSeparator, boolean dirOnly) {
18 super(pattern, pathSeparator, dirOnly, true);
19
20 if (subPattern.charAt(0) != '*')
21 throw new IllegalArgumentException(
22 "Pattern must have leading asterisk: " + pattern);
23 }
24
25
26 @Override
27 public boolean matches(String segment, int startIncl, int endExcl) {
28
29 String s = subPattern;
30
31
32 int subLength = s.length() - 1;
33
34 if (subLength == 0)
35 return true;
36
37 if (subLength > (endExcl - startIncl))
38 return false;
39
40 for (int i = subLength, j = endExcl - 1; i > 0; i--, j--) {
41 char c1 = s.charAt(i);
42 char c2 = segment.charAt(j);
43 if (c1 != c2)
44 return false;
45 }
46 return true;
47 }
48
49 }