Commit db0e3580 authored by Rob Pike's avatar Rob Pike

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
parent 8c7a73bb
......@@ -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})
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment