| 546 | } |
| 547 | |
| 548 | std::string UrlDecode(std::string_view url, bool allow_null) |
| 549 | { |
| 550 | std::string decoded; |
| 551 | decoded.reserve (url.length ()); |
| 552 | size_t start = 0; |
| 553 | for (size_t i = 0; i < url.length (); i++) |
| 554 | { |
| 555 | auto c = url[i]; |
| 556 | if (c == '%') |
| 557 | { |
| 558 | decoded.append (url, start, i - start); |
| 559 | if (i + 2 <= url.length ()) |
| 560 | { |
| 561 | unsigned char ch; |
| 562 | auto res = std::from_chars(url.data() + i + 1, url.data() + i + 3, ch, 16); |
| 563 | if (res.ec == std::errc() && (ch || allow_null)) |
| 564 | decoded += ch; |
| 565 | else |
| 566 | decoded.append (url, i, 3); |
| 567 | i += 2; |
| 568 | start = i + 1; |
| 569 | } |
| 570 | else |
| 571 | break; |
| 572 | } |
| 573 | } |
| 574 | if (start < url.length ()) |
| 575 | decoded.append (url, start); |
| 576 | return decoded; |
| 577 | } |
| 578 | |
| 579 | bool MergeChunkedResponse (std::istream& in, std::ostream& out) |
| 580 | { |
no outgoing calls