Skip to content

Commit 7a3fb0c

Browse files
author
Federico Fissore
committed
Merge branch 'ide-1.5.x' into ide-1.5.x-jssc
2 parents 5dc9e53 + e1579af commit 7a3fb0c

File tree

3 files changed

+10
-46
lines changed

3 files changed

+10
-46
lines changed

app/src/processing/app/preproc/PdePreprocessor.java

Lines changed: 9 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -334,49 +334,16 @@ public ArrayList<String> prototypes(String in) {
334334
* Utility function used here and in the preprocessor.
335335
*/
336336
static public String scrubComments(String what) {
337-
char p[] = what.toCharArray();
338-
339-
int index = 0;
340-
while (index < p.length) {
341-
// for any double slash comments, ignore until the end of the line
342-
if ((p[index] == '/') &&
343-
(index < p.length - 1) &&
344-
(p[index+1] == '/')) {
345-
p[index++] = ' ';
346-
p[index++] = ' ';
347-
while ((index < p.length) &&
348-
(p[index] != '\n')) {
349-
p[index++] = ' ';
350-
}
337+
List<Pattern> patterns = new ArrayList<Pattern>();
338+
patterns.add(Pattern.compile("('\\\\\"')", Pattern.MULTILINE));
339+
patterns.add(Pattern.compile("(//.*?$)", Pattern.MULTILINE));
340+
patterns.add(Pattern.compile("(/\\*[^*]*(?:\\*(?!/)[^*]*)*\\*/)", Pattern.MULTILINE));
351341

352-
// check to see if this is the start of a new multiline comment.
353-
// if it is, then make sure it's actually terminated somewhere.
354-
} else if ((p[index] == '/') &&
355-
(index < p.length - 1) &&
356-
(p[index+1] == '*')) {
357-
p[index++] = ' ';
358-
p[index++] = ' ';
359-
boolean endOfRainbow = false;
360-
while (index < p.length - 1) {
361-
if ((p[index] == '*') && (p[index+1] == '/')) {
362-
p[index++] = ' ';
363-
p[index++] = ' ';
364-
endOfRainbow = true;
365-
break;
366-
367-
} else {
368-
// continue blanking this area
369-
p[index++] = ' ';
370-
}
371-
}
372-
if (!endOfRainbow) {
373-
throw new RuntimeException(_("Missing the */ from the end of a " +
374-
"/* comment */"));
375-
}
376-
} else { // any old character, move along
377-
index++;
378-
}
342+
String result = what;
343+
for (Pattern p : patterns) {
344+
result = p.matcher(result).replaceAll("");
379345
}
380-
return new String(p);
346+
347+
return result;
381348
}
382349
}

app/test/processing/app/preproc/PdePreprocessorTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public void testSourceWithQuoteAndDoubleQuotesEscapedAndFinalQuoteShouldNotRaise
1616
String actualOutput = new PdePreprocessor().strip(s);
1717
String expectedOutput = FileUtils.readFileToString(new File(PdePreprocessorTest.class.getResource("RemoteCallLogger_v1e0.stripped.ino").getFile()));
1818

19-
assertEquals(actualOutput, expectedOutput);
19+
assertEquals(expectedOutput, actualOutput);
2020
}
2121

2222
@Test

app/test/processing/app/preproc/RemoteCallLogger_v1e0.stripped.ino

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11

22

3-
4-
5-
63

74

85

0 commit comments

Comments
 (0)