Oolite 1.91.0.7646-241128-10e222e
Loading...
Searching...
No Matches
OOPListParsing.m File Reference
import "OOPListParsing.h"
import "OOLogging.h"
import "OOStringParsing.h"
import "NSDataOOExtensions.h"
#include <ctype.h>
#include <string.h>
+ Include dependency graph for OOPListParsing.m:

Go to the source code of this file.

Macros

#define NO_DYNAMIC_PLIST_DTD_CHANGE
 

Functions

static NSData * CopyDataFromFile (NSString *path)
 
static id ValueIfClass (id value, Class class)
 
id OOPropertyListFromData (NSData *data, NSString *whereFrom)
 
id OOPropertyListFromFile (NSString *path)
 
NSDictionary * OODictionaryFromData (NSData *data, NSString *whereFrom)
 
NSDictionary * OODictionaryFromFile (NSString *path)
 
NSArray * OOArrayFromData (NSData *data, NSString *whereFrom)
 
NSArray * OOArrayFromFile (NSString *path)
 

Variables

static NSString *const kOOLogPListFoundationParseError = @"plist.parse.failed"
 
static NSString *const kOOLogPListWrongType = @"plist.wrongType"
 

Macro Definition Documentation

◆ NO_DYNAMIC_PLIST_DTD_CHANGE

#define NO_DYNAMIC_PLIST_DTD_CHANGE

Definition at line 35 of file OOPListParsing.m.

Function Documentation

◆ CopyDataFromFile()

static NSData * CopyDataFromFile ( NSString * path)
static

Definition at line 173 of file OOPListParsing.m.

174{
175 return [[NSData oo_dataWithOXZFile:path] retain];
176#if 0
177// without OXZ extension. Code to be deleted once everything is working
178#if OOLITE_MAC_OS_X
179 return [[NSData alloc] initWithContentsOfMappedFile:path];
180#else
181 NSFileManager *fmgr = [NSFileManager defaultManager];
182 BOOL dir;
183
184 if ([fmgr fileExistsAtPath:path isDirectory:&dir])
185 {
186 if (!dir)
187 {
188 return [[NSData alloc] initWithContentsOfMappedFile:path];
189 }
190 else
191 {
192 OOLog(kOOLogFileNotFound, @"Expected property list but found directory at %@", path);
193 }
194 }
195
196 return nil;
197#endif
198#endif
199}
#define OOLog(class, format,...)
Definition OOLogging.h:88
NSString *const kOOLogFileNotFound
Definition OOLogging.m:652
return nil

References kOOLogFileNotFound, nil, and OOLog.

Referenced by OOPropertyListFromFile().

+ Here is the caller graph for this function:

◆ OOArrayFromData()

NSArray * OOArrayFromData ( NSData * data,
NSString * whereFrom )

Definition at line 215 of file OOPListParsing.m.

216{
217 id result = OOPropertyListFromData(data, whereFrom);
218 return ValueIfClass(result, [NSArray class]);
219}
static id ValueIfClass(id value, Class class)
id OOPropertyListFromData(NSData *data, NSString *whereFrom)

References OOPropertyListFromData(), and ValueIfClass().

+ Here is the call graph for this function:

◆ OOArrayFromFile()

NSArray * OOArrayFromFile ( NSString * path)

Definition at line 222 of file OOPListParsing.m.

223{
224 id result = OOPropertyListFromFile(path);
225 return ValueIfClass(result, [NSArray class]);
226}
id OOPropertyListFromFile(NSString *path)

References OOPropertyListFromFile(), and ValueIfClass().

Referenced by OOScript::descriptionComponents.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ OODictionaryFromData()

NSDictionary * OODictionaryFromData ( NSData * data,
NSString * whereFrom )

Definition at line 201 of file OOPListParsing.m.

202{
203 id result = OOPropertyListFromData(data, whereFrom);
204 return ValueIfClass(result, [NSDictionary class]);
205}

References OOPropertyListFromData(), and ValueIfClass().

+ Here is the call graph for this function:

◆ OODictionaryFromFile()

NSDictionary * OODictionaryFromFile ( NSString * path)

Definition at line 208 of file OOPListParsing.m.

209{
210 id result = OOPropertyListFromFile(path);
211 return ValueIfClass(result, [NSDictionary class]);
212}

References OOPropertyListFromFile(), and ValueIfClass().

Referenced by NSFileManager(OOExtensions)::commanderContentsOfPath:, and LoadExplicitSettings().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ OOPropertyListFromData()

id OOPropertyListFromData ( NSData * data,
NSString * whereFrom )

Definition at line 51 of file OOPListParsing.m.

52{
53 id result = nil;
54 NSString *error = nil;
55
56 if (data != nil)
57 {
58#ifndef NO_DYNAMIC_PLIST_DTD_CHANGE
59 data = ChangeDTDIfApplicable(data);
60#endif
61
62 result = [NSPropertyListSerialization propertyListFromData:data mutabilityOption:NSPropertyListImmutable format:NULL errorDescription:&error];
63 if (result == nil) // Foundation parser failed
64 {
65#if OOLITE_RELEASE_PLIST_ERROR_STRINGS
66 [error autorelease];
67#endif
68 // Ensure we can say something sensible...
69 if (error == nil) error = @"<no error message>";
70 if (whereFrom == nil) whereFrom = @"<data in memory>";
71
72 OOLog(kOOLogPListFoundationParseError, @"Failed to parse %@ as a property list.\n%@", whereFrom, error);
73 }
74 }
75
76 return result;
77}
static NSString *const kOOLogPListFoundationParseError

References kOOLogPListFoundationParseError, nil, and OOLog.

Referenced by OOArrayFromData(), OODictionaryFromData(), and OOPropertyListFromFile().

+ Here is the caller graph for this function:

◆ OOPropertyListFromFile()

id OOPropertyListFromFile ( NSString * path)

Definition at line 80 of file OOPListParsing.m.

81{
82 id result = nil;
83 NSData *data = nil;
84
85 if (path != nil)
86 {
87 // Load file, if it exists...
88 data = CopyDataFromFile(path);
89 if (data != nil)
90 {
91 // ...and parse it
92 result = OOPropertyListFromData(data, path);
93 [data release];
94 }
95 // Non-existent file is not an error.
96 }
97
98 return result;
99}
static NSData * CopyDataFromFile(NSString *path)

References CopyDataFromFile(), nil, and OOPropertyListFromData().

Referenced by OOArrayFromFile(), and OODictionaryFromFile().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ValueIfClass()

static id ValueIfClass ( id value,
Class class )
static

Definition at line 230 of file OOPListParsing.m.

231{
232 if (value != nil && ![value isKindOfClass:class])
233 {
234 OOLog(kOOLogPListWrongType, @"Property list is wrong type - expected %@, got %@.", class, [value class]);
235 value = nil;
236 }
237 return value;
238}
static NSString *const kOOLogPListWrongType

References kOOLogPListWrongType, nil, and OOLog.

Referenced by OOArrayFromData(), OOArrayFromFile(), OODictionaryFromData(), and OODictionaryFromFile().

+ Here is the caller graph for this function:

Variable Documentation

◆ kOOLogPListFoundationParseError

NSString* const kOOLogPListFoundationParseError = @"plist.parse.failed"
static

Definition at line 39 of file OOPListParsing.m.

Referenced by OOPropertyListFromData().

◆ kOOLogPListWrongType

NSString* const kOOLogPListWrongType = @"plist.wrongType"
static

Definition at line 40 of file OOPListParsing.m.

Referenced by ValueIfClass().