Re: Convert Charatcers
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.