import mir.format: stringBuf; stringBuf w; assert(w.printEscaped("Hi \a\v\0\f\t\b \\\r\n" ~ `"@nogc"`).data == `Hi \a\v\0\f\t\b \\\r\n\"@nogc\"`); w.reset; assert(w.printEscaped("\x03").data == `\x03`, w.data);
See Implementation