aboutsummaryrefslogtreecommitdiffhomepage
path: root/io.c
diff options
context:
space:
mode:
authorlemon <lsof@mailbox.org>2023-06-19 09:49:50 +0200
committerlemon <lsof@mailbox.org>2023-06-19 09:49:50 +0200
commit43abf782b12e883fdf3b15402b7fa09546acb9af (patch)
tree9b22685742cc99484592059072620bbea2291dfc /io.c
parent7a6b76f519695d686c378f2450658504448c75f6 (diff)
add %y symbol printing
Diffstat (limited to 'io.c')
-rw-r--r--io.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/io.c b/io.c
index 5c15600..eb29ca7 100644
--- a/io.c
+++ b/io.c
@@ -361,6 +361,7 @@ vbfmt(struct wbuf *out, const char *fmt, va_list ap)
n += bwriteS(buf, "(null)");
break;
}
+ QuotedStr:
n += bputc(buf, '"');
if (lmod) /* lower */
for (; *s; ++s) n += putquoted(buf, aisalpha(*s) ? *s|32 : *s, '"', s[1]);
@@ -388,6 +389,17 @@ vbfmt(struct wbuf *out, const char *fmt, va_list ap)
n += i;
}
break;
+ case 'y': /* symbol: print string literally if valid identifier, or quote it */
+ s = va_arg(ap, const char *);
+ assert(s && "%y null");
+ for (i = 0; s[i]; ++i) {
+ if (aisalpha(s[i]) || s[i] == '_' || (i > 0 && aisdigit(s[i])))
+ continue;
+ goto QuotedStr;
+ }
+ /* valid identifier */
+ while (*s) n += bputc(buf, *s++);
+ break;
case 'd': /* decimal */
base = 10;
Int: