From 97bc3324ead8d3bcfef2c058de45e2f66f75ecca Mon Sep 17 00:00:00 2001 From: mccallum Date: Mon, 13 May 1996 16:43:29 +0000 Subject: [PATCH] ([NSData -description]): Implemented by Nathan Urban. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@1535 72102866-910b-0410-8b05-ffd578937521 --- Source/NSData.m | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/Source/NSData.m b/Source/NSData.m index a3513e0e8..7fcdaf711 100644 --- a/Source/NSData.m +++ b/Source/NSData.m @@ -243,12 +243,27 @@ static Class NSMutableData_concrete_class; - (NSString*) description { - /* xxx worry about escaping, NSString does that? */ - /* FIXME: Well, according to the docs, this is suppossed to create a - * string which has a hexadecimal representation of the data - * contained in the NSData object. NSString certainly won't do - * *that* all on its own. Hmmm. */ - return [NSString stringWithCString:[self bytes] length:[self length]]; + const char *src = [self bytes]; + char *dest; + int length = [self length]; + int i,j; + +#define num2char(num) ((num) < 0xa ? ((num)+'0') : ((num)+0x57)) + + /* we can just build a cString and convert it to an NSString */ + dest = (char*) malloc (2*length+length/4+3); + dest[0] = '<'; + for (i=0,j=1; i>4) & 0x0f); + dest[j] = num2char(src[i] & 0x0f); + if((i&0x3) == 3) + /* if we've just finished a 32-bit int, print a space */ + dest[++j] = ' '; + } + dest[j++] = '>'; + dest[j] = '\0'; + return [NSString stringWithCString: dest]; } - (void)getBytes: (void*)buffer