Skip to content

Commit

Permalink
lib/format.c: simplify escape characters
Browse files Browse the repository at this point in the history
  • Loading branch information
Duncaen committed Mar 14, 2023
1 parent 6d46066 commit 02f7bcd
Showing 1 changed file with 9 additions and 15 deletions.
24 changes: 9 additions & 15 deletions lib/format.c
Original file line number Diff line number Diff line change
Expand Up @@ -133,17 +133,12 @@ nexttok(const char **pos, struct strbuf *buf)
case 'r': r = strbuf_putc(buf, '\r'); break;
case 't': r = strbuf_putc(buf, '\t'); break;
case '0': r = strbuf_putc(buf, '\0'); break;
case '{': r = strbuf_putc(buf, '{'); break;
case '}': r = strbuf_putc(buf, '}'); break;
default:
r = strbuf_putc(buf, '\\');
if (r < 0)
break;
r = strbuf_putc(buf, *p);
default: r = *p ? strbuf_putc(buf, *p) : 0;
}
if (r < 0)
return r;
p++;
if (*p)
p++;
break;
default:
r = strbuf_putc(buf, *p++);
Expand Down Expand Up @@ -241,9 +236,8 @@ parse_default(const char **pos, struct xbps_fmt *fmt, struct strbuf *buf,
return r;
str = buf->mem + buf->len;
}
for (; *p && *p != '"'; p++) {
switch (*p) {
case '\\':
for (; *p && *p != '"';) {
if (*p == '\\') {
switch (*++p) {
case '\\': r = strbuf_putc(buf, '\\'); break;
case 'a': r = strbuf_putc(buf, '\a'); break;
Expand All @@ -253,15 +247,15 @@ parse_default(const char **pos, struct xbps_fmt *fmt, struct strbuf *buf,
case 'r': r = strbuf_putc(buf, '\r'); break;
case 't': r = strbuf_putc(buf, '\t'); break;
case '0': r = strbuf_putc(buf, '\0'); break;
case '"': r = strbuf_putc(buf, '"'); break;
default: r = -EINVAL;
default: r = *p ? strbuf_putc(buf, *p) : 0;
}
break;
default:
} else {
r = strbuf_putc(buf, *p);
}
if (r < 0)
goto err;
if (*p)
p++;
}
if (*p++ != '"') {
r = -EINVAL;
Expand Down

0 comments on commit 02f7bcd

Please sign in to comment.