Oolite
Loading...
Searching...
No Matches
OOPListParsing.m File Reference
import "OOPListParsing.h"
import "NSDataOOExtensions.h"
import "OOLogging.h"
import "OOStringParsing.h"
import "Universe.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"
static NSString *const kOOLogPListInformation = @"plist.information"

Macro Definition Documentation

◆ NO_DYNAMIC_PLIST_DTD_CHANGE

#define NO_DYNAMIC_PLIST_DTD_CHANGE

Definition at line 34 of file OOPListParsing.m.

Function Documentation

◆ CopyDataFromFile()

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:84
NSString *const kOOLogFileNotFound
Definition OOLogging.m:601
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 213 of file OOPListParsing.m.

214{
215 id result = OOPropertyListFromData(data, whereFrom);
216 return ValueIfClass(result, [NSArray class]);
217}
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 219 of file OOPListParsing.m.

220{
221 id result = OOPropertyListFromFile(path);
222 return ValueIfClass(result, [NSArray class]);
223}
id OOPropertyListFromFile(NSString *path)

References OOPropertyListFromFile(), and ValueIfClass().

Referenced by ResourceManager::arrayFromFilesNamed:inFolder:andMerge:cache:, ResourceManager::checkOXPMessagesInPath:, and OOScript::worldScriptsAtPath:.

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()

◆ OOPropertyListFromData()

id OOPropertyListFromData ( NSData * data,
NSString * whereFrom )

Definition at line 48 of file OOPListParsing.m.

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

References kOOLogPListFoundationParseError, kOOLogPListInformation, nil, OOLog, and UNIVERSE.

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

Here is the caller graph for this function:

◆ OOPropertyListFromFile()

id OOPropertyListFromFile ( NSString * path)

Definition at line 83 of file OOPListParsing.m.

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

id ValueIfClass ( id value,
Class class )
static

Definition at line 226 of file OOPListParsing.m.

227{
228 if (value != nil && ![value isKindOfClass:class]) {
229 OOLog(kOOLogPListWrongType, @"Property list is wrong type - expected %@, got %@.", class, [value class]);
230 value = nil;
231 }
232 return value;
233}
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 37 of file OOPListParsing.m.

Referenced by OOPropertyListFromData().

◆ kOOLogPListInformation

NSString* const kOOLogPListInformation = @"plist.information"
static

Definition at line 39 of file OOPListParsing.m.

Referenced by OOPropertyListFromData().

◆ kOOLogPListWrongType

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

Definition at line 38 of file OOPListParsing.m.

Referenced by ValueIfClass().