mirror of
https://github.com/gnustep/libs-base.git
synced 2025-05-31 08:41:03 +00:00
Fix memory leaks
This commit is contained in:
parent
546ca94ede
commit
5aa5692768
1 changed files with 46 additions and 43 deletions
|
@ -59,6 +59,7 @@
|
||||||
#import "Foundation/NSCharacterSet.h"
|
#import "Foundation/NSCharacterSet.h"
|
||||||
|
|
||||||
#import "GNUstepBase/GSLocale.h"
|
#import "GNUstepBase/GSLocale.h"
|
||||||
|
#import "GSPrivate.h"
|
||||||
|
|
||||||
@class NSDoubleNumber;
|
@class NSDoubleNumber;
|
||||||
|
|
||||||
|
@ -1407,55 +1408,57 @@ static NSUInteger _defaultBehavior = NSNumberFormatterBehavior10_4;
|
||||||
|
|
||||||
- (NSNumber *) numberFromString: (NSString *)string
|
- (NSNumber *) numberFromString: (NSString *)string
|
||||||
{
|
{
|
||||||
|
NSNumber *result = nil;
|
||||||
// This is a 10.4 and above method and should not work with earlier version.
|
// This is a 10.4 and above method and should not work with earlier version.
|
||||||
#if GS_USE_ICU == 1
|
#if GS_USE_ICU == 1
|
||||||
NSNumber *result;
|
NSUInteger length = [string length];
|
||||||
NSUInteger length;
|
|
||||||
NSRange range;
|
if (length > 0)
|
||||||
UErrorCode err = U_ZERO_ERROR;
|
|
||||||
unichar *ustring;
|
|
||||||
int64_t intNum;
|
|
||||||
double doubleNum;
|
|
||||||
|
|
||||||
if (string == nil)
|
|
||||||
return nil;
|
|
||||||
|
|
||||||
length = [string length];
|
|
||||||
ustring = NSZoneMalloc ([self zone], sizeof(unichar) * length);
|
|
||||||
if (ustring == NULL)
|
|
||||||
return nil;
|
|
||||||
|
|
||||||
[string getCharacters: ustring range: NSMakeRange(0, length)];
|
|
||||||
|
|
||||||
// FIXME: Not sure if this is correct....
|
|
||||||
range = [string rangeOfString: @"."];
|
|
||||||
if (range.location == NSNotFound)
|
|
||||||
{
|
{
|
||||||
intNum = unum_parseInt64(internal->_formatter,
|
NSRange range;
|
||||||
ustring, length, NULL, &err);
|
UErrorCode err = U_ZERO_ERROR;
|
||||||
if (U_FAILURE(err))
|
int64_t intNum;
|
||||||
return nil;
|
double doubleNum;
|
||||||
if (intNum == 0 || intNum == 1)
|
GS_BEGINITEMBUF(ustring, length * sizeof(unichar), unichar)
|
||||||
result = [NSNumber numberWithBool: (BOOL) intNum];
|
|
||||||
else if (intNum < INT_MAX && intNum > INT_MIN)
|
[string getCharacters: ustring range: NSMakeRange(0, length)];
|
||||||
result = [NSNumber numberWithInt: (int32_t)intNum];
|
|
||||||
|
// FIXME: Not sure if this is correct....
|
||||||
|
range = [string rangeOfString: @"."];
|
||||||
|
if (range.location == NSNotFound)
|
||||||
|
{
|
||||||
|
intNum = unum_parseInt64(internal->_formatter,
|
||||||
|
ustring, length, NULL, &err);
|
||||||
|
if (!U_FAILURE(err))
|
||||||
|
{
|
||||||
|
if (intNum == 0 || intNum == 1)
|
||||||
|
{
|
||||||
|
result = [NSNumber numberWithBool: (BOOL) intNum];
|
||||||
|
}
|
||||||
|
else if (intNum < INT_MAX && intNum > INT_MIN)
|
||||||
|
{
|
||||||
|
result = [NSNumber numberWithInt: (int32_t)intNum];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
result = [NSNumber numberWithLongLong: intNum];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
result = [NSNumber numberWithLongLong: intNum];
|
{
|
||||||
|
doubleNum = unum_parseDouble(internal->_formatter,
|
||||||
|
ustring, length, NULL, &err);
|
||||||
|
if (!U_FAILURE(err))
|
||||||
|
{
|
||||||
|
result = [NSNumber numberWithDouble: doubleNum];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
GS_ENDITEMBUF()
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
doubleNum = unum_parseDouble(internal->_formatter,
|
|
||||||
ustring, length, NULL, &err);
|
|
||||||
if (U_FAILURE(err))
|
|
||||||
return nil;
|
|
||||||
result = [NSNumber numberWithDouble: doubleNum];
|
|
||||||
}
|
|
||||||
|
|
||||||
NSZoneFree ([self zone], ustring);
|
|
||||||
return result;
|
|
||||||
#else
|
|
||||||
return nil;
|
|
||||||
#endif
|
#endif
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue