MCPcopy Create free account
hub / github.com/davisking/dlib / urldecode

Method urldecode

dlib/http_client/http_client.cpp:40–63  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

38// ----------------------------------------------------------------------------------------
39
40 std::string http_client::urldecode( const std::string& s )
41 {
42 std::stringstream ss;
43
44 for ( char const * p_read = s.c_str(), * p_end = (s.c_str() + s.size()); p_read < p_end; p_read++ )
45 {
46 if ( p_read[0] == '%' && p_read+1 != p_end && p_read+2 != p_end && isXdigit(p_read[1]) && isXdigit(p_read[2]) )
47 {
48 ss << static_cast<char>((( (p_read[1] & 0xf) + ((p_read[1] >= 'A') ? 9 : 0) ) << 4 ) | ( (p_read[2] & 0xf) + ((p_read[2] >= 'A') ? 9 : 0) ));
49 p_read += 2;
50 }
51 else if ( p_read[0] == '+' )
52 {
53 // Undo the encoding that replaces spaces with plus signs.
54 ss << ' ';
55 }
56 else
57 {
58 ss << p_read[0];
59 }
60 }
61
62 return ss.str();
63 }
64
65// ----------------------------------------------------------------------------------------
66

Callers

nothing calls this directly

Calls 3

isXdigitFunction · 0.85
sizeMethod · 0.45
strMethod · 0.45

Tested by

no test coverage detected