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

Method urlencode

dlib/http_client/http_client.cpp:230–253  ·  view source on GitHub ↗

static

Source from the content-addressed store, hash-verified

228
229// static
230 std::string http_client::urlencode(const std::string& in, bool post_encode)
231 {
232 static std::string allowed_chars("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_");
233
234 std::stringstream ss;
235 ss << std::hex;
236 for (std::string::const_iterator ci = in.begin(); ci != in.end(); ++ci)
237 {
238 if ( allowed_chars.find(*ci) != std::string::npos )
239 {
240 ss << *ci;
241 }
242 else if ( post_encode && *ci == ' ' )
243 {
244 ss << '+';
245 }
246 else
247 {
248 ss << '%' << std::setfill('0') << std::setw(2) << std::right << static_cast<int>(*ci);
249 }
250 }
251
252 return ss.str();
253 }
254
255// ----------------------------------------------------------------------------------------
256

Callers

nothing calls this directly

Calls 4

beginMethod · 0.45
endMethod · 0.45
findMethod · 0.45
strMethod · 0.45

Tested by

no test coverage detected