Advertisement
Guest User

KoD

a guest
Oct 20th, 2020
779
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.58 KB | None | 0 0
  1. string urlDecode(string text)
  2.     {
  3.       string escaped;
  4.  
  5.       for (auto i = text.begin(), nd = text.end(); i < nd; ++i)
  6.       {
  7.         auto c = ( *i );
  8.  
  9.         switch(c)
  10.         {
  11.           case '%':
  12.             if (i[1] && i[2]) {
  13.                 char hs[]{ i[1], i[2] };
  14.                 escaped += static_cast<char>(strtol(hs, nullptr, 16));
  15.                 i += 2;
  16.             }
  17.             break;
  18.           case '+':
  19.             escaped += ' ';
  20.             break;
  21.           default:
  22.             escaped += c;
  23.         }
  24.       }
  25.  
  26.       return escaped;
  27.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement