Re: How to code a NSString literal with UTF8?
Re: How to code a NSString literal with UTF8?
- Subject: Re: How to code a NSString literal with UTF8?
- From: Ali Ozer <email@hidden>
- Date: Wed, 30 Mar 2005 11:02:06 -0800
NSString *s = [NSString stringWithUTF8String:"Long -- dash"]; //
Not safe; you're at the mercy of any tools you use
As I understand it, the danger here is that the compiler has no way of
knowing the file's text encoding, right? The compiler will have to
assume ASCII, MacRoman, UTF8, or whatever, and if it assumes wrong,
badness ensues. (In the XCode IDE, a user can specify a file's
encoding,
which helps.) And since ASCII is the common denominator, only 7bit
characters are 'safe'. Correct?
Correct. I think in the world of Xcode you'd be fine, since Xcode now
has per-file-encodings and such; but if you ever used another editor,
things might become questionable.
and the following is not allowed:
NSString *s = @"Long -- dash"; // Not allowed
"Not allowed" but still accepted by gcc 3.3 (and CW 9.4). <rdar://
4073313>
This I understand to be disallowed because it is so documented:
"@"string" - Defines a constant NSString object in the current
module and
initializes the object with the specified 7-bit ASCII-encoded string."
Fair enough.
But am I the only one who thinks it should be allowed? Apple could
change the Obj-C language to allow it. I doubt much code would break.
Do people really depend on such strings being NSConstantStrings? We'd
still have the problem of the compiler having to know/guess the file's
encoding, but that problem is always there.
You're not the only one who thinks this should be allowed and it is
something that is on several investigation/future-feature lists.
Ali
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden