MCPcopy Create free account
hub / github.com/amule-project/amule / DumpMemToStr

Function DumpMemToStr

src/OtherFunctions.cpp:972–1024  ·  view source on GitHub ↗

* Dumps a buffer to a wxString */

Source from the content-addressed store, hash-verified

970 * Dumps a buffer to a wxString
971 */
972wxString DumpMemToStr(const void *buff, int n, const wxString& msg, bool ok)
973{
974 const unsigned char *p = (const unsigned char *)buff;
975 int lines = (n + 15)/ 16;
976
977 wxString result;
978 // Allocate aproximetly what is needed
979 result.Alloc( ( lines + 1 ) * 80 );
980 if ( !msg.IsEmpty() ) {
981 result += msg + " - ok=" + ( ok ? "true, " : "false, " );
982 }
983
984 result += CFormat("%d bytes\n") % n;
985 for ( int i = 0; i < lines; ++i) {
986 // Show address
987 result += CFormat("%08x ") % (i * 16);
988
989 // Show two columns of hex-values
990 for ( int j = 0; j < 2; ++j) {
991 for ( int k = 0; k < 8; ++k) {
992 int pos = 16 * i + 8 * j + k;
993
994 if ( pos < n ) {
995 result += CFormat("%02x ") % p[pos];
996 } else {
997 result += " ";
998 }
999 }
1000 result += " ";
1001 }
1002 result += "|";
1003 // Show a column of ascii-values
1004 for ( int k = 0; k < 16; ++k) {
1005 int pos = 16 * i + k;
1006
1007 if ( pos < n ) {
1008 if ( isspace( p[pos] ) ) {
1009 result += " ";
1010 } else if ( !isgraph( p[pos] ) ) {
1011 result += ".";
1012 } else {
1013 result += (wxChar)p[pos];
1014 }
1015 } else {
1016 result += " ";
1017 }
1018 }
1019 result += "|\n";
1020 }
1021 result.Shrink();
1022
1023 return result;
1024}
1025
1026
1027/**

Callers 1

DumpMemFunction · 0.85

Calls 2

CFormatClass · 0.85
IsEmptyMethod · 0.45

Tested by

no test coverage detected