Re: getCString a good idea here?
Re: getCString a good idea here?
- Subject: Re: getCString a good idea here?
- From: Chris Hanson <email@hidden>
- Date: Sun, 13 Jul 2003 16:31:16 -0500
On Saturday, July 12, 2003, at 05:30 PM, Michael Hanna wrote:
Hi I'm trying to output to the stdout with a foundation tool. But it
seems I'm not using getCString improperly.. I'm certain that the array
returns an NSString.
(1) -[NSString getCString:] takes an existing buffer as an argument.
This buffer must be large enough to hold a copy of the string converted
to the current user's locale's default string encoding. It does *not*
return anything. It raises an NSCharacterConversionException if this
conversion fails.
(2) Don't use -[NSString getCString:] *or* -[NSString cString]. Ever.
Period. Their behavior will differ based on the current user's
locale's default string encoding -- you will get different results on
different systems for the same string. Instead, always use -[NSString
UTF8String] or explicitly get a string's data in an encoding you
specify. Or use -[NSString fileSystemRepresentation] if you're going
to pass an NSString representing a path to something like fopen().
Apple should have Xcode sound a klaxon and flash your screen whenever
it encounters a deprecated method that can cause serious
internationalization issues like -[NSString getCString:] or -[NSString
cString].
-- Chris
--
Chris Hanson, bDistributed.com, Inc. | Email: email@hidden
Custom Application Development | Phone: +1-847-372-3955
http://bdistributed.com/ | Fax: +1-847-589-3738
http://bdistributed.com/Articles/ | Personal Email: email@hidden
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.