mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-22 16:33:29 +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
15210c5f59
commit
f0705e979e
4 changed files with 158 additions and 51 deletions
|
@ -6,7 +6,8 @@
|
|||
* Source/NSArray.m: Use new plist code
|
||||
* Source/NSData.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
|
||||
like MacOS and OpenStep spec by having a central mechanism for
|
||||
generating property lists rather than spreading the code across the
|
||||
|
|
|
@ -482,7 +482,7 @@ OAppend(id obj, NSDictionary *loc, unsigned lev, unsigned step,
|
|||
}
|
||||
else
|
||||
{
|
||||
Append(@"YES", dest);
|
||||
Append(@"<*BY>", dest);
|
||||
}
|
||||
}
|
||||
else if (val == 0.0)
|
||||
|
@ -493,7 +493,7 @@ OAppend(id obj, NSDictionary *loc, unsigned lev, unsigned step,
|
|||
}
|
||||
else
|
||||
{
|
||||
Append(@"NO", dest);
|
||||
Append(@"<*BN>", dest);
|
||||
}
|
||||
}
|
||||
else if (rint(val) == val)
|
||||
|
@ -506,7 +506,9 @@ OAppend(id obj, NSDictionary *loc, unsigned lev, unsigned step,
|
|||
}
|
||||
else
|
||||
{
|
||||
Append(@"<*I", dest);
|
||||
PString([obj stringValue], dest);
|
||||
Append(@">", dest);
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -519,7 +521,9 @@ OAppend(id obj, NSDictionary *loc, unsigned lev, unsigned step,
|
|||
}
|
||||
else
|
||||
{
|
||||
Append(@"<*R", dest);
|
||||
PString([obj stringValue], dest);
|
||||
Append(@">", dest);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -571,14 +575,16 @@ OAppend(id obj, NSDictionary *loc, unsigned lev, unsigned step,
|
|||
if (x == YES)
|
||||
{
|
||||
Append(@"<date>", dest);
|
||||
Append([obj descriptionWithCalendarFormat: @"%Y-%m-%d %H:%M:%S %z"],
|
||||
dest);
|
||||
Append([obj descriptionWithCalendarFormat: @"%Y-%m-%d %H:%M:%S %z"
|
||||
timeZone: nil locale: nil], dest);
|
||||
Append(@"</date>\n", dest);
|
||||
}
|
||||
else
|
||||
{
|
||||
PString([obj descriptionWithCalendarFormat: @"%Y-%m-%d %H:%M:%S %z"],
|
||||
dest);
|
||||
Append(@"<*D", dest);
|
||||
Append([obj descriptionWithCalendarFormat: @"%Y-%m-%d %H:%M:%S %z"
|
||||
timeZone: nil locale: nil], dest);
|
||||
Append(@">", dest);
|
||||
}
|
||||
}
|
||||
else if ([obj isKindOfClass: [NSArray class]])
|
||||
|
|
|
@ -4770,52 +4770,138 @@ static id parsePlItem(pldata* pld)
|
|||
break;
|
||||
|
||||
case '<':
|
||||
{
|
||||
NSMutableData *data;
|
||||
unsigned max = pld->end - 1;
|
||||
unsigned char buf[BUFSIZ];
|
||||
unsigned len = 0;
|
||||
pld->pos++;
|
||||
if (pld->pos < pld->end && pld->ptr[pld->pos] == '*')
|
||||
{
|
||||
const unichar *ptr;
|
||||
unsigned min;
|
||||
unsigned len = 0;
|
||||
int i;
|
||||
|
||||
data = [[NSMutableData alloc] initWithCapacity: 0];
|
||||
pld->pos++;
|
||||
skipSpace(pld);
|
||||
while (pld->pos < max
|
||||
&& GS_IS_HEXDIGIT(pld->ptr[pld->pos])
|
||||
&& GS_IS_HEXDIGIT(pld->ptr[pld->pos+1]))
|
||||
{
|
||||
unsigned char byte;
|
||||
pld->pos++;
|
||||
min = pld->pos;
|
||||
ptr = &(pld->ptr[min]);
|
||||
while (pld->pos < pld->end && pld->ptr[pld->pos] != '>')
|
||||
{
|
||||
pld->pos++;
|
||||
}
|
||||
len = pld->pos - min;
|
||||
if (len > 1)
|
||||
{
|
||||
unichar type = *ptr++;
|
||||
|
||||
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;
|
||||
}
|
||||
len--;
|
||||
if (type == 'I')
|
||||
{
|
||||
char buf[len+1];
|
||||
|
||||
for (i = 0; i < len; i++) buf[i] = (char)ptr[i];
|
||||
buf[len] = '\0';
|
||||
result = [[NSNumber alloc] initWithLong: atol(buf)];
|
||||
}
|
||||
else if (type == 'B')
|
||||
{
|
||||
if (ptr[0] == 'Y')
|
||||
{
|
||||
result = [[NSNumber alloc] initWithBool: YES];
|
||||
}
|
||||
else if (ptr[0] == 'N')
|
||||
{
|
||||
result = [[NSNumber alloc] initWithBool: NO];
|
||||
}
|
||||
else
|
||||
{
|
||||
pld->err = @"bad value for bool";
|
||||
return nil;
|
||||
}
|
||||
}
|
||||
else if (type == 'D')
|
||||
{
|
||||
NSString *str;
|
||||
|
||||
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;
|
||||
|
||||
case '"':
|
||||
|
|
|
@ -33,8 +33,22 @@ int main ()
|
|||
{
|
||||
id pool = [NSAutoreleasePool new];
|
||||
id o = [NSObject new];
|
||||
id x;
|
||||
NSString *s;
|
||||
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();
|
||||
test2();
|
||||
|
|
Loading…
Reference in a new issue