Browse Source

Redo comment filtering logic. The previous one was buggy. I will add a testcase this evening.

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@271788 13f79535-47bb-0310-9956-ffa450edef68
master
Magesh Umasankar 23 years ago
parent
commit
a1e68fb8c7
1 changed files with 37 additions and 37 deletions
  1. +37
    -37
      src/main/org/apache/tools/ant/filters/StripJavaComments.java

+ 37
- 37
src/main/org/apache/tools/ant/filters/StripJavaComments.java View File

@@ -62,11 +62,17 @@ import java.io.Reader;
* (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,52 +96,46 @@ public final class StripJavaComments
* 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;
}



Loading…
Cancel
Save