mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-23 00:41:02 +00:00
Add a few missing 10.4 initWithContentsOfXXX: methods. Fixes part of bug report #29736.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@30279 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
b32ebbe2d7
commit
4ad4022924
3 changed files with 186 additions and 1 deletions
|
@ -1,3 +1,9 @@
|
|||
2010-05-02 Fred Kiefer <FredKiefer@gmx.de>
|
||||
|
||||
* Headers/Foundation/NSString.h,
|
||||
* Source/NSString.m: Add a few missing 10.4 initWithContentsOfXXX:
|
||||
methods. Fixes part of bug report #29736.
|
||||
|
||||
2010-05-01 Wolfgang Lux <wolfgang.lux@gmail.com>
|
||||
|
||||
* Source/Additions/GSObjCRuntime.m (GSObjCAllSubclassesOfClass):
|
||||
|
|
|
@ -273,13 +273,33 @@ typedef NSUInteger NSStringEncodingConversionOptions;
|
|||
encoding: (NSStringEncoding)encoding
|
||||
freeWhenDone: (BOOL)flag;
|
||||
#endif
|
||||
#if OS_API_VERSION(100500,GS_API_LATEST)
|
||||
#if OS_API_VERSION(100400,GS_API_LATEST)
|
||||
+ (id) stringWithContentsOfFile: (NSString*)path
|
||||
usedEncoding: (NSStringEncoding*)enc
|
||||
error: (NSError**)error;
|
||||
- (id) initWithContentsOfFile: (NSString*)path
|
||||
usedEncoding: (NSStringEncoding*)enc
|
||||
error: (NSError**)error;
|
||||
+ (id) stringWithContentsOfFile: (NSString*)path
|
||||
encoding: (NSStringEncoding)enc
|
||||
error: (NSError**)error;
|
||||
- (id) initWithContentsOfFile: (NSString*)path
|
||||
encoding: (NSStringEncoding)enc
|
||||
error: (NSError**)error;
|
||||
+ (id) stringWithContentsOfURL: (NSURL*)url
|
||||
usedEncoding: (NSStringEncoding*)enc
|
||||
error: (NSError**)error;
|
||||
- (id) initWithContentsOfURL: (NSURL*)url
|
||||
usedEncoding: (NSStringEncoding*)enc
|
||||
error: (NSError**)error;
|
||||
+ (id) stringWithContentsOfURL: (NSURL*)url
|
||||
encoding: (NSStringEncoding)enc
|
||||
error: (NSError**)error;
|
||||
- (id) initWithContentsOfURL: (NSURL*)url
|
||||
encoding: (NSStringEncoding)enc
|
||||
error: (NSError**)error;
|
||||
#endif
|
||||
#if OS_API_VERSION(100500,GS_API_LATEST)
|
||||
- (NSString*)stringByReplacingOccurrencesOfString: (NSString*)replace
|
||||
withString: (NSString*)by
|
||||
options: (NSStringCompareOptions)opts
|
||||
|
|
|
@ -807,6 +807,21 @@ handle_printf_atsign (FILE *stream,
|
|||
return AUTORELEASE(obj);
|
||||
}
|
||||
|
||||
/**
|
||||
* Load contents of file at path into a new string using the
|
||||
* -initWithContentsOfFile:encoding:error: method.
|
||||
*/
|
||||
+ (id) stringWithContentsOfFile: (NSString*)path
|
||||
encoding: (NSStringEncoding)enc
|
||||
error: (NSError**)error
|
||||
{
|
||||
NSString *obj;
|
||||
|
||||
obj = [self allocWithZone: NSDefaultMallocZone()];
|
||||
obj = [obj initWithContentsOfFile: path encoding: enc error: error];
|
||||
return AUTORELEASE(obj);
|
||||
}
|
||||
|
||||
/**
|
||||
* Load contents of given URL into a new string. Will interpret contents as
|
||||
* containing direct unicode if it begins with the unicode byte order mark,
|
||||
|
@ -821,6 +836,28 @@ handle_printf_atsign (FILE *stream,
|
|||
return AUTORELEASE(obj);
|
||||
}
|
||||
|
||||
+ (id) stringWithContentsOfURL: (NSURL*)url
|
||||
usedEncoding: (NSStringEncoding*)enc
|
||||
error: (NSError**)error
|
||||
{
|
||||
NSString *obj;
|
||||
|
||||
obj = [self allocWithZone: NSDefaultMallocZone()];
|
||||
obj = [obj initWithContentsOfURL: url usedEncoding: enc error: error];
|
||||
return AUTORELEASE(obj);
|
||||
}
|
||||
|
||||
+ (id) stringWithContentsOfURL: (NSURL*)url
|
||||
encoding: (NSStringEncoding)enc
|
||||
error: (NSError**)error
|
||||
{
|
||||
NSString *obj;
|
||||
|
||||
obj = [self allocWithZone: NSDefaultMallocZone()];
|
||||
obj = [obj initWithContentsOfURL: url encoding: enc error: error];
|
||||
return AUTORELEASE(obj);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new string using C printf-style formatting. First argument should
|
||||
* be a constant format string, like '<code>@"float val = %f"</code>', remaining
|
||||
|
@ -1318,6 +1355,40 @@ handle_printf_atsign (FILE *stream,
|
|||
return self;
|
||||
}
|
||||
|
||||
- (id) initWithContentsOfFile: (NSString*)path
|
||||
encoding: (NSStringEncoding)enc
|
||||
error: (NSError**)error
|
||||
{
|
||||
NSData *d;
|
||||
unsigned int len;
|
||||
|
||||
d = [[NSDataClass alloc] initWithContentsOfFile: path];
|
||||
if (d == nil)
|
||||
{
|
||||
DESTROY(self);
|
||||
return nil;
|
||||
}
|
||||
len = [d length];
|
||||
if (len == 0)
|
||||
{
|
||||
RELEASE(d);
|
||||
DESTROY(self);
|
||||
return @"";
|
||||
}
|
||||
self = [self initWithData: d encoding: enc];
|
||||
RELEASE(d);
|
||||
if (self == nil)
|
||||
{
|
||||
if (error != 0)
|
||||
{
|
||||
*error = [NSError errorWithDomain: NSCocoaErrorDomain
|
||||
code: NSFileReadCorruptFileError
|
||||
userInfo: nil];
|
||||
}
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Initialises the receiver with the contents of the given URL.
|
||||
* </p>
|
||||
|
@ -1379,6 +1450,94 @@ handle_printf_atsign (FILE *stream,
|
|||
return self;
|
||||
}
|
||||
|
||||
- (id) initWithContentsOfURL: (NSURL*)url
|
||||
usedEncoding: (NSStringEncoding*)enc
|
||||
error: (NSError**)error
|
||||
{
|
||||
NSData *d;
|
||||
unsigned int len;
|
||||
const unsigned char *data_bytes;
|
||||
|
||||
d = [[NSDataClass alloc] dataWithContentsOfURL: url];
|
||||
if (d == nil)
|
||||
{
|
||||
DESTROY(self);
|
||||
return nil;
|
||||
}
|
||||
*enc = _DefaultStringEncoding;
|
||||
len = [d length];
|
||||
if (len == 0)
|
||||
{
|
||||
RELEASE(d);
|
||||
DESTROY(self);
|
||||
return @"";
|
||||
}
|
||||
data_bytes = [d bytes];
|
||||
if ((data_bytes != NULL) && (len >= 2))
|
||||
{
|
||||
const unichar *data_ucs2chars = (const unichar *) data_bytes;
|
||||
if ((data_ucs2chars[0] == byteOrderMark)
|
||||
|| (data_ucs2chars[0] == byteOrderMarkSwapped))
|
||||
{
|
||||
/* somebody set up us the BOM! */
|
||||
*enc = NSUnicodeStringEncoding;
|
||||
}
|
||||
else if (len >= 3
|
||||
&& data_bytes[0] == 0xEF
|
||||
&& data_bytes[1] == 0xBB
|
||||
&& data_bytes[2] == 0xBF)
|
||||
{
|
||||
*enc = NSUTF8StringEncoding;
|
||||
}
|
||||
}
|
||||
self = [self initWithData: d encoding: *enc];
|
||||
RELEASE(d);
|
||||
if (self == nil)
|
||||
{
|
||||
if (error != 0)
|
||||
{
|
||||
*error = [NSError errorWithDomain: NSCocoaErrorDomain
|
||||
code: NSFileReadCorruptFileError
|
||||
userInfo: nil];
|
||||
}
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (id) initWithContentsOfURL: (NSURL*)url
|
||||
encoding: (NSStringEncoding)enc
|
||||
error: (NSError**)error
|
||||
{
|
||||
NSData *d;
|
||||
unsigned int len;
|
||||
|
||||
d = [[NSDataClass alloc] dataWithContentsOfURL: url];
|
||||
if (d == nil)
|
||||
{
|
||||
DESTROY(self);
|
||||
return nil;
|
||||
}
|
||||
len = [d length];
|
||||
if (len == 0)
|
||||
{
|
||||
RELEASE(d);
|
||||
DESTROY(self);
|
||||
return @"";
|
||||
}
|
||||
self = [self initWithData: d encoding: enc];
|
||||
RELEASE(d);
|
||||
if (self == nil)
|
||||
{
|
||||
if (error != 0)
|
||||
{
|
||||
*error = [NSError errorWithDomain: NSCocoaErrorDomain
|
||||
code: NSFileReadCorruptFileError
|
||||
userInfo: nil];
|
||||
}
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of Unicode characters in this string, including the
|
||||
* individual characters of composed character sequences,
|
||||
|
|
Loading…
Reference in a new issue