• 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
Re: Convert Charatcers
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Convert Charatcers


  • Subject: Re: Convert Charatcers
  • From: Allan Odgaard <email@hidden>
  • Date: Tue, 9 Mar 2004 18:55:37 +0100

On 9. Mar 2004, at 18:19, Lorenzo wrote:

I create a NSString with [NSString stringWithContentsOfURL:myURL];

I hope Alastair answered your letter satisfyingly. Otherwise feel free to follow up with more detailed questions. But I would really suggest you read: http://www.catb.org/~esr/faqs/smart-questions.html and/or http://perl.plover.com/Questions.html

I have not yet a table mapping entities to char code. What is it?

That would be something like:
struct { char const* name; char code; } entities[] =
{
{ "quot", '"' },
{ "amp", '&' },
{ "lt", '<' },
{ "gt", '>' },
...
};

Now you can have a function like this:
char map_name_to_char (char* name)
{
for(size_t i = 0; i < sizeofA(entities); i++)
if(strcmp(entities[i].name, name) == 0)
return entities[i].code;
return 0;
}

So you then go through the HTML, find each &<name>; occurrence and use the above function to get the character code...

Hint: if efficiency matters, you can a) sort the table alphabetically and use binary search to find the code and b) use strncmp so that the name passed to map_name_to_char doesn't need to be null-terminated.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.


  • Follow-Ups:
    • Re: Convert Charatcers
      • From: Ondra Cada <email@hidden>
  • Prev by Date: Re: OK, but what do 'attributes' look like?
  • Next by Date: Re: NSDocument Deferred loading
  • Previous by thread: Re: Convert Charatcers
  • Next by thread: Re: Convert Charatcers
  • Index(es):
    • Date
    • Thread