-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathint.go
34 lines (29 loc) · 853 Bytes
/
int.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package pretty
import (
"reflect"
"github.com/pierrre/go-libs/strconvio"
"github.com/pierrre/pretty/internal"
)
// IntValueWriter is a [ValueWriter] that handles int values.
//
// It should be created with [NewIntValueWriter].
type IntValueWriter struct {
// Base is the base used to format the integer.
// Default: 10.
Base int
}
// NewIntValueWriter creates a new [IntValueWriter] with default values.
func NewIntValueWriter() *IntValueWriter {
return &IntValueWriter{
Base: 10,
}
}
// WriteValue implements [ValueWriter].
func (vw *IntValueWriter) WriteValue(st *State, v reflect.Value) bool {
switch v.Kind() { //nolint:exhaustive // Only handles int.
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
internal.MustWrite(strconvio.WriteInt(st.Writer, v.Int(), vw.Base))
return true
}
return false
}