Decoding html entities
Decoding html entities
- Subject: Decoding html entities
- From: Thom McGrath <email@hidden>
- Date: Sun, 11 Jun 2006 20:14:27 -0400
My application receives data from a server which is encoded using the
PHP function htmlspecialchars($string,ENT_QUOTES,'UTF-8') <http://
us3.php.net/manual/en/function.htmlspecialchars.php>.
I'm attempting to decode it using cocoa, and have already searched
the archives but have not found something that works. The trick with
NSAttributedString appears to be the best bet, but is ungodly slow,
and returns a null string in the end. What am I doing wrong?
NSDictionary *nameAttributes;
NSAttributedString *nameFormat;
NSData *nameData;
NSLog(@"Creating NSData from `%@`...",[objectDictionary
objectForKey:@"name"]);
nameData = [[objectDictionary objectForKey:@"name"]
dataUsingEncoding:NSUTF8StringEncoding];
NSLog(@"Creating NSAttributedString from `%@`...",nameData); // <--
between this and the next NSLog is usually a minute, no lie.
nameFormat = [[NSAttributedString alloc] initWithHTML:nameData
documentAttributes:&nameAttributes];
NSLog(@"Found string `%@`",[nameFormat string]);
The first NSLog shows the proper encoded data. The data being decoded
is short, < 50 characters. However, the process is expected to run
many thousands of times. The user is presented with a progress bar
during, but the faster the better of course. Given that I only have 5
characters to decode, I wonder if it'd be better to use a find-
replace instead. But it feels error-prone, and I see no method on the
docs which can do a find-replace.
--
Thom McGrath, <http://www.thezaz.com/>
"You don't need eyes to see, you need vision" - Maxi Jazz in
"Reverence" by Faithless
_______________________________________________
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