Skip to content

Commit

Permalink
improve character escaping
Browse files Browse the repository at this point in the history
easier to modify and also safer
  • Loading branch information
odrling committed Aug 10, 2024
1 parent 5103106 commit c826330
Showing 1 changed file with 24 additions and 14 deletions.
38 changes: 24 additions & 14 deletions libdakara_check.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 '\\':
Expand All @@ -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];
}
Expand Down

0 comments on commit c826330

Please sign in to comment.