MCPcopy
hub / github.com/tidwall/sjson / appendRawPaths

Function appendRawPaths

sjson.go:250–405  ·  view source on GitHub ↗
(buf []byte, jstr string, paths []pathResult, raw string,
	stringify, del bool)

Source from the content-addressed store, hash-verified

248var errNoChange = &errorType{"no change"}
249
250func appendRawPaths(buf []byte, jstr string, paths []pathResult, raw string,
251 stringify, del bool) ([]byte, error) {
252 var err error
253 var res gjson.Result
254 var found bool
255 if del {
256 if paths[0].part == "-1" && !paths[0].force {
257 res = gjson.Get(jstr, "#")
258 if res.Int() > 0 {
259 res = gjson.Get(jstr, strconv.FormatInt(int64(res.Int()-1), 10))
260 found = true
261 }
262 }
263 }
264 if !found {
265 res = gjson.Get(jstr, paths[0].gpart)
266 }
267 if res.Index > 0 {
268 if len(paths) > 1 {
269 buf = append(buf, jstr[:res.Index]...)
270 buf, err = appendRawPaths(buf, res.Raw, paths[1:], raw,
271 stringify, del)
272 if err != nil {
273 return nil, err
274 }
275 buf = append(buf, jstr[res.Index+len(res.Raw):]...)
276 return buf, nil
277 }
278 buf = append(buf, jstr[:res.Index]...)
279 var exidx int // additional forward stripping
280 if del {
281 var delNextComma bool
282 buf, delNextComma = deleteTailItem(buf)
283 if delNextComma {
284 i, j := res.Index+len(res.Raw), 0
285 for ; i < len(jstr); i, j = i+1, j+1 {
286 if jstr[i] <= ' ' {
287 continue
288 }
289 if jstr[i] == ',' {
290 exidx = j + 1
291 }
292 break
293 }
294 }
295 } else {
296 if stringify {
297 buf = appendStringify(buf, raw)
298 } else {
299 buf = append(buf, raw...)
300 }
301 }
302 buf = append(buf, jstr[res.Index+len(res.Raw)+exidx:]...)
303 return buf, nil
304 }
305 if del {
306 return nil, errNoChange
307 }

Callers 1

setFunction · 0.85

Calls 6

deleteTailItemFunction · 0.85
appendStringifyFunction · 0.85
atouiFunction · 0.85
appendBuildFunction · 0.85
trimFunction · 0.85
appendRepeatFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…