From c8263302d14ed81299d8ffc8d3d0a2acbba83823 Mon Sep 17 00:00:00 2001 From: odrling Date: Sat, 10 Aug 2024 14:59:15 +0200 Subject: [PATCH] improve character escaping easier to modify and also safer --- libdakara_check.c | 38 ++++++++++++++++++++++++-------------- 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/libdakara_check.c b/libdakara_check.c index 139cc6e..4ffa0f8 100644 --- a/libdakara_check.c +++ b/libdakara_check.c @@ -272,11 +272,12 @@ void dakara_check_subtitle_events(ASS_Track *track, dakara_check_sub_results *re unsigned long write_head = 0; bool tags = false; bool drawing = false; + bool escaped = false; for (unsigned long read_head = 0; line[read_head] != '\0'; read_head++) { if (tags) { switch (line[read_head]) { - case '{': + case '}': tags = false; break; case '\\': @@ -289,20 +290,29 @@ void dakara_check_subtitle_events(ASS_Track *track, dakara_check_sub_results *re if (line[read_head] == '}') { tags = false; } - } else { - switch (line[read_head]) { - case '{': - tags = true; - break; - case '\\': - read_head++; - if (line[read_head] != 'n' && line[read_head] != 'N') { - goto write; + } else if (!drawing) { + if (escaped) { + escaped = false; + switch (line[read_head]) { + case 'n': + case 'N': + // ignore + break; + default: + if (read_head != write_head) { + line[write_head] = line[read_head]; + } + write_head++; } - break; - default: - write: - if (!drawing) { + } else { + switch (line[read_head]) { + case '{': + tags = true; + break; + case '\\': + escaped = true; + break; + default: if (read_head != write_head) { line[write_head] = line[read_head]; }