Converting from Unicode UTF-16 to 8bit MacCyrillic
Converting from Unicode UTF-16 to 8bit MacCyrillic
- Subject: Converting from Unicode UTF-16 to 8bit MacCyrillic
- From: Horst Hoesel <email@hidden>
- Date: Fri, 23 Jun 2006 12:02:11 +0200
Hi all,
for a small tool I need to convert user entered Russian text into
MacCyrillic characters. User input is into a NSTextField output is
via the scrap. (Yep, using Carbon, because I found no way to put old
style 8 bit characters into the pasteboard without evoking some kind
of unwanted conversion. But that is not my trouble)
Trouble is the following (except for not getting any points for
pretty code :)
NSData* myRet; // should receive the input converted to 8 bit
MacCyrillic on exit
NSString* utf16String; // contains the text to convert
if ([utf16String
canBeConvertedToEncoding:kCFStringEncodingMacCyrillic] == YES) {
myRet = [utf16String dataUsingEncoding:kCFStringEncodingMacCyrillic];
} else {
myRet = [NSData dataWithBytes:"Cannot encode string in MacCyrillic"
length:sizeof("Cannot encode string in MacCyrillic")];
}
myRet will contain "\u041c\u0435\u0434\u0438\u0430" for an
utf16string of "Медиа". This is a valid representation of the
source, but surely not the conversion I'd expect. I had expected it
to contain 5 8 bit characters based on the MacCyrillic encoding of
"Медиа".
What am I doing wrong?
Any ideas and hints appreciated.
TIA,
Horst
--
Horst Hoesel
VierZwo Software GmbH
Ruebezahlstr. 20
81739 Muenchen
Germany
_______________________________________________
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