(e *encodeState, v reflect.Value, opts encOpts)
| 589 | ) |
| 590 | |
| 591 | func 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 | |
| 616 | func interfaceEncoder(e *encodeState, v reflect.Value, opts encOpts) { |
| 617 | if v.IsNil() { |
nothing calls this directly
no test coverage detected