MCPcopy Create free account
hub / github.com/cockroachdb/cockroachdb-parser / Format

Method Format

pkg/util/json/json.go:810–828  ·  view source on GitHub ↗
(buf *bytes.Buffer)

Source from the content-addressed store, hash-verified

808func (jsonTrue) Format(buf *bytes.Buffer) { buf.WriteString("true") }
809
810func (j jsonNumber) Format(buf *bytes.Buffer) {
811 dec := apd.Decimal(j)
812 // Make sure non-finite values are encoded as valid strings by
813 // quoting them. Unfortunately, since this is JSON, there's no
814 // defined way to express the three special numeric values (+inf,
815 // -inf, nan) except as a string. This means that the decoding
816 // side can't tell whether the field should be a float or a
817 // string. Testing for exact types is thus tricky. As of this
818 // comment, our current tests for this behavior happen it the SQL
819 // package, not here in the JSON package.
820 nonfinite := dec.Form != apd.Finite
821 if nonfinite {
822 buf.WriteByte('"')
823 }
824 buf.WriteString(dec.String())
825 if nonfinite {
826 buf.WriteByte('"')
827 }
828}
829
830func (j jsonString) Format(buf *bytes.Buffer) {
831 encodeJSONString(buf, string(j))

Callers 1

formatEncodedJSONValueFunction · 0.95

Calls 2

DecimalMethod · 0.65
StringMethod · 0.65

Tested by

no test coverage detected