Tidied PL handling

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@15139 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
CaS 2002-11-27 13:56:00 +00:00
parent bb74d6f839
commit e825c3ea98
5 changed files with 73 additions and 37 deletions

View file

@ -4,6 +4,8 @@
from NSObjCRuntime, plus renamed behavior functions, plus a few other from NSObjCRuntime, plus renamed behavior functions, plus a few other
runtime manipulation functions. EXPERIMENTAL runtime manipulation functions. EXPERIMENTAL
* Headers/gnustep/base/GSObjCRuntime.h: declarations for above. * Headers/gnustep/base/GSObjCRuntime.h: declarations for above.
* Source/GSCompatibility.m: Don't use new format plists when writing
descriptions.
2002-11-26 Richard Frith-Macdonald <rfm@gnu.org> 2002-11-26 Richard Frith-Macdonald <rfm@gnu.org>

View file

@ -446,21 +446,24 @@ static NSString *indentStrings[] = {
@"\t\t\t\t\t\t" @"\t\t\t\t\t\t"
}; };
#define PLNEW 0
#define PLXML 1
#define PLOLD 2
/** /**
* obj is the object to be written out<br /> * obj is the object to be written out<br />
* loc is the locale for formatting (or nil to indicate no formatting)<br /> * loc is the locale for formatting (or nil to indicate no formatting)<br />
* lev is the level of indentation to use<br /> * lev is the level of indentation to use<br />
* step is the indentation step (0 == 0, 1 = 2, 2 = 4, 3 = 8)<br /> * step is the indentation step (0 == 0, 1 = 2, 2 = 4, 3 = 8)<br />
* x is a flag to indicate xml property list format<br /> * x is an indicator for xml or old/new openstep property list format<br />
* dest is the output buffer. * dest is the output buffer.
*/ */
static void static void
OAppend(id obj, NSDictionary *loc, unsigned lev, unsigned step, OAppend(id obj, NSDictionary *loc, unsigned lev, unsigned step,
BOOL x, GSMutableString *dest) int x, GSMutableString *dest)
{ {
if ([obj isKindOfClass: [NSString class]]) if ([obj isKindOfClass: [NSString class]])
{ {
if (x == YES) if (x == PLXML)
{ {
Append(@"<string>", dest); Append(@"<string>", dest);
XString(obj, dest); XString(obj, dest);
@ -477,60 +480,76 @@ OAppend(id obj, NSDictionary *loc, unsigned lev, unsigned step,
if (val == 1.0) if (val == 1.0)
{ {
if (x) if (x == PLXML)
{ {
Append(@"<true/>\n", dest); Append(@"<true/>\n", dest);
} }
else else if (x == PLNEW)
{ {
Append(@"<*BY>", dest); Append(@"<*BY>", dest);
} }
else
{
PString([obj description], dest);
}
} }
else if (val == 0.0) else if (val == 0.0)
{ {
if (x) if (x == PLXML)
{ {
Append(@"<false/>\n", dest); Append(@"<false/>\n", dest);
} }
else else if (x == PLNEW)
{ {
Append(@"<*BN>", dest); Append(@"<*BN>", dest);
} }
else
{
PString([obj description], dest);
}
} }
else if (rint(val) == val) else if (rint(val) == val)
{ {
if (x == YES) if (x == PLXML)
{ {
Append(@"<integer>", dest); Append(@"<integer>", dest);
XString([obj stringValue], dest); XString([obj stringValue], dest);
Append(@"</integer>\n", dest); Append(@"</integer>\n", dest);
} }
else else if (x == PLNEW)
{ {
Append(@"<*I", dest); Append(@"<*I", dest);
PString([obj stringValue], dest); PString([obj stringValue], dest);
Append(@">", dest); Append(@">", dest);
} }
else
{
PString([obj description], dest);
}
} }
else else
{ {
if (x == YES) if (x == PLXML)
{ {
Append(@"<real>", dest); Append(@"<real>", dest);
XString([obj stringValue], dest); XString([obj stringValue], dest);
Append(@"</real>\n", dest); Append(@"</real>\n", dest);
} }
else else if (x == PLNEW)
{ {
Append(@"<*R", dest); Append(@"<*R", dest);
PString([obj stringValue], dest); PString([obj stringValue], dest);
Append(@">", dest); Append(@">", dest);
} }
else
{
PString([obj description], dest);
}
} }
} }
else if ([obj isKindOfClass: [NSData class]]) else if ([obj isKindOfClass: [NSData class]])
{ {
if (x == YES) if (x == PLXML)
{ {
Append(@"<data>", dest); Append(@"<data>", dest);
Append(encodeBase64(obj), dest); Append(encodeBase64(obj), dest);
@ -573,20 +592,24 @@ OAppend(id obj, NSDictionary *loc, unsigned lev, unsigned step,
} }
else if ([obj isKindOfClass: [NSDate class]]) else if ([obj isKindOfClass: [NSDate class]])
{ {
if (x == YES) if (x == PLXML)
{ {
Append(@"<date>", dest); Append(@"<date>", dest);
Append([obj descriptionWithCalendarFormat: @"%Y-%m-%d %H:%M:%S %z" Append([obj descriptionWithCalendarFormat: @"%Y-%m-%d %H:%M:%S %z"
timeZone: nil locale: nil], dest); timeZone: nil locale: nil], dest);
Append(@"</date>\n", dest); Append(@"</date>\n", dest);
} }
else else if (x == PLNEW)
{ {
Append(@"<*D", dest); Append(@"<*D", dest);
Append([obj descriptionWithCalendarFormat: @"%Y-%m-%d %H:%M:%S %z" Append([obj descriptionWithCalendarFormat: @"%Y-%m-%d %H:%M:%S %z"
timeZone: nil locale: nil], dest); timeZone: nil locale: nil], dest);
Append(@">", dest); Append(@">", dest);
} }
else
{
PString([obj description], dest);
}
} }
else if ([obj isKindOfClass: [NSArray class]]) else if ([obj isKindOfClass: [NSArray class]])
{ {
@ -614,7 +637,7 @@ OAppend(id obj, NSDictionary *loc, unsigned lev, unsigned step,
= indentStrings[sizeof(indentStrings)/sizeof(id)-1]; = indentStrings[sizeof(indentStrings)/sizeof(id)-1];
} }
if (x == YES) if (x == PLXML)
{ {
NSEnumerator *e; NSEnumerator *e;
@ -623,7 +646,7 @@ OAppend(id obj, NSDictionary *loc, unsigned lev, unsigned step,
while ((obj = [e nextObject])) while ((obj = [e nextObject]))
{ {
Append(iSizeString, dest); Append(iSizeString, dest);
OAppend(obj, loc, level, step, YES, dest); OAppend(obj, loc, level, step, x, dest);
} }
Append(iBaseString, dest); Append(iBaseString, dest);
Append(@"</array>\n", dest); Append(@"</array>\n", dest);
@ -701,7 +724,7 @@ OAppend(id obj, NSDictionary *loc, unsigned lev, unsigned step,
= indentStrings[sizeof(indentStrings)/sizeof(id)-1]; = indentStrings[sizeof(indentStrings)/sizeof(id)-1];
} }
if (x == YES) if (x == PLXML)
{ {
NSEnumerator *e; NSEnumerator *e;
id key; id key;
@ -873,7 +896,7 @@ OAppend(id obj, NSDictionary *loc, unsigned lev, unsigned step,
{ {
NSDebugLog(@"Non-property-list class (%@) encoded as string", NSDebugLog(@"Non-property-list class (%@) encoded as string",
NSStringFromClass([obj class])); NSStringFromClass([obj class]));
if (x == YES) if (x == PLXML)
{ {
Append(@"<string>", dest); Append(@"<string>", dest);
XString([obj description], dest); XString([obj description], dest);
@ -887,9 +910,11 @@ OAppend(id obj, NSDictionary *loc, unsigned lev, unsigned step,
} }
void void
GSPropertyListMake(id obj, NSDictionary *loc, BOOL xml, unsigned step, id *str) GSPropertyListMake(id obj, NSDictionary *loc, BOOL xml,
BOOL forDescription, unsigned step, id *str)
{ {
GSMutableString *dest; GSMutableString *dest;
int style = PLNEW;
if (plQuotablesBitmapRep == NULL) if (plQuotablesBitmapRep == NULL)
{ {
@ -942,10 +967,19 @@ GSPropertyListMake(id obj, NSDictionary *loc, BOOL xml, unsigned step, id *str)
"PUBLIC \"-//GNUstep//DTD plist 0.9//EN\" " "PUBLIC \"-//GNUstep//DTD plist 0.9//EN\" "
"\"http://www.gnustep.org/plist-0_9.xml\">\n" "\"http://www.gnustep.org/plist-0_9.xml\">\n"
"<plist version=\"0.9\">\n"], dest); "<plist version=\"0.9\">\n"], dest);
style = PLXML;
}
else if (forDescription || GSUserDefaultsFlag(NSWriteOldStylePropertyLists))
{
style = PLOLD;
}
else
{
style = PLNEW;
} }
OAppend(obj, loc, 0, step > 3 ? 3 : step, xml, dest); OAppend(obj, loc, 0, step > 3 ? 3 : step, style, dest);
if (xml == YES) if (style == PLXML)
{ {
Append(@"</plist>", dest); Append(@"</plist>", dest);
} }

View file

@ -46,7 +46,7 @@
#include "GSPrivate.h" #include "GSPrivate.h"
extern BOOL GSMacOSXCompatiblePropertyLists(void); extern BOOL GSMacOSXCompatiblePropertyLists(void);
extern void GSPropertyListMake(id, NSDictionary*, BOOL, unsigned, id*); extern void GSPropertyListMake(id,NSDictionary*,BOOL,BOOL,unsigned,id*);
@class NSArrayEnumerator; @class NSArrayEnumerator;
@class NSArrayEnumeratorReverse; @class NSArrayEnumeratorReverse;
@ -997,7 +997,7 @@ static int compare(id elem1, id elem2, void* context)
{ {
NSString *result = nil; NSString *result = nil;
GSPropertyListMake(self, locale, NO, level == 1 ? 3 : 2, &result); GSPropertyListMake(self, locale, NO, YES, level == 1 ? 3 : 2, &result);
return result; return result;
} }
@ -1032,11 +1032,11 @@ static int compare(id elem1, id elem2, void* context)
if (GSMacOSXCompatiblePropertyLists() == YES) if (GSMacOSXCompatiblePropertyLists() == YES)
{ {
GSPropertyListMake(self, loc, YES, 2, &desc); GSPropertyListMake(self, loc, YES, NO, 2, &desc);
} }
else else
{ {
GSPropertyListMake(self, loc, NO, 2, &desc); GSPropertyListMake(self, loc, NO, NO, 2, &desc);
} }
return [[desc dataUsingEncoding: NSUTF8StringEncoding] return [[desc dataUsingEncoding: NSUTF8StringEncoding]
@ -1056,11 +1056,11 @@ static int compare(id elem1, id elem2, void* context)
if (GSMacOSXCompatiblePropertyLists() == YES) if (GSMacOSXCompatiblePropertyLists() == YES)
{ {
GSPropertyListMake(self, loc, YES, 2, &desc); GSPropertyListMake(self, loc, YES, NO, 2, &desc);
} }
else else
{ {
GSPropertyListMake(self, loc, NO, 2, &desc); GSPropertyListMake(self, loc, NO, NO, 2, &desc);
} }
return [[desc dataUsingEncoding: NSUTF8StringEncoding] return [[desc dataUsingEncoding: NSUTF8StringEncoding]

View file

@ -678,10 +678,10 @@ failure:
- (NSString*) description - (NSString*) description
{ {
extern void GSPropertyListMake(id, NSDictionary*, BOOL, unsigned, id*); extern void GSPropertyListMake(id,NSDictionary*,BOOL,BOOL,unsigned,id*);
NSMutableString *result = nil; NSMutableString *result = nil;
GSPropertyListMake(self, nil, NO, 0, &result); GSPropertyListMake(self, nil, NO, YES, 0, &result);
return result; return result;
} }

View file

@ -46,7 +46,7 @@
@class GSMutableDictionary; @class GSMutableDictionary;
extern BOOL GSMacOSXCompatiblePropertyLists(void); extern BOOL GSMacOSXCompatiblePropertyLists(void);
extern void GSPropertyListMake(id, NSDictionary*, BOOL, unsigned, id*); extern void GSPropertyListMake(id,NSDictionary*,BOOL,BOOL,unsigned,id*);
static Class NSArray_class; static Class NSArray_class;
@ -746,11 +746,11 @@ compareIt(id o1, id o2, void* context)
if (GSMacOSXCompatiblePropertyLists() == YES) if (GSMacOSXCompatiblePropertyLists() == YES)
{ {
GSPropertyListMake(self, loc, YES, 2, &desc); GSPropertyListMake(self, loc, YES, NO, 2, &desc);
} }
else else
{ {
GSPropertyListMake(self, loc, NO, 2, &desc); GSPropertyListMake(self, loc, NO, NO, 2, &desc);
} }
return [[desc dataUsingEncoding: NSUTF8StringEncoding] return [[desc dataUsingEncoding: NSUTF8StringEncoding]
@ -770,11 +770,11 @@ compareIt(id o1, id o2, void* context)
if (GSMacOSXCompatiblePropertyLists() == YES) if (GSMacOSXCompatiblePropertyLists() == YES)
{ {
GSPropertyListMake(self, loc, YES, 2, &desc); GSPropertyListMake(self, loc, YES, NO, 2, &desc);
} }
else else
{ {
GSPropertyListMake(self, loc, NO, 2, &desc); GSPropertyListMake(self, loc, NO, NO, 2, &desc);
} }
return [[desc dataUsingEncoding: NSUTF8StringEncoding] return [[desc dataUsingEncoding: NSUTF8StringEncoding]
@ -807,11 +807,11 @@ compareIt(id o1, id o2, void* context)
{ {
id val = (*myObj)(self, objSel, key); id val = (*myObj)(self, objSel, key);
GSPropertyListMake(key, nil, NO, 0, &result); GSPropertyListMake(key, nil, NO, YES, 0, &result);
if (val != nil && [val isEqualToString: @""] == NO) if (val != nil && [val isEqualToString: @""] == NO)
{ {
[result appendString: @" = "]; [result appendString: @" = "];
GSPropertyListMake(val, nil, NO, 0, &result); GSPropertyListMake(val, nil, NO, YES, 0, &result);
} }
[result appendString: @";\n"]; [result appendString: @";\n"];
} }
@ -844,7 +844,7 @@ compareIt(id o1, id o2, void* context)
{ {
NSMutableString *result = nil; NSMutableString *result = nil;
GSPropertyListMake(self, locale, NO, level == 1 ? 3 : 2, &result); GSPropertyListMake(self, locale, NO, YES, level == 1 ? 3 : 2, &result);
return result; return result;
} }