mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
path: make Join variadic
R=rsc, r CC=golang-dev https://golang.org/cl/198049
This commit is contained in:
parent
0e47c75f60
commit
bc43cc3db0
2 changed files with 34 additions and 16 deletions
|
|
@ -115,13 +115,15 @@ func Split(path string) (dir, file string) {
|
|||
return "", path
|
||||
}
|
||||
|
||||
// Join joins dir and file into a single path, adding a separating
|
||||
// slash if necessary. If dir is empty, it returns file.
|
||||
func Join(dir, file string) string {
|
||||
if dir == "" {
|
||||
return file
|
||||
// Join joins any number of path elemets into a single path, adding a
|
||||
// separating slash if necessary. All empty strings are ignored.
|
||||
func Join(elem ...string) string {
|
||||
for i, e := range elem {
|
||||
if e != "" {
|
||||
return Clean(strings.Join(elem[i:], "/"))
|
||||
}
|
||||
}
|
||||
return Clean(dir + "/" + file)
|
||||
return ""
|
||||
}
|
||||
|
||||
// Ext returns the file name extension used by path.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue