* Source/GSString.m: Remove GSString copyWithZone:.

* Source/NSString.m: Raise exception when no is provided for the
string. This brings our implementation closer to the Cocoa one.
* Source/GSString.m: Add similar exceptions.
This commit is contained in:
fredkiefer 2018-07-06 23:53:32 +02:00
parent 1066ec7015
commit 5a72e1cfa8
3 changed files with 49 additions and 23 deletions

View file

@ -1,3 +1,10 @@
2018-07-06 Fred Kiefer <fredkiefer@gmx.de>
* Source/GSString.m: Remove GSString copyWithZone:.
* Source/NSString.m: Raise exception when no is provided for the
string. This brings our implementation closer to the Cocoa one.
* Source/GSString.m: Add similar exceptions.
2018-07-02 Richard Frith-Macdonald <rfm@gnu.org>
* Tests/base/NSString/test00.m: : Move _unicodeString from here...

View file

@ -1556,6 +1556,9 @@ fixBOM(unsigned char **bytes, NSUInteger*length, BOOL *owned,
size_t len;
GSStr me;
if (NULL == format)
[NSException raise: NSInvalidArgumentException
format: @"[GSPlaceholderString-initWithFormat:locale:arguments:]: NULL format"];
/*
* First we provide an array of unichar characters containing the
* format string. For performance reasons we try to use an on-stack
@ -1630,7 +1633,7 @@ fixBOM(unsigned char **bytes, NSUInteger*length, BOOL *owned,
if (string == nil)
[NSException raise: NSInvalidArgumentException
format: @"-initWithString: given nil string"];
format: @"GSPlaceholderString-initWithString: given nil string"];
if (NO == [string isKindOfClass: NSStringClass]) // may be proxy
[NSException raise: NSInvalidArgumentException
format: @"-initWithString: given non-string object"];
@ -1679,10 +1682,9 @@ fixBOM(unsigned char **bytes, NSUInteger*length, BOOL *owned,
GSStr me;
uint8_t c;
if (0 == bytes)
{
return (id)@"";
}
if (NULL == bytes)
[NSException raise: NSInvalidArgumentException
format: @"[GSPlaceholderString-initWithUTF8String:]: NULL cString"];
/* Skip leading BOM
*/
if (b[0] == 0xEF && b[1] == 0xBB && b[2] == 0xBF)
@ -3649,12 +3651,6 @@ transmute(GSStr self, NSString *aString)
setup(YES);
}
- (id) copyWithZone: (NSZone*)z
{
[self subclassResponsibility: _cmd];
return nil;
}
/*
* Return a 28-bit hash value for the string contents - this
* MUST match the algorithm used by the NSString base class.
@ -5062,6 +5058,9 @@ NSAssert(_flags.owned == 1 && _zone != 0, NSInternalInconsistencyException);
unichar *fmt = fbuf;
size_t len;
if (NULL == format)
[NSException raise: NSInvalidArgumentException
format: @"[GSMutableString-initWithFormat:locale:arguments:]: NULL format"];
/*
* First we provide an array of unichar characters containing the
* format string. For performance reasons we try to use an on-stack

View file

@ -938,6 +938,9 @@ GSICUCollatorOpen(NSStringCompareOptions mask, NSLocale *locale)
{
NSString *obj;
if (NULL == aString)
[NSException raise: NSInvalidArgumentException
format: @"[NSString+stringWithString:]: NULL string"];
obj = [self allocWithZone: NSDefaultMallocZone()];
obj = [obj initWithString: aString];
return AUTORELEASE(obj);
@ -964,10 +967,12 @@ GSICUCollatorOpen(NSStringCompareOptions mask, NSLocale *locale)
+ (id) stringWithCString: (const char*)byteString
{
NSString *obj;
unsigned length = byteString ? strlen(byteString) : 0;
if (NULL == byteString)
[NSException raise: NSInvalidArgumentException
format: @"[NSString+stringWithCString:]: NULL cString"];
obj = [self allocWithZone: NSDefaultMallocZone()];
obj = [obj initWithCString: byteString length: length];
obj = [obj initWithCString: byteString];
return AUTORELEASE(obj);
}
@ -1115,16 +1120,16 @@ GSICUCollatorOpen(NSStringCompareOptions mask, NSLocale *locale)
+ (id) stringWithFormat: (NSString*)format,...
{
va_list ap;
id ret;
NSString *obj;
if (NULL == format)
[NSException raise: NSInvalidArgumentException
format: @"[NSString+stringWithFormat:]: NULL format"];
va_start(ap, format);
if (format == nil)
ret = nil;
else
ret = AUTORELEASE([[self allocWithZone: NSDefaultMallocZone()]
initWithFormat: format arguments: ap]);
obj = [self allocWithZone: NSDefaultMallocZone()];
obj = [obj initWithFormat: format arguments: ap];
va_end(ap);
return ret;
return AUTORELEASE(obj);
}
@ -1275,8 +1280,11 @@ GSICUCollatorOpen(NSStringCompareOptions mask, NSLocale *locale)
- (id) initWithCString: (const char*)byteString
encoding: (NSStringEncoding)encoding
{
if (NULL == byteString)
[NSException raise: NSInvalidArgumentException
format: @"[NSString-initWithCString:encoding:]: NULL cString"];
return [self initWithBytes: byteString
length: (byteString ? strlen(byteString) : 0)
length: strlen(byteString)
encoding: encoding];
}
@ -1299,8 +1307,11 @@ GSICUCollatorOpen(NSStringCompareOptions mask, NSLocale *locale)
*/
- (id) initWithCString: (const char*)byteString
{
if (NULL == byteString)
[NSException raise: NSInvalidArgumentException
format: @"[NSString-initWithCString:]: NULL cString"];
return [self initWithBytes: byteString
length: (byteString ? strlen(byteString) : 0)
length: strlen(byteString)
encoding: _DefaultStringEncoding];
}
@ -1311,6 +1322,9 @@ GSICUCollatorOpen(NSStringCompareOptions mask, NSLocale *locale)
{
unsigned length = [string length];
if (NULL == string)
[NSException raise: NSInvalidArgumentException
format: @"[NSString-initWithString:]: NULL string"];
if (length > 0)
{
unichar *s = NSZoneMalloc([self zone], sizeof(unichar)*length);
@ -1334,8 +1348,11 @@ GSICUCollatorOpen(NSStringCompareOptions mask, NSLocale *locale)
*/
- (id) initWithUTF8String: (const char *)bytes
{
if (NULL == bytes)
[NSException raise: NSInvalidArgumentException
format: @"[NSString-initWithUTF8String:]: NULL cString"];
return [self initWithBytes: bytes
length: (bytes ? strlen(bytes) : 0)
length: strlen(bytes)
encoding: NSUTF8StringEncoding];
}
@ -1387,6 +1404,9 @@ GSICUCollatorOpen(NSStringCompareOptions mask, NSLocale *locale)
unichar *fmt = fbuf;
size_t len;
if (NULL == format)
[NSException raise: NSInvalidArgumentException
format: @"[NSString-initWithFormat:locale:arguments:]: NULL format"];
/*
* First we provide an array of unichar characters containing the
* format string. For performance reasons we try to use an on-stack