From 3d54b4ea0c96a2420973dc840c1b32545bf2b05d Mon Sep 17 00:00:00 2001 From: Szczepan Zalega Date: Wed, 18 Jan 2017 00:11:25 +0100 Subject: Fix getting card serial todo: remove whitespace at the string end Signed-off-by: Szczepan Zalega --- misc.cc | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) (limited to 'misc.cc') diff --git a/misc.cc b/misc.cc index 3f15520..a76bfb6 100644 --- a/misc.cc +++ b/misc.cc @@ -36,7 +36,8 @@ std::vector hex_string_to_byte(const char* hexString){ }; #include -std::string hexdump(const char *p, size_t size, bool print_header) { +std::string hexdump(const char *p, size_t size, bool print_header, + bool print_ascii, bool print_empty) { std::stringstream out; char formatbuf[128]; const char *pstart = p; @@ -53,18 +54,20 @@ std::string hexdump(const char *p, size_t size, bool print_header) { snprintf(formatbuf, 128, "%02x ", uint8_t(*p)); out << formatbuf; } else { - out << "-- "; + if(print_empty) + out << "-- "; } } - out << "\t"; - - for (const char *le = pp + 16; pp < le && pp < pend; pp++) { - if (std::isgraph(*pp)) - out << uint8_t(*pp); - else - out << '.'; - } + if(print_ascii){ + out << "\t"; + for (const char *le = pp + 16; pp < le && pp < pend; pp++) { + if (std::isgraph(*pp)) + out << uint8_t(*pp); + else + out << '.'; + } + } out << std::endl; } return out.str(); -- cgit v1.2.1