Attribute |
diff --git a/docs/manual/CoreTypes/regexp.html b/docs/manual/CoreTypes/regexp.html
new file mode 100644
index 000000000..b8edda158
--- /dev/null
+++ b/docs/manual/CoreTypes/regexp.html
@@ -0,0 +1,98 @@
+
+
+
+
+Regexp Type
+
+
+
+
+
+
+Regexp represents a regular expression.
+
Parameters
+
+
+ Attribute |
+ Description |
+ Required |
+
+
+ pattern |
+ regular expression pattern |
+ Yes |
+
+
+
+Examples
+
+ <regexp id="myregexp" pattern="alpha(.+)beta"/>
+
+
+Defines a regular expression for later use with id myregexp.
+
+
+ <regexp refid="myregexp"/>
+
+
+Use the regular expression with id myregexp.
+
+
+Choice of regular expression implementation
+
+Ant comes with
+wrappers for
+the java.util.regex package of JDK 1.4,
+jakarta-regexp
+and jakarta-ORO,
+See installation dependencies
+ concerning the supporting libraries.
+
+The property ant.regexp.regexpimpl
governs which regular expression implementation will be chosen.
+Possible values for this property are :
+
+-
+org.apache.tools.ant.util.regexp.Jdk14RegexpRegexp
+
+-
+org.apache.tools.ant.util.regexp.JakartaOroRegexp
+
+-
+org.apache.tools.ant.util.regexp.JakartaRegexpRegexp
+
+
+It can also be another implementation of the interface org.apache.tools.ant.util.regexp.Regexp
.
+If ant.regexp.regexpimpl
is not defined, ant checks in the order Jdk14Regexp, JakartaOroRegexp,
+ JakartaRegexp for the availability of the corresponding library. The first of these 3 which is found will be used.
+
+There are cross-platform issues for matches related to line terminator.
+For example if you use $ to anchor your regular expression on the end of a line
+the results might be very different depending on both your platform and the regular
+expression library you use. It is 'highly recommended' that you test your pattern on
+both Unix and Windows platforms before you rely on it.
+
+ - Jakarta Oro defines a line terminator as '\n' and is consistent with Perl.
+ - Jakarta RegExp uses a system-dependant line terminator.
+ - JDK 1.4 uses '\n', '\r\n', '\u0085', '\u2028', '\u2029' as a default
+ but is configured in the wrapper to use only '\n' (UNIX_LINE)
+
+We strongly recommend that you use Jakarta Oro.
+
+Usage
+The following tasks and types use the Regexp type :
+
+
+These string filters also use the mechanism of regexp to choose a regular expression implementation :
+
+
+
+Copyright © 2003 Apache Software Foundation.
+All rights Reserved.
+
+
diff --git a/docs/manual/OptionalTasks/replaceregexp.html b/docs/manual/OptionalTasks/replaceregexp.html
index dec669b85..543205889 100644
--- a/docs/manual/OptionalTasks/replaceregexp.html
+++ b/docs/manual/OptionalTasks/replaceregexp.html
@@ -19,7 +19,8 @@ have been regenerated by this task.
Similar to regexp
type mappers this task needs a supporting regular expression
library and an implementation of
-org.apache.tools.ant.util.regexp.Regexp
. See details below.
+org.apache.tools.ant.util.regexp.Regexp
.
+See details in the documentation of the Regexp Type.
Parameters
@@ -79,51 +80,11 @@ library and an implementation of
replaces occurrences of the property name "OldProperty"
with "NewProperty" in a properties file, preserving the existing
value, in the file ${src}/build.properties
-
-Choice of regular expression implementation
-
-Ant comes with
-wrappers for
-the java.util.regex package of JDK 1.4,
-jakarta-regexp
-and jakarta-ORO,
-See installation dependencies
- concerning the supporting libraries.
-
-The system property ant.regexp.regexpimpl
governs which regular expression implementation will be chosen.
-Possible values for this property are :
-
--
-org.apache.tools.ant.util.regexp.Jdk14RegexpRegexp
-
--
-org.apache.tools.ant.util.regexp.JakartaOroRegexp
-
--
-org.apache.tools.ant.util.regexp.JakartaRegexpRegexp
-
-
-It can also be another implementation of the interface org.apache.tools.ant.util.regexp.Regexp
.
-If ant.regexp.regexpimpl
is not defined, ant checks in the order Jdk14Regexp, JakartaOroRegexp,
- JakartaRegexp for the availability of the corresponding library. The first of these 3 which is found will be used.
-
-There are cross-platform issues for matches related to line terminator.
-For example if you use $ to anchor your regular expression on the end of a line
-the results might be very different depending on both your platform and the regular
-expression library you use. It is 'highly recommended' that you test your pattern on
-both Unix and Windows platforms before you rely on it.
-
- - Jakarta Oro defines a line terminator as '\n' and is consistent with Perl.
- - Jakarta RegExp uses a system-dependant line terminator.
- - JDK 1.4 uses '\n', '\r\n', '\u0085', '\u2028', '\u2029' as a default
- but is configured in the wrapper to use only '\n' (UNIX_LINE)
-
-We strongly recommend that you use Jakarta Oro.
-
+
Parameters specified as nested elements
This task supports a nested FileSet
element.
-This task supports a nested Regexp element to specify
+
This task supports a nested Regexp element to specify
the regular expression. You can use this element to refer to a previously
defined regular expression datatype instance.
diff --git a/docs/manual/conceptstypeslist.html b/docs/manual/conceptstypeslist.html
index 3ec9ed6b2..a9cfa6021 100644
--- a/docs/manual/conceptstypeslist.html
+++ b/docs/manual/conceptstypeslist.html
@@ -27,6 +27,7 @@
Path-like Structures
Permissions
PropertySet
+Regexp
Selectors
XMLCatalog
ZipFileSet
diff --git a/src/main/org/apache/tools/ant/types/RegularExpression.java b/src/main/org/apache/tools/ant/types/RegularExpression.java
index bd76aed9e..78508d447 100644
--- a/src/main/org/apache/tools/ant/types/RegularExpression.java
+++ b/src/main/org/apache/tools/ant/types/RegularExpression.java
@@ -1,7 +1,7 @@
/*
* The Apache Software License, Version 1.1
*
- * Copyright (c) 2001-2002 The Apache Software Foundation. All rights
+ * Copyright (c) 2001-2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -99,42 +99,81 @@ import org.apache.tools.ant.util.regexp.RegexpFactory;
public class RegularExpression extends DataType {
/** Name of this data type */
public static final String DATA_TYPE_NAME = "regexp";
+ private boolean alreadyInit = false;
// The regular expression factory
- private static final RegexpFactory factory = new RegexpFactory();
+ private static final RegexpFactory FACTORY = new RegexpFactory();
- private Regexp regexp;
+ private Regexp regexp = null;
+ // temporary variable
+ private String myPattern;
+ private boolean setPatternPending = false;
+ /**
+ * default constructor
+ */
public RegularExpression() {
- this.regexp = factory.newRegexp();
}
+ private void init(Project p) {
+ if (!alreadyInit) {
+ this.regexp = FACTORY.newRegexp(p);
+ alreadyInit = true;
+ }
+ }
+ private void setPattern() {
+ if (setPatternPending) {
+ regexp.setPattern(myPattern);
+ setPatternPending = false;
+ }
+ }
+ /**
+ * sets the regular expression pattern
+ * @param pattern regular expression pattern
+ */
public void setPattern(String pattern) {
- this.regexp.setPattern(pattern);
+ if (regexp == null) {
+ myPattern = pattern;
+ setPatternPending = true;
+ } else {
+ regexp.setPattern(pattern);
+ }
}
/***
* 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();
}
+ /**
+ * provides a reference to the Regexp contained in this
+ * @param p project
+ * @return Regexp instance associated with this RegularExpression instance
+ */
public Regexp getRegexp(Project p) {
+ init(p);
if (isReference()) {
return getRef(p).getRegexp(p);
}
+ setPattern();
return this.regexp;
}
/***
* Get the RegularExpression this reference refers to in
* the given project. Check for circular references too
+ * @param p project
+ * @return resolved RegularExpression instance
*/
public RegularExpression getRef(Project p) {
if (!isChecked()) {
@@ -147,7 +186,7 @@ public class RegularExpression extends DataType {
Object o = getRefid().getReferencedObject(p);
if (!(o instanceof RegularExpression)) {
String msg = getRefid().getRefId() + " doesn\'t denote a "
- + DATA_TYPE_NAME;
+ + DATA_TYPE_NAME;
throw new BuildException(msg);
} else {
return (RegularExpression) o;