Re: endian problems with UTF16 on Intel Macs [SOLVED]
Re: endian problems with UTF16 on Intel Macs [SOLVED]
- Subject: Re: endian problems with UTF16 on Intel Macs [SOLVED]
- From: Chris Suter <email@hidden>
- Date: Wed, 30 Aug 2006 15:58:05 +1000
Hi Don,
You're missing an autorelease.
The other thing I had to check on (and you're fine) is what
__BIG_ENDIAN__ and __LITTLE_ENDIAN__ are defined as. I've certainly
accidentally made the mistake of using #if when I should have used
#ifdef where the macros where just #defined rather than #defined to a
non-zero value. As it turns out, __BIG_ENDIAN__ and __LITTLE_ENDIAN__
are defined as 1 but I thought it's worth mentioning.
Lastly, one thing I haven't tried is actually seeing whether the
UTF16BE constant works on Panther. I doubt whether it does, but the
documentation left me wondering whether the constant just wasn't in
the headers on Panther or if it just wasn't supported.
- Chris
On 30/08/2006, at 3:14 PM, Donald Hall wrote:
Many thanks to Rick and Chris for their feedback. Here is what I
ended up with:
- (NSData *)dataRepresentationOfType:(NSString *)aType
{
[self updateString];
CFStringBuiltInEncodings stringEncoding;
#if __BIG_ENDIAN__
stringEncoding = kCFStringEncodingUnicode;
#elif __LITTLE_ENDIAN__
stringEncoding = kCFStringEncodingUTF16BE;
#endif
CFDataRef myDataRef = CFStringCreateExternalRepresentation
(kCFAllocatorDefault, (CFStringRef)string, stringEncoding,'?');
return (NSData *)myDataRef;
}
Since 'kCFStringEncodingUTF16BE' isn't available in Panther I
needed the conditional compile - Panther is always big endian, so
it can use what I originally had - 'kCFStringEncodingUnicode', and
endian is not an issue on PPC Macs whether running Panther or
Tiger. Now when my Cocoa program saves the Unicode text file it
will be in the same format as my AppleScript application is using
when adding to the file.
Don
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