mirror of
https://github.com/gnustep/libs-base.git
synced 2025-05-30 16:30:41 +00:00
([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
This commit is contained in:
parent
18f389e663
commit
97bc3324ea
1 changed files with 21 additions and 6 deletions
|
@ -243,12 +243,27 @@ static Class NSMutableData_concrete_class;
|
||||||
|
|
||||||
- (NSString*) description
|
- (NSString*) description
|
||||||
{
|
{
|
||||||
/* xxx worry about escaping, NSString does that? */
|
const char *src = [self bytes];
|
||||||
/* FIXME: Well, according to the docs, this is suppossed to create a
|
char *dest;
|
||||||
* string which has a hexadecimal representation of the data
|
int length = [self length];
|
||||||
* contained in the NSData object. NSString certainly won't do
|
int i,j;
|
||||||
* *that* all on its own. Hmmm. */
|
|
||||||
return [NSString stringWithCString:[self bytes] length:[self length]];
|
#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<length; i++,j++)
|
||||||
|
{
|
||||||
|
dest[j++] = num2char((src[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
|
- (void)getBytes: (void*)buffer
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue