From bc43cc3db0091fa697c65d0239c70abf099945e3 Mon Sep 17 00:00:00 2001 From: Stephen Weinberg Date: Fri, 5 Feb 2010 02:39:33 -0800 Subject: path: make Join variadic R=rsc, r CC=golang-dev https://golang.org/cl/198049 --- src/pkg/path/path.go | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'src/pkg/path/path.go') diff --git a/src/pkg/path/path.go b/src/pkg/path/path.go index e03f2ecf60..c45f77be55 100644 --- a/src/pkg/path/path.go +++ b/src/pkg/path/path.go @@ -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. -- cgit v1.3-5-g9baa