• 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: endian problems with UTF16 on Intel Macs
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: endian problems with UTF16 on Intel Macs


  • Subject: Re: endian problems with UTF16 on Intel Macs
  • From: Chris Suter <email@hidden>
  • Date: Tue, 29 Aug 2006 15:58:43 +1000


On 29/08/2006, at 3:47 PM, Donald Hall wrote:

I have run into an endian problem with Intel Macs that I don't know how to solve despite some good hints in the archives and documentation. I have an AppleScript application that is feeding UTF16 text into a log file. A second Cocoa based app reads the file and displays it in a window. Everything looks okay until I make a change to the log file in the Cocoa app and resave the file. Any new data added to the log file by the AppleScript application after the save is obviously byte reversed as it comes out in Oriental characters. Saving the file must change the endian-ness of the data to Intel native format.

I understood from reading the documentation that pairing the functions CFStringCreateExternalRepresentation and CFStringCreateFromExternalRepresentation would keep the stored data in "external representation" rather than platform native "internal representation".

There are two different UTF16 formats, UTF16 big-endian and UTF-16 little-endian and they are valid on all platforms. When reading a file that's UTF-16, readers look for a byte order mark to tell which format they are. If you want to write out using one particular encoding, use kCFStringEncodingUTF16BE or kCFStringEncodingUTF16LE. Note that these aren't available on Panther.


Furthermore, I understood that "external representation" was always big endian.

No. The representation is as dictated by the encoding. Some encodings don't have an endian aspect to them (UTF-8 for example). I'm guessing if you pick kCFStringEncodingUTF16, OS X is free to choose big-endian or little-endian.


- Chris

Attachment: smime.p7s
Description: S/MIME cryptographic signature

 _______________________________________________
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

  • Follow-Ups:
    • Re: endian problems with UTF16 on Intel Macs
      • From: Ricky Sharp <email@hidden>
References: 
 >endian problems with UTF16 on Intel Macs (From: Donald Hall <email@hidden>)

  • Prev by Date: endian problems with UTF16 on Intel Macs
  • Next by Date: Escaping a Degree Symbol
  • Previous by thread: endian problems with UTF16 on Intel Macs
  • Next by thread: Re: endian problems with UTF16 on Intel Macs
  • Index(es):
    • Date
    • Thread