bytes, strings: add TrimPrefix and TrimSuffix

Everybody either gets confused and thinks this is
TrimLeft/TrimRight or does this by hand which gets
repetitive looking.

R=rsc, kevlar
CC=golang-dev
https://golang.org/cl/7239044
This commit is contained in:
Brad Fitzpatrick 2013-02-01 08:41:25 -08:00
parent fe14ee52cc
commit e515d80d5d
21 changed files with 117 additions and 54 deletions

View file

@ -1542,8 +1542,8 @@ func godefsFields(fld []*ast.Field) {
npad := 0
for _, f := range fld {
for _, n := range f.Names {
if strings.HasPrefix(n.Name, prefix) && n.Name != prefix {
n.Name = n.Name[len(prefix):]
if n.Name != prefix {
n.Name = strings.TrimPrefix(n.Name, prefix)
}
if n.Name == "_" {
// Use exported name instead.