1 11 package org.eclipse.search.internal.core.text; 12 13 import java.util.regex.Matcher ; 14 import java.util.regex.Pattern ; 15 import java.util.regex.PatternSyntaxException ; 16 17 import org.eclipse.core.runtime.CoreException; 18 import org.eclipse.core.runtime.IProgressMonitor; 19 import org.eclipse.core.runtime.OperationCanceledException; 20 21 import org.eclipse.core.resources.IResourceProxy; 22 23 import org.eclipse.search.internal.ui.SearchMessages; 24 25 29 public class MatchLocator { 30 31 private Matcher fMatcher; 32 33 public MatchLocator(Pattern pattern) { 34 fMatcher= pattern.matcher(""); } 36 37 public MatchLocator(String pattern, boolean isCaseSensitive, boolean isRegexSearch) throws PatternSyntaxException { 38 this(PatternConstructor.createPattern(pattern, isCaseSensitive, isRegexSearch)); 39 } 40 41 public boolean isEmpty() { 42 return fMatcher.pattern().pattern().length() == 0; 43 } 44 45 public void locateMatches(IProgressMonitor progressMonitor, CharSequence searchInput, ITextSearchResultCollector collector, IResourceProxy proxy) throws CoreException { 46 fMatcher.reset(searchInput); 47 int k= 0; 48 while (fMatcher.find()) { 49 int start= fMatcher.start(); 50 int end= fMatcher.end(); 51 if (end != start) { collector.accept(proxy, start, end - start); 53 } 54 if (k++ == 20) { 55 if (progressMonitor.isCanceled()) { 56 throw new OperationCanceledException(SearchMessages.TextSearchVisitor_canceled); 57 } 58 k= 0; 59 } 60 } 61 } 62 } 63 | Popular Tags |