On Sun, Apr 06, 2008 at 11:08:13PM +0000, corvid wrote:
I ponder having a:
const char *dStr_printable(dStr *in, int maxlen)
that returns a pointer to an internal static dStr. It has the advantage of minimal interface overhead. e.g.
- MSG_WARN(" \"%s\"\n", io->Buf->str); + MSG_WARN(" \"%s\"\n", dStr_printable(io->Buf, 2048));
of course it's not MT-safe, but we don't need it now.
Implementing a MT-safe version is easy, but involves more calling overhead:
dStr *dStr_printable(dStr *in, int maxlen)
- MSG_WARN(" \"%s\"\n", io->Buf->str); + Dstr *printable = dStr_printable(io->Buf, 2048)); + MSG_WARN(" \"%s\"\n", printable->str)); + dStr_free(printable, 1);
and disabling the message is not as clean as prepending an "_" to the macro.
I'd go with the first alternative.
Attached.
I wasn't too sure about representation. Text has \x0D where ^M would be much less surprising, but \x is easier to read for arbitrary bytes.
It's funny that I had been calling truncation a bug and now I'm truncating intentionally, but there is only so much a person wants to see...
Committed. -- Cheers Jorge.-