summaryrefslogtreecommitdiff
path: root/main.c
diff options
context:
space:
mode:
authorWormHeamer2026-01-01 21:58:30 -0500
committerWormHeamer2026-01-01 21:58:30 -0500
commit4c02da2c32fd3313897fdd5280b203d9e5d60ea6 (patch)
treef5f020000f69104c0762b10d994a63f83e1cc578 /main.c
parent0f48a3fc058c29e004249f2dbfd6d54c5c57e631 (diff)
fix match_bracket() getting stuck on backslashes
Diffstat (limited to 'main.c')
-rw-r--r--main.c26
1 files changed, 10 insertions, 16 deletions
diff --git a/main.c b/main.c
index 350ebf8..e9bc93c 100644
--- a/main.c
+++ b/main.c
@@ -220,29 +220,23 @@ int match_bracket(TxtLoc l, TxtLoc *out, u32 c) {
u32 o = bracket_opp(c);
if (txt_chr(l) != c) return 0;
int dir = bracket_dir(c);
+ if (!dir) return 0;
int in_str = 0, in_chr = 0;
while (depth > 0) {
if (dir < 0 && at_start(l)) break;
if (dir > 0 && at_end(l)) break;
l = dir < 0 ? cprev(l) : cnext(l);
u32 x = txt_chr(l);
- if (dir > 0 && x == '\\') {
- l = cnext(l);
- continue;
- } else if (dir < 0 && txt_chr(cprev(l)) == '\\') {
- l = cprev(l);
- continue;
+ int bs = (txt_chr(cprev(l)) == '\\') && (txt_chr(cprev(cprev(l))) != '\\');
+ if (in_chr) {
+ if (!bs && x == '\'') in_chr = 0;
+ } else if (in_str) {
+ if (!bs && x == '"') in_str = 0;
} else {
- if (in_chr) {
- if (x == '\'') in_chr = 0;
- } else if (in_str) {
- if (x == '"') in_str = 0;
- } else {
- if (x == '\'') in_chr = 1;
- else if (x == '"') in_str = 1;
- else if (x == c) depth++;
- else if (x == o) depth--;
- }
+ if (x == '\'') in_chr = 1;
+ else if (x == '"') in_str = 1;
+ else if (x == c) depth++;
+ else if (x == o) depth--;
}
}
if (depth == 0) {