Rewrite -unicodeString method.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@20671 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
CaS 2005-02-08 11:20:42 +00:00
parent 3698291b1e
commit 4b20910745
2 changed files with 16 additions and 17 deletions

View file

@ -1,3 +1,8 @@
2005-02-08 11:20 Richard Frith-Macdonald <rfm@gnu.org>
* Source/NSString.m: (unicodeString) rewrite to conform to coding
standards and to be more efficient.
2005-02-08 10:10 Richard Frith-Macdonald <rfm@gnu.org>
* Tools/gdnc.m: Rewrite startup code to create a daemon using NSTask

View file

@ -2611,28 +2611,22 @@ handle_printf_atsign (FILE *stream,
/**
* Returns a pointer to a null terminated string of 16-bit unichar
* The memory pointed to is not owned by the caller, so the
* caller must copy its contents to keep it. Raises an
* caller must copy its contents to keep it.
*/
- (const unichar*) unicharString
{
NSData *returnData = nil;
int len = [self length];
unichar buf[64];
unichar *uniStr = (len < 64) ? buf :
NSZoneMalloc(NSDefaultMallocZone(), (len+1) * sizeof(unichar));
if (uniStr != NULL)
{
[self getCharacters:uniStr];
uniStr[len] = L'\0';
returnData = [NSData dataWithBytes:uniStr length:(len+1)*sizeof(unichar)];
if (uniStr != buf)
NSZoneFree(NSDefaultMallocZone(), uniStr);
NSMutableData *data;
unichar *uniStr;
return ((const unichar*)[returnData bytes]);
}
return(NULL);
data = [NSMutableData dataWithLength: ([self length] + 1) * sizeof(unichar)];
uniStr = (unichar*)[data mutableBytes];
if (uniStr != 0)
{
[self getCharacters: uniStr];
}
return uniStr;
}
/**
* Returns a pointer to a null terminated string of 8-bit characters in the
* default encoding. The memory pointed to is not owned by the caller, so the