• 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: using UTF-32 in NSString.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: using UTF-32 in NSString.


  • Subject: Re: using UTF-32 in NSString.
  • From: Aki Inoue <email@hidden>
  • Date: Sun, 27 Jun 2010 14:36:33 -0700

Georg,

NSString/CFString is conceptually an object wrapping around UTF-16 character array (just like many other string objects).  The length 2 returned from your example is, thus, the expected behavior.

When you're creating a string with Universal Character Names that containing non-BMP points, the official syntax is \UXXXXXXXX so it should be @"\\U0001ABCD".

> 	int Char = 0x1ABCD;
> 	NSString *aString = [NSString stringWithFormat:@"%C", Char]; //The resulting string contains one character with a unicode value of "ABCD".

%C takes a short value.

You can do something like this:
UniChar characters[2];
CFIndex length = (CFStringGetSurrogatePairForLongCharacter(0x1ABCD, characters) ? 2 : 1);

CFStringCreateWithCharacters(NULL, characters, length);

Aki

On 2010/06/27, at 14:18, Georg Seifert wrote:

> Hi,
>
> Does anyone has information on how to use Unicode code points higher than 0xFFFF.
> I need to add some supplementary multilingual plane code points to a NSString.
>
> I can use something like this:
> 	NSString *aString = @"\\u0001ABCD"; //this prints fine but the [aString length] is 2
>
> But if I have the unicode value as a int (unichar is to small)
> 	int Char = 0x1ABCD;
> 	NSString *aString = [NSString stringWithFormat:@"%C", Char]; //The resulting string contains one character with a unicode value of "ABCD".
>
> What is the recommended way to use/create UTF-32 strings in Cocoa.
>
> Best Regards
> Georg
>
> _______________________________________________
>
> Cocoa-dev mailing list (email@hidden)
>
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
>
> Help/Unsubscribe/Update your Subscription:
>
> This email sent to email@hidden

_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: using UTF-32 in NSString.
      • From: Georg Seifert <email@hidden>
References: 
 >using UTF-32 in NSString. (From: Georg Seifert <email@hidden>)

  • Prev by Date: Re: Text rendered in NSImage is fuzzy
  • Next by Date: Re: using UTF-32 in NSString.
  • Previous by thread: using UTF-32 in NSString.
  • Next by thread: Re: using UTF-32 in NSString.
  • Index(es):
    • Date
    • Thread