From 598fcbfa25dce64c635fbafffd0b74c9924c58b0 Mon Sep 17 00:00:00 2001 From: q66 Date: Wed, 1 Jul 2015 23:11:32 +0100 Subject: [PATCH] use c style formatting for strings (but type-generic, i.e. %s prints any value) --- octa/format.hh | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/octa/format.hh b/octa/format.hh index 6ea8fe2..89dc83d 100644 --- a/octa/format.hh +++ b/octa/format.hh @@ -120,21 +120,24 @@ static inline octa::Size formatted_write(R writer, octa::Size &fmtn, const char *fmt, const A &...args) { octa::Size argidx = 0, written = 0, retn = 0; while (*fmt) { - if (*fmt == '{') { + if (*fmt == '%') { + ++fmt; + if (*fmt == '%') goto plain; octa::Size needidx = argidx; - if (*++fmt != '}') { + if (*fmt != 's') { char idx[8] = { '\0' }; for (octa::Size i = 0; isdigit(*fmt); ++i) idx[i] = *fmt++; - assert((*fmt == '}') && "malformed format string"); + assert((*fmt++ == '$') && "malformed format string"); needidx = atoi(idx); } else ++argidx; - ++fmt; + assert((*fmt++ == 's') && "malformed format string"); retn = octa::max(needidx, retn); written += octa::detail::write_idx(writer, needidx, args...); continue; } + plain: writer.put(*fmt++); ++written; }