mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-23 09:04:13 +00:00
Fix a check for a null pointer and various whitespace/indentation tidyups
This commit is contained in:
parent
95a71ea552
commit
7ecb170800
2 changed files with 79 additions and 74 deletions
|
@ -32,91 +32,96 @@ static IMP originalRead = 0;
|
|||
static IMP originalWrite = 0;
|
||||
|
||||
@implementation NSPropertyListSerialization (PLUtilAdditions)
|
||||
+ (NSData *)_pdataFromPropertyList:(id)aPropertyList
|
||||
format:(NSPropertyListFormat)aFormat
|
||||
errorDescription:(NSString **)anErrorString
|
||||
+ (NSData*) _pdataFromPropertyList: (id)aPropertyList
|
||||
format: (NSPropertyListFormat)aFormat
|
||||
errorDescription: (NSString **)anErrorString
|
||||
{
|
||||
NSError * myError = nil;
|
||||
NSData * dest;
|
||||
NSDictionary *loc;
|
||||
NSError *myError = nil;
|
||||
NSData *dest;
|
||||
NSDictionary *loc;
|
||||
|
||||
loc = [[NSUserDefaults standardUserDefaults] dictionaryRepresentation];
|
||||
switch (aFormat)
|
||||
{
|
||||
case NSPropertyListJSONFormat:
|
||||
dest = [NSJSONSerialization
|
||||
dataWithJSONObject:aPropertyList
|
||||
options:loc != nil ? NSJSONWritingPrettyPrinted : 0
|
||||
error:&myError];
|
||||
if (myError != nil && anErrorString != NULL)
|
||||
{
|
||||
*anErrorString = [myError description];
|
||||
}
|
||||
return dest;
|
||||
case NSPropertyListObjectiveCFormat:
|
||||
case NSPropertyListSwiftFormat:
|
||||
*anErrorString = @"Not implemented";
|
||||
return nil;
|
||||
default:
|
||||
return (*originalWrite)(self, _cmd, aPropertyList, aFormat, anErrorString);
|
||||
case NSPropertyListJSONFormat:
|
||||
dest = [NSJSONSerialization
|
||||
dataWithJSONObject: aPropertyList
|
||||
options: loc != nil ? NSJSONWritingPrettyPrinted : 0
|
||||
error: &myError];
|
||||
if (myError != nil && anErrorString != NULL)
|
||||
{
|
||||
*anErrorString = [myError description];
|
||||
}
|
||||
return dest;
|
||||
case NSPropertyListObjectiveCFormat:
|
||||
case NSPropertyListSwiftFormat:
|
||||
*anErrorString = @"Not implemented";
|
||||
return nil;
|
||||
default:
|
||||
return (*originalWrite)(self, _cmd, aPropertyList,
|
||||
aFormat, anErrorString);
|
||||
}
|
||||
}
|
||||
|
||||
+ (id)_ppropertyListWithData:(NSData *)data
|
||||
options:(NSPropertyListReadOptions)anOption
|
||||
format:(NSPropertyListFormat *)aFormat
|
||||
error:(out NSError **)error;
|
||||
+ (id) _ppropertyListWithData: (NSData *)data
|
||||
options: (NSPropertyListReadOptions)anOption
|
||||
format: (NSPropertyListFormat *)aFormat
|
||||
error: (out NSError **)error;
|
||||
{
|
||||
NSError * myError = nil;
|
||||
NSPropertyListFormat format;
|
||||
NSJSONReadingOptions jsonOptions = NSJSONReadingAllowFragments;
|
||||
id prop = (*originalRead)(self, _cmd, data, anOption, &format, &myError);
|
||||
if (prop == nil)
|
||||
if (format == NSPropertyListOpenStepFormat
|
||||
NSError *myError = nil;
|
||||
NSPropertyListFormat format;
|
||||
NSJSONReadingOptions jsonOptions = NSJSONReadingAllowFragments;
|
||||
id prop;
|
||||
|
||||
prop = (*originalRead)(self, _cmd, data, anOption, &format, &myError);
|
||||
if (nil == prop)
|
||||
{
|
||||
if (format == NSPropertyListOpenStepFormat
|
||||
|| format == NSPropertyListGNUstepFormat)
|
||||
// rescue as json when we know it is not anything else
|
||||
{
|
||||
switch (anOption)
|
||||
{
|
||||
case NSPropertyListMutableContainersAndLeaves:
|
||||
jsonOptions |= NSJSONReadingMutableLeaves;
|
||||
/* FALLTHROUGH */
|
||||
case NSPropertyListMutableContainers:
|
||||
jsonOptions |= NSJSONReadingMutableContainers;
|
||||
}
|
||||
format = NSPropertyListJSONFormat;
|
||||
prop = [NSJSONSerialization JSONObjectWithData:data
|
||||
options:jsonOptions
|
||||
error:&myError];
|
||||
}
|
||||
// rescue as json when we know it is not anything else
|
||||
{
|
||||
switch (anOption)
|
||||
{
|
||||
case NSPropertyListMutableContainersAndLeaves:
|
||||
jsonOptions |= NSJSONReadingMutableLeaves;
|
||||
/* FALLTHROUGH */
|
||||
case NSPropertyListMutableContainers:
|
||||
jsonOptions |= NSJSONReadingMutableContainers;
|
||||
}
|
||||
format = NSPropertyListJSONFormat;
|
||||
prop = [NSJSONSerialization JSONObjectWithData: data
|
||||
options: jsonOptions
|
||||
error: &myError];
|
||||
}
|
||||
}
|
||||
if (error != NULL)
|
||||
*error = myError;
|
||||
if (*aFormat != NULL)
|
||||
*aFormat = format;
|
||||
{
|
||||
*error = myError;
|
||||
}
|
||||
if (aFormat != NULL)
|
||||
{
|
||||
*aFormat = format;
|
||||
}
|
||||
return prop;
|
||||
}
|
||||
|
||||
+ (void)load
|
||||
+ (void) load
|
||||
{
|
||||
Method replacementRead;
|
||||
Method replacementWrite;
|
||||
|
||||
replacementRead
|
||||
= class_getClassMethod(self, @selector
|
||||
(_ppropertyListWithData:options:format:error:));
|
||||
replacementWrite
|
||||
= class_getClassMethod(self, @selector
|
||||
(_pdataFromPropertyList:format:errorDescription:));
|
||||
replacementRead = class_getClassMethod(self,
|
||||
@selector(_ppropertyListWithData:options:format:error:));
|
||||
replacementWrite = class_getClassMethod(self,
|
||||
@selector(_pdataFromPropertyList:format:errorDescription:));
|
||||
|
||||
originalRead
|
||||
= class_replaceMethod(object_getClass(self),
|
||||
@selector(propertyListWithData:options:format:error:),
|
||||
method_getImplementation(replacementRead),
|
||||
method_getTypeEncoding(replacementRead));
|
||||
originalWrite
|
||||
= class_replaceMethod(object_getClass(self),
|
||||
@selector(dataFromPropertyList:
|
||||
format:errorDescription:),
|
||||
method_getImplementation(replacementWrite),
|
||||
method_getTypeEncoding(replacementWrite));
|
||||
originalRead = class_replaceMethod(object_getClass(self),
|
||||
@selector(propertyListWithData:options:format:error:),
|
||||
method_getImplementation(replacementRead),
|
||||
method_getTypeEncoding(replacementRead));
|
||||
originalWrite = class_replaceMethod(object_getClass(self),
|
||||
@selector(dataFromPropertyList:format:errorDescription:),
|
||||
method_getImplementation(replacementWrite),
|
||||
method_getTypeEncoding(replacementWrite));
|
||||
}
|
||||
@end
|
||||
|
|
|
@ -64,9 +64,9 @@ static const unsigned char quotables[32] = {
|
|||
id
|
||||
plIndex(id obj, NSString *key)
|
||||
{
|
||||
const char *ckey;
|
||||
char * endptr = NULL;
|
||||
NSInteger res;
|
||||
const char *ckey;
|
||||
char *endptr = NULL;
|
||||
NSInteger res;
|
||||
|
||||
if ([obj isKindOfClass: [NSDictionary class]])
|
||||
{
|
||||
|
@ -102,9 +102,9 @@ plIndex(id obj, NSString *key)
|
|||
void
|
||||
mutate(id obj, NSString *key, id leaf, BOOL replace)
|
||||
{
|
||||
const char *ckey;
|
||||
char * endptr = NULL;
|
||||
NSInteger res;
|
||||
const char *ckey;
|
||||
char *endptr = NULL;
|
||||
NSInteger res;
|
||||
|
||||
if ([obj isKindOfClass: [NSMutableDictionary class]])
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue