From bdb5c897087d3588f456c020b3633cbd694003da Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sun, 8 Aug 2021 16:14:50 +0100 Subject: Tests, fixes, improvements to WritePqCopyStream --- lib/output/pq/writePqCopyStrm.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'lib/output/pq') diff --git a/lib/output/pq/writePqCopyStrm.cpp b/lib/output/pq/writePqCopyStrm.cpp index dd402e7..4664e6b 100644 --- a/lib/output/pq/writePqCopyStrm.cpp +++ b/lib/output/pq/writePqCopyStrm.cpp @@ -59,7 +59,7 @@ namespace MyGrate::Output::Pq { fwrite(pos, esc - pos, 1, out); pos = esc; } - while (pos != v.end()) { + while (pos != v.end() && std::iscntrl(*pos)) { fprintf(out, "\\%03o", *pos); pos++; } @@ -74,9 +74,17 @@ namespace MyGrate::Output::Pq { void WritePqCopyStream::operator()(Blob v) const { + static constexpr const auto hex {[] { + std::array, 256> h {}; + std::array hc {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'}; + for (int x {}; x < 256; x += 1) { + h[x] = {hc[x >> 4], hc[x & 0xF]}; + } + return h; + }()}; fputs("\\\\x", out); std::for_each(v.begin(), v.end(), [this](auto b) { - fprintf(out, "%02hhx", (uint8_t)b); + fwrite(hex[(uint8_t)b].data(), 2, 1, out); }); } } -- cgit v1.2.3