* @version 1.0
*/
#include <string>
+#include <algorithm>
+
+#include <base64.h>
#include <db-wrapper.h>
namespace {
-const size_t MAX_LEN = 32;
+const size_t MAX_LEN = 64;
const char ELLIPSIS[] = "...";
const size_t ELLIPSIS_LEN = sizeof(ELLIPSIS) / sizeof(ELLIPSIS[0]);
for (auto it = row.begin(); it != row.end(); it++) {
std::string col = *it;
+ /*
+ * Convert unprintable data to base64. Note that a row may contain an incomplete data
+ * since it holds a binary data as a string.
+ */
+ if (std::any_of(col.begin(),
+ col.end(),
+ [](const char c){ return isprint(c) + iscntrl(c) == 0; })) {
+ Base64Encoder b64enc;
+ RawBuffer tmp(col.begin(), col.end());
+ b64enc.append(tmp);
+ b64enc.finalize();
+ col = "b64:";
+ RawBuffer encoded = b64enc.get();
+ std::copy(encoded.begin(), encoded.end(), std::back_inserter(col));
+ }
+
if (trim && col.size() > MAX_LEN) {
col.resize(MAX_LEN);
col.replace(MAX_LEN - ELLIPSIS_LEN, ELLIPSIS_LEN, ELLIPSIS);