jakarta-oro-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d..@apache.org
Subject cvs commit: jakarta-oro/src/java/org/apache/oro/text/regex Perl5Substitution.java
Date Tue, 20 Feb 2001 02:31:28 GMT
dfs         01/02/19 18:31:28

  Modified:    src/java/examples printPasswd.java
               src/java/examples/awk splitExample.java
               src/java/org/apache/oro/text/regex Perl5Substitution.java
  Log:
  Removed the use of deprecated split method in printPasswd.
  Replaced use of Vector with ArrayList in splitExample.
  Changed _substitutions to an ArrayList in Perl5Substitution.
  
  Revision  Changes    Path
  1.3       +11 -5     jakarta-oro/src/java/examples/printPasswd.java
  
  Index: printPasswd.java
  ===================================================================
  RCS file: /home/cvs/jakarta-oro/src/java/examples/printPasswd.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- printPasswd.java	2000/07/23 23:25:11	1.2
  +++ printPasswd.java	2001/02/20 02:31:28	1.3
  @@ -66,7 +66,7 @@
    * on a Unix system) and printing out the formatted entries.
    *
    @author <a href="mailto:dfs@savarese.org">Daniel F. Savarese</a>
  - @version $Id: printPasswd.java,v 1.2 2000/07/23 23:25:11 jon Exp $
  + @version $Id: printPasswd.java,v 1.3 2001/02/20 02:31:28 dfs Exp $
    */
   public final class printPasswd {
     public static final String[] fieldNames = {
  @@ -78,8 +78,9 @@
       BufferedReader input = null;
       int field, record;
       String line;
  -    Enumeration fields;
       Perl5Util perl;
  +    ArrayList fields;
  +    Iterator it;
   
       try {
         input = new BufferedReader(new FileReader("/etc/passwd"));
  @@ -93,15 +94,20 @@
       record = 0;
   
       try {
  +      fields = new ArrayList();
  +
         while((line = input.readLine()) != null) {
  -	fields = perl.split("/:/", line).elements();
  +	fields.clear();
  +	perl.split(fields, "/:/", line);
  +
  +	it = fields.iterator();
   	field = 0;
   
   	System.out.println("Record " + record++); 
   
  -	while(fields.hasMoreElements() && field < fieldNames.length)
  +	while(it.hasNext() && field < fieldNames.length)
   	  System.out.println(fieldNames[field++] + 
  -			     (String)fields.nextElement());
  +			     (String)it.next());
   
   	System.out.print("\n\n");
         }
  
  
  
  1.3       +10 -6     jakarta-oro/src/java/examples/awk/splitExample.java
  
  Index: splitExample.java
  ===================================================================
  RCS file: /home/cvs/jakarta-oro/src/java/examples/awk/splitExample.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- splitExample.java	2000/07/23 23:25:13	1.2
  +++ splitExample.java	2001/02/20 02:31:28	1.3
  @@ -64,7 +64,7 @@
    * it uses Awk classes instead of Perl classes.
    *
    @author <a href="mailto:dfs@savarese.org">Daniel F. Savarese</a>
  - @version $Id: splitExample.java,v 1.2 2000/07/23 23:25:13 jon Exp $
  + @version $Id: splitExample.java,v 1.3 2001/02/20 02:31:28 dfs Exp $
    */
   public final class splitExample {
   
  @@ -88,10 +88,11 @@
     public static final void main(String args[]) {
       int limit, i;
       String regularExpression, input;
  -    Vector results;
  +    List results = new ArrayList();
       Pattern pattern = null;
       PatternMatcher matcher;
       PatternCompiler compiler;
  +    Iterator elements;
   
       // Make sure there are sufficient arguments
       if(args.length < 2) {
  @@ -124,9 +125,12 @@
   
       // Split the input and print the resulting list.
       System.out.println("split results: ");
  -    results = Util.split(matcher, pattern, input, limit);
  -    for(i = 0; i < results.size(); i++){
  -      System.out.println("item " + i + ": " + (String)results.elementAt(i));
  -    }
  +    Util.split(results, matcher, pattern, input, limit);
  +    elements = results.iterator();
  +
  +    i = 0;
  +    while(elements.hasNext())
  +      System.out.println("item " + i++ + ": " + (String)elements.next());
  +
     }
   }
  
  
  
  1.3       +17 -16    jakarta-oro/src/java/org/apache/oro/text/regex/Perl5Substitution.java
  
  Index: Perl5Substitution.java
  ===================================================================
  RCS file: /home/cvs/jakarta-oro/src/java/org/apache/oro/text/regex/Perl5Substitution.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- Perl5Substitution.java	2000/07/23 23:25:27	1.2
  +++ Perl5Substitution.java	2001/02/20 02:31:28	1.3
  @@ -57,7 +57,7 @@
    * by Daniel F. Savarese. We appreciate his contributions.
    */
   
  -import java.util.Vector;
  +import java.util.*;
   
   /**
    * Perl5Substitution implements a Substitution consisting of a
  @@ -112,7 +112,7 @@
    * Also, <b>$0</b> is always interpreted literally.
   
    @author <a href="mailto:dfs@savarese.org">Daniel F. Savarese</a>
  - @version $Id: Perl5Substitution.java,v 1.2 2000/07/23 23:25:27 jon Exp $
  + @version $Id: Perl5Substitution.java,v 1.3 2001/02/20 02:31:28 dfs Exp $
   
    * @see Substitution
    * @see Util
  @@ -136,17 +136,17 @@
     public static final int INTERPOLATE_NONE = -1;
   
     int _numInterpolations;
  -  Vector _substitutions;
  +  ArrayList _substitutions;
     transient String _lastInterpolation;
   
  -  static Vector _parseSubs(String sub) {
  +  static ArrayList _parseSubs(String sub) {
       boolean saveDigits, storedInterpolation;
       int current;
       char[] str;
  -    Vector subs;
  +    ArrayList subs;
       StringBuffer numBuffer, strBuffer;
   
  -    subs = new Vector(5);
  +    subs = new ArrayList(5);
       numBuffer = new StringBuffer(5);
       strBuffer = new StringBuffer(10);
   
  @@ -160,16 +160,16 @@
   	numBuffer.append(str[current]);
   
   	if(strBuffer.length() > 0) {
  -	  subs.addElement(strBuffer.toString());
  +	  subs.add(strBuffer.toString());
   	  strBuffer.setLength(0);
   	}
         } else {
   	if(saveDigits) {
   	  try {
  -	    subs.addElement(new Integer(numBuffer.toString()));
  +	    subs.add(new Integer(numBuffer.toString()));
   	    storedInterpolation = true;
   	  } catch(NumberFormatException e) {
  -	    subs.addElement(numBuffer.toString());
  +	    subs.add(numBuffer.toString());
   	  }
   
   	  numBuffer.setLength(0);
  @@ -190,13 +190,13 @@
   
       if(saveDigits) {
         try {
  -	subs.addElement(new Integer(numBuffer.toString()));
  +	subs.add(new Integer(numBuffer.toString()));
   	storedInterpolation = true;
         } catch(NumberFormatException e) {
  -	subs.addElement(numBuffer.toString());
  +	subs.add(numBuffer.toString());
         }
       } else if(strBuffer.length() > 0)
  -      subs.addElement(strBuffer.toString());
  +      subs.add(strBuffer.toString());
   
       return (storedInterpolation ? subs : null);
     }
  @@ -209,15 +209,16 @@
     }
   
     void _calcSub(StringBuffer buffer, MatchResult result) {
  -    int size, element, value;
  +    int size, value;
       Object obj;
       Integer integer;
       String group;
  +    Iterator it;
   
  -    size = _substitutions.size();
  +    it = _substitutions.iterator();
   
  -    for(element=0; element < size; element++) {
  -      obj = _substitutions.elementAt(element);
  +    while(it.hasNext()) {
  +      obj = it.next();
   
         if(obj instanceof String)
   	buffer.append(obj);
  
  
  

Mime
View raw message