summaryrefslogtreecommitdiff
path: root/src/cmd/godoc/mapping.go
diff options
context:
space:
mode:
authorOndřej Surý <ondrej@sury.org>2012-01-30 15:38:19 +0100
committerOndřej Surý <ondrej@sury.org>2012-01-30 15:38:19 +0100
commit4cecda6c347bd6902b960c6a35a967add7070b0d (patch)
treea462e224ff41ec9f3eb1a0b6e815806f9e8804ad /src/cmd/godoc/mapping.go
parent6c7ca6e4d4e26e4c8cbe0d183966011b3b088a0a (diff)
downloadgolang-4cecda6c347bd6902b960c6a35a967add7070b0d.tar.gz
Imported Upstream version 2012.01.27upstream-weekly/2012.01.27
Diffstat (limited to 'src/cmd/godoc/mapping.go')
-rw-r--r--src/cmd/godoc/mapping.go29
1 files changed, 14 insertions, 15 deletions
diff --git a/src/cmd/godoc/mapping.go b/src/cmd/godoc/mapping.go
index 51f23ab98..89e531e2f 100644
--- a/src/cmd/godoc/mapping.go
+++ b/src/cmd/godoc/mapping.go
@@ -139,13 +139,18 @@ func (m *Mapping) Fprint(w io.Writer) {
}
}
+// splitFirst splits a path at the first path separator and returns
+// the path's head (the top-most directory specified by the path) and
+// its tail (the rest of the path). If there is no path separator,
+// splitFirst returns path as head, and the the empty string as tail.
+// Specifically, splitFirst("foo") == splitFirst("foo/").
+//
func splitFirst(path string) (head, tail string) {
- i := strings.Index(path, string(filepath.Separator))
- if i > 0 {
+ if i := strings.Index(path, string(filepath.Separator)); i > 0 {
// 0 < i < len(path)
return path[0:i], path[i+1:]
}
- return "", path
+ return path, ""
}
// ToAbsolute maps a slash-separated relative path to an absolute filesystem
@@ -156,20 +161,14 @@ func (m *Mapping) ToAbsolute(spath string) string {
fpath := filepath.FromSlash(spath)
prefix, tail := splitFirst(fpath)
for _, e := range m.list {
- switch {
- case e.prefix == prefix:
- // use tail
- case e.prefix == "":
- tail = fpath
- default:
- continue // no match
- }
- abspath := filepath.Join(e.path, tail)
- if _, err := fs.Stat(abspath); err == nil {
- return abspath
+ if e.prefix == prefix {
+ // found potential mapping
+ abspath := filepath.Join(e.path, tail)
+ if _, err := fs.Stat(abspath); err == nil {
+ return abspath
+ }
}
}
-
return "" // no match
}