From db0e3580225ef11a3a8be0de608cb56ddd4aee55 Mon Sep 17 00:00:00 2001 From: Rob Pike Date: Mon, 4 Jul 2011 11:45:31 +1000 Subject: [PATCH] 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 --- src/pkg/reflect/value.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/pkg/reflect/value.go b/src/pkg/reflect/value.go index 889d9455bd..bfeb3267c7 100644 --- a/src/pkg/reflect/value.go +++ b/src/pkg/reflect/value.go @@ -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}) }