Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: do i have to convert each unichar on ppc and intel




Le 30 avr. 08 à 17:24, Nick Rogers a écrit :

hi,
I'm using:
[NSString stringWithCharacters:gptEntry.partName length:36];
where gptEntry struct have been filled in from the disk.
The string shows correct on ppc, while shows garbage on intel.
So how can I convert an entire such unichar array to correct-endian format?
Is there any built-in support?


Thanks,
Nick


Note this quote from the documentation:

“When creating an NSString object from a UTF-16-encoded string (or a byte stream interpreted as UTF-16), if the byte order is not otherwise specified, NSStringassumes that the UTF-16 characters are big-endian, unless there is a BOM (byte-order mark), in which case the BOM dictates the byte order. When creating anNSString object from an array of Unicode characters, the returned string is always native-endian, since the array always contains Unicode characters in native byte order.”

If you create your string from the disk, you may use the function

+stringWithContentsOfFile:usedEncoding:error:
or
-initWithContentsOfFile:usedEncoding:error:

And if you want to create your string from a character array (and not from a file), I think you can use the -initWithBytes:length:encoding: method passing NSUnicodeStringEncoding as parameter. It may try to use the BOM in this case, as the encoding parameter do not specified it.


_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/email@hidden

This email sent to email@hidden
References: 
 >do i have to convert each unichar on ppc and intel (From: Nick Rogers <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.