summaryrefslogtreecommitdiff
path: root/vendor/github.com/goccy/go-json/internal/decoder/slice.go
diff options
context:
space:
mode:
authorLibravatar Daenney <daenney@users.noreply.github.com>2023-02-25 13:12:40 +0100
committerLibravatar GitHub <noreply@github.com>2023-02-25 12:12:40 +0000
commitecdc8379fa8f9d88faca626e7de748c2afbe4910 (patch)
tree8c20a5826db2136fc89bee45e15355c5899fa65b /vendor/github.com/goccy/go-json/internal/decoder/slice.go
parent[bugfix] Fix deleted status causing issues when getting bookmark (#1551) (diff)
downloadgotosocial-ecdc8379fa8f9d88faca626e7de748c2afbe4910.tar.xz
[chore] Update gin to v1.9.0 (#1553)
Diffstat (limited to 'vendor/github.com/goccy/go-json/internal/decoder/slice.go')
-rw-r--r--vendor/github.com/goccy/go-json/internal/decoder/slice.go79
1 files changed, 79 insertions, 0 deletions
diff --git a/vendor/github.com/goccy/go-json/internal/decoder/slice.go b/vendor/github.com/goccy/go-json/internal/decoder/slice.go
index 85b6e1119..30a23e4b5 100644
--- a/vendor/github.com/goccy/go-json/internal/decoder/slice.go
+++ b/vendor/github.com/goccy/go-json/internal/decoder/slice.go
@@ -299,3 +299,82 @@ func (d *sliceDecoder) Decode(ctx *RuntimeContext, cursor, depth int64, p unsafe
}
}
}
+
+func (d *sliceDecoder) DecodePath(ctx *RuntimeContext, cursor, depth int64) ([][]byte, int64, error) {
+ buf := ctx.Buf
+ depth++
+ if depth > maxDecodeNestingDepth {
+ return nil, 0, errors.ErrExceededMaxDepth(buf[cursor], cursor)
+ }
+
+ ret := [][]byte{}
+ for {
+ switch buf[cursor] {
+ case ' ', '\n', '\t', '\r':
+ cursor++
+ continue
+ case 'n':
+ if err := validateNull(buf, cursor); err != nil {
+ return nil, 0, err
+ }
+ cursor += 4
+ return [][]byte{nullbytes}, cursor, nil
+ case '[':
+ cursor++
+ cursor = skipWhiteSpace(buf, cursor)
+ if buf[cursor] == ']' {
+ cursor++
+ return ret, cursor, nil
+ }
+ idx := 0
+ for {
+ child, found, err := ctx.Option.Path.node.Index(idx)
+ if err != nil {
+ return nil, 0, err
+ }
+ if found {
+ if child != nil {
+ oldPath := ctx.Option.Path.node
+ ctx.Option.Path.node = child
+ paths, c, err := d.valueDecoder.DecodePath(ctx, cursor, depth)
+ if err != nil {
+ return nil, 0, err
+ }
+ ctx.Option.Path.node = oldPath
+ ret = append(ret, paths...)
+ cursor = c
+ } else {
+ start := cursor
+ end, err := skipValue(buf, cursor, depth)
+ if err != nil {
+ return nil, 0, err
+ }
+ ret = append(ret, buf[start:end])
+ cursor = end
+ }
+ } else {
+ c, err := skipValue(buf, cursor, depth)
+ if err != nil {
+ return nil, 0, err
+ }
+ cursor = c
+ }
+ cursor = skipWhiteSpace(buf, cursor)
+ switch buf[cursor] {
+ case ']':
+ cursor++
+ return ret, cursor, nil
+ case ',':
+ idx++
+ default:
+ return nil, 0, errors.ErrInvalidCharacter(buf[cursor], "slice", cursor)
+ }
+ cursor++
+ }
+ case '-', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9':
+ return nil, 0, d.errNumber(cursor)
+ default:
+ return nil, 0, errors.ErrUnexpectedEndOfJSON("slice", cursor)
+ }
+ }
+}