MCPcopy Create free account
hub / github.com/blues/note / stringEncoder

Function stringEncoder

jsonxt/encode.go:591–614  ·  view source on GitHub ↗
(e *encodeState, v reflect.Value, opts encOpts)

Source from the content-addressed store, hash-verified

589)
590
591func stringEncoder(e *encodeState, v reflect.Value, opts encOpts) {
592 if v.Type() == numberType {
593 numStr := v.String()
594 // In Go1.5 the empty string encodes to "0", while this is not a valid number literal
595 // we keep compatibility so check validity after this.
596 if numStr == "" {
597 numStr = "0" // Number's zero-val
598 }
599 if !isValidNumber(numStr) {
600 e.error(fmt.Errorf("json: invalid number literal %q", numStr))
601 }
602 e.WriteString(numStr)
603 return
604 }
605 if opts.quoted {
606 sb, err := Marshal(v.String())
607 if err != nil {
608 e.error(err)
609 }
610 e.string(string(sb), opts.escapeHTML)
611 } else {
612 e.string(v.String(), opts.escapeHTML)
613 }
614}
615
616func interfaceEncoder(e *encodeState, v reflect.Value, opts encOpts) {
617 if v.IsNil() {

Callers

nothing calls this directly

Calls 5

isValidNumberFunction · 0.85
MarshalFunction · 0.85
stringMethod · 0.80
StringMethod · 0.45
errorMethod · 0.45

Tested by

no test coverage detected