Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
go
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
go
Commits
bc43cc3d
Commit
bc43cc3d
authored
Feb 05, 2010
by
Stephen Weinberg
Committed by
Russ Cox
Feb 05, 2010
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
path: make Join variadic
R=rsc, r CC=golang-dev
https://golang.org/cl/198049
parent
0e47c75f
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
34 additions
and
16 deletions
+34
-16
src/pkg/path/path.go
src/pkg/path/path.go
+8
-6
src/pkg/path/path_test.go
src/pkg/path/path_test.go
+26
-10
No files found.
src/pkg/path/path.go
View file @
bc43cc3d
...
@@ -115,13 +115,15 @@ func Split(path string) (dir, file string) {
...
@@ -115,13 +115,15 @@ func Split(path string) (dir, file string) {
return
""
,
path
return
""
,
path
}
}
// Join joins dir and file into a single path, adding a separating
// Join joins any number of path elemets into a single path, adding a
// slash if necessary. If dir is empty, it returns file.
// separating slash if necessary. All empty strings are ignored.
func
Join
(
dir
,
file
string
)
string
{
func
Join
(
elem
...
string
)
string
{
if
dir
==
""
{
for
i
,
e
:=
range
elem
{
return
file
if
e
!=
""
{
return
Clean
(
strings
.
Join
(
elem
[
i
:
],
"/"
))
}
}
}
return
Clean
(
dir
+
"/"
+
file
)
return
""
}
}
// Ext returns the file name extension used by path.
// Ext returns the file name extension used by path.
...
...
src/pkg/path/path_test.go
View file @
bc43cc3d
...
@@ -92,23 +92,39 @@ func TestSplit(t *testing.T) {
...
@@ -92,23 +92,39 @@ func TestSplit(t *testing.T) {
}
}
type
JoinTest
struct
{
type
JoinTest
struct
{
dir
,
file
,
path
string
elem
[]
string
path
string
}
}
var
jointests
=
[]
JoinTest
{
var
jointests
=
[]
JoinTest
{
JoinTest
{
"a"
,
"b"
,
"a/b"
},
// zero parameters
JoinTest
{
"a"
,
""
,
"a"
},
JoinTest
{[]
string
{},
""
},
JoinTest
{
""
,
"b"
,
"b"
},
JoinTest
{
"/"
,
"a"
,
"/a"
},
// one parameter
JoinTest
{
"/"
,
""
,
"/"
},
JoinTest
{[]
string
{
""
},
""
},
JoinTest
{
"a/"
,
"b"
,
"a/b"
},
JoinTest
{[]
string
{
"a"
},
"a"
},
JoinTest
{
"a/"
,
""
,
"a"
},
// two parameters
JoinTest
{[]
string
{
"a"
,
"b"
},
"a/b"
},
JoinTest
{[]
string
{
"a"
,
""
},
"a"
},
JoinTest
{[]
string
{
""
,
"b"
},
"b"
},
JoinTest
{[]
string
{
"/"
,
"a"
},
"/a"
},
JoinTest
{[]
string
{
"/"
,
""
},
"/"
},
JoinTest
{[]
string
{
"a/"
,
"b"
},
"a/b"
},
JoinTest
{[]
string
{
"a/"
,
""
},
"a"
},
JoinTest
{[]
string
{
""
,
""
},
""
},
}
// join takes a []string and passes it to Join.
func
join
(
elem
[]
string
,
args
...
string
)
string
{
args
=
elem
return
Join
(
args
)
}
}
func
TestJoin
(
t
*
testing
.
T
)
{
func
TestJoin
(
t
*
testing
.
T
)
{
for
_
,
test
:=
range
jointests
{
for
_
,
test
:=
range
jointests
{
if
p
:=
Join
(
test
.
dir
,
test
.
file
);
p
!=
test
.
path
{
if
p
:=
join
(
test
.
elem
);
p
!=
test
.
path
{
t
.
Errorf
(
"
Join(%q, %q) = %q, want %q"
,
test
.
dir
,
test
.
file
,
p
,
test
.
path
)
t
.
Errorf
(
"
join(%q) = %q, want %q"
,
test
.
elem
,
p
,
test
.
path
)
}
}
}
}
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment