]> Cypherpunks repositories - gostls13.git/commitdiff
reflect: allow Len on String values.
authorRob Pike <r@golang.org>
Mon, 4 Jul 2011 01:45:31 +0000 (11:45 +1000)
committerRob Pike <r@golang.org>
Mon, 4 Jul 2011 01:45:31 +0000 (11:45 +1000)
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

src/pkg/reflect/value.go

index 889d9455bda2b4806a233a88637bbef36231653f..bfeb3267c7c3a746a075d11570a3453e3d6f6ecf 100644 (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})
 }