• 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
Decoding html entities
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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
  • Follow-Ups:
    • Re: Decoding html entities
      • From: John Pannell <email@hidden>
    • Re: Decoding html entities
      • From: Adam Leonard <email@hidden>
  • Prev by Date: Re: Cocoa newb - Bus Error from TCP Server
  • Next by Date: Re: Cocoa newb - Bus Error from TCP Server
  • Previous by thread: Re: NSAttributedString gains default font and paragraph style after round tripping through pasteboard?
  • Next by thread: Re: Decoding html entities
  • Index(es):
    • Date
    • Thread