From 05bf2b0be90bbd94271cee599047006a2c48a4f7 Mon Sep 17 00:00:00 2001 From: Federico Fissore Date: Mon, 11 Nov 2013 12:18:42 +0100 Subject: [PATCH] PrePreprocess.scrubComments doesn't properly work: using RegExp from PrePreprocess.strip. Fixes #817 --- .../app/preproc/PdePreprocessor.java | 51 ++++--------------- 1 file changed, 9 insertions(+), 42 deletions(-) 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; } }