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

Function calcAllocateSpace

parser.go:837–877  ·  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

835
836// SYS-REQ-009, SYS-REQ-111
837func calcAllocateSpace(keys []string, setValue []byte, comma, object bool) int {
838 // guard: empty key component — not an array index.
839 isIndex := len(keys[0]) > 0 && string(keys[0][0]) == "["
840 lk := 0
841 if comma {
842 // ,
843 lk += 1
844 }
845 if isIndex && !comma {
846 // []
847 lk += 2
848 } else {
849 if object {
850 // {
851 lk += 1
852 }
853 if !isIndex {
854 // "keys[0]"
855 lk += len(keys[0]) + 3
856 }
857 }
858
859 lk += len(setValue)
860 for i := 1; i < len(keys); i++ {
861 // guard: empty key component — treat as object key, not array index.
862 if len(keys[i]) > 0 && string(keys[i][0]) == "[" {
863 // []
864 lk += 2
865 } else {
866 // {"keys[i]":setValue}
867 lk += len(keys[i]) + 5
868 }
869 }
870
871 if object && !isIndex {
872 // }
873 lk += 1
874 }
875
876 return lk
877}
878
879// SYS-REQ-009
880func WriteToBuffer(buffer []byte, str string) int {

Callers 3

createInsertComponentFunction · 0.85

Calls

no outgoing calls

Tested by 2