@@ -87,7 +87,7 @@ public int writePrefix(String program)
87
87
// an OutOfMemoryError or NullPointerException will happen.
88
88
// again, not gonna bother tracking this down, but here's a hack.
89
89
// http://dev.processing.org/bugs/show_bug.cgi?id=16
90
- scrubComments (program );
90
+ program = scrubComments (program );
91
91
// If there are errors, an exception is thrown and this fxn exits.
92
92
93
93
if (Preferences .getBoolean ("preproc.substitute_unicode" )) {
@@ -242,26 +242,27 @@ public int firstStatement(String in) {
242
242
*/
243
243
public String strip (String in ) {
244
244
// XXX: doesn't properly handle special single-quoted characters
245
+ List <Pattern > patterns = new ArrayList <Pattern >();
245
246
// single-quoted character
246
- String p = "('.')" ;
247
-
248
- p += "|('\\ \\ \" ')" ;
249
-
250
- // double-quoted string
251
- p += "|(\" (?:[^\" \\ \\ ]|\\ \\ .)*\" )" ;
252
-
247
+ patterns .add (Pattern .compile ("('.')" , Pattern .MULTILINE ));
253
248
// single and multi-line comment
254
- //p += "|" + "(//\\s*?$)|(/\\*\\s*?\\*/)" ;
255
- p += "| (//.*?$)|(/ \\ *[^*]*(?: \\ *(?!/)[^*]*)* \\ */)" ;
256
-
249
+ patterns . add ( Pattern . compile ( "(' \\ \\ \" ')" , Pattern . MULTILINE )) ;
250
+ patterns . add ( Pattern . compile ( " (//.*?$)" , Pattern . MULTILINE )) ;
251
+ patterns . add ( Pattern . compile ( "(/ \\ *[^*]*(?: \\ *(?!/)[^*]*)* \\ */)" , Pattern . MULTILINE ));
257
252
// pre-processor directive
258
- p += "|" + "(^\\ s*#.*?$)" ;
253
+ patterns .add (Pattern .compile ("(^\\ s*#.*?$)" , Pattern .MULTILINE ));
254
+ // double-quoted string
255
+ patterns .add (Pattern .compile ("(\" (?:[^\" \\ \\ ]|\\ \\ .)*\" )" , Pattern .MULTILINE ));
259
256
260
- Pattern pattern = Pattern .compile (p , Pattern .MULTILINE );
261
- Matcher matcher = pattern .matcher (in );
262
- return matcher .replaceAll (" " );
257
+ String code = in ;
258
+ for (Pattern p : patterns ) {
259
+ Matcher matcher = p .matcher (code );
260
+ code = matcher .replaceAll (" " );
261
+ }
262
+
263
+ return code ;
263
264
}
264
-
265
+
265
266
/**
266
267
* Removes the contents of all top-level curly brace pairs {}.
267
268
* @param in the String to collapse
0 commit comments