Re: cString deprecated!
Re: cString deprecated!
- Subject: Re: cString deprecated!
- From: Peter Sichel <email@hidden>
- Date: Wed, 4 Sep 2002 04:17:10 -0400
On Tue, 03 Sep 2002 13:01:33 -0700, Kris Amico
<email@hidden> said:
Forgive my ignorance, but I am wondering how the technique you describe
below is different from using NSString's lossyCString instance method?
On 9/3/02 9:20 AM, "Matt Neuburg" <email@hidden> wrote:
- (const char*) myCString: (int) encoding {
return [[[self stringByAppendingString:
@"\0"] dataUsingEncoding: encoding
allowLossyConversion:YES]
bytes];
}
You seem to have missed the point of what this thread is about.
The technique supplied here differs crucially from lossyCString in that it
lets you specify an encoding. lossyCString does not, and is therefore yet
another in the "axis of evil" C string methods that should be deprecated
(thank you for pointing this out).
The problem that this thread is about is that cString, lossyCString, and
stringWithCString all use the "default C-string encoding", which will
differ on different systems and over which you (the programmer) have no
control whatever. Therefore you shouldn't use those calls at all. m.
--
cString has two potential problems:
(1) It throws an exception if it can't encode some character using
the "defaultCStringEncoding".
(2) It always uses defaultCStringEncoding encoding.
Problem (1) makes it a poor choice for most programs, but lossyCString
avoids this.
Problem (2) seems more subtle and might depend on the intended use.
If "fileSystemRepresentation" is the best choice for encoding
the names of file system objects, might not defaultCStringEncoding
be a better choice for encoding common BSD unix API strings? [Such
as BSD interface names, or user and group names]
That is, if your program were to actually encounter a system
where the defaultCStringEncoding mattered, would using the
defaultCStringEncoding be a better choice than imposing UTF-8
with no knowledge of the user's system?
If UTF-8 is always the best choice, why not just make it the
defaultCStringEncoding? Why shift the decision to each application
developer instead of the user or API maintainer?
- Peter
_______________________________________________
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.