comparison src/org/tmatesoft/hg/internal/PathGlobMatcher.java @ 118:68ba22a2133a

Defects in the filter initialization
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Fri, 04 Feb 2011 02:44:32 +0100
parents 46291ec605a0
children 7567f4a42fe5
comparison
equal deleted inserted replaced
117:6c0be854d149 118:68ba22a2133a
56 private static String glob2regexp(String glob) { 56 private static String glob2regexp(String glob) {
57 int end = glob.length() - 1; 57 int end = glob.length() - 1;
58 boolean needLineEndMatch = glob.charAt(end) != '*'; 58 boolean needLineEndMatch = glob.charAt(end) != '*';
59 while (end > 0 && glob.charAt(end) == '*') end--; // remove trailing * that are useless for Pattern.find() 59 while (end > 0 && glob.charAt(end) == '*') end--; // remove trailing * that are useless for Pattern.find()
60 StringBuilder sb = new StringBuilder(end*2); 60 StringBuilder sb = new StringBuilder(end*2);
61 if (glob.charAt(0) != '*') {
62 sb.append('^');
63 }
61 for (int i = 0; i <= end; i++) { 64 for (int i = 0; i <= end; i++) {
62 char ch = glob.charAt(i); 65 char ch = glob.charAt(i);
63 if (ch == '*') { 66 if (ch == '*') {
64 if (glob.charAt(i+1) == '*') { // i < end because we've stripped any trailing * earlier 67 if (glob.charAt(i+1) == '*') { // i < end because we've stripped any trailing * earlier
65 // any char, including path segment separator 68 // any char, including path segment separator
66 sb.append(".*?"); 69 sb.append(".*?");
70 i++;
67 } else { 71 } else {
68 // just path segments 72 // just path segments
69 sb.append("[^/]*?"); 73 sb.append("[^/]*?");
70 } 74 }
71 continue; 75 continue;