18 std::string pointer =
"";
21 auto pointer_separator = uri.find(
'#');
22 if (pointer_separator != std::string::npos) {
23 pointer = uri.substr(pointer_separator + 1);
26 std::size_t pos = pointer.size() - 1;
28 pos = pointer.rfind(
'%', pos);
29 if (pos == std::string::npos)
32 if (pos >= pointer.size() - 2) {
37 std::string hex = pointer.substr(pos + 1, 2);
38 char ascii =
static_cast<
char>(std::strtoul(hex.c_str(),
nullptr, 16));
39 pointer.replace(pos, 3, 1, ascii);
45 auto location = uri.substr(0, pointer_separator);
47 if (location.size()) {
50 if (location.find(
"urn:") == 0) {
62 auto proto = location.find(
"://", pos);
63 if (proto != std::string::npos) {
67 scheme_ = location.substr(pos, proto - pos);
70 auto authority = location.find(
"/", pos);
71 if (authority != std::string::npos) {
72 authority_ = location.substr(pos, authority - pos);
77 auto path = location.substr(pos);
80 if (
urn_.size() && path.size())
81 throw std::invalid_argument(
"Cannot add a path (" + path +
") to an URN URI (" +
urn_ +
")");
86 auto last_slash =
path_.rfind(
'/');
87 path_ =
path_.substr(0, last_slash) +
'/' + path;
96 if (pointer[0] ==
'/')
97 pointer_ = json::json_pointer(pointer);
139 std::vector<std::pair<std::string, std::string>> chars = {
145 for (
const auto &c : chars) {
148 pos = l.find(c.first, pos);
149 if (pos == std::string::npos)
151 l.replace(pos, 1, c.second);
152 pos += c.second.size();