MCPcopy Create free account
hub / github.com/buger/jsonparser / calcAllocateSpace

Function calcAllocateSpace

parser.go:817–857  ·  view source on GitHub ↗

SYS-REQ-009, SYS-REQ-111

(keys []string, setValue []byte, comma, object bool)

Source from the content-addressed store, hash-verified

815
816// SYS-REQ-009, SYS-REQ-111
817func calcAllocateSpace(keys []string, setValue []byte, comma, object bool) int {
818 // guard: empty key component — not an array index.
819 isIndex := len(keys[0]) > 0 && string(keys[0][0]) == "["
820 lk := 0
821 if comma {
822 // ,
823 lk += 1
824 }
825 if isIndex && !comma {
826 // []
827 lk += 2
828 } else {
829 if object {
830 // {
831 lk += 1
832 }
833 if !isIndex {
834 // "keys[0]"
835 lk += len(keys[0]) + 3
836 }
837 }
838
839 lk += len(setValue)
840 for i := 1; i < len(keys); i++ {
841 // guard: empty key component — treat as object key, not array index.
842 if len(keys[i]) > 0 && string(keys[i][0]) == "[" {
843 // []
844 lk += 2
845 } else {
846 // {"keys[i]":setValue}
847 lk += len(keys[i]) + 5
848 }
849 }
850
851 if object && !isIndex {
852 // }
853 lk += 1
854 }
855
856 return lk
857}
858
859// SYS-REQ-009
860func WriteToBuffer(buffer []byte, str string) int {

Callers 3

createInsertComponentFunction · 0.85

Calls

no outgoing calls

Tested by 2