• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Converting from Unicode UTF-16 to 8bit MacCyrillic
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Converting from Unicode UTF-16 to 8bit MacCyrillic


  • Subject: Re: Converting from Unicode UTF-16 to 8bit MacCyrillic
  • From: Ricky Sharp <email@hidden>
  • Date: Fri, 23 Jun 2006 07:18:33 -0500


On Jun 23, 2006, at 5:02 AM, Horst Hoesel wrote:

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")];
}

When using the Core Foundation constants in APIs that expect NS constants, you need to convert them:


myRet = [utf16String dataUsingEncoding:CFStringConvertEncodingToNSStringEncoding (kCFStringEncodingMacCyrillic)];


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 "Медиа".

The value of kCFStringEncodingMacCyrillic is 7. Looking at the NS constant with that value shows that it is NSNonLossyASCIIStringEncoding. That's why your string is "\u041c..."; it's giving you "7-bit verbose ASCII to represent all Unicode characters".


___________________________________________________________
Ricky A. Sharp         mailto:email@hidden
Instant Interactive(tm)   http://www.instantinteractive.com

_______________________________________________
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


References: 
 >Converting from Unicode UTF-16 to 8bit MacCyrillic (From: Horst Hoesel <email@hidden>)

  • Prev by Date: NSOpenPanel isn't listening to me? I told it to only allow .zip and .xml!
  • Next by Date: Re: NSOpenPanel isn't listening to me? I told it to only allow .zip and .xml!
  • Previous by thread: Converting from Unicode UTF-16 to 8bit MacCyrillic
  • Next by thread: [SOVLED] Re: Converting from Unicode UTF-16 to 8bit MacCyrillic
  • Index(es):
    • Date
    • Thread