bug-gnustep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[RFC/base] -description for non-property-list object in collections


From: David Ayers
Subject: [RFC/base] -description for non-property-list object in collections
Date: Sat, 26 Feb 2005 19:03:54 +0100
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.5) Gecko/20041217

Hello everyone,

While porting an application which encodes it's data into manually assembled plists, I stumbled on the following issue.

When custom objects, who's -description is designed to be in property list format, are inserted into NSArray's or NSDictionary's and these are then sent -description for an aggregated plist, the current NSPropertyList implementation quotes the the non-plist object's description. I'm not sure how Cocoa handles this but OPENSTEP did not quote those descriptions.

I'm proposing the following patch, which will attempt to parse the description into a property list and include the returned object in the generated description tree instead. If parsing as a property list fails, it falls back to simply using the description.

I'm posting this here in case someone has an objection or an idea for an alternative approach. Save objections, I'll commit it.

Cheers,
David

Index: Source/NSPropertyList.m
===================================================================
RCS file: /cvsroot/gnustep/gnustep/core/base/Source/NSPropertyList.m,v
retrieving revision 1.24
diff -u -r1.24 NSPropertyList.m
--- Source/NSPropertyList.m     22 Feb 2005 11:22:44 -0000      1.24
+++ Source/NSPropertyList.m     26 Feb 2005 16:20:03 -0000
@@ -2002,9 +2002,25 @@
        }
       else
        {
-         NSDebugLog(@"Non-property-list class (%@) encoded as string",
-           NSStringFromClass([obj class]));
-         PString([obj description], dest);
+         NSString *desc;
+         volatile id plobj = nil;
+
+         desc = [obj description];
+         NS_DURING
+           {
+             plobj = [desc propertyList];
+             NSDebugLog(@"Non-property-list class (%@) "
+                        @"encoded as description's property-list",
+                        NSStringFromClass([obj class]));
+           }
+         NS_HANDLER
+           {
+             plobj = desc;
+             NSDebugLog(@"Non-property-list class (%@) encoded as string",
+                        NSStringFromClass([obj class]));
+           }
+         NS_ENDHANDLER
+         OAppend(plobj, loc, lev, step, x, dest);
        }
     }
 }


reply via email to

[Prev in Thread] Current Thread [Next in Thread]