1 21 22 package org.gjt.sp.jedit.search; 23 24 import java.util.regex.Matcher ; 25 import java.util.regex.Pattern ; 26 27 35 public class PatternSearchMatcher extends SearchMatcher 36 { 37 38 45 public PatternSearchMatcher(String search, boolean ignoreCase) 46 { 47 pattern = search; 48 flags = Pattern.MULTILINE; 49 if (ignoreCase) 50 flags |= Pattern.CASE_INSENSITIVE; 51 } 52 53 71 public SearchMatcher.Match nextMatch(CharSequence text, boolean start, 72 boolean end, boolean firstTime, boolean reverse) 73 { 74 if (re == null) 75 re = Pattern.compile(pattern, flags); 76 77 Matcher match = re.matcher(text); 78 if (!match.find()) 79 return null; 80 81 if (!start && match.start() == 0 85 && re.pattern().charAt(0) == '^' && !match.find()) 86 return null; 87 88 if (!end && match.end() == (text.length() - 1) 92 && pattern.charAt(pattern.length() - 1) == '$') 93 return null; 94 95 returnValue.substitutions = new String [match.groupCount() + 1]; 96 for(int i = 0; i < returnValue.substitutions.length; i++) 97 { 98 returnValue.substitutions[i] = match.group(i); 99 } 100 101 int _start = match.start(); 102 int _end = match.end(); 103 104 returnValue.start = _start; 105 returnValue.end = _end; 106 return returnValue; 107 } 108 109 public boolean isMatchingEOL() 110 { 111 return pattern.charAt(pattern.length() - 1) == '$'; 112 } 113 114 public String toString() 116 { 117 return "PatternSearchMatcher[" + pattern + ']'; 118 } 120 private int flags; 121 private Pattern re; 122 private String pattern; 123 124 } 125 126 | Popular Tags |