diff --git a/app/src/processing/app/preproc/PdePreprocessor.java b/app/src/processing/app/preproc/PdePreprocessor.java index e6af0e8df..27a28b455 100644 --- a/app/src/processing/app/preproc/PdePreprocessor.java +++ b/app/src/processing/app/preproc/PdePreprocessor.java @@ -334,49 +334,16 @@ public class PdePreprocessor { * Utility function used here and in the preprocessor. */ static public String scrubComments(String what) { - char p[] = what.toCharArray(); + List patterns = new ArrayList(); + patterns.add(Pattern.compile("('\\\\\"')", Pattern.MULTILINE)); + patterns.add(Pattern.compile("(//.*?$)", Pattern.MULTILINE)); + patterns.add(Pattern.compile("(/\\*[^*]*(?:\\*(?!/)[^*]*)*\\*/)", Pattern.MULTILINE)); - int index = 0; - while (index < p.length) { - // for any double slash comments, ignore until the end of the line - if ((p[index] == '/') && - (index < p.length - 1) && - (p[index+1] == '/')) { - p[index++] = ' '; - p[index++] = ' '; - while ((index < p.length) && - (p[index] != '\n')) { - p[index++] = ' '; - } - - // check to see if this is the start of a new multiline comment. - // if it is, then make sure it's actually terminated somewhere. - } else if ((p[index] == '/') && - (index < p.length - 1) && - (p[index+1] == '*')) { - p[index++] = ' '; - p[index++] = ' '; - boolean endOfRainbow = false; - while (index < p.length - 1) { - if ((p[index] == '*') && (p[index+1] == '/')) { - p[index++] = ' '; - p[index++] = ' '; - endOfRainbow = true; - break; - - } else { - // continue blanking this area - p[index++] = ' '; - } - } - if (!endOfRainbow) { - throw new RuntimeException(_("Missing the */ from the end of a " + - "/* comment */")); - } - } else { // any old character, move along - index++; - } + String result = what; + for (Pattern p : patterns) { + result = p.matcher(result).replaceAll(""); } - return new String(p); + + return result; } }