mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
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
This commit is contained in:
parent
555feea117
commit
b06dc26a58
5 changed files with 55 additions and 8 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue