1 18 package org.apache.tools.ant.util.regexp; 19 20 21 import java.util.Vector ; 22 import org.apache.regexp.RE; 23 import org.apache.tools.ant.BuildException; 24 25 28 public class JakartaRegexpRegexp extends JakartaRegexpMatcher 29 implements Regexp { 30 31 32 public JakartaRegexpRegexp() { 33 super(); 34 } 35 36 42 protected int getSubsOptions(int options) { 43 int subsOptions = RE.REPLACE_FIRSTONLY; 44 if (RegexpUtil.hasFlag(options, REPLACE_ALL)) { 45 subsOptions = RE.REPLACE_ALL; 46 } 47 return subsOptions; 48 } 49 50 58 public String substitute(String input, String argument, int options) 59 throws BuildException { 60 Vector v = getGroups(input, options); 61 62 StringBuffer result = new StringBuffer (); 64 for (int i = 0; i < argument.length(); i++) { 65 char c = argument.charAt(i); 66 if (c == '\\') { 67 if (++i < argument.length()) { 68 c = argument.charAt(i); 69 int value = Character.digit(c, 10); 70 if (value > -1) { 71 result.append((String ) v.elementAt(value)); 72 } else { 73 result.append(c); 74 } 75 } else { 76 result.append('\\'); 78 } 79 } else { 80 result.append(c); 81 } 82 } 83 argument = result.toString(); 84 85 RE reg = getCompiledPattern(options); 86 int sOptions = getSubsOptions(options); 87 return reg.subst(input, argument, sOptions); 88 } 89 } 90 | Popular Tags |