| 74 | } |
| 75 | |
| 76 | inline std::size_t URIDecode(const std::string &input, std::string &output) |
| 77 | { |
| 78 | auto src_iter = std::begin(input); |
| 79 | const auto src_end = std::end(input); |
| 80 | output.resize(input.size() + 1); |
| 81 | std::size_t decoded_length = 0; |
| 82 | for (decoded_length = 0; src_iter != src_end; ++decoded_length) |
| 83 | { |
| 84 | if (src_iter[0] == '%' && src_iter[1] && src_iter[2] && isxdigit(src_iter[1]) && |
| 85 | isxdigit(src_iter[2])) |
| 86 | { |
| 87 | std::string::value_type a = src_iter[1]; |
| 88 | std::string::value_type b = src_iter[2]; |
| 89 | a -= src_iter[1] < 58 ? 48 : src_iter[1] < 71 ? 55 : 87; |
| 90 | b -= src_iter[2] < 58 ? 48 : src_iter[2] < 71 ? 55 : 87; |
| 91 | output[decoded_length] = 16 * a + b; |
| 92 | src_iter += 3; |
| 93 | continue; |
| 94 | } |
| 95 | output[decoded_length] = *src_iter++; |
| 96 | } |
| 97 | output.resize(decoded_length); |
| 98 | return decoded_length; |
| 99 | } |
| 100 | |
| 101 | inline std::size_t URIDecodeInPlace(std::string &URI) { return URIDecode(URI, URI); } |
| 102 | } // namespace osrm::util |
no test coverage detected