Re: Nonbreaking spaces in alerts
Re: Nonbreaking spaces in alerts
- Subject: Re: Nonbreaking spaces in alerts
- From: Elias Mårtenson <email@hidden>
- Date: Tue, 18 Oct 2005 23:31:02 +0200
18 okt 2005 kl. 23.22 skrev John Stiles:
On Oct 18, 2005, at 2:23 PM, Elias Mårtenson wrote:
Um, I don't think that will work. @"" strings only work with
ASCII because there is no encoding specified. They might
coincidentally work with MacRoman at present, but this is not
guaranteed behavior, and the docs specifically warn against
relying on this.
The \u notation is specified in C99, and it's certainly accepted
by Apple's gcc when using the -std=c99 option. However, I was
surprised to see that while the compiler accepted the code, the
result wasn't what I had expected.
My guess is that gcc erroneously does in fact let the string pass
through some locale encoding, even though it shouldn't. The \u
notation is supposed to allow you to enter Unicode values in the
code without having to worry about the encoding of the local
system that runs the compile.
GCC isn't mangling the string. @"" is designed to take ASCII
encoding, not UTF8 or MacRoman or anything else. What you'll get
for any character above 127 is just undefined. Why Apple/NeXT chose
to make @"" work this way, I don't know, but that's the situation.
No, it's not GCC that is mangling the string, it's whatever code runs
when the @ is seen before a string. GCC itself delivers UTF-8 when it
encounters a \u inside a string. Therefore the following works:
(remember that you need the -std=c99 compiler option for this to work)
NSString *s = [NSString stringWithUTF8String:"Mac\u00A0OS\u00A0X"];
And yes, I just tried it myself. :-)
_______________________________________________
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