aboutsummaryrefslogtreecommitdiff
path: root/src/pkg/path/path.go
diff options
context:
space:
mode:
authorBenny Siegert <bsiegert@gmail.com>2010-11-30 17:17:45 -0800
committerRob Pike <r@golang.org>2010-11-30 17:17:45 -0800
commitb06dc26a58df0a79e6be3004484809ffd2c60d74 (patch)
treead513997489aa9d89cf5442e2eb9b409bafd84ad /src/pkg/path/path.go
parent555feea117532a5c033478997e1ce9b77b4f8eea (diff)
downloadgo-b06dc26a58df0a79e6be3004484809ffd2c60d74.tar.xz
path: Windows support for Split
Make Split work on backslashes as well as on slashes under Windows and support the "C:filename" special case. Also add corresponding tests. R=r, rsc, PeterGo, r2, brainman CC=golang-dev https://golang.org/cl/3008041
Diffstat (limited to 'src/pkg/path/path.go')
-rw-r--r--src/pkg/path/path.go12
1 files changed, 4 insertions, 8 deletions
diff --git a/src/pkg/path/path.go b/src/pkg/path/path.go
index 79b3000930..61eea88588 100644
--- a/src/pkg/path/path.go
+++ b/src/pkg/path/path.go
@@ -102,17 +102,13 @@ func Clean(path string) string {
return string(buf[0:w])
}
-// Split splits path immediately following the final slash,
+// Split splits path immediately following the final path separator,
// separating it into a directory and file name component.
-// If there is no slash in path, Split returns an empty dir and
+// If there is no separator in path, Split returns an empty dir and
// file set to path.
func Split(path string) (dir, file string) {
- for i := len(path) - 1; i >= 0; i-- {
- if path[i] == '/' {
- return path[0 : i+1], path[i+1:]
- }
- }
- return "", path
+ i := strings.LastIndexAny(path, PathSeps)
+ return path[:i+1], path[i+1:]
}
// Join joins any number of path elements into a single path, adding a