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

Method StringOmitEmpty

encode_string.go:82–94  ·  view source on GitHub ↗

StringOmitEmpty 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

80// StringOmitEmpty adds a string to be encoded or skips it if it is zero value.
81// Must be used inside a slice or array encoding (does not encode a key)
82func (enc *Encoder) StringOmitEmpty(v string) {
83 if v == "" {
84 return
85 }
86 r := enc.getPreviousRune()
87 if r != '[' {
88 enc.writeTwoBytes(',', '"')
89 } else {
90 enc.writeByte('"')
91 }
92 enc.writeStringEscape(v)
93 enc.writeByte('"')
94}
95
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)

Callers 2

AddStringOmitEmptyMethod · 0.95

Calls 4

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

Tested by

no test coverage detected