Add a few MacOS-X methods

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@17222 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
CaS 2003-07-15 16:35:11 +00:00
parent f65f0ffe09
commit b3c270ab07
5 changed files with 149 additions and 0 deletions

View file

@ -1,3 +1,10 @@
2003-07-15 Richard Frith-Macdonald <rfm@gnu.org>
* Headers/gnustep/base/NSArray.h: Add methods for creating from URL
* Headers/gnustep/base/NSDictionary.h: ditto
* Source/NSArray.m: ditto
* Source/NSDictionary.m: ditto
2003-07-15 David Ayers <d.ayers@inode.at>
* Headers/gnustep/base/NSUndoManager.h: Add

View file

@ -35,6 +35,9 @@
+ (id) array;
+ (id) arrayWithArray: (NSArray*)array;
+ (id) arrayWithContentsOfFile: (NSString*)file;
#ifndef STRICT_OPENSTEP
+ (id) arrayWithContentsOfURL: (NSURL*)aURL;
#endif
+ (id) arrayWithObject: (id)anObject;
+ (id) arrayWithObjects: (id)firstObject, ...;
+ (id) arrayWithObjects: (id*)objects count: (unsigned)count;
@ -54,6 +57,9 @@
- (id) initWithArray: (NSArray*)array copyItems: (BOOL)shouldCopy;
#endif
- (id) initWithContentsOfFile: (NSString*)file;
#ifndef STRICT_OPENSTEP
- (id) initWithContentsOfURL: (NSURL*)aURL;
#endif
- (id) initWithObjects: firstObject, ...;
- (id) initWithObjects: (id*)objects count: (unsigned)count; // Primitive

View file

@ -31,6 +31,9 @@
@interface NSDictionary : NSObject <NSCoding, NSCopying, NSMutableCopying>
+ (id) dictionary;
+ (id) dictionaryWithContentsOfFile: (NSString*)path;
#ifndef STRICT_OPENSTEP
+ (id) dictionaryWithContentsOfURL: (NSURL*)aURL;
#endif
+ (id) dictionaryWithDictionary: (NSDictionary*)otherDictionary;
+ (id) dictionaryWithObject: (id)object forKey: (id)key;
+ (id) dictionaryWithObjects: (NSArray*)objects forKeys: (NSArray*)keys;
@ -50,6 +53,9 @@
indent: (unsigned int)level;
- (id) initWithContentsOfFile: (NSString*)path;
#ifndef STRICT_OPENSTEP
- (id) initWithContentsOfURL: (NSURL*)aURL;
#endif
- (id) initWithDictionary: (NSDictionary*)otherDictionary;
- (id) initWithDictionary: (NSDictionary*)other copyItems: (BOOL)shouldCopy;
- (id) initWithObjects: (NSArray*)objects forKeys: (NSArray*)keys;

View file

@ -202,6 +202,21 @@ static SEL rlSel;
return AUTORELEASE(o);
}
/**
* Returns an autoreleased array from the contenta of aURL. The new array is
* created using +allocWithZone: and initialised using the
* -initWithContentsOfURL: method. See the documentation for those
* methods for more detail.
*/
+ (id) arrayWithContentsOfURL: (NSURL*)aURL
{
id o;
o = [self allocWithZone: NSDefaultMallocZone()];
o = [o initWithContentsOfURL: aURL];
return AUTORELEASE(o);
}
/**
* Returns an autoreleased array containing anObject.
*/
@ -597,6 +612,58 @@ static SEL rlSel;
return self;
}
/**
* <p>Initialises the array with the contents of the specified URL,
* which must contain an array in property-list format.
* </p>
* <p>In GNUstep, the property-list format may be either the OpenStep
* format (ASCII data), or the MacOS-X format (URF8 XML data) ... this
* method will recognise which it is.
* </p>
* <p>If there is a failure to load the URL for any reason, the receiver
* will be released, the method will return nil, and a warning may be logged.
* </p>
* <p>Works by invoking [NSString-initWithContentsOfURL:] and
* [NSString-propertyList] then checking that the result is an array.
* </p>
*/
- (id) initWithContentsOfURL: (NSURL*)aURL
{
NSString *myString;
myString = [[NSString allocWithZone: NSDefaultMallocZone()]
initWithContentsOfURL: aURL];
if (myString == nil)
{
DESTROY(self);
}
else
{
id result;
NS_DURING
{
result = [myString propertyList];
}
NS_HANDLER
{
result = nil;
}
NS_ENDHANDLER
RELEASE(myString);
if ([result isKindOfClass: NSArrayClass])
{
self = [self initWithArray: result];
}
else
{
NSWarnMLog(@"Contents of URL '%@' does not contain an array", aURL);
DESTROY(self);
}
}
return self;
}
/** <init />
* Initialize the array with count objects.<br />
* Retains each object placed in the array.<br />

View file

@ -442,6 +442,59 @@ static SEL appSel;
return self;
}
/**
* <p>Initialises the dictionary with the contents of the specified URL,
* which must contain a dictionary in property-list format.
* </p>
* <p>In GNUstep, the property-list format may be either the OpenStep
* format (ASCII data), or the MacOS-X format (URF8 XML data) ... this
* method will recognise which it is.
* </p>
* <p>If there is a failure to load the URL for any reason, the receiver
* will be released and the method will return nil.
* </p>
* <p>Works by invoking [NSString-initWithContentsOfURL:] and
* [NSString-propertyList] then checking that the result is a dictionary.
* </p>
*/
- (id) initWithContentsOfURL: (NSURL*)aURL
{
NSString *myString;
myString = [[NSString allocWithZone: NSDefaultMallocZone()]
initWithContentsOfURL: aURL];
if (myString == nil)
{
DESTROY(self);
}
else
{
id result;
NS_DURING
{
result = [myString propertyList];
}
NS_HANDLER
{
result = nil;
}
NS_ENDHANDLER
RELEASE(myString);
if ([result isKindOfClass: NSDictionaryClass])
{
self = [self initWithDictionary: result];
}
else
{
NSWarnMLog(@"Contents of URL '%@' does not contain a dictionary",
aURL);
DESTROY(self);
}
}
return self;
}
/**
* Returns a dictionary using the file located at path.
* The file must be a property list containing a dictionary as its root object.
@ -452,6 +505,16 @@ static SEL appSel;
initWithContentsOfFile: path]);
}
/**
* Returns a dictionary using the contents of aURL.
* The URL must be a property list containing a dictionary as its root object.
*/
+ (id) dictionaryWithContentsOfURL: (NSURL*)aURL
{
return AUTORELEASE([[self allocWithZone: NSDefaultMallocZone()]
initWithContentsOfURL: aURL]);
}
- (BOOL) isEqual: other
{
if (other == self)