Re: cString deprecated!
Re: cString deprecated!
- Subject: Re: cString deprecated!
- From: Charles Srstka <email@hidden>
- Date: Mon, 2 Sep 2002 18:30:50 -0500
UTF8String is probably the best way to go - to the best of my knowledge
UTF8 is the same as plain ASCII encoding whenever special characters
aren't involved - only when you have something that can't be
represented in ASCII does the format deviate at all. So for most
strings, it will be the same as a normal cString. With lossyCString,
you could possibly lose some information, whereas with UTF8 it should
always be encoded.
On Monday, September 2, 2002, at 05:40 PM, Dennis De Mars wrote:
Thanks for the head-up on that, I probably never would have caught it
otherwise!
My initial reaction was negative, since I have used this method on
occasion. On re-reading the documentation for cString, however, I
noted that it will raise an exception if the NSString cannot be
translated to a C string without loss of information. This raises the
possibility that an application will run fine for the developer and
then crash later when run, for instance, under another language
preference if the developer didn't remember to handle the exception.
Given this behavior, I can understand why it is considered
"troublesome."
There is another method (which they don't mention in the release
notes) called lossyCString that will peform the same function without
raising the exception. And, as has been pointed out, UTF8String can
serve the same purposes.
- Dennis D.
On Monday, September 2, 2002, at 02:17 PM, Charles Srstka wrote:
Just wanted to provide a heads-up to anyone who didn't notice this
already in the Foundation release notes:
Expect -[NSString cString] method to be deprecated and removed from
public API at some point in the near future. This method was
originally introduced as a convenient way to bridge the gap between
NSStrings and original c-string APIs. However, this method is also
rather troublesome, as it works in the user's default encoding, which
is dependent on the user's language choice, and as it's not always
capable of converting arbitrary Unicode strings to 8-bit.
We recommend you go through and remove your usages of the cString
method from your code, in new versions of your apps or frameworks.
(Note that binary compatibility will be maintained as long as
appropriate --- we don't intend to break existing binaries which use
this method.)
The most common 8-bit encoding needed these days is the UTF-8
encoding, for which you can use the method UTF8String. For file
system
strings, use fileSystemRepresentation (declared in
NSPathUtilities.h).
_______________________________________________
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.
_______________________________________________
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.
_______________________________________________
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.