How can I decode HTML entities in C++?
For example:
HTML: "Music" & "video"
Decoded: "Music" & "video"
Thanks.
How can I decode HTML entities in C++?
For example:
HTML: "Music" & "video"
Decoded: "Music" & "video"
Thanks.
If you're comfortable with using C-strings, you might be interested in my answer to a similar question.
There's no need to compile the code as C++: compile entities.c
as -std=c99
and link the object file with your C++ code, eg if you have the follwing example program foo.cpp
#include <iostream>
extern "C" size_t decode_html_entities_utf8(char *dest, const char *src);
int main()
{
char line[100];
std::cout << "Enter encoded line: ";
std::cin.getline(line, sizeof line);
decode_html_entities_utf8(line, 0);
std::cout << line;
return 0;
}
use
g++ -o foo foo.cpp entities.o
Thanks for that quick answer, but I got this error:
$ gcc -c entities.c -std=c99
entities.c: In function ‘parse_entity’:
entities.c:328: error: ‘errno’ undeclared (first use in this function)
entities.c:328: error: (Each undeclared identifier is reported only once
entities.c:328: error: for each function it appears in.)
That I solve adding int errno; in the line 324. Now I'm going to try it.