00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include <ctype.h>
00019 #include "HexDumpBuffer.h"
00020
00021 namespace oasys {
00022
00023 void
00024 HexDumpBuffer::hexify()
00025 {
00026
00027 size_t len = length();
00028 std::string contents(data(), len);
00029 char strbuf[16];
00030
00031
00032 trim(length());
00033
00034
00035 u_char* bp = (u_char*)contents.data();
00036 for (size_t i = 0; i < len; ++i, ++bp)
00037 {
00038
00039 if (i % 16 == 0) {
00040 appendf("%07x ", (u_int)i);
00041 }
00042
00043
00044 else if (i % 2 == 0) {
00045 append(" ");
00046 }
00047
00048
00049 appendf("%02x", *bp);
00050
00051
00052 if (isalnum(*bp) || ispunct(*bp) || (*bp == ' ')) {
00053 strbuf[i % 16] = *bp;
00054 } else {
00055 strbuf[i % 16] = '.';
00056 }
00057
00058 if (i % 16 == 15)
00059 {
00060 appendf(" | %.*s\n", 16, strbuf);
00061 }
00062 }
00063
00064
00065 for (size_t i = len % 16; i < 16; ++i) {
00066 if (i % 2 == 0) {
00067 append(" ");
00068 }
00069
00070 append(" ");
00071 }
00072
00073 appendf(" | %.*s\n", (int)len % 16, strbuf);
00074 }
00075
00076 }