Commit 1d23cc67 authored by Pino Toscano's avatar Pino Toscano
Browse files

[cpp] add "human friendly" output representation for byte_array

parent a337c1d7
......@@ -22,6 +22,7 @@
#include <ctime>
#include <cstring>
#include <iostream>
using namespace poppler;
......@@ -154,3 +155,25 @@ unsigned int convert_date(const std::string &date)
time.tm_isdst = -1;
return mktime(&time);
}
std::ostream& operator<<(std::ostream& stream, const byte_array &array)
{
stream << "[";
const std::ios_base::fmtflags f = stream.flags();
std::hex(stream);
const char *data = array.data();
const byte_array::size_type out_len = std::min<byte_array::size_type>(array.size(), 50);
for (byte_array::size_type i = 0; i < out_len; ++i)
{
if (i != 0) {
stream << " ";
}
stream << ((data[i] & 0xf0) >> 4) << (data[i] & 0xf);
}
stream.flags(f);
if (out_len < array.size()) {
stream << " ...";
}
stream << "]";
return stream;
}
......@@ -33,6 +33,7 @@
# define POPPLER_CPP_EXPORT LIB_IMPORT
#endif
#include <iosfwd>
#include <string>
#include <vector>
......@@ -88,6 +89,8 @@ private:
POPPLER_CPP_EXPORT unsigned int /*time_t*/ convert_date(const std::string &date);
POPPLER_CPP_EXPORT std::ostream& operator<<(std::ostream& stream, const byte_array &array);
}
#endif
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment