Skip to content

Commit 9b6d78b

Browse files
committed
Backported ';' fix from Asar 2.0 branch
1 parent 378f537 commit 9b6d78b

File tree

2 files changed

+29
-13
lines changed

2 files changed

+29
-13
lines changed

src/asar/libstr.h

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -504,24 +504,33 @@ inline const char * dequote(char * str)
504504

505505
inline char * strqchr(const char * str, char key)
506506
{
507-
while (*str)
507+
while (*str != '\0')
508508
{
509-
if (*str=='"')
509+
if (*str == key) { return const_cast<char*>(str); }
510+
else if (*str == '"' || *str == '\'')
510511
{
511-
str++;
512-
while (*str!='"')
512+
// Special case hack for ''', which is currently our official way of handling the ' character.
513+
// Even though it really stinks.
514+
if (str[0] == '\'' && str[1] == '\'' && str[2] == '\'') { str += 2; }
515+
else
513516
{
514-
if (!*str) return nullptr;
515-
str++;
517+
char delimiter = *str;
518+
519+
do
520+
{
521+
str++;
522+
523+
// If we want to support backslash escapes, we'll have to add that right here.
524+
} while (*str != delimiter && *str != '\0');
525+
526+
// This feels like a superfluous check, but I can't really find a clean way to avoid it.
527+
if (*str == '\0') { return nullptr; }
516528
}
517-
str++;
518-
}
519-
else
520-
{
521-
if (*str==key) return const_cast<char*>(str);
522-
str++;
523529
}
530+
531+
str++;
524532
}
533+
525534
return nullptr;
526535
}
527536

tests/tablefiles.asm

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
;`10 20 30 10
88
;`11 21 31 11
99
;`42 42
10+
;`43 43
1011

1112
org $008000
1213

@@ -24,6 +25,12 @@ db "test"
2425
db 't','e','s','t'
2526
db 't'+1,'e'+1,'s'+1,'t'+1
2627

27-
''' = $42
28+
''' = $42 ; Comment after actual line
29+
; ''' = $44 ; This line is a comment and should be ignored
2830
db "'"
2931
db '''
32+
33+
';' = $43 ; Comment after actual line
34+
; ';' = $45 ; This line is a comment and should be ignored
35+
db ";"
36+
db ';'

0 commit comments

Comments
 (0)