How to encode/decode a HTML using C++??

M

marko.suonpera

Be more specific.

In several application development softwares there are readymade
components which can interpret HTML.
 
B

Ben Pope

Hi,

Is there a way to encode/decode HTML using C++??

Encode and decode into what? Where is the html/source coming from?
Where should it go to?

Take a look at:

std::string;

Ben Pope
 
A

Alf P. Steinbach

* (e-mail address removed):
Is there a way to encode/decode HTML using C++??

No way. Those web-browser said to implemented in C or C++? Well, it's
just a sham, they're all implemented in JavaScript.

Hth.,

- Alf


PS: HTML is just plain text, so what is the problem?
 
S

sarada7

I have a C++ function which returns a string and later this string is
used by ASP for display. If I use HTMLEncode in ASP this solves my
problem. But there are some cases where the string output is an image
tag and I don't want HTMLEncode to show the tag as it is. I am trying
to remove the HTMLEncode in ASP and try to encode the string in C++
before sending it to ASP. Please let me know if this is clear or any
thoughts are welcome.
Thanks
 
C

carlmuller

Encoding it is simple. Decoding takes a slightly longer function, doing
the same thing in reverse. Note that this won't work on EBCDIC based
machines (silly IBM).

To selectively encode different tags, parse the input string and output
the code depending on what you want.

Assuming you don't have an operating system or library function to do
the work for you, it is:

string EncodeHtml(const wstring& html)
{
ostringstream result;
wstring::const_iterator i;
for (i = html.begin(); i != html.end(); ++i)
{
if (*i >= 128)
result << "&#" << static_cast<int>(*i) << ";";
else if (*i == '<')
result << "&lt;";
else if (*i == '>')
result << "&gt;";
else if (*i == '&')
result << "&amp;";
else if (*i == '"')
result << "&quot;";
else
result << static_cast<char>(*i); // Copy untranslated
}
return result.str();
}
 
C

carlmuller

Hmm, I don't know about your newsreader, but my posted code is showing
up wrong on google groups, despite "Preview" working.
i.e. "ampersand L T semicolon" ("&lt;") is showing up as "<" which
defeats the point really. The appropriate strings (using string literal
concatenation) are:
"&" "lt;"
"&" "gt;"
"&" "amp;"
"&" "quot;"
I hope the mangling was just at the client end, but still it could be
annoying if you are viewing newsgroups using a web browser. Oh well.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top