diff --git a/Source/NSGCString.m b/Source/NSGCString.m index 998cce45d..f0ae02157 100644 --- a/Source/NSGCString.m +++ b/Source/NSGCString.m @@ -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 diff --git a/Source/proplist.l b/Source/proplist.l index f9041141d..7ef6100be 100644 --- a/Source/proplist.l +++ b/Source/proplist.l @@ -51,7 +51,7 @@ hexdata \<{wsnl}*({hexword}{wsnl}*)*({hexnum}{wsnl}*)*\> {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 - length: dest_ptr - dest - freeWhenDone: YES] autorelease]; + return [[[NSGCString alloc] initWithCStringNoCopy: dest + length: dest_ptr - dest + freeWhenDone: YES] autorelease]; } diff --git a/Source/proplist.y b/Source/proplist.y index 54acf0358..2a1546b71 100644 --- a/Source/proplist.y +++ b/Source/proplist.y @@ -17,7 +17,7 @@ id obj; } -%type root object array objlist dictionary keyval_list keyval_pair +%type 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,24 +69,16 @@ 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]; - } + } ; %%