* sarada7@gmail.c om:[color=blue]
>
> Is there a way to encode/decode HTML using C++??[/color]
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?
--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
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
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(cons t 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 << "<";
else if (*i == '>')
result << ">";
else if (*i == '&')
result << "&";
else if (*i == '"')
result << """;
else
result << static_cast<cha r>(*i); // Copy untranslated
}
return result.str();
}
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" ("<") 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.
Comment