Reputation: 11
In my app, I download rss file with encoding="windows-1255".
I read, that I need to convert it to UTF8 before passing it to NSXMLParser
.
If that true, (any comments about that will help offcourse..)
I also have this code sample, but I dont see the const for 1255 encoding.
NSString *myStr = [[NSString alloc]initWithData:myData encoding:NSWindowsCP1252StringEncoding];
How can i convert with 1255
, instead of 1252
?
tnx
Upvotes: 1
Views: 842
Reputation: 57040
It is actually possible.
NSString* encoding = @"windows-1255";
CFStringEncoding cfEncoding = CFStringConvertIANACharSetNameToEncoding((__bridge CFStringRef)encoding);
NSStringEncoding nsEncoding = CFStringConvertEncodingToNSStringEncoding(cfEncoding);
NSString* decodedString = [[NSString alloc] initWithData:data encoding:nsEncoding];
CFStringConvertIANACharSetNameToEncoding
converts the encoding name to a CFStringEncoding
value, and CFStringConvertEncodingToNSStringEncoding
converts the CFStringEncoding
to NSStringEncoding
which you can use creating the NSString
from NSData
.
Upvotes: 1
Reputation: 111
I suggest you to go ahead and try to parse your file directly. Don't try to solve a problem if you haven't actually encountered it.
There are strong probabilities that your file will be parsed fine without any exotic conversion, especially if it's a standard RSS feed, no matter the version.
Upvotes: 0
Reputation: 14160
It seems that there is no such encoding in SDK. However, you can write encoding by yourself - put unicode characters (from http://en.wikipedia.org/wiki/Windows-1255, for instance) in array [0..255], and put the needed char in string instead of each byte in NSData.
Upvotes: 0