views:

419

answers:

2

Given a charset string, such as "utf-8", "iso-8859-1", "us-ascii" etc, is there any built-in way to get the appropriate NSStringEncoding in Cocoa?

Right now I'm looking at just building a NSDictionary containing a canonicalized version of the name mapped to the NSStringEncoding, then having a lookup mechanism that canonicalizes the input in the same way. But is there really no way to get NSUTF8StringEncoding given the string "UTF-8", etc?

+1  A: 

I don't think there is any built-in way of achieving this. I think what you suggest - building a dictionary with the values - is a sensible way to go here. There aren't that many encodings so it should be quite trivial, and probably quicker than trying to find a built-in way of doing it.

pheelicks
+4  A: 

You have to go through CoreFoundation.

CFStringConvertIANACharSetNameToEncoding
CFStringConvertEncodingToNSStringEncoding
drawnonward
Thanks, that seems like it should do the trick.
d11wtq