mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-22 16:33:29 +00:00
Ensure property-list file storage is in UTF8 or ASCII
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@13181 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
e7affc80ba
commit
51f3983b3d
4 changed files with 112 additions and 10 deletions
|
@ -1,3 +1,8 @@
|
|||
2002-03-21 Richard Frith-Macdonald <rfm@gnu.org>
|
||||
|
||||
* Source/NSArray.m: Ensure property-list read/write uses UTF8
|
||||
* Source/NSDictionary.m: ditto
|
||||
|
||||
2002-03-20 Richard Frith-Macdonald <rfm@gnu.org>
|
||||
|
||||
* Source/GSString.m: lossyCString_u() handle case where cString
|
||||
|
|
|
@ -89,9 +89,9 @@
|
|||
- (NSString*) descriptionWithLocale: (NSDictionary*)locale
|
||||
indent: (unsigned int)level;
|
||||
|
||||
- (BOOL) writeToFile: (NSString*)path atomically: (BOOL)useAuxilliaryFile;
|
||||
- (BOOL) writeToFile: (NSString*)path atomically: (BOOL)useAuxiliaryFile;
|
||||
#ifndef STRICT_OPENSTEP
|
||||
- (BOOL) writeToURL: (NSURL*)url atomically: (BOOL)useAuxilliaryFile;
|
||||
- (BOOL) writeToURL: (NSURL*)url atomically: (BOOL)useAuxiliaryFile;
|
||||
#endif
|
||||
@end
|
||||
|
||||
|
|
|
@ -33,6 +33,7 @@
|
|||
#include <base/behavior.h>
|
||||
#include <Foundation/NSArray.h>
|
||||
#include <Foundation/NSCoder.h>
|
||||
#include <Foundation/NSData.h>
|
||||
#include <Foundation/NSString.h>
|
||||
#include <Foundation/NSRange.h>
|
||||
#include <limits.h>
|
||||
|
@ -418,12 +419,29 @@ static SEL rlSel;
|
|||
return [self initWithObjects: 0 count: 0];
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Initialises the array with the contents of the specified file,
|
||||
* 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 file for any reason, the receiver
|
||||
* will be released and the method will return nil.
|
||||
* </p>
|
||||
*/
|
||||
- (id) initWithContentsOfFile: (NSString*)file
|
||||
{
|
||||
NSString *myString;
|
||||
NSData *someData;
|
||||
|
||||
myString = [[NSString allocWithZone: NSDefaultMallocZone()]
|
||||
someData = [[NSData allocWithZone: NSDefaultMallocZone()]
|
||||
initWithContentsOfFile: file];
|
||||
myString = [[NSString allocWithZone: NSDefaultMallocZone()]
|
||||
initWithData: someData encoding: NSUTF8StringEncoding];
|
||||
RELEASE(someData);
|
||||
|
||||
if (myString)
|
||||
{
|
||||
id result;
|
||||
|
@ -831,7 +849,30 @@ static NSString *indentStrings[] = {
|
|||
}
|
||||
}
|
||||
|
||||
- (BOOL) writeToFile: (NSString *)path atomically: (BOOL)useAuxilliaryFile
|
||||
/**
|
||||
* <p>Writes the contents of the array to the file specified by path.
|
||||
* The file contents will be in property-list format ... under GNUstep
|
||||
* this is either OpenStep style (ASCII characters using \U hexadecimal
|
||||
* escape sequences for unicode), or MacOS-X style (XML in the UTF8
|
||||
* character set).
|
||||
* </p>
|
||||
* <p>If the useAuxiliaryFile flag is YES, the file write operation is
|
||||
* atomic ... the data is written to a temporary file, which is then
|
||||
* renamed to the actual file name.
|
||||
* </p>
|
||||
* <p>If the conversion of data into the correct property-list format fails
|
||||
* or the write operation fails, the method returns NO, otherwise it
|
||||
* returns YES.
|
||||
* </p>
|
||||
* <p>NB. The fact that the file is in property-list format does not
|
||||
* necessarily mean that it can be used to reconstruct the array using
|
||||
* the -initWithContentsOfFile: method. If the original array contains
|
||||
* non-property-list objects, the descriptions of those objects will
|
||||
* have been written, and reading in the file as a property-list will
|
||||
* result in a new array containing the string descriptions.
|
||||
* </p>
|
||||
*/
|
||||
- (BOOL) writeToFile: (NSString *)path atomically: (BOOL)useAuxiliaryFile
|
||||
{
|
||||
extern BOOL GSMacOSXCompatiblePropertyLists();
|
||||
NSDictionary *loc;
|
||||
|
@ -857,10 +898,17 @@ static NSString *indentStrings[] = {
|
|||
desc = result;
|
||||
}
|
||||
|
||||
return [desc writeToFile: path atomically: useAuxilliaryFile];
|
||||
return [[desc dataUsingEncoding: NSUTF8StringEncoding]
|
||||
writeToFile: path atomically: useAuxiliaryFile];
|
||||
}
|
||||
|
||||
- (BOOL) writeToURL: (NSURL *)url atomically: (BOOL)useAuxilliaryFile
|
||||
/**
|
||||
* <p>Writes the contents of the array to the specified url.
|
||||
* This functions just like -writeToFile:atomically: except that the
|
||||
* output may be written to any URL, not just a local file.
|
||||
* </p>
|
||||
*/
|
||||
- (BOOL) writeToURL: (NSURL *)url atomically: (BOOL)useAuxiliaryFile
|
||||
{
|
||||
extern BOOL GSMacOSXCompatiblePropertyLists();
|
||||
NSDictionary *loc;
|
||||
|
@ -886,7 +934,8 @@ static NSString *indentStrings[] = {
|
|||
desc = result;
|
||||
}
|
||||
|
||||
return [desc writeToURL: url atomically: useAuxilliaryFile];
|
||||
return [[desc dataUsingEncoding: NSUTF8StringEncoding]
|
||||
writeToURL: url atomically: useAuxiliaryFile];
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
|
@ -29,6 +29,7 @@
|
|||
#include <base/behavior.h>
|
||||
#include <Foundation/NSDictionary.h>
|
||||
#include <Foundation/NSArray.h>
|
||||
#include <Foundation/NSData.h>
|
||||
#include <Foundation/NSUtilities.h>
|
||||
#include <Foundation/NSString.h>
|
||||
#include <Foundation/NSException.h>
|
||||
|
@ -412,12 +413,28 @@ static SEL appSel;
|
|||
return self;
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Initialises the dictionary with the contents of the specified file,
|
||||
* 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 file for any reason, the receiver
|
||||
* will be released and the method will return nil.
|
||||
* </p>
|
||||
*/
|
||||
- (id) initWithContentsOfFile: (NSString*)path
|
||||
{
|
||||
NSString *myString;
|
||||
NSData *someData;
|
||||
|
||||
myString = [[NSString allocWithZone: NSDefaultMallocZone()]
|
||||
someData = [[NSData allocWithZone: NSDefaultMallocZone()]
|
||||
initWithContentsOfFile: path];
|
||||
myString = [[NSString allocWithZone: NSDefaultMallocZone()]
|
||||
initWithData: someData encoding: NSUTF8StringEncoding];
|
||||
RELEASE(someData);
|
||||
if (myString)
|
||||
{
|
||||
id result;
|
||||
|
@ -630,6 +647,29 @@ compareIt(id o1, id o2, void* context)
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Writes the contents of the dictionary to the file specified by path.
|
||||
* The file contents will be in property-list format ... under GNUstep
|
||||
* this is either OpenStep style (ASCII characters using \U hexadecimal
|
||||
* escape sequences for unicode), or MacOS-X style (XML in the UTF8
|
||||
* character set).
|
||||
* </p>
|
||||
* <p>If the useAuxiliaryFile flag is YES, the file write operation is
|
||||
* atomic ... the data is written to a temporary file, which is then
|
||||
* renamed to the actual file name.
|
||||
* </p>
|
||||
* <p>If the conversion of data into the correct property-list format fails
|
||||
* or the write operation fails, the method returns NO, otherwise it
|
||||
* returns YES.
|
||||
* </p>
|
||||
* <p>NB. The fact that the file is in property-list format does not
|
||||
* necessarily mean that it can be used to reconstruct the dictionary using
|
||||
* the -initWithContentsOfFile: method. If the original dictionary contains
|
||||
* non-property-list objects, the descriptions of those objects will
|
||||
* have been written, and reading in the file as a property-list will
|
||||
* result in a new dictionary containing the string descriptions.
|
||||
* </p>
|
||||
*/
|
||||
- (BOOL) writeToFile: (NSString *)path atomically: (BOOL)useAuxiliaryFile
|
||||
{
|
||||
extern BOOL GSMacOSXCompatiblePropertyLists();
|
||||
|
@ -656,9 +696,16 @@ compareIt(id o1, id o2, void* context)
|
|||
desc = result;
|
||||
}
|
||||
|
||||
return [desc writeToFile: path atomically: useAuxiliaryFile];
|
||||
return [[desc dataUsingEncoding: NSUTF8StringEncoding]
|
||||
writeToFile: path atomically: useAuxiliaryFile];
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Writes the contents of the dictionary to the specified url.
|
||||
* This functions just like -writeToFile:atomically: except that the
|
||||
* output may be written to any URL, not just a local file.
|
||||
* </p>
|
||||
*/
|
||||
- (BOOL) writeToURL: (NSURL *)url atomically: (BOOL)useAuxiliaryFile
|
||||
{
|
||||
extern BOOL GSMacOSXCompatiblePropertyLists();
|
||||
|
@ -685,7 +732,8 @@ compareIt(id o1, id o2, void* context)
|
|||
desc = result;
|
||||
}
|
||||
|
||||
return [desc writeToURL: url atomically: useAuxiliaryFile];
|
||||
return [[desc dataUsingEncoding: NSUTF8StringEncoding]
|
||||
writeToURL: url atomically: useAuxiliaryFile];
|
||||
}
|
||||
|
||||
- (NSString*) description
|
||||
|
|
Loading…
Reference in a new issue