HTML entities

Please post support and help requests here.
Posts: 129
Joined: 11 Aug 2008, 22:47
Location: Belgium

HTML entities

Postby fbraem » 12 Nov 2012, 13:30

Just a quick question before I start developing my own solution while it is maybe already part of POCO (A donkey does not bump into the same stone twice, they say in Dutch).

Is there a way to encode &, <, >, ... for HTML?

Zumuta!, that's the way to do IT!

Posts: 1268
Joined: 11 Jul 2006, 16:27
Location: Austria

Re: HTML entities

Postby guenter » 12 Nov 2012, 13:38

Not yet. I use following function, which I plan to make a static member of HTTPRequestHandler some day...

Code: Select all

   std::string htmlize(const std::string& str)
      std::string::const_iterator it(str.begin());
      std::string::const_iterator end(str.end());
      std::string html;
      for (; it != end; ++it)
         switch (*it)
         case '<': html += "&lt;"; break;
         case '>': html += "&gt;"; break;
         case '"': html += "&quot;"; break;
         case '&': html += "&amp;"; break;
         default:  html += *it; break;
      return html;

Posts: 77
Joined: 03 Dec 2009, 12:55

Re: HTML entities

Postby killerbot » 12 Nov 2012, 21:34

why not declare the iterator in the for(), and no var for the end() ==> that way reduction of the scope of the variable ?
The fact that the end 'could' be calculated at every loop check might even be optimized out by the compiler, and on the other hand is probably not a bottleneck on its own.
The scope reduction make the code easier to grasp/read.

Just my 2 cents ;-)

Or an std::transform with a functor ?

Of C++11 : auto / cbegin() / cend() :-) :-) , I know : too early for this.

Return to “Support”

Who is online

Users browsing this forum: No registered users and 7 guests