add missing methods

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@30283 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Richard Frith-MacDonald 2010-05-03 06:00:45 +00:00
parent 4ad4022924
commit 886aa2d93c
3 changed files with 84 additions and 4 deletions

View file

@ -1,3 +1,9 @@
2010-05-03 Richard Frith-Macdonald <rfm@gnu.org>
* Headers/Foundation/NSString.h,
* Source/NSString.m: Add 10.4 write methods.
Fixes part of bug report #29736.
2010-05-02 Fred Kiefer <FredKiefer@gmx.de>
* Headers/Foundation/NSString.h,

View file

@ -298,6 +298,14 @@ typedef NSUInteger NSStringEncodingConversionOptions;
- (id) initWithContentsOfURL: (NSURL*)url
encoding: (NSStringEncoding)enc
error: (NSError**)error;
- (BOOL) writeToFile: (NSString*)path
atomically: (BOOL)atomically
encoding: (NSStringEncoding)enc
error: (NSError**)error;
- (BOOL) writeToURL: (NSURL*)url
atomically: (BOOL)atomically
encoding: (NSStringEncoding)enc
error: (NSError**)error;
#endif
#if OS_API_VERSION(100500,GS_API_LATEST)
- (NSString*)stringByReplacingOccurrencesOfString: (NSString*)replace

View file

@ -837,8 +837,8 @@ handle_printf_atsign (FILE *stream,
}
+ (id) stringWithContentsOfURL: (NSURL*)url
usedEncoding: (NSStringEncoding*)enc
error: (NSError**)error
usedEncoding: (NSStringEncoding*)enc
error: (NSError**)error
{
NSString *obj;
@ -848,8 +848,8 @@ handle_printf_atsign (FILE *stream,
}
+ (id) stringWithContentsOfURL: (NSURL*)url
encoding: (NSStringEncoding)enc
error: (NSError**)error
encoding: (NSStringEncoding)enc
error: (NSError**)error
{
NSString *obj;
@ -4702,6 +4702,72 @@ static NSFileManager *fm = nil;
return [d writeToFile: filename atomically: useAuxiliaryFile];
}
/**
* Writes contents out to file at filename, using the default C string encoding
* unless this would result in information loss, otherwise straight unicode.
* The '<code>atomically</code>' option if set will cause the contents to be
* written to a temp file, which is then closed and renamed to filename. Thus,
* an incomplete file at filename should never result.<br />
* If there is a problem and error is not NULL, the cause of the problem is
* returned in *error.
*/
- (BOOL) writeToFile: (NSString*)path
atomically: (BOOL)atomically
encoding: (NSStringEncoding)enc
error: (NSError**)error
{
id d = [self dataUsingEncoding: enc];
if (d == nil)
{
if (error != 0)
{
*error = [NSError errorWithDomain: NSCocoaErrorDomain
code: NSFileReadCorruptFileError
userInfo: nil];
}
return NO;
}
return [d writeToFile: path
options: atomically ? NSAtomicWrite : 0
error: error];
}
/**
* Writes contents out to anURL, using the default C string encoding
* unless this would result in information loss, otherwise straight unicode.
* See [NSURLHandle-writeData:] on which URL types are supported.
* The '<code>atomically</code>' option is only heeded if the URL is a
* <code>file://</code> URL; see -writeToFile:atomically: .<br />
* If there is a problem and error is not NULL, the cause of the problem is
* returned in *error.
*/
- (BOOL) writeToURL: (NSURL*)anURL
atomically: (BOOL)atomically
encoding: (NSStringEncoding)enc
error: (NSError**)error
{
id d = [self dataUsingEncoding: enc];
if (d == nil)
{
d = [self dataUsingEncoding: NSUnicodeStringEncoding];
}
if (d == nil)
{
if (error != 0)
{
*error = [NSError errorWithDomain: NSCocoaErrorDomain
code: NSFileReadCorruptFileError
userInfo: nil];
}
return NO;
}
return [d writeToURL: anURL
options: atomically ? NSAtomicWrite : 0
error: error];
}
/**
* Writes contents out to anURL, using the default C string encoding
* unless this would result in information loss, otherwise straight unicode.