mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
utf8: add InString routines for decoding in strings
reflect: add InterfaceValue.Get(), remove Empty strconv: add Quote, CanBackquote fmt: * %q go-quoted " string * %#q go-quoted ` string if possible, " string otherwise * %x hexadecimal string * anywhere a string is okay, *[]byte is okay * flags # 0 - + space * print value inside interface, not interface itself * tests R=r DELTA=756 (597 added, 121 deleted, 38 changed) OCL=19888 CL=19916
This commit is contained in:
parent
508277debe
commit
b65a930453
14 changed files with 636 additions and 158 deletions
|
|
@ -36,14 +36,13 @@ func AddrToPtrString(Addr) *string
|
|||
func AddrToPtrBool(Addr) *bool
|
||||
func AddrToPtrRuntimeArray(Addr) *RuntimeArray
|
||||
func PtrRuntimeArrayToAddr(*RuntimeArray) Addr
|
||||
|
||||
export type Empty interface {} // TODO(r): Delete when no longer needed?
|
||||
func AddrToPtrInterface(Addr) *interface{}
|
||||
|
||||
export type Value interface {
|
||||
Kind() int;
|
||||
Type() Type;
|
||||
Addr() Addr;
|
||||
Interface() Empty;
|
||||
Interface() interface {};
|
||||
}
|
||||
|
||||
// Common fields and functionality for all values
|
||||
|
|
@ -66,7 +65,7 @@ func (c *Common) Addr() Addr {
|
|||
return c.addr
|
||||
}
|
||||
|
||||
func (c *Common) Interface() Empty {
|
||||
func (c *Common) Interface() interface {} {
|
||||
return sys.unreflect(*AddrToPtrAddr(c.addr), c.typ.String());
|
||||
}
|
||||
|
||||
|
|
@ -714,12 +713,17 @@ func StructCreator(typ Type, addr Addr) Value {
|
|||
export type InterfaceValue interface {
|
||||
Kind() int;
|
||||
Type() Type;
|
||||
Get() interface {};
|
||||
}
|
||||
|
||||
type InterfaceValueStruct struct {
|
||||
Common
|
||||
}
|
||||
|
||||
func (v *InterfaceValueStruct) Get() interface{} {
|
||||
return *AddrToPtrInterface(v.addr);
|
||||
}
|
||||
|
||||
func InterfaceCreator(typ Type, addr Addr) Value {
|
||||
return &InterfaceValueStruct{ Common{InterfaceKind, typ, addr} }
|
||||
}
|
||||
|
|
@ -824,7 +828,7 @@ export func NewOpenArrayValue(typ ArrayType, len, cap int) ArrayValue {
|
|||
return NewValueAddr(typ, PtrRuntimeArrayToAddr(array));
|
||||
}
|
||||
|
||||
export func NewValue(e Empty) Value {
|
||||
export func NewValue(e interface {}) Value {
|
||||
value, typestring := sys.reflect(e);
|
||||
p, ok := typecache[typestring];
|
||||
if !ok {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue