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

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • sarada7@gmail.com

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

    Hi,

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

    Thanks,
    Sarada.

  • marko.suonpera@24net.zzn.com

    #2
    Re: How to encode/decode a HTML using C++??

    Be more specific.

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

    Comment

    • Ben Pope

      #3
      Re: How to encode/decode a HTML using C++??

      sarada7@gmail.c om wrote:[color=blue]
      > Hi,
      >
      > Is there a way to encode/decode HTML using C++??[/color]

      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
      --
      I'm not just a number. To many, I'm known as a string...

      Comment

      • Alf P. Steinbach

        #4
        Re: How to encode/decode a HTML using C++??

        * 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?

        Comment

        • sarada7@gmail.com

          #5
          Re: How to encode/decode a HTML using C++??

          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

          Comment

          • carlmuller@hotmail.com

            #6
            Re: How to encode/decode a HTML using C++??

            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 << "&lt;";
            else if (*i == '>')
            result << "&gt;";
            else if (*i == '&')
            result << "&amp;";
            else if (*i == '"')
            result << "&quot;";
            else
            result << static_cast<cha r>(*i); // Copy untranslated
            }
            return result.str();
            }

            Comment

            • sarada7@gmail.com

              #7
              Re: How to encode/decode a HTML using C++??

              Thanks for your help!

              Comment

              • carlmuller@hotmail.com

                #8
                Re: How to encode/decode a HTML using C++??

                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.

                Comment

                Working...