MCPcopy Create free account
hub / github.com/PurpleI2P/i2pd / UrlDecode

Function UrlDecode

libi2pd/HTTP.cpp:548–577  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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 {

Callers 3

ExtractAddressHelperMethod · 0.85
mainFunction · 0.85
HandleCommandMethod · 0.85

Calls

no outgoing calls

Tested by 1

mainFunction · 0.68