mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-25 01:31:08 +00:00
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:
parent
f65f0ffe09
commit
b3c270ab07
5 changed files with 149 additions and 0 deletions
|
@ -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>
|
2003-07-15 David Ayers <d.ayers@inode.at>
|
||||||
|
|
||||||
* Headers/gnustep/base/NSUndoManager.h: Add
|
* Headers/gnustep/base/NSUndoManager.h: Add
|
||||||
|
|
|
@ -35,6 +35,9 @@
|
||||||
+ (id) array;
|
+ (id) array;
|
||||||
+ (id) arrayWithArray: (NSArray*)array;
|
+ (id) arrayWithArray: (NSArray*)array;
|
||||||
+ (id) arrayWithContentsOfFile: (NSString*)file;
|
+ (id) arrayWithContentsOfFile: (NSString*)file;
|
||||||
|
#ifndef STRICT_OPENSTEP
|
||||||
|
+ (id) arrayWithContentsOfURL: (NSURL*)aURL;
|
||||||
|
#endif
|
||||||
+ (id) arrayWithObject: (id)anObject;
|
+ (id) arrayWithObject: (id)anObject;
|
||||||
+ (id) arrayWithObjects: (id)firstObject, ...;
|
+ (id) arrayWithObjects: (id)firstObject, ...;
|
||||||
+ (id) arrayWithObjects: (id*)objects count: (unsigned)count;
|
+ (id) arrayWithObjects: (id*)objects count: (unsigned)count;
|
||||||
|
@ -54,6 +57,9 @@
|
||||||
- (id) initWithArray: (NSArray*)array copyItems: (BOOL)shouldCopy;
|
- (id) initWithArray: (NSArray*)array copyItems: (BOOL)shouldCopy;
|
||||||
#endif
|
#endif
|
||||||
- (id) initWithContentsOfFile: (NSString*)file;
|
- (id) initWithContentsOfFile: (NSString*)file;
|
||||||
|
#ifndef STRICT_OPENSTEP
|
||||||
|
- (id) initWithContentsOfURL: (NSURL*)aURL;
|
||||||
|
#endif
|
||||||
- (id) initWithObjects: firstObject, ...;
|
- (id) initWithObjects: firstObject, ...;
|
||||||
- (id) initWithObjects: (id*)objects count: (unsigned)count; // Primitive
|
- (id) initWithObjects: (id*)objects count: (unsigned)count; // Primitive
|
||||||
|
|
||||||
|
|
|
@ -31,6 +31,9 @@
|
||||||
@interface NSDictionary : NSObject <NSCoding, NSCopying, NSMutableCopying>
|
@interface NSDictionary : NSObject <NSCoding, NSCopying, NSMutableCopying>
|
||||||
+ (id) dictionary;
|
+ (id) dictionary;
|
||||||
+ (id) dictionaryWithContentsOfFile: (NSString*)path;
|
+ (id) dictionaryWithContentsOfFile: (NSString*)path;
|
||||||
|
#ifndef STRICT_OPENSTEP
|
||||||
|
+ (id) dictionaryWithContentsOfURL: (NSURL*)aURL;
|
||||||
|
#endif
|
||||||
+ (id) dictionaryWithDictionary: (NSDictionary*)otherDictionary;
|
+ (id) dictionaryWithDictionary: (NSDictionary*)otherDictionary;
|
||||||
+ (id) dictionaryWithObject: (id)object forKey: (id)key;
|
+ (id) dictionaryWithObject: (id)object forKey: (id)key;
|
||||||
+ (id) dictionaryWithObjects: (NSArray*)objects forKeys: (NSArray*)keys;
|
+ (id) dictionaryWithObjects: (NSArray*)objects forKeys: (NSArray*)keys;
|
||||||
|
@ -50,6 +53,9 @@
|
||||||
indent: (unsigned int)level;
|
indent: (unsigned int)level;
|
||||||
|
|
||||||
- (id) initWithContentsOfFile: (NSString*)path;
|
- (id) initWithContentsOfFile: (NSString*)path;
|
||||||
|
#ifndef STRICT_OPENSTEP
|
||||||
|
- (id) initWithContentsOfURL: (NSURL*)aURL;
|
||||||
|
#endif
|
||||||
- (id) initWithDictionary: (NSDictionary*)otherDictionary;
|
- (id) initWithDictionary: (NSDictionary*)otherDictionary;
|
||||||
- (id) initWithDictionary: (NSDictionary*)other copyItems: (BOOL)shouldCopy;
|
- (id) initWithDictionary: (NSDictionary*)other copyItems: (BOOL)shouldCopy;
|
||||||
- (id) initWithObjects: (NSArray*)objects forKeys: (NSArray*)keys;
|
- (id) initWithObjects: (NSArray*)objects forKeys: (NSArray*)keys;
|
||||||
|
|
|
@ -202,6 +202,21 @@ static SEL rlSel;
|
||||||
return AUTORELEASE(o);
|
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.
|
* Returns an autoreleased array containing anObject.
|
||||||
*/
|
*/
|
||||||
|
@ -597,6 +612,58 @@ static SEL rlSel;
|
||||||
return self;
|
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 />
|
/** <init />
|
||||||
* Initialize the array with count objects.<br />
|
* Initialize the array with count objects.<br />
|
||||||
* Retains each object placed in the array.<br />
|
* Retains each object placed in the array.<br />
|
||||||
|
|
|
@ -442,6 +442,59 @@ static SEL appSel;
|
||||||
return self;
|
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.
|
* Returns a dictionary using the file located at path.
|
||||||
* The file must be a property list containing a dictionary as its root object.
|
* The file must be a property list containing a dictionary as its root object.
|
||||||
|
@ -452,6 +505,16 @@ static SEL appSel;
|
||||||
initWithContentsOfFile: path]);
|
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
|
- (BOOL) isEqual: other
|
||||||
{
|
{
|
||||||
if (other == self)
|
if (other == self)
|
||||||
|
|
Loading…
Reference in a new issue