Skip navigation.
 
mlRe: endian problems with UTF16 on Intel Macs [SOLVED]
FROM : Chris Suter
DATE : Wed Aug 30 07:58:05 2006

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

Related mailsAuthorDate
mlendian problems with UTF16 on Intel Macs Donald Hall Aug 29, 07:47
mlRe: endian problems with UTF16 on Intel Macs Chris Suter Aug 29, 07:58
mlRe: endian problems with UTF16 on Intel Macs Ricky Sharp Aug 29, 13:42
mlRe: endian problems with UTF16 on Intel Macs Chris Suter Aug 29, 13:56
mlRe: endian problems with UTF16 on Intel Macs Ricky Sharp Aug 29, 17:23
mlRe: endian problems with UTF16 on Intel Macs [SOLVED] Donald Hall Aug 30, 07:14
mlRe: endian problems with UTF16 on Intel Macs [SOLVED] Chris Suter Aug 30, 07:58