Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- bool isKey = true;
- std::string lastKey;
- std::string lastValue;
- for (size_t i = 0, size = url.size (); i < size; ++i)
- {
- std::string& current = isKey ? lastKey : lastValue;
- const char ch = url [i];
- if (ch == '%')
- {
- if (i + 3 > size)
- {
- IsValid_ = false;
- return;
- }
- int val = 0;
- std::istringstream is (url.substr (i + 1, 2));
- if (is >> std::hex >> val)
- {
- current += static_cast<char> (val);
- i += 2;
- }
- else
- {
- IsValid_ = false;
- return;
- }
- }
- else if (ch == '+')
- current += ' ';
- else if (ch == '=')
- {
- if (isKey)
- isKey = false;
- else
- {
- IsValid_ = false;
- return;
- }
- }
- else if (ch == '&')
- {
- isKey = true;
- Params_ [lastKey] = lastValue;
- lastKey.clear ();
- lastValue.clear ();
- }
- else
- current += ch;
- }
- if (lastKey.size ())
- Params_ [lastKey] = lastValue;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement