Re: wchar_t and NSString
Re: wchar_t and NSString
- Subject: Re: wchar_t and NSString
- From: Wade Tregaskis <email@hidden>
- Date: Tue, 14 Oct 2003 22:47:01 +1000
I'm using some internal cross platform libraries that use wstring and
wchar_t to store string data. Trouble is on a Mac these are all stored
as 4 byte unicode data. As far as I can see the unicode functions for
NSString all expect 2 byte. This leaves me with having to strip or pad
data before putting it in the NSStrings for display.
So is there any way of putting and getting the NSString data as 4 byte?
Also anyone know how safe it "ignore" the top two bytes? I don't think
it affects too much as it's the more obscure character set code pages
- but I'm not sure.
The ATSUI supports Unicode 3.2, which includes UTF-32, which is if I
understand correctly what your wstring/wchar_t uses (alternatively, it
may officially use UCS-4, which is compatible with UTF-32). NSString's
do prefer UTF-8 or UTF-16 normally, you are correct. However, there
should not be anything stopping you from creating an NSString with
UTF-32 - you need only make sure the string prefix is the correct one
for UTF-32, if I understand correctly.
Retrieving UTF-32 from the NSString seems trickier, since internally I
think they use UTF-16, and there's no way of differentiating between
UTF-16 and UTF-32 encoding formats, since they're both lumped under
"Unicode". You may have to resort to other methods - perhaps in
CoreFoundation or the ATSUI - to get the data out as you want.
I'm not Unicode expert, so I can't give you an authoritative answer on
the stripping aspect, but it seems like you will eventually run afoul
of this, if your usage is wide enough. You probably would be better
off finding a proper way to do what you want.
Perhaps there is some UTF-16 to UTF-32 conversion code out there you
could use (and vice versa, too)?
Wade Tregaskis
-- Sed quis custodiet ipsos custodes?
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.