diff --git a/octa/format.hh b/octa/format.hh index 1f2414e..ba4f411 100644 --- a/octa/format.hh +++ b/octa/format.hh @@ -298,12 +298,11 @@ namespace detail { /* C string */ template - octa::Ptrdiff write(R &writer, const char *val) { + octa::Ptrdiff write(R &writer, const char *val, octa::Size n) { if (this->spec != 's') { assert(false && "cannot format strings with the given spec"); return -1; } - octa::Size n = strlen(val); octa::Ptrdiff r = n; r += this->write_ws(writer, n, true); writer.put_n(val, n); @@ -311,19 +310,15 @@ namespace detail { return r; } + template + octa::Ptrdiff write(R &writer, const char *val) { + return write(writer, val, strlen(val)); + } + /* OctaSTD string */ template octa::Ptrdiff write(R &writer, const octa::AnyString &val) { - if (this->spec != 's') { - assert(false && "cannot format strings with the given spec"); - return -1; - } - octa::Size n = val.size(); - octa::Ptrdiff r = n; - r += this->write_ws(writer, n, true); - writer.put_n(val.data(), n); - r += this->write_ws(writer, n, false); - return r; + return write(writer, val.data(), val.size()); } /* character */