summaryrefslogtreecommitdiff
path: root/src/cmd/godoc/dirtrees.go
diff options
context:
space:
mode:
authorMichael Stapelberg <stapelberg@debian.org>2013-03-04 21:27:36 +0100
committerMichael Stapelberg <michael@stapelberg.de>2013-03-04 21:27:36 +0100
commit04b08da9af0c450d645ab7389d1467308cfc2db8 (patch)
treedb247935fa4f2f94408edc3acd5d0d4f997aa0d8 /src/cmd/godoc/dirtrees.go
parent917c5fb8ec48e22459d77e3849e6d388f93d3260 (diff)
downloadgolang-upstream/1.1_hg20130304.tar.gz
Imported Upstream version 1.1~hg20130304upstream/1.1_hg20130304
Diffstat (limited to 'src/cmd/godoc/dirtrees.go')
-rw-r--r--src/cmd/godoc/dirtrees.go23
1 files changed, 7 insertions, 16 deletions
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