1 18 package org.apache.tools.ant.util.regexp; 19 20 import org.apache.oro.text.regex.Perl5Substitution; 21 import org.apache.oro.text.regex.Substitution; 22 import org.apache.oro.text.regex.Util; 23 import org.apache.tools.ant.BuildException; 24 25 26 27 30 public class JakartaOroRegexp extends JakartaOroMatcher implements Regexp { 31 32 33 public JakartaOroRegexp() { 34 super(); 35 } 36 37 45 public String substitute(String input, String argument, int options) 46 throws BuildException { 47 StringBuffer subst = new StringBuffer (); 49 for (int i = 0; i < argument.length(); i++) { 50 char c = argument.charAt(i); 51 if (c == '$') { 52 subst.append('\\'); 53 subst.append('$'); 54 } else if (c == '\\') { 55 if (++i < argument.length()) { 56 c = argument.charAt(i); 57 int value = Character.digit(c, 10); 58 if (value > -1) { 59 subst.append("$").append(value); 60 } else { 61 subst.append(c); 62 } 63 } else { 64 subst.append('\\'); 66 } 67 } else { 68 subst.append(c); 69 } 70 } 71 72 73 Substitution s = 75 new Perl5Substitution(subst.toString(), 76 Perl5Substitution.INTERPOLATE_ALL); 77 return Util.substitute(matcher, 78 getCompiledPattern(options), 79 s, 80 input, 81 getSubsOptions(options)); 82 } 83 84 90 protected int getSubsOptions(int options) { 91 boolean replaceAll = RegexpUtil.hasFlag(options, REPLACE_ALL); 92 int subsOptions = 1; 93 if (replaceAll) { 94 subsOptions = Util.SUBSTITUTE_ALL; 95 } 96 return subsOptions; 97 } 98 99 } 100 | Popular Tags |