static*/
| 135 | |
| 136 | |
| 137 | /*static*/ const Value* Path::evalJSONPointer(slice specifier, const Value *root) |
| 138 | { |
| 139 | slice_istream in(specifier); |
| 140 | auto current = root; |
| 141 | throwIf(in.readByte() != '/', PathSyntaxError, "JSONPointer does not start with '/'"); |
| 142 | while (!in.eof()) { |
| 143 | if (!current) |
| 144 | return nullptr; |
| 145 | |
| 146 | auto slash = in.findByteOrEnd('/'); |
| 147 | slice_istream param(in.buf, slash); |
| 148 | |
| 149 | switch(current->type()) { |
| 150 | case kArray: { |
| 151 | auto i = param.readDecimal(); |
| 152 | if (_usuallyFalse(param.size > 0 || i > INT32_MAX)) |
| 153 | FleeceException::_throw(PathSyntaxError, "Invalid array index in JSONPointer"); |
| 154 | current = ((const Array*)current)->get((uint32_t)i); |
| 155 | break; |
| 156 | } |
| 157 | case kDict: { |
| 158 | string key = param.asString(); |
| 159 | current = ((const Dict*)current)->get(key); |
| 160 | break; |
| 161 | } |
| 162 | default: |
| 163 | current = nullptr; |
| 164 | break; |
| 165 | } |
| 166 | |
| 167 | if (slash == in.end()) |
| 168 | break; |
| 169 | in.setStart(slash+1); |
| 170 | } |
| 171 | return current; |
| 172 | } |
| 173 | |
| 174 | |
| 175 | #pragma mark - PARSING: |
nothing calls this directly
no test coverage detected