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

Method StringNullEmpty

encode_string.go:98–116  ·  view source on GitHub ↗

StringNullEmpty adds a string to be encoded or skips it if it is zero value. Must be used inside a slice or array encoding (does not encode a key)

(v string)

Source from the content-addressed store, hash-verified

96// StringNullEmpty adds a string to be encoded or skips it if it is zero value.
97// Must be used inside a slice or array encoding (does not encode a key)
98func (enc *Encoder) StringNullEmpty(v string) {
99 r := enc.getPreviousRune()
100 if v == "" {
101 if r != '[' {
102 enc.writeByte(',')
103 enc.writeBytes(nullBytes)
104 } else {
105 enc.writeBytes(nullBytes)
106 }
107 return
108 }
109 if r != '[' {
110 enc.writeTwoBytes(',', '"')
111 } else {
112 enc.writeByte('"')
113 }
114 enc.writeStringEscape(v)
115 enc.writeByte('"')
116}
117
118// StringKey adds a string to be encoded, must be used inside an object as it will encode a key
119func (enc *Encoder) StringKey(key, v string) {

Callers 5

AddStringNullEmptyMethod · 0.95

Calls 5

getPreviousRuneMethod · 0.95
writeByteMethod · 0.95
writeBytesMethod · 0.95
writeTwoBytesMethod · 0.95
writeStringEscapeMethod · 0.95

Tested by 2