-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpprint.go
83 lines (72 loc) · 1.79 KB
/
pprint.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package pprint
import (
"io"
"reflect"
)
var defaultDispatchMap = make(DispatchMap)
var builtinScalars []any
func PPrint(
object any,
stream io.Writer,
indent, width, depth int,
compact, sortMaps, underscoreNumbers bool,
) {
printer, error := NewPrettyPrinter(stream, indent, width, depth, compact, sortMaps, underscoreNumbers)
if error != nil {
panic(error)
}
printer.PPrint(object)
}
func PFormat(
object any,
stream io.Writer,
indent, width, depth int,
compact, sortMaps, underscoreNumbers bool,
) string {
printer, error := NewPrettyPrinter(stream, indent, width, depth, compact, sortMaps, underscoreNumbers)
if error != nil {
panic(error)
}
return printer.PFormat(object)
}
func PP(
object any,
stream io.Writer,
indent, width, depth int,
compact, sortMaps, underscoreNumbers bool,
) {
PPrint(object, stream, indent, width, depth, compact, sortMaps, underscoreNumbers)
}
func SafeRepr(object any) any {
str, _, _ := PrettyPrinter{}.safeRepr(object, Context{}, 0, 0)
return str
}
func IsReadable(object any) any {
_, readable, _ := PrettyPrinter{}.safeRepr(object, Context{}, 0, 0)
return readable
}
func IsRecurcive(object any) any {
_, _, recursive := PrettyPrinter{}.safeRepr(object, Context{}, 0, 0)
return recursive
}
func init() {
defaultDispatchMap[reflect.Map] = PrettyPrinter.pprintMap
defaultDispatchMap[reflect.Slice] = PrettyPrinter.pprintSlice
defaultDispatchMap[reflect.Struct] = PrettyPrinter.pprintStruct
defaultDispatchMap[reflect.Pointer] = PrettyPrinter.pprintPointer
builtinScalars = []any{
getType[bool](),
getType[int](),
getType[int8](),
getType[int16](),
getType[int32](),
getType[int64](),
getType[float32](),
getType[float64](),
getType[complex64](),
getType[complex128](),
getType[string](),
getType[rune](),
getType[byte](),
}
}