feat: add Decoder.UseNumber and the Number type
Test / test (push) Successful in 1m52s

Assisted-by: GLM 5.3 Flash
This commit is contained in:
2026-09-21 23:49:39 +02:00
parent 582222738b
commit ce0c1ebd9d
9 changed files with 320 additions and 4 deletions
+11
View File
@@ -750,6 +750,11 @@ func normaliseValue(v reflect.Value) (any, error) {
if v.Type() == durationType {
return time.Duration(v.Int()).String(), nil
}
// A Number goes out as the literal it carries, the one string-kind value
// that is not written quoted.
if v.Type() == numberType {
return Number(v.String()), nil
}
// A type that renders itself as text becomes a TOML string, scalar kinds
// and structs alike.
s, isText, err := textValue(v)
@@ -1171,6 +1176,12 @@ func (e *encoder) writeValue(val any) error {
case int64:
e.buf.WriteString(strconv.FormatInt(v, 10))
return nil
case Number:
if _, err := decodeNumber(string(v)); err != nil {
return fmt.Errorf("interpres: %w", err)
}
e.buf.WriteString(string(v))
return nil
case float64:
return e.writeFloat(v)
case time.Time: