• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: 8-bit chars in @""
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: 8-bit chars in @""


  • Subject: Re: 8-bit chars in @""
  • From: Matt Neuburg <email@hidden>
  • Date: Mon, 25 Mar 2002 11:32:14 -0800

On Sun, 24 Mar 2002 11:21:28 -0800, Ali Ozer <email@hidden> said:

>
>>>> Oh, I see, I have to set Localizable.strings to be UTF-8. Is that
>>>> it? (I
>>> I'd use Unicode myself, but in principle, of course.
>> Oops... I think Unicode is the "recommend" way to go, not UTF-8 (I had
>> suggested UTF-8 in my prior message).
>
>Yup, for strings files, please use Unicode, that is, UTF-16.

Okey-dokey, will do. Just to summarize (and in case someone searches the
archives on this issue), here's my current understanding of the matter,
i.e. how to get hi-ascii and especially Unicode characters into an NSString:

You're not supposed to use @"" for anything but lo-ascii. This is a pity
because @"" is a really cool mechanism, but there it is.

The following are the main alternative ways. For purposes of illustration,
we will make an NSString consisting of a bullet character:

NSLocalizedString(@"bullet", "")

where we have a Localizable.strings file containing "bullet"="*"; (that
character is a bullet) saved as Unicode. The main advantage here is
obviously that you can read the actual character!

[NSString stringWithUTF8String: "\xE2\x80\xA2"]

which would probably be useful primarily where most of the string is
lo-ascii with just a couple of Unicode characters intermingled.

[NSString stringWithCharacters:&aBullet length:1]

where unichar aBullet = 0x2022; but I find this clumsy in comparison to the
next syntax which does the same thing:

[NSString stringWithCharacters:(unichar*)"\x20\x22" length:1]

That's my favorite as being easiest to read when you know the hex unicode
values, and as being self-contained. The cast is just to stave off the
compiler warning; it isn't really necessary.

If you have just a few constants of this sort you can set them up using
#define or a static var. Still, this is not as cool or efficient as if @""
would accept \u syntax directly. Seems to me we're going all round the moon
here for something that ought to be dead simple.

Additions and corrections solicited. m.

--

matt neuburg, phd = email@hidden, http://www.tidbits.com/matt
pantes gar anthropoi tou eidenai oregontai phusei
Subscribe to TidBITS! It's free and smart. http://www.tidbits.com/
_______________________________________________
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.

  • Follow-Ups:
    • Re: 8-bit chars in @""
      • From: Ondra Cada <email@hidden>
    • Re: 8-bit chars in @""
      • From: Douglas Davidson <email@hidden>
    • Re: 8-bit chars in @""
      • From: Ali Ozer <email@hidden>
  • Prev by Date: Re: [ANN] My experiences with Apple
  • Next by Date: Re: 8-bit chars in @""
  • Previous by thread: Re: 8-bit chars in @""
  • Next by thread: Re: 8-bit chars in @""
  • Index(es):
    • Date
    • Thread