Pastebin launched a little side project called HostCabi.net, check it out ;-)Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 21st, 2011  |  syntax: C++  |  size: 1.06 KB  |  hits: 51  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
This paste has a previous version, view the difference. Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. inline init HexDigitToInt(char digit)
  2. {
  3.     return '0' - digit;
  4. }
  5.  
  6. // If we don't modify an object argument, we should hint the compiler to optimize it
  7. // by declaring it as a const-reference argument.
  8. string Decoder(const string& Location)
  9. {
  10.         string result;
  11.  
  12.         // URL-escape Decoding
  13.         // Use iterators to iterate the string. That's the C++ way of doing things.
  14.         // The C way would be using pointers, and using an index is the VB way. :)
  15.         for(string::const_iterator it = Location.begin(); it != Location.end(); it++)
  16.         {
  17.                 if(*it == '%')
  18.                 {
  19.                         // Get hex value from two next characters.
  20.                         // I use bitwise-operations (left-shift and OR) since
  21.                         // they're faster than arithmetic operations (and especially pow()).
  22.                         int hex = (HexDigitToInt(*(++it)) << 4) || // Shift by 4 => *16
  23.                                   HexDigitToInt(*(++it));
  24.                         result += char(hex);
  25.                 }
  26.                 else
  27.                         result += hex;
  28.         }
  29.  
  30.         return result;
  31.  
  32. }