Advertisement
Guest User

Untitled

a guest
Apr 28th, 2012
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.95 KB | None | 0 0
  1.         bool isKey = true;
  2.         std::string lastKey;
  3.         std::string lastValue;
  4.         for (size_t i = 0, size = url.size (); i < size; ++i)
  5.         {
  6.             std::string& current = isKey ? lastKey : lastValue;
  7.  
  8.             const char ch = url [i];
  9.  
  10.             if (ch == '%')
  11.             {
  12.                 if (i + 3 > size)
  13.                 {
  14.                     IsValid_ = false;
  15.                     return;
  16.                 }
  17.                 int val = 0;
  18.                 std::istringstream is (url.substr (i + 1, 2));
  19.                 if (is >> std::hex >> val)
  20.                 {
  21.                     current += static_cast<char> (val);
  22.                     i += 2;
  23.                 }
  24.                 else
  25.                 {
  26.                     IsValid_ = false;
  27.                     return;
  28.                 }
  29.             }
  30.             else if (ch == '+')
  31.                 current += ' ';
  32.             else if (ch == '=')
  33.             {
  34.                 if (isKey)
  35.                     isKey = false;
  36.                 else
  37.                 {
  38.                     IsValid_ = false;
  39.                     return;
  40.                 }
  41.             }
  42.             else if (ch == '&')
  43.             {
  44.                 isKey = true;
  45.                 Params_ [lastKey] = lastValue;
  46.                 lastKey.clear ();
  47.                 lastValue.clear ();
  48.             }
  49.             else
  50.                 current += ch;
  51.         }
  52.         if (lastKey.size ())
  53.             Params_ [lastKey] = lastValue;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement