Re: Decoding html entities
Re: Decoding html entities
- Subject: Re: Decoding html entities
- From: John Pannell <email@hidden>
- Date: Sun, 11 Jun 2006 22:47:17 -0600
Hi Thom-
Have you looked at the Core Foundation function...
CFURLCreateStringByReplacingPercentEscapesUsingEncoding
I have found it works quite well for me. HTH!
John
John Pannell
Positive Spin Media
http://www.positivespinmedia.com
On Jun 11, 2006, at 6:14 PM, Thom McGrath wrote:
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:
40positivespinmedia.com
This email sent to email@hidden
_______________________________________________
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