Skip to content

Commit 83a8493

Browse files
author
jdf
committed
Fix spurious error message emitted by bracket code.
1 parent cba83c8 commit 83a8493

1 file changed

Lines changed: 17 additions & 12 deletions

File tree

app/src/processing/app/syntax/Brackets.java

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,12 @@ public void invalidate() {
1616
}
1717

1818
public int findMatchingBracket(final String text, final int pos) {
19-
if (offsets == null)
20-
parse(text);
21-
// find this bracket
22-
int p;
23-
for (p = 0; p < offsets.size(); p++)
24-
if (offsets.get(p) == pos)
25-
break;
26-
if (p == offsets.size()) {
19+
if (pos < 0 || pos > text.length())
2720
return -1;
28-
}
29-
final int direction;
30-
final char alpha = text.charAt(offsets.get(p));
21+
22+
final char alpha = text.charAt(pos);
3123
final char beta;
24+
final int direction;
3225
switch (alpha) {
3326
case '(':
3427
beta = ')';
@@ -55,9 +48,21 @@ public int findMatchingBracket(final String text, final int pos) {
5548
direction = -1;
5649
break;
5750
default:
58-
System.err.println("Unexpected char " + alpha + " at position " + p);
5951
return -1;
6052
}
53+
54+
if (offsets == null)
55+
parse(text);
56+
57+
// find this bracket
58+
int p;
59+
for (p = 0; p < offsets.size(); p++)
60+
if (offsets.get(p) == pos)
61+
break;
62+
if (p == offsets.size()) {
63+
return -1;
64+
}
65+
6166
int depth = 1;
6267
for (p += direction; p >= 0 && p < offsets.size(); p += direction) {
6368
final int offset = offsets.get(p);

0 commit comments

Comments
 (0)