mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-22 16:33:29 +00:00
Add validation
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@14962 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
dda2ce15f6
commit
1e45aef232
2 changed files with 69 additions and 1 deletions
|
@ -2,6 +2,8 @@
|
|||
|
||||
* Source/NSObject.m: use NSString implementation of
|
||||
([descriptionWithLocale:indent:to:])
|
||||
* Source/NSUserDefaults.m: ([setObject:forKey:]) validate and raise
|
||||
exceptions if given bad info.
|
||||
|
||||
2002-11-07 02:21 Alexander Malmberg <alexander@malmberg.org>
|
||||
|
||||
|
|
|
@ -1030,6 +1030,60 @@ static NSString *pathForUser(NSString *user)
|
|||
return;
|
||||
}
|
||||
|
||||
static BOOL isPlistObject(id o)
|
||||
{
|
||||
if ([o isKindOfClass: [NSString class]] == YES)
|
||||
{
|
||||
return YES;
|
||||
}
|
||||
if ([o isKindOfClass: [NSData class]] == YES)
|
||||
{
|
||||
return YES;
|
||||
}
|
||||
if ([o isKindOfClass: [NSDate class]] == YES)
|
||||
{
|
||||
return YES;
|
||||
}
|
||||
if ([o isKindOfClass: [NSNumber class]] == YES)
|
||||
{
|
||||
return YES;
|
||||
}
|
||||
if ([o isKindOfClass: [NSArray class]] == YES)
|
||||
{
|
||||
NSEnumerator *e = [o objectEnumerator];
|
||||
id tmp;
|
||||
|
||||
while ((tmp = [e nextObject]) != nil)
|
||||
{
|
||||
if (isPlistObject(tmp) == NO)
|
||||
{
|
||||
return NO;
|
||||
}
|
||||
}
|
||||
return YES;
|
||||
}
|
||||
if ([o isKindOfClass: [NSDictionary class]] == YES)
|
||||
{
|
||||
NSEnumerator *e = [o keyEnumerator];
|
||||
id tmp;
|
||||
|
||||
while ((tmp = [e nextObject]) != nil)
|
||||
{
|
||||
if (isPlistObject(tmp) == NO)
|
||||
{
|
||||
return NO;
|
||||
}
|
||||
tmp = [o objectForKey: tmp];
|
||||
if (isPlistObject(tmp) == NO)
|
||||
{
|
||||
return NO;
|
||||
}
|
||||
}
|
||||
return YES;
|
||||
}
|
||||
return NO;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets an object value for defaultName in the application domain.
|
||||
* <br />Causes a NSUserDefaultsDidChangeNotification to be posted
|
||||
|
@ -1038,7 +1092,19 @@ static NSString *pathForUser(NSString *user)
|
|||
*/
|
||||
- (void) setObject: (id)value forKey: (NSString*)defaultName
|
||||
{
|
||||
if (value && defaultName && ([defaultName length] > 0))
|
||||
if (value == nil)
|
||||
{
|
||||
[NSException raise: NSInvalidArgumentException
|
||||
format: @"attempt to set nil object for key (%@)", defaultName];
|
||||
}
|
||||
if (isPlistObject(value) == NO)
|
||||
{
|
||||
[NSException raise: NSInvalidArgumentException
|
||||
format: @"attempt to set non propetrty list object for key (%@)",
|
||||
defaultName];
|
||||
}
|
||||
|
||||
if (defaultName != nil && ([defaultName length] > 0))
|
||||
{
|
||||
NSMutableDictionary *dict;
|
||||
id obj;
|
||||
|
|
Loading…
Reference in a new issue