Re: problem with NSString, UTF8, pathnames
Re: problem with NSString, UTF8, pathnames
- Subject: Re: problem with NSString, UTF8, pathnames
- From: Dave Hersey <email@hidden>
- Date: Thu, 25 Oct 2007 14:04:19 -0400
It's been pointed out many times that you should always use a format
string in NSLog. This is especially a problem with URL strings where
you might have % encodings that are going to be misinterpreted as
format specifiers...
Also, I'd use absoluteString instead of description to get the
absoluteURL in string form. description is more of a convenience
method for an object's description which can be a string in any
format that the developer desires, and absoluteString is specifically
provided for what you want.
- d
On Oct 25, 2007, at 1:46 PM, James Stein wrote:
To my surprise:
an NSString returned by Cocoa will cause NSLog to crash.
Details:
I override 'openDocumentWithContentsOfURL:display:error'
in order to see what is happening.
The NSURL (absoluteURL) passed in comes from Cocoa's normal open
file dialog.
so:
NSString *s = [absoluteURL description]; // make NSString from NSURL
NSLog(s); // often works, sometimes crashes.
I think the problem is that the pathname is UTF8-encoded,
but has not been properly decoded when it arrives in string 's'.
On the web I found methods to create NSStrings from c-strings
and from UTF8-encoded strings; but I don't find a way to reverse
the process.
Seems like a bug to me, that Coca will create an object
that will create description than will crash when passed to NSLog.
(Maybe it will be gone tomorrow, thanks to Leopard & XCode 3.0)
But whatever, is there a workaround, or must I consider this as
harmful?
NSLog( [validCocoaObject description] );
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden