ant-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject svn commit: r986445 - in /ant/core/trunk/src/main/org/apache/tools/ant: filters/ taskdefs/condition/ taskdefs/optional/ types/resources/selectors/ types/selectors/ util/ util/regexp/
Date Tue, 17 Aug 2010 18:30:52 GMT
Author: bodewig
Date: Tue Aug 17 18:30:52 2010
New Revision: 986445

URL: http://svn.apache.org/viewvc?rev=986445&view=rev
Log:
merge redundant code

Modified:
    ant/core/trunk/src/main/org/apache/tools/ant/filters/TokenFilter.java
    ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/condition/Matches.java
    ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/ReplaceRegExp.java
    ant/core/trunk/src/main/org/apache/tools/ant/types/resources/selectors/Name.java
    ant/core/trunk/src/main/org/apache/tools/ant/types/selectors/FilenameSelector.java
    ant/core/trunk/src/main/org/apache/tools/ant/util/RegexpPatternMapper.java
    ant/core/trunk/src/main/org/apache/tools/ant/util/regexp/RegexpUtil.java

Modified: ant/core/trunk/src/main/org/apache/tools/ant/filters/TokenFilter.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/filters/TokenFilter.java?rev=986445&r1=986444&r2=986445&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/filters/TokenFilter.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/filters/TokenFilter.java Tue Aug 17 18:30:52
2010
@@ -29,6 +29,7 @@ import org.apache.tools.ant.util.Tokeniz
 import org.apache.tools.ant.util.LineTokenizer;
 import org.apache.tools.ant.util.StringUtils;
 import org.apache.tools.ant.util.regexp.Regexp;
+import org.apache.tools.ant.util.regexp.RegexpUtil;
 
 /**
  * This splits up input into tokens and passes
@@ -705,22 +706,6 @@ public class TokenFilter extends BaseFil
      * @return the Regexp option bits
      */
     public static int convertRegexOptions(String flags) {
-        if (flags == null) {
-            return 0;
-        }
-        int options = 0;
-        if (flags.indexOf('g') != -1) {
-            options |= Regexp.REPLACE_ALL;
-        }
-        if (flags.indexOf('i') != -1) {
-            options |= Regexp.MATCH_CASE_INSENSITIVE;
-        }
-        if (flags.indexOf('m') != -1) {
-            options |= Regexp.MATCH_MULTILINE;
-        }
-        if (flags.indexOf('s') != -1) {
-            options |= Regexp.MATCH_SINGLELINE;
-        }
-        return options;
+        return RegexpUtil.asOptions(flags);
     }
 }

Modified: ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/condition/Matches.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/condition/Matches.java?rev=986445&r1=986444&r2=986445&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/condition/Matches.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/condition/Matches.java Tue Aug 17
18:30:52 2010
@@ -19,9 +19,9 @@ package org.apache.tools.ant.taskdefs.co
 
 import org.apache.tools.ant.BuildException;
 import org.apache.tools.ant.ProjectComponent;
-import org.apache.tools.ant.util.regexp.Regexp;
 import org.apache.tools.ant.types.RegularExpression;
-import org.apache.tools.ant.util.regexp.RegexpMatcher;
+import org.apache.tools.ant.util.regexp.Regexp;
+import org.apache.tools.ant.util.regexp.RegexpUtil;
 
 /**
  * Simple regular expression condition.
@@ -112,16 +112,7 @@ public class Matches extends ProjectComp
         if (regularExpression == null) {
             throw new BuildException("Missing pattern in matches.");
         }
-        int options = RegexpMatcher.MATCH_DEFAULT;
-        if (!caseSensitive) {
-            options = options | RegexpMatcher.MATCH_CASE_INSENSITIVE;
-        }
-        if (multiLine) {
-            options = options | RegexpMatcher.MATCH_MULTILINE;
-        }
-        if (singleLine) {
-            options = options | RegexpMatcher.MATCH_SINGLELINE;
-        }
+        int options = RegexpUtil.asOptions(caseSensitive, multiLine, singleLine);
         Regexp regexp = regularExpression.getRegexp(getProject());
         return regexp.matches(string, options);
     }

Modified: ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/ReplaceRegExp.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/ReplaceRegExp.java?rev=986445&r1=986444&r2=986445&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/ReplaceRegExp.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/ReplaceRegExp.java Tue
Aug 17 18:30:52 2010
@@ -43,6 +43,7 @@ import org.apache.tools.ant.types.resour
 import org.apache.tools.ant.types.resources.Union;
 import org.apache.tools.ant.util.FileUtils;
 import org.apache.tools.ant.util.regexp.Regexp;
+import org.apache.tools.ant.util.regexp.RegexpUtil;
 
 /**
  * Performs regular expression string replacements in a text
@@ -513,23 +514,7 @@ public class ReplaceRegExp extends Task 
                                      + "time.");
         }
 
-        int options = 0;
-
-        if (flags.indexOf('g') != -1) {
-            options |= Regexp.REPLACE_ALL;
-        }
-
-        if (flags.indexOf('i') != -1) {
-            options |= Regexp.MATCH_CASE_INSENSITIVE;
-        }
-
-        if (flags.indexOf('m') != -1) {
-            options |= Regexp.MATCH_MULTILINE;
-        }
-
-        if (flags.indexOf('s') != -1) {
-            options |= Regexp.MATCH_SINGLELINE;
-        }
+        int options = RegexpUtil.asOptions(flags);
 
         if (file != null && file.exists()) {
             try {

Modified: ant/core/trunk/src/main/org/apache/tools/ant/types/resources/selectors/Name.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/types/resources/selectors/Name.java?rev=986445&r1=986444&r2=986445&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/types/resources/selectors/Name.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/types/resources/selectors/Name.java Tue Aug
17 18:30:52 2010
@@ -22,6 +22,7 @@ import org.apache.tools.ant.types.Regula
 import org.apache.tools.ant.types.Resource;
 import org.apache.tools.ant.types.selectors.SelectorUtils;
 import org.apache.tools.ant.util.regexp.Regexp;
+import org.apache.tools.ant.util.regexp.RegexpUtil;
 
 /**
  * Name ResourceSelector.
@@ -137,11 +138,7 @@ public class Name implements ResourceSel
                 reg.setPattern(regex);
                 expression = reg.getRegexp(project);
             }
-            int options = Regexp.MATCH_DEFAULT;
-            if (!cs) {
-                options |= Regexp.MATCH_CASE_INSENSITIVE;
-            }
-            return expression.matches(modify(name), options);
+            return expression.matches(modify(name), RegexpUtil.asOptions(cs));
         }
     }
 

Modified: ant/core/trunk/src/main/org/apache/tools/ant/types/selectors/FilenameSelector.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/types/selectors/FilenameSelector.java?rev=986445&r1=986444&r2=986445&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/types/selectors/FilenameSelector.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/types/selectors/FilenameSelector.java Tue
Aug 17 18:30:52 2010
@@ -24,6 +24,7 @@ import org.apache.tools.ant.Project;
 import org.apache.tools.ant.types.Parameter;
 import org.apache.tools.ant.types.RegularExpression;
 import org.apache.tools.ant.util.regexp.Regexp;
+import org.apache.tools.ant.util.regexp.RegexpUtil;
 
 /**
  * Selector that filters files based on the filename.
@@ -185,10 +186,7 @@ public class FilenameSelector extends Ba
                 reg.setPattern(regex);
                 expression = reg.getRegexp(getProject());
             }
-            int options = Regexp.MATCH_DEFAULT;
-            if (!casesensitive) {
-                options |= Regexp.MATCH_CASE_INSENSITIVE;
-            }
+            int options = RegexpUtil.asOptions(casesensitive);
             return expression.matches(filename, options) == !negated;
         }
     }

Modified: ant/core/trunk/src/main/org/apache/tools/ant/util/RegexpPatternMapper.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/util/RegexpPatternMapper.java?rev=986445&r1=986444&r2=986445&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/util/RegexpPatternMapper.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/util/RegexpPatternMapper.java Tue Aug 17
18:30:52 2010
@@ -22,6 +22,7 @@ import java.util.Vector;
 import org.apache.tools.ant.BuildException;
 import org.apache.tools.ant.util.regexp.RegexpMatcher;
 import org.apache.tools.ant.util.regexp.RegexpMatcherFactory;
+import org.apache.tools.ant.util.regexp.RegexpUtil;
 
 /**
  * Implementation of FileNameMapper that does regular expression
@@ -67,11 +68,7 @@ public class RegexpPatternMapper impleme
      * @since Ant 1.6.3
      */
     public void setCaseSensitive(boolean caseSensitive) {
-        if (!caseSensitive) {
-            regexpOptions = RegexpMatcher.MATCH_CASE_INSENSITIVE;
-        } else {
-            regexpOptions = 0;
-        }
+        regexpOptions = RegexpUtil.asOptions(caseSensitive);
     }
 
     /**

Modified: ant/core/trunk/src/main/org/apache/tools/ant/util/regexp/RegexpUtil.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/util/regexp/RegexpUtil.java?rev=986445&r1=986444&r2=986445&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/util/regexp/RegexpUtil.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/util/regexp/RegexpUtil.java Tue Aug 17 18:30:52
2010
@@ -46,4 +46,64 @@ public class RegexpUtil {
     public static int removeFlag(int options, int flag) {
         return (options & (0xFFFFFFFF - flag));
     }
+
+    /**
+     * convert regex option flag characters to regex options
+     * <dl>
+     *   <li>g -  Regexp.REPLACE_ALL</li>
+     *   <li>i -  RegexpMatcher.MATCH_CASE_INSENSITIVE</li>
+     *   <li>m -  RegexpMatcher.MATCH_MULTILINE</li>
+     *   <li>s -  RegexpMatcher.MATCH_SINGLELINE</li>
+     * </dl>
+     * @param flags the string containing the flags
+     * @return the Regexp option bits
+     * @since Ant 1.8.2
+     */
+    public static int asOptions(String flags) {
+        int options = RegexpMatcher.MATCH_DEFAULT;
+        if (flags != null) {
+            options = asOptions(flags.indexOf('i') == -1,
+                                flags.indexOf('m') != -1,
+                                flags.indexOf('s') != -1);
+            if (flags.indexOf('g') != -1) {
+                options |= Regexp.REPLACE_ALL;
+            }
+        }
+        return options;
+    }
+
+    /**
+     * 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 flags to regex options.
+     *
+     * @param caseSensitive opposite of RegexpMatcher.MATCH_CASE_INSENSITIVE
+     * @param multiLine RegexpMatcher.MATCH_MULTILINE
+     * @param singleLine RegexpMatcher.MATCH_SINGLELINE
+     * @return the Regexp option bits
+     * @since Ant 1.8.2
+     */
+    public static int asOptions(boolean caseSensitive, boolean multiLine,
+                                boolean singleLine) {
+        int options = RegexpMatcher.MATCH_DEFAULT;
+        if (!caseSensitive) {
+            options = options | RegexpMatcher.MATCH_CASE_INSENSITIVE;
+        }
+        if (multiLine) {
+            options = options | RegexpMatcher.MATCH_MULTILINE;
+        }
+        if (singleLine) {
+            options = options | RegexpMatcher.MATCH_SINGLELINE;
+        }
+        return options;
+    }
 }



Mime
View raw message