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