@@ -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}
0 commit comments