private void init(Project p) { if (!alreadyInit) { this.regexp = FACTORY.newRegexp(p); alreadyInit = true; } } private void setPattern() {
/** * Does the given argument match the pattern using default options? * @param argument the string to match against * @return true if the pattern matches * @throws BuildException on error */ @Override public boolean matches(String argument) throws BuildException { return matches(argument, MATCH_DEFAULT); }
/** * Constructor for RegexpPatternMapper. * @throws BuildException on error. */ public RegexpPatternMapper() throws BuildException { reg = (new RegexpMatcherFactory()).newRegexpMatcher(); }
/** * Convert ant regexp substitution option to jdk1.4 options. * * @param options the ant regexp options * @return the jdk14 substitution options */ protected int getSubsOptions(int options) { int subsOptions = REPLACE_FIRST; if (RegexpUtil.hasFlag(options, REPLACE_ALL)) { subsOptions = REPLACE_ALL; } return subsOptions; }
/** * @return true if the string matches the regular expression pattern * @exception BuildException if the attributes are not set correctly */ public boolean eval() throws BuildException { if (string == null) { throw new BuildException( "Parameter string is required in matches."); } if (regularExpression == null) { throw new BuildException("Missing pattern in matches."); } int options = RegexpUtil.asOptions(caseSensitive, multiLine, singleLine); Regexp regexp = regularExpression.getRegexp(getProject()); return regexp.matches(string, options); } }
/*** * Create a new regular expression instance. * * @param p Project whose ant.regexp.regexpimpl property will be used. * @return the matcher * @throws BuildException on error */ public RegexpMatcher newRegexpMatcher(Project p) throws BuildException { String systemDefault; if (p == null) { systemDefault = System.getProperty(MagicNames.REGEXP_IMPL); } else { systemDefault = p.getProperty(MagicNames.REGEXP_IMPL); } if (systemDefault != null) { return createInstance(systemDefault); // TODO should we silently catch possible exceptions and try to // load a different implementation? } return new Jdk14RegexpMatcher(); }
/** * Attribute specifying whether to ignore the case difference * in the names. * * @param caseSensitive a boolean, default is false. * @since Ant 1.6.3 */ public void setCaseSensitive(boolean caseSensitive) { regexpOptions = RegexpUtil.asOptions(caseSensitive); }
/** * sets the regular expression pattern * @param pattern regular expression pattern */ public void setPattern(String pattern) { if (regexp == null) { myPattern = pattern; setPatternPending = true; } else { regexp.setPattern(pattern); } }
/*** * Create a new regular expression instance. * @return the matcher * @throws BuildException on error */ public RegexpMatcher newRegexpMatcher() throws BuildException { return newRegexpMatcher(null); }
/** * Returns a Vector of matched groups found in the argument * using default options. * * <p>Group 0 will be the full match, the rest are the * parenthesized subexpressions</p>. * * @param argument the string to match against * @return the vector of groups * @throws BuildException on error */ @Override public Vector<String> getGroups(String argument) throws BuildException { return getGroups(argument, MATCH_DEFAULT); }
/** * Sets the "from" pattern. Required. * @param from the from pattern. * @throws BuildException on error. */ @Override public void setFrom(String from) throws BuildException { if (from == null) { throw new BuildException("this mapper requires a 'from' attribute"); } try { reg.setPattern(from); } catch (NoClassDefFoundError e) { // depending on the implementation the actual RE won't // get instantiated in the constructor. throw new BuildException("Cannot load regular expression matcher", e); } }
/*** * Gets the pattern string for this RegularExpression in the * given project. * @param p project * @return pattern */ public String getPattern(Project p) { init(p); if (isReference()) { return getRef(p).getPattern(p); } setPattern(); return regexp.getPattern(); }
/** * Checks if a RegExp-Matcher is available. * @param project The project to check for (may be <code>null</code>) * @return <code>true</code> if available otherwise <code>false</code> */ public static boolean regexpMatcherPresent(Project project) { try { // The factory throws a BuildException if no usable matcher // cannot be instantiated. We don't need the matcher itself here. new RegexpMatcherFactory().newRegexpMatcher(project); return true; } catch (Throwable ex) { return false; } } }
/** * Convert the generic options to the regex compiler specific options. * @param options the generic options * @return the specific options */ protected int getCompilerOptions(int options) { // be strict about line separator int cOptions = Pattern.UNIX_LINES; if (RegexpUtil.hasFlag(options, MATCH_CASE_INSENSITIVE)) { cOptions |= Pattern.CASE_INSENSITIVE; } if (RegexpUtil.hasFlag(options, MATCH_MULTILINE)) { cOptions |= Pattern.MULTILINE; } if (RegexpUtil.hasFlag(options, MATCH_SINGLELINE)) { cOptions |= Pattern.DOTALL; } return cOptions; }
private boolean matches(String name) { if (pattern != null) { return SelectorUtils.match(modify(pattern), modify(name), cs); } if (reg == null) { reg = new RegularExpression(); reg.setPattern(regex); expression = reg.getRegexp(project); } return expression.matches(modify(name), RegexpUtil.asOptions(cs)); }
/** * Whether to match casesensitively. * @param b boolean * @since Ant 1.8.2 */ public void setCaseSensitive(boolean b) { regexpOptions = RegexpUtil.asOptions(b); }
/*** * Create a new regular expression matcher instance. * @return the matcher instance * @throws BuildException on error */ public Regexp newRegexp() throws BuildException { return newRegexp(null); }
private void setPattern() { if (setPatternPending) { regexp.setPattern(myPattern); setPatternPending = false; } } /**
/** * Convert flag to regex options. * * @param caseSensitive opposite of RegexpMatcher.MATCH_CASE_INSENSITIVE * @return the Regexp option bits * @since Ant 1.8.2 */ public static int asOptions(boolean caseSensitive) { return asOptions(caseSensitive, false, false); }
/** * convert regex option flag characters to regex options * <ul> * <li>g - Regexp.REPLACE_ALL</li> * <li>i - Regexp.MATCH_CASE_INSENSITIVE</li> * <li>m - Regexp.MATCH_MULTILINE</li> * <li>s - Regexp.MATCH_SINGLELINE</li> * </ul> * @param flags the string containing the flags * @return the Regexp option bits */ public static int convertRegexOptions(String flags) { return RegexpUtil.asOptions(flags); } }