提交 d52572e8 编写于 作者: A Alessandro Arzilli 提交者: Derek Parker

service/api: add quotes around types when needed in prettyprint.go (#1500)

Type names need to be quoted when that expression is evaluated, by
printing them quoted the user can just copy and paste the output.
上级 b9c842b4
......@@ -5,6 +5,7 @@ import (
"fmt"
"io"
"reflect"
"strings"
)
const (
......@@ -52,7 +53,11 @@ func (v *Variable) writeTo(buf io.Writer, top, newlines, includeType bool, inden
if v.Type == "" || len(v.Children) == 0 {
fmt.Fprint(buf, "nil")
} else if v.Children[0].OnlyAddr && v.Children[0].Addr != 0 {
fmt.Fprintf(buf, "(%s)(0x%x)", v.Type, v.Children[0].Addr)
if strings.Contains(v.Type, "/") {
fmt.Fprintf(buf, "(%q)(%#x)", v.Type, v.Children[0].Addr)
} else {
fmt.Fprintf(buf, "(%s)(%#x)", v.Type, v.Children[0].Addr)
}
} else {
fmt.Fprint(buf, "*")
v.Children[0].writeTo(buf, false, newlines, includeType, indent)
......@@ -61,7 +66,7 @@ func (v *Variable) writeTo(buf io.Writer, top, newlines, includeType bool, inden
if len(v.Children) == 0 {
fmt.Fprintf(buf, "unsafe.Pointer(nil)")
} else {
fmt.Fprintf(buf, "unsafe.Pointer(0x%x)", v.Children[0].Addr)
fmt.Fprintf(buf, "unsafe.Pointer(%#x)", v.Children[0].Addr)
}
case reflect.String:
v.writeStringTo(buf)
......@@ -107,7 +112,11 @@ func (v *Variable) writeTo(buf io.Writer, top, newlines, includeType bool, inden
v.Children[0].writeTo(buf, false, newlines, !includeType, indent)
}
} else if data.OnlyAddr {
fmt.Fprintf(buf, "*(*%q)(0x%x)", v.Type, v.Addr)
if strings.Contains(v.Type, "/") {
fmt.Fprintf(buf, "*(*%q)(%#x)", v.Type, v.Addr)
} else {
fmt.Fprintf(buf, "*(*%s)(%#x)", v.Type, v.Addr)
}
} else {
v.Children[0].writeTo(buf, false, newlines, !includeType, indent)
}
......@@ -158,7 +167,11 @@ func (v *Variable) writeArrayTo(buf io.Writer, newlines, includeType bool, inden
func (v *Variable) writeStructTo(buf io.Writer, newlines, includeType bool, indent string) {
if int(v.Len) != len(v.Children) && len(v.Children) == 0 {
fmt.Fprintf(buf, "(*%s)(0x%x)", v.Type, v.Addr)
if strings.Contains(v.Type, "/") {
fmt.Fprintf(buf, "(*%q)(%#x)", v.Type, v.Addr)
} else {
fmt.Fprintf(buf, "(*%s)(%#x)", v.Type, v.Addr)
}
return
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册