| 93 | |
| 94 | template <typename CharT> |
| 95 | class basic_json_pointer |
| 96 | { |
| 97 | public: |
| 98 | // Member types |
| 99 | using char_type = CharT; |
| 100 | using string_type = std::basic_string<char_type>; |
| 101 | using string_view_type = jsoncons::basic_string_view<char_type>; |
| 102 | using const_iterator = typename std::vector<string_type>::const_iterator; |
| 103 | using iterator = const_iterator; |
| 104 | using const_reverse_iterator = typename std::vector<string_type>::const_reverse_iterator; |
| 105 | using reverse_iterator = const_reverse_iterator; |
| 106 | private: |
| 107 | std::vector<string_type> tokens_; |
| 108 | public: |
| 109 | // Constructors |
| 110 | basic_json_pointer() |
| 111 | { |
| 112 | } |
| 113 | |
| 114 | basic_json_pointer(const std::vector<string_type>& tokens) |
| 115 | : tokens_(tokens) |
| 116 | { |
| 117 | } |
| 118 | |
| 119 | basic_json_pointer(std::vector<string_type>&& tokens) |
| 120 | : tokens_(std::move(tokens)) |
| 121 | { |
| 122 | } |
| 123 | |
| 124 | explicit basic_json_pointer(const string_view_type& s) |
| 125 | { |
| 126 | std::error_code ec; |
| 127 | auto jp = parse(s, ec); |
| 128 | if (JSONCONS_UNLIKELY(ec)) |
| 129 | { |
| 130 | JSONCONS_THROW(jsonpointer_error(ec)); |
| 131 | } |
| 132 | tokens_ = std::move(jp.tokens_); |
| 133 | } |
| 134 | |
| 135 | explicit basic_json_pointer(const string_view_type& s, std::error_code& ec) |
| 136 | { |
| 137 | auto jp = parse(s, ec); |
| 138 | if (!ec) |
| 139 | { |
| 140 | tokens_ = std::move(jp.tokens_); |
| 141 | } |
| 142 | } |
| 143 | |
| 144 | basic_json_pointer(const basic_json_pointer&) = default; |
| 145 | |
| 146 | basic_json_pointer(basic_json_pointer&&) = default; |
| 147 | |
| 148 | static basic_json_pointer parse(const string_view_type& input, std::error_code& ec) |
| 149 | { |
| 150 | std::vector<string_type> tokens; |
| 151 | if (input.empty()) |
| 152 | { |