@@ -27,7 +27,6 @@ package attributes
2727
2828import (
2929 "fmt"
30- "reflect"
3130 "strings"
3231)
3332
@@ -128,54 +127,7 @@ func str(x any) (s string) {
128127 } else if v , ok := x .(string ); ok {
129128 return v
130129 }
131- value := reflect .ValueOf (x )
132- switch value .Kind () {
133- case reflect .Chan , reflect .Func , reflect .Map , reflect .Pointer , reflect .Slice , reflect .UnsafePointer :
134- return fmt .Sprintf ("<%p>" , x )
135- default :
136- // This will call badVerb to print as "<%p>", but without leading "%!(" and tailing ")"
137- return badVerb (x , value )
138- }
139- }
140-
141- const nilAngleString = "<nil>"
142-
143- // badVerb is like fmt.Sprintf("%p", arg), but with
144- // leading "%!verb(" replaced by "<" and tailing ")" replaced by ">".
145- // If an invalid argument is given for a '%p', such as providing
146- // an int to %p, the generated string will contain a
147- // description of the problem, as in these examples:
148- //
149- // # our style
150- //
151- // Wrong type or unknown verb: <type=value>
152- // Printf("%p", 1): <int=1>
153- //
154- // # fmt style as `fmt.Sprintf("%p", arg)`
155- //
156- // Wrong type or unknown verb: %!verb(type=value)
157- // Printf("%p", 1): %!d(int=1)
158- //
159- // Adapted from the code in fmt/print.go.
160- func badVerb (arg any , value reflect.Value ) string {
161- var buf strings.Builder
162- switch {
163- case arg != nil :
164- buf .WriteByte ('<' )
165- buf .WriteString (reflect .TypeOf (arg ).String ())
166- buf .WriteByte ('=' )
167- _ , _ = fmt .Fprintf (& buf , "%v" , arg )
168- buf .WriteByte ('>' )
169- case value .IsValid ():
170- buf .WriteByte ('<' )
171- buf .WriteString (value .Type ().String ())
172- buf .WriteByte ('=' )
173- _ , _ = fmt .Fprintf (& buf , "%v" , 0 )
174- buf .WriteByte ('>' )
175- default :
176- buf .WriteString (nilAngleString )
177- }
178- return buf .String ()
130+ return fmt .Sprintf ("%#v" , x )
179131}
180132
181133// MarshalJSON helps implement the json.Marshaler interface, thereby rendering
0 commit comments