• 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: From Big Endian to Little Endian
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: From Big Endian to Little Endian


  • Subject: Re: From Big Endian to Little Endian
  • From: "Adam R. Maxwell" <email@hidden>
  • Date: Fri, 11 Aug 2006 13:36:57 -0700


On Aug 11, 2006, at 12:54, Julio Cesar Silva dos Santos wrote:

Hi, a couple of months ago I sent a message to the list explaining a problem with strings returned from iTunes and Intel Macs. My solution was to create a CFString using CFStringCreateWithBytes. (see http://www.cocoabuilder.com/archive/message/cocoa/ 2006/6/27/166393)
Now a user that is using Panther asked me that when he tries to save strings back to iTunes, they are saved as chinese characters. This happened because I had to change the code to check if the program is running on Tiger or Panther.
When using Tiger the code looks like this (value is an NSString):


len = [value lengthOfBytesUsingEncoding:NSUnicodeStringEncoding];

This should be the same as [value length].

err = AEBuildDesc(&valueDesc, NULL, "'utxt'(@)", len, [value cStringUsingEncoding:NSUnicodeStringEncoding]);

When using Panther I tried this:

len = [value cStringLength];

This is the length in the default C string encoding (deprecated)...

err = AEBuildDesc(&valueDesc, NULL, "'utxt'(@)", len, [value UTF8String]);

You're using a mismatched length (default C encoding), data (UTF-8) and type (UTF-16 native) here. Try this:


NSData *data = [value dataUsingEncoding:NSUTF8StringEncoding];
len = [data length];
if(data)
  err = AEBuildDesc(&valueDesc, NULL, "'utf8'(@", len, [data bytes]);

which should work regardless of endianness on Tiger and Panther. This code uses typeUTF8Text instead of 'utxt' (which is also deprecated according to AEDataModel.h).

-- Adam



_______________________________________________
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: 
 >From Big Endian to Little Endian (From: Julio Cesar Silva dos Santos <email@hidden>)

  • Prev by Date: (no subject)
  • Next by Date: Re: printf with "%@"
  • Previous by thread: From Big Endian to Little Endian
  • Next by thread: (no subject)
  • Index(es):
    • Date
    • Thread