• 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: String conversion help.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: String conversion help.


  • Subject: Re: String conversion help.
  • From: Ali Ozer <email@hidden>
  • Date: Thu, 23 Jun 2005 13:32:05 -0700

The NSUnicodeStringEncoding encoding has been there for some time (10 + years) to support UTF-16 (back then "UCS-2") characters. In addition, as I said earlier, the canonical representation of NSString objects is in terms of these characters, so, the support has been there.

Note that NSUnicodeStringEncoding is the "same" as kCFStringEncodingUnicode (but different value), and the 10.4 introduced kCFStringEncodingUTF16 is simply an alias to that. CF encoding values can be used in NS with the CFStringConvertEncodingToNSStringEncoding() function.

The following encoding constants were also introduced in 10.4, as a way to support explicit endianness settings:

kCFStringEncodingUTF16 = 0x0100, /* kTextEncodingUnicodeDefault + kUnicodeUTF16Format (alias of kCFStringEncodingUnicode) */
kCFStringEncodingUTF16BE = 0x10000100, /* kTextEncodingUnicodeDefault + kUnicodeUTF16BEFormat */
kCFStringEncodingUTF16LE = 0x14000100, /* kTextEncodingUnicodeDefault + kUnicodeUTF16LEFormat */


kCFStringEncodingUTF32 = 0x0c000100, /* kTextEncodingUnicodeDefault + kUnicodeUTF32Format */
kCFStringEncodingUTF32BE = 0x18000100, /* kTextEncodingUnicodeDefault + kUnicodeUTF32BEFormat */
kCFStringEncodingUTF32LE = 0x1c000100 /* kTextEncodingUnicodeDefault + kUnicodeUTF32LEFormat */


However note that this functionality was there pre-10.4, but you had to build up the constant values yourself.
Ali







Begin forwarded message:

From: John Draper <email@hidden>
Date: June 23, 2005 13:19:03 PDT
To: Ali Ozer <email@hidden>, email@hidden
Subject: Re: String conversion help.


Ali Ozer wrote:


In NSString APIs all references to "characters" is UTF-16, in native endianness.


Hmmm!! I'm going to have to go back and check on this, but I'm sure I tried it.
But I'll go back and look anyway.




So initWithCharacters:... and getCharacters: should have worked for you, at least for big endian data on the PowerPC.



Will try it again - just to be sure, but I'm almost for certain I tried it last week with this
assumption.




However, if the characters are not native endianness, it's best to use one of the encoding methods joar points out.



I have utilities to convert back and forth for buffers of 16 bit (words). But once I get
data into the Mac, it's all treated as Big Endian.


I'm surprised that Apple waited until just now to support this..... because none of the encodings
Apple supports seems to indicate any 16 bit character encodings, unless they named it
differently. In the Docs, most indicate 8 or 7 bit characters, but 2 or 3 -


NSUnicodeStringEncoding
NSWindowsCP1250StringEncoding
 <and a number of other winBlows encodings>

Don't seem to explicitly say the character sizes are 16 bits.

Knowing nothing about WinBlows, I hardly can be expected to know this. Can I assume that since they don't explicitly specify the character sizes of 8 or 7 bits
that they are assumed to be 16 bits?


John


_______________________________________________
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


References: 
 >String conversion help. (From: John Draper <email@hidden>)
 >Re: String conversion help. (From: j o a r <email@hidden>)
 >Re: String conversion help. (From: Ali Ozer <email@hidden>)
 >Re: String conversion help. (From: John Draper <email@hidden>)

  • Prev by Date: Re: NSImage is a pain
  • Next by Date: Re: NSImage is a pain
  • Previous by thread: Re: String conversion help.
  • Next by thread: Re: String conversion help.
  • Index(es):
    • Date
    • Thread