mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-23 00:41:02 +00:00
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:
parent
4ad4022924
commit
886aa2d93c
3 changed files with 84 additions and 4 deletions
|
@ -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,
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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.
|
||||
|
|
Loading…
Reference in a new issue