| 16 | { |
| 17 | |
| 18 | std::string UrlDecode (const std::string& url) |
| 19 | { |
| 20 | std::string result; |
| 21 | |
| 22 | const size_t length = url.length (); |
| 23 | |
| 24 | for (auto it = url.begin (), end = url.end (); it != end; ++it) |
| 25 | { |
| 26 | const char c = *it; |
| 27 | |
| 28 | if (c != '%') |
| 29 | { |
| 30 | result.push_back (c); |
| 31 | } |
| 32 | else |
| 33 | { |
| 34 | if (++it == url.end ()) |
| 35 | break; // Malformed input string |
| 36 | |
| 37 | const char c1 = *it; |
| 38 | |
| 39 | if (++it == url.end ()) |
| 40 | break; // Malformed input string |
| 41 | |
| 42 | const char c2 = *it; |
| 43 | |
| 44 | result.push_back (HexCharToNum (c1) << 4 | HexCharToNum (c2)); |
| 45 | } |
| 46 | } |
| 47 | |
| 48 | return result; |
| 49 | } |
| 50 | |
| 51 | } |
no test coverage detected