1 32 package net.sf.retrotranslator.runtime.java.util.regex; 33 34 import java.util.regex.*; 35 import net.sf.retrotranslator.runtime.impl.MatchResultImpl; 36 37 40 public class _Matcher { 41 42 public static String quoteReplacement(String s) { 43 if (s.indexOf('\\') < 0 && s.indexOf('$') < 0) return s; 44 StringBuffer buffer = new StringBuffer (); 45 for (int i = 0; i < s.length(); i++) { 46 char c = s.charAt(i); 47 if (c == '\\' || c == '$') buffer.append('\\'); 48 buffer.append(c); 49 } 50 return buffer.toString(); 51 } 52 53 public static MatchResult toMatchResult(Matcher matcher) { 54 boolean available = true; 55 int groupCount = matcher.groupCount(); 56 int[] starts = new int[groupCount + 1]; 57 int[] ends = new int[groupCount + 1]; 58 String [] groups = new String [groupCount + 1]; 59 try { 60 for (int i = 0; i <= groupCount; i++) { 61 starts[i] = matcher.start(i); 62 ends[i] = matcher.end(i); 63 groups[i] = matcher.group(i); 64 } 65 } catch (IllegalStateException e) { 66 available = false; 67 } 68 return new MatchResultImpl(available, groupCount, starts, ends, groups); 69 } 70 71 } 72 | Popular Tags |