From 80a27b24c507e175ee8b616aebbfac560a358e53 Mon Sep 17 00:00:00 2001 From: Richard Frith-Macdonald Date: Tue, 8 Feb 2005 11:20:42 +0000 Subject: [PATCH] Rewrite -unicodeString method. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@20671 72102866-910b-0410-8b05-ffd578937521 --- ChangeLog | 5 +++++ Source/NSString.m | 28 +++++++++++----------------- 2 files changed, 16 insertions(+), 17 deletions(-) diff --git a/ChangeLog b/ChangeLog index f247f94af..375f4b1f6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2005-02-08 11:20 Richard Frith-Macdonald + + * Source/NSString.m: (unicodeString) rewrite to conform to coding + standards and to be more efficient. + 2005-02-08 10:10 Richard Frith-Macdonald * Tools/gdnc.m: Rewrite startup code to create a daemon using NSTask diff --git a/Source/NSString.m b/Source/NSString.m index ef05e333f..9f0644cf5 100644 --- a/Source/NSString.m +++ b/Source/NSString.m @@ -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