From 04b08da9af0c450d645ab7389d1467308cfc2db8 Mon Sep 17 00:00:00 2001 From: Michael Stapelberg Date: Mon, 4 Mar 2013 21:27:36 +0100 Subject: Imported Upstream version 1.1~hg20130304 --- src/cmd/godoc/dirtrees.go | 23 +++++++---------------- 1 file changed, 7 insertions(+), 16 deletions(-) (limited to 'src/cmd/godoc/dirtrees.go') diff --git a/src/cmd/godoc/dirtrees.go b/src/cmd/godoc/dirtrees.go index b9b529f87..fda7adce5 100644 --- a/src/cmd/godoc/dirtrees.go +++ b/src/cmd/godoc/dirtrees.go @@ -74,7 +74,7 @@ func (b *treeBuilder) newDirTree(fset *token.FileSet, path, name string, depth i // determine number of subdirectories and if there are package files ndirs := 0 hasPkgFiles := false - var synopses [4]string // prioritized package documentation (0 == highest priority) + var synopses [3]string // prioritized package documentation (0 == highest priority) for _, d := range list { switch { case isPkgDir(d): @@ -95,12 +95,10 @@ func (b *treeBuilder) newDirTree(fset *token.FileSet, path, name string, depth i switch file.Name.Name { case name: i = 0 // normal case: directory name matches package name - case fakePkgName: - i = 1 // synopses for commands case "main": - i = 2 // directory contains a main package + i = 1 // directory contains a main package default: - i = 3 // none of the above + i = 2 // none of the above } if 0 <= i && i < len(synopses) && synopses[i] == "" { synopses[i] = doc.Synopsis(file.Doc.Text()) @@ -229,9 +227,7 @@ func (dir *Directory) lookupLocal(name string) *Directory { } func splitPath(p string) []string { - if strings.HasPrefix(p, "/") { - p = p[1:] - } + p = strings.TrimPrefix(p, "/") if p == "" { return nil } @@ -264,7 +260,7 @@ type DirEntry struct { Height int // = DirList.MaxHeight - Depth, > 0 Path string // directory path; includes Name, relative to DirList root Name string // directory name - HasPkg bool // true if the directory contains at least one package + HasPkg bool // true if the directory contains at least one package Synopsis string // package documentation, if any } @@ -310,14 +306,9 @@ func (root *Directory) listing(skipRoot bool) *DirList { // the path is relative to root.Path - remove the root.Path // prefix (the prefix should always be present but avoid // crashes and check) - path := d.Path - if strings.HasPrefix(d.Path, root.Path) { - path = d.Path[len(root.Path):] - } + path := strings.TrimPrefix(d.Path, root.Path) // remove leading separator if any - path must be relative - if len(path) > 0 && path[0] == '/' { - path = path[1:] - } + path = strings.TrimPrefix(path, "/") p.Path = path p.Name = d.Name p.HasPkg = d.HasPkg -- cgit v1.2.3