MCPcopy Create free account
hub / github.com/francoispqt/gojay / StringKeyNullEmpty

Method StringKeyNullEmpty

encode_string.go:164–186  ·  view source on GitHub ↗

StringKeyNullEmpty adds a string to be encoded or skips it if it is zero value. Must be used inside an object as it will encode a key

(key, v string)

Source from the content-addressed store, hash-verified

162// StringKeyNullEmpty adds a string to be encoded or skips it if it is zero value.
163// Must be used inside an object as it will encode a key
164func (enc *Encoder) StringKeyNullEmpty(key, v string) {
165 if enc.hasKeys {
166 if !enc.keyExists(key) {
167 return
168 }
169 }
170 enc.grow(len(key) + len(v) + 5)
171 r := enc.getPreviousRune()
172 if r != '{' {
173 enc.writeTwoBytes(',', '"')
174 } else {
175 enc.writeByte('"')
176 }
177 enc.writeStringEscape(key)
178 enc.writeBytes(objKey)
179 if v == "" {
180 enc.writeBytes(nullBytes)
181 return
182 }
183 enc.writeByte('"')
184 enc.writeStringEscape(v)
185 enc.writeByte('"')
186}

Callers 4

AddStringKeyNullEmptyMethod · 0.95
MarshalJSONObjectMethod · 0.80

Calls 7

keyExistsMethod · 0.95
growMethod · 0.95
getPreviousRuneMethod · 0.95
writeTwoBytesMethod · 0.95
writeByteMethod · 0.95
writeStringEscapeMethod · 0.95
writeBytesMethod · 0.95

Tested by 2

MarshalJSONObjectMethod · 0.64