1
0
mirror of https://github.com/golang/go synced 2024-11-19 14:34:42 -07:00

reflect: allow Len on String values.

It's probably just an oversight that it doesn't work,
perhaps caused by analogy with Cap.

R=golang-dev, dsymonds
CC=golang-dev
https://golang.org/cl/4634125
This commit is contained in:
Rob Pike 2011-07-04 11:45:31 +10:00
parent 8c7a73bbbb
commit db0e358022

View File

@ -933,7 +933,7 @@ func (v Value) Kind() Kind {
}
// Len returns v's length.
// It panics if v's Kind is not Array, Chan, Map, or Slice.
// It panics if v's Kind is not Array, Chan, Map, Slice, or String.
func (v Value) Len() int {
iv := v.internal()
switch iv.kind {
@ -945,6 +945,8 @@ func (v Value) Len() int {
return int(maplen(iv.word))
case Slice:
return (*SliceHeader)(iv.addr).Len
case String:
return (*StringHeader)(iv.addr).Len
}
panic(&ValueError{"reflect.Value.Len", iv.kind})
}