Browse Source

<stripjavacomments> would consider // inside String constants comments.

PR: 17441
Submitted by:	Jan Materne <jan at materne dot de>


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@274330 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 22 years ago
parent
commit
c699181d06
2 changed files with 12 additions and 3 deletions
  1. +1
    -1
      src/etc/testcases/filters/expected/stripjavacomments.test
  2. +11
    -2
      src/main/org/apache/tools/ant/filters/StripJavaComments.java

+ 1
- 1
src/etc/testcases/filters/expected/stripjavacomments.test View File

@@ -14,6 +14,6 @@ public class NormalLine {
} }


private String url = "http://ant.apache.org/"; private String url = "http://ant.apache.org/";
private String url2 = "\"http://ant.apache.org/\"";
private String url2 = "\"http://ant.apache.org/\"";


} }

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

@@ -1,7 +1,7 @@
/* /*
* The Apache Software License, Version 1.1 * The Apache Software License, Version 1.1
* *
* Copyright (c) 2002 The Apache Software Foundation. All rights
* Copyright (c) 2002-2003 The Apache Software Foundation. All rights
* reserved. * reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@@ -80,6 +80,11 @@ public final class StripJavaComments
*/ */
private boolean inString = false; private boolean inString = false;


/**
* Whether or not the last char has been a backslash.
*/
private boolean quoted = false;

/** /**
* Constructor for "dummy" instances. * Constructor for "dummy" instances.
* *
@@ -116,9 +121,13 @@ public final class StripJavaComments
readAheadCh = -1; readAheadCh = -1;
} else { } else {
ch = in.read(); ch = in.read();
if (ch == '"') {
if (ch == '"' && !quoted) {
inString = !inString; inString = !inString;
quoted = false;
} else if (ch == '\\') {
quoted = !quoted;
} else { } else {
quoted = false;
if (!inString) { if (!inString) {
if (ch == '/') { if (ch == '/') {
ch = in.read(); ch = in.read();


Loading…
Cancel
Save