From 43abf782b12e883fdf3b15402b7fa09546acb9af Mon Sep 17 00:00:00 2001 From: lemon Date: Mon, 19 Jun 2023 09:49:50 +0200 Subject: add %y symbol printing --- io.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'io.c') 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: -- cgit v1.2.3