Advertisement
obernardovieira

utf8decode (can use with PHP utf8_encode)

Apr 2nd, 2014
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.67 KB | None | 0 0
  1. //not by me
  2.  
  3. std::string toEscaped( std::string const& original )//<< utf8decode - use utf8_encode in PHP and get the normal string
  4. {
  5.     std::string results ;
  6.     for ( std::string::const_iterator iter = original.begin();
  7.             iter != original.end();
  8.             ++ iter ) {
  9.         static bool const allowed[256];
  10.         if ( allowed[static_cast<unsigned char>(*iter)] ) {
  11.             results += *iter;
  12.         } else {
  13.             static char const hexChars[] = "0123456789ABCDEF";
  14.             results += '%';
  15.             results += hexChars[(*iter >> 4) & 0x0F];
  16.             results += hexChars[(*iter     ) & 0x0F];
  17.         }
  18.     }
  19.     return results;
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement