ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From umag...@apache.org
Subject cvs commit: jakarta-ant/src/main/org/apache/tools/ant/filters StripJavaComments.java
Date Thu, 07 Mar 2002 18:30:17 GMT
umagesh     02/03/07 10:30:17

  Modified:    src/main/org/apache/tools/ant/filters StripJavaComments.java
  Log:
  Redo comment filtering logic.  The previous one was buggy.  I will add a testcase this evening.
  
  Revision  Changes    Path
  1.2       +37 -37    jakarta-ant/src/main/org/apache/tools/ant/filters/StripJavaComments.java
  
  Index: StripJavaComments.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/filters/StripJavaComments.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- StripJavaComments.java	6 Mar 2002 03:25:50 -0000	1.1
  +++ StripJavaComments.java	7 Mar 2002 18:30:17 -0000	1.2
  @@ -62,11 +62,17 @@
    * (if you have more complex Java parsing needs, use a real lexer).
    * Since this class heavily relies on the single char read function,
    * you are reccomended to make it work on top of a buffered reader.
  + *
  + * @author <a href="mailto:umagesh@apache.org">Magesh Umasankar</a>
    */
   public final class StripJavaComments
       extends BaseFilterReader
       implements ChainableReader
   {
  +    private int readAheadCh = -1;
  +
  +    private boolean inString = false;
  +
       /**
        * This constructor is a dummy constructor and is
        * not meant to be used by any class other than Ant's
  @@ -90,50 +96,44 @@
        * Filter out Java Style comments
        */
       public final int read() throws IOException {
  -        int ch = in.read();
  -        if (ch == '/') {
  +        int ch = -1;
  +        if (readAheadCh != -1) {
  +            ch = readAheadCh;
  +            readAheadCh = -1;
  +        } else {
               ch = in.read();
  -            if (ch == '/') {
  -                while (ch != '\n' && ch != -1) {
  -                    ch = in.read();
  -                }
  -            } else if (ch == '*') {
  -                while (ch != -1) {
  -                    ch = in.read();
  -                    if (ch == '*') {
  +            if (ch == '"') {
  +                inString = !inString;
  +            } else {
  +                if (!inString) {
  +                    if (ch == '/') {
                           ch = in.read();
  -                        while (ch == '*' && ch != -1) {
  -                            ch = in.read();
  -                        }
  -
                           if (ch == '/') {
  -                            ch = read();
  -                            break;
  +                            while (ch != '\n' && ch != -1) {
  +                                ch = in.read();
  +                            }
  +                        } else if (ch == '*') {
  +                            while (ch != -1) {
  +                                ch = in.read();
  +                                if (ch == '*') {
  +                                    ch = in.read();
  +                                    while (ch == '*' && ch != -1) {
  +                                        ch = in.read();
  +                                    }
  +
  +                                    if (ch == '/') {
  +                                        ch = read();
  +                                        break;
  +                                    }
  +                                }
  +                            }
  +                        } else {
  +                            readAheadCh = ch;
  +                            ch = '/';
                           }
                       }
                   }
               }
  -        }
  -
  -        if (ch == '"') {
  -            while (ch != -1) {
  -                ch = in.read();
  -                if (ch == '\\') {
  -                    ch = in.read();
  -                } else if (ch == '"') {
  -                    ch = read();
  -                    break;
  -                }
  -            }
  -        }
  -
  -        if (ch == '\'') {
  -            ch = in.read();
  -            if (ch == '\\') {
  -                ch = in.read();
  -            }
  -            ch = in.read();
  -            ch = read();
           }
   
           return ch;
  
  
  

--
To unsubscribe, e-mail:   <mailto:ant-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:ant-dev-help@jakarta.apache.org>


Mime
View raw message