diff options
| author | 2023-06-19 09:49:50 +0200 | |
|---|---|---|
| committer | 2023-06-19 09:49:50 +0200 | |
| commit | 43abf782b12e883fdf3b15402b7fa09546acb9af (patch) | |
| tree | 9b22685742cc99484592059072620bbea2291dfc /io.c | |
| parent | 7a6b76f519695d686c378f2450658504448c75f6 (diff) | |
add %y symbol printing
Diffstat (limited to 'io.c')
| -rw-r--r-- | io.c | 12 |
1 files changed, 12 insertions, 0 deletions
@@ -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: |