summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2021-08-08 16:14:50 +0100
committerDan Goodliffe <dan@randomdan.homeip.net>2021-08-08 16:15:07 +0100
commitbdb5c897087d3588f456c020b3633cbd694003da (patch)
treeef09420dad64a438e097645850b8596eebe28a97 /lib
parentSimplify some bits with concepts (diff)
downloadmygrate-bdb5c897087d3588f456c020b3633cbd694003da.tar.bz2
mygrate-bdb5c897087d3588f456c020b3633cbd694003da.tar.xz
mygrate-bdb5c897087d3588f456c020b3633cbd694003da.zip
Tests, fixes, improvements to WritePqCopyStream
Diffstat (limited to 'lib')
-rw-r--r--lib/dbTypes.h4
-rw-r--r--lib/output/pq/writePqCopyStrm.cpp12
2 files changed, 12 insertions, 4 deletions
diff --git a/lib/dbTypes.h b/lib/dbTypes.h
index 31793e4..f49c929 100644
--- a/lib/dbTypes.h
+++ b/lib/dbTypes.h
@@ -13,10 +13,10 @@ struct timespec;
namespace MyGrate {
template<typename T> struct printer;
template<> struct printer<double> {
- constexpr static const char * const fmt {"%f"};
+ constexpr static const char * const fmt {"%g"};
};
template<> struct printer<float> {
- constexpr static const char * const fmt {"%f"};
+ constexpr static const char * const fmt {"%g"};
};
template<> struct printer<int8_t> {
constexpr static const char * const fmt {"%hhd"};
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<std::array<char, 2>, 256> h {};
+ std::array<char, 16> 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);
});
}
}