MCPcopy Create free account
hub / github.com/couchbase/fleece / evalJSONPointer

Method evalJSONPointer

Fleece/Core/Path.cc:137–172  ·  view source on GitHub ↗

static*/

Source from the content-addressed store, hash-verified

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:

Callers

nothing calls this directly

Calls 9

readByteMethod · 0.80
eofMethod · 0.80
findByteOrEndMethod · 0.80
readDecimalMethod · 0.80
setStartMethod · 0.80
typeMethod · 0.45
getMethod · 0.45
asStringMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected