mirror of
https://github.com/gnustep/libs-base.git
synced 2025-05-31 00:30:53 +00:00
Added more property list support.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@14967 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
b8b64cb3e5
commit
963c232265
4 changed files with 158 additions and 51 deletions
|
@ -6,7 +6,8 @@
|
||||||
* Source/NSArray.m: Use new plist code
|
* Source/NSArray.m: Use new plist code
|
||||||
* Source/NSData.m: ditto
|
* Source/NSData.m: ditto
|
||||||
* Source/NSDictionary.m: ditto
|
* Source/NSDictionary.m: ditto
|
||||||
* Source/NSString.m: ditto
|
* Source/NSString.m: ditto, plus implement extensions to old plist
|
||||||
|
support so we can encode NSNumber and NSDate values.
|
||||||
Remove GNUstep property list extensions from the api ... make more
|
Remove GNUstep property list extensions from the api ... make more
|
||||||
like MacOS and OpenStep spec by having a central mechanism for
|
like MacOS and OpenStep spec by having a central mechanism for
|
||||||
generating property lists rather than spreading the code across the
|
generating property lists rather than spreading the code across the
|
||||||
|
|
|
@ -482,7 +482,7 @@ OAppend(id obj, NSDictionary *loc, unsigned lev, unsigned step,
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Append(@"YES", dest);
|
Append(@"<*BY>", dest);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (val == 0.0)
|
else if (val == 0.0)
|
||||||
|
@ -493,7 +493,7 @@ OAppend(id obj, NSDictionary *loc, unsigned lev, unsigned step,
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Append(@"NO", dest);
|
Append(@"<*BN>", dest);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (rint(val) == val)
|
else if (rint(val) == val)
|
||||||
|
@ -506,7 +506,9 @@ OAppend(id obj, NSDictionary *loc, unsigned lev, unsigned step,
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
Append(@"<*I", dest);
|
||||||
PString([obj stringValue], dest);
|
PString([obj stringValue], dest);
|
||||||
|
Append(@">", dest);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -519,7 +521,9 @@ OAppend(id obj, NSDictionary *loc, unsigned lev, unsigned step,
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
Append(@"<*R", dest);
|
||||||
PString([obj stringValue], dest);
|
PString([obj stringValue], dest);
|
||||||
|
Append(@">", dest);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -571,14 +575,16 @@ OAppend(id obj, NSDictionary *loc, unsigned lev, unsigned step,
|
||||||
if (x == YES)
|
if (x == YES)
|
||||||
{
|
{
|
||||||
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"
|
||||||
dest);
|
timeZone: nil locale: nil], dest);
|
||||||
Append(@"</date>\n", dest);
|
Append(@"</date>\n", dest);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
PString([obj descriptionWithCalendarFormat: @"%Y-%m-%d %H:%M:%S %z"],
|
Append(@"<*D", dest);
|
||||||
dest);
|
Append([obj descriptionWithCalendarFormat: @"%Y-%m-%d %H:%M:%S %z"
|
||||||
|
timeZone: nil locale: nil], dest);
|
||||||
|
Append(@">", dest);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if ([obj isKindOfClass: [NSArray class]])
|
else if ([obj isKindOfClass: [NSArray class]])
|
||||||
|
|
|
@ -4770,52 +4770,138 @@ static id parsePlItem(pldata* pld)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case '<':
|
case '<':
|
||||||
{
|
pld->pos++;
|
||||||
NSMutableData *data;
|
if (pld->pos < pld->end && pld->ptr[pld->pos] == '*')
|
||||||
unsigned max = pld->end - 1;
|
{
|
||||||
unsigned char buf[BUFSIZ];
|
const unichar *ptr;
|
||||||
unsigned len = 0;
|
unsigned min;
|
||||||
|
unsigned len = 0;
|
||||||
|
int i;
|
||||||
|
|
||||||
data = [[NSMutableData alloc] initWithCapacity: 0];
|
pld->pos++;
|
||||||
pld->pos++;
|
min = pld->pos;
|
||||||
skipSpace(pld);
|
ptr = &(pld->ptr[min]);
|
||||||
while (pld->pos < max
|
while (pld->pos < pld->end && pld->ptr[pld->pos] != '>')
|
||||||
&& GS_IS_HEXDIGIT(pld->ptr[pld->pos])
|
{
|
||||||
&& GS_IS_HEXDIGIT(pld->ptr[pld->pos+1]))
|
pld->pos++;
|
||||||
{
|
}
|
||||||
unsigned char byte;
|
len = pld->pos - min;
|
||||||
|
if (len > 1)
|
||||||
|
{
|
||||||
|
unichar type = *ptr++;
|
||||||
|
|
||||||
byte = (char2num(pld->ptr[pld->pos])) << 4;
|
len--;
|
||||||
pld->pos++;
|
if (type == 'I')
|
||||||
byte |= char2num(pld->ptr[pld->pos]);
|
{
|
||||||
pld->pos++;
|
char buf[len+1];
|
||||||
buf[len++] = byte;
|
|
||||||
if (len == sizeof(buf))
|
for (i = 0; i < len; i++) buf[i] = (char)ptr[i];
|
||||||
{
|
buf[len] = '\0';
|
||||||
[data appendBytes: buf length: len];
|
result = [[NSNumber alloc] initWithLong: atol(buf)];
|
||||||
len = 0;
|
}
|
||||||
}
|
else if (type == 'B')
|
||||||
skipSpace(pld);
|
{
|
||||||
}
|
if (ptr[0] == 'Y')
|
||||||
if (pld->pos >= pld->end)
|
{
|
||||||
{
|
result = [[NSNumber alloc] initWithBool: YES];
|
||||||
pld->err = @"unexpected end of string when parsing data";
|
}
|
||||||
RELEASE(data);
|
else if (ptr[0] == 'N')
|
||||||
return nil;
|
{
|
||||||
}
|
result = [[NSNumber alloc] initWithBool: NO];
|
||||||
if (pld->ptr[pld->pos] != '>')
|
}
|
||||||
{
|
else
|
||||||
pld->err = @"unexpected character in string";
|
{
|
||||||
RELEASE(data);
|
pld->err = @"bad value for bool";
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
if (len > 0)
|
}
|
||||||
{
|
else if (type == 'D')
|
||||||
[data appendBytes: buf length: len];
|
{
|
||||||
}
|
NSString *str;
|
||||||
pld->pos++;
|
|
||||||
result = data;
|
str = [[NSString alloc] initWithCharacters: ptr
|
||||||
}
|
length: len];
|
||||||
|
result = [[NSCalendarDate alloc] initWithString: str
|
||||||
|
calendarFormat: @"%Y-%m-%d %H:%M:%S %z"];
|
||||||
|
RELEASE(str);
|
||||||
|
}
|
||||||
|
else if (type == 'R')
|
||||||
|
{
|
||||||
|
char buf[len+1];
|
||||||
|
|
||||||
|
for (i = 0; i < len; i++) buf[i] = (char)ptr[i];
|
||||||
|
buf[len] = '\0';
|
||||||
|
result = [[NSNumber alloc] initWithDouble: atof(buf)];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
pld->err = @"unrecognized type code after '<*'";
|
||||||
|
return nil;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
pld->err = @"missing type code after '<*'";
|
||||||
|
return nil;
|
||||||
|
}
|
||||||
|
if (pld->pos >= pld->end)
|
||||||
|
{
|
||||||
|
pld->err = @"unexpected end of string when parsing data";
|
||||||
|
return nil;
|
||||||
|
}
|
||||||
|
if (pld->ptr[pld->pos] != '>')
|
||||||
|
{
|
||||||
|
pld->err = @"unexpected character in string";
|
||||||
|
return nil;
|
||||||
|
}
|
||||||
|
pld->pos++;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
NSMutableData *data;
|
||||||
|
unsigned max = pld->end - 1;
|
||||||
|
unsigned char buf[BUFSIZ];
|
||||||
|
unsigned len = 0;
|
||||||
|
|
||||||
|
data = [[NSMutableData alloc] initWithCapacity: 0];
|
||||||
|
skipSpace(pld);
|
||||||
|
while (pld->pos < max
|
||||||
|
&& GS_IS_HEXDIGIT(pld->ptr[pld->pos])
|
||||||
|
&& GS_IS_HEXDIGIT(pld->ptr[pld->pos+1]))
|
||||||
|
{
|
||||||
|
unsigned char byte;
|
||||||
|
|
||||||
|
byte = (char2num(pld->ptr[pld->pos])) << 4;
|
||||||
|
pld->pos++;
|
||||||
|
byte |= char2num(pld->ptr[pld->pos]);
|
||||||
|
pld->pos++;
|
||||||
|
buf[len++] = byte;
|
||||||
|
if (len == sizeof(buf))
|
||||||
|
{
|
||||||
|
[data appendBytes: buf length: len];
|
||||||
|
len = 0;
|
||||||
|
}
|
||||||
|
skipSpace(pld);
|
||||||
|
}
|
||||||
|
if (pld->pos >= pld->end)
|
||||||
|
{
|
||||||
|
pld->err = @"unexpected end of string when parsing data";
|
||||||
|
RELEASE(data);
|
||||||
|
return nil;
|
||||||
|
}
|
||||||
|
if (pld->ptr[pld->pos] != '>')
|
||||||
|
{
|
||||||
|
pld->err = @"unexpected character in string";
|
||||||
|
RELEASE(data);
|
||||||
|
return nil;
|
||||||
|
}
|
||||||
|
if (len > 0)
|
||||||
|
{
|
||||||
|
[data appendBytes: buf length: len];
|
||||||
|
}
|
||||||
|
pld->pos++;
|
||||||
|
result = data;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case '"':
|
case '"':
|
||||||
|
|
|
@ -33,8 +33,22 @@ int main ()
|
||||||
{
|
{
|
||||||
id pool = [NSAutoreleasePool new];
|
id pool = [NSAutoreleasePool new];
|
||||||
id o = [NSObject new];
|
id o = [NSObject new];
|
||||||
|
id x;
|
||||||
|
NSString *s;
|
||||||
NSArray *a = [NSArray arrayWithObjects: @"a", @"b", nil];
|
NSArray *a = [NSArray arrayWithObjects: @"a", @"b", nil];
|
||||||
|
|
||||||
|
o = [NSDictionary dictionaryWithObjectsAndKeys:
|
||||||
|
@"test", @"one",
|
||||||
|
[NSNumber numberWithBool: YES], @"two",
|
||||||
|
[NSDate date], @"three",
|
||||||
|
[NSNumber numberWithInt: 33], @"four",
|
||||||
|
[NSNumber numberWithFloat: 4.5], @"five",
|
||||||
|
nil];
|
||||||
|
s = [o description];
|
||||||
|
NSLog(@"%@", s);
|
||||||
|
x = [s propertyList];
|
||||||
|
NSLog(@"%d", [o isEqual: x]);
|
||||||
|
|
||||||
|
|
||||||
test1();
|
test1();
|
||||||
test2();
|
test2();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue