Skip to content

Commit 87f8a3d

Browse files
committed
more parsing code for quoted strings, fixes processing#3394
1 parent 1e0e434 commit 87f8a3d

1 file changed

Lines changed: 55 additions & 2 deletions

File tree

java/src/processing/mode/java/preproc/PdePreprocessor.java

Lines changed: 55 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -288,12 +288,20 @@ make sure that it uses numbers (or displayWidth/Height), copy into settings
288288
char[] c = searchArea.toCharArray();
289289
int depth = 0;
290290
int closeBrace = -1;
291-
// boolean literal; // inside a quoted literal?
292291
StringBuilder sb = new StringBuilder();
293292
for (int i = openBrace; i < c.length; i++) {
294293
if (c[i] == '{') {
295294
depth++;
296-
// } else if (c[i] == '\'') {
295+
} else if (c[i] == '\'') {
296+
String quoted = readSingleQuote(c, i);
297+
sb.append(quoted);
298+
i += quoted.length() - 1;
299+
300+
} else if (c[i] == '\"') {
301+
String quoted = readDoubleQuote(c, i);
302+
sb.append(quoted);
303+
i += quoted.length() - 1;
304+
297305
} else if (c[i] == '}') {
298306
depth--;
299307
if (depth == 0) {
@@ -429,6 +437,51 @@ make sure that it uses numbers (or displayWidth/Height), copy into settings
429437
}
430438

431439

440+
static String readSingleQuote(char[] c, int i) {
441+
StringBuilder sb = new StringBuilder();
442+
try {
443+
sb.append(c[i++]); // add the quote
444+
if (c[i] == '\\') {
445+
sb.append(c[i++]); // add the escape
446+
if (c[i] == 'u') {
447+
// grabs uNNN and the fourth N will be added below
448+
for (int j = 0; j < 4; j++) {
449+
sb.append(c[i++]);
450+
}
451+
}
452+
}
453+
sb.append(c[i++]); // get the char, escapee, or last unicode digit
454+
sb.append(c[i++]); // get the closing quote
455+
456+
} catch (ArrayIndexOutOfBoundsException ignored) {
457+
// this means they have bigger problems with their code
458+
}
459+
return sb.toString();
460+
}
461+
462+
463+
static String readDoubleQuote(char[] c, int i) {
464+
StringBuilder sb = new StringBuilder();
465+
try {
466+
sb.append(c[i++]); // add the quote
467+
while (i < c.length) {
468+
if (c[i] == '\\') {
469+
sb.append(c[i++]); // add the escape
470+
sb.append(c[i++]); // add whatever was escaped
471+
} else if (c[i] == '\"') {
472+
sb.append(c[i++]);
473+
break;
474+
} else {
475+
sb.append(c[i++]);
476+
}
477+
}
478+
} catch (ArrayIndexOutOfBoundsException ignored) {
479+
// this means they have bigger problems with their code
480+
}
481+
return sb.toString();
482+
}
483+
484+
432485
static protected String[] matchMethod(String methodName, String searchArea) {
433486
final String left = "(?:^|\\s|;)";
434487
// doesn't match empty pairs of parens

0 commit comments

Comments
 (0)