]>
git.proxmox.com Git - ceph.git/blob - ceph/src/common/url_escape.cc
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 #include "url_escape.h"
9 std::string
url_escape(const std::string
& s
)
13 if (std::isalnum(c
) || c
== '-' || c
== '.' || c
== '_' || c
== '~' ||
18 snprintf(t
, sizeof(t
), "%%%02x", (int)(unsigned char)c
);
25 std::string
url_unescape(const std::string
& s
)
28 const char *end
= s
.c_str() + s
.size();
29 for (const char *c
= s
.c_str(); c
< end
; ++c
) {
34 for (unsigned i
=0; i
<2; ++i
) {
37 std::ostringstream ss
;
38 ss
<< "invalid escaped string at pos " << (c
- s
.c_str()) << " of '"
40 throw std::runtime_error(ss
.str());
43 if (*c
>= '0' && *c
<= '9') {
45 } else if (*c
>= 'a' && *c
<= 'f') {
47 } else if (*c
>= 'A' && *c
<= 'F') {
50 std::ostringstream ss
;
51 ss
<< "invalid escaped string at pos " << (c
- s
.c_str()) << " of '"
53 throw std::runtime_error(ss
.str());