mirror of
https://github.com/gnustep/libs-base.git
synced 2025-05-31 16:50:58 +00:00
Tiny property-list parsing optimisations
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@3046 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
7694a7f14e
commit
bd110748d4
3 changed files with 93 additions and 20 deletions
|
@ -339,6 +339,88 @@
|
|||
return [self initWithCString:[string cString]];
|
||||
}
|
||||
|
||||
- (NSString*) descriptionForPropertyList
|
||||
{
|
||||
if (_count == 0) {
|
||||
return @"\"\"";
|
||||
}
|
||||
else {
|
||||
unsigned i;
|
||||
unsigned length = _count;
|
||||
BOOL needQuote = NO;
|
||||
|
||||
for (i = 0; i < _count; i++) {
|
||||
char val = _contents_chars[i];
|
||||
|
||||
switch (val) {
|
||||
case '\a':
|
||||
case '\b':
|
||||
case '\t':
|
||||
case '\r':
|
||||
case '\n':
|
||||
case '\v':
|
||||
case '\f':
|
||||
case '\\':
|
||||
case '\'' :
|
||||
case '"' :
|
||||
length += 2;
|
||||
break;
|
||||
|
||||
default:
|
||||
if (val == ' ') {
|
||||
needQuote = YES;
|
||||
}
|
||||
else if (isprint(val) == 0) {
|
||||
length += 4;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (needQuote || length != _count) {
|
||||
char *buf = objc_malloc(length+3);
|
||||
char *ptr = buf;
|
||||
NSString *result;
|
||||
|
||||
*ptr++ = '"';
|
||||
for (i = 0; i < _count; i++) {
|
||||
char val = _contents_chars[i];
|
||||
|
||||
switch (val) {
|
||||
case '\a': *ptr++ = '\\'; *ptr++ = 'a'; break;
|
||||
case '\b': *ptr++ = '\\'; *ptr++ = 'b'; break;
|
||||
case '\t': *ptr++ = '\\'; *ptr++ = 't'; break;
|
||||
case '\r': *ptr++ = '\\'; *ptr++ = 'r'; break;
|
||||
case '\n': *ptr++ = '\\'; *ptr++ = 'n'; break;
|
||||
case '\v': *ptr++ = '\\'; *ptr++ = 'v'; break;
|
||||
case '\f': *ptr++ = '\\'; *ptr++ = 'f'; break;
|
||||
case '\\': *ptr++ = '\\'; *ptr++ = '\\'; break;
|
||||
case '\'': *ptr++ = '\\'; *ptr++ = '\''; break;
|
||||
case '"' : *ptr++ = '\\'; *ptr++ = '"'; break;
|
||||
|
||||
default:
|
||||
if (isprint(val) || val == ' ') {
|
||||
*ptr++ = val;
|
||||
}
|
||||
else {
|
||||
*ptr++ = '\\';
|
||||
*ptr++ = '0';
|
||||
*ptr++ = ((val&0700)>>6)+'0';
|
||||
*ptr++ = ((val&070)>>3)+'0';
|
||||
*ptr++ = (val&07)+'0';
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
*ptr++ = '"';
|
||||
*ptr = '\0';
|
||||
result = [[[_fastCls._NSGCString alloc] initWithCStringNoCopy: buf
|
||||
length: length+2 freeWhenDone: YES] autorelease];
|
||||
return result;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
}
|
||||
@end
|
||||
|
||||
|
||||
|
|
|
@ -51,7 +51,7 @@ hexdata \<{wsnl}*({hexword}{wsnl}*)*({hexnum}{wsnl}*)*\>
|
|||
<QUOTE>{qstring} {
|
||||
if(plleng==1) {
|
||||
BEGIN INITIAL;
|
||||
pllval.obj=[NSString stringWithCString:""];
|
||||
pllval.obj=@"";
|
||||
return NSSTRING;
|
||||
}
|
||||
if(pltext[plleng-2] == '\\') {
|
||||
|
@ -168,7 +168,7 @@ unescstr (char *src)
|
|||
|
||||
*dest_ptr = '\0'; /* terminate dest */
|
||||
|
||||
return [[[NSString alloc] initWithCStringNoCopy: dest
|
||||
return [[[NSGCString alloc] initWithCStringNoCopy: dest
|
||||
length: dest_ptr - dest
|
||||
freeWhenDone: YES] autorelease];
|
||||
}
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
id obj;
|
||||
}
|
||||
|
||||
%type <obj> root object array objlist dictionary keyval_list keyval_pair
|
||||
%type <obj> root object array objlist dictionary keyval_list
|
||||
|
||||
/* rules section */
|
||||
%%
|
||||
|
@ -57,8 +57,7 @@ objlist: objlist ',' object
|
|||
}
|
||||
| object
|
||||
{
|
||||
$$ = [[[NSMutableArray alloc]
|
||||
initWithCapacity:1] autorelease];
|
||||
$$ = [NSMutableArray arrayWithCapacity: 1];
|
||||
[$$ addObject:$1];
|
||||
}
|
||||
;
|
||||
|
@ -70,22 +69,14 @@ dictionary: '{' keyval_list '}'
|
|||
| '{' '}'
|
||||
{$$ = [NSDictionary dictionary];}
|
||||
;
|
||||
keyval_list: keyval_list ';' keyval_pair
|
||||
keyval_list: keyval_list ';' NSSTRING '=' object
|
||||
{
|
||||
$$ = $1;
|
||||
[$$ addEntriesFromDictionary:$3];
|
||||
[$3 release];
|
||||
[$$ setObject:$5 forKey:$3];
|
||||
}
|
||||
| keyval_pair
|
||||
| NSSTRING '=' object
|
||||
{
|
||||
$$ = $1;
|
||||
[$$ autorelease];
|
||||
}
|
||||
;
|
||||
keyval_pair: NSSTRING '=' object
|
||||
{
|
||||
$$ = [[NSMutableDictionary alloc]
|
||||
initWithCapacity:1];
|
||||
$$ = [NSMutableDictionary dictionaryWithCapacity:1];
|
||||
[$$ setObject:$3 forKey:$1];
|
||||
}
|
||||
;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue