mirror of
https://github.com/golang/go
synced 2024-11-12 09:20:22 -07:00
correct meaning of "absolute" and "relative"
(implementation was swapped) R=adg CC=golang-dev, rsc https://golang.org/cl/207069
This commit is contained in:
parent
a91fa9d52e
commit
a75ebe192e
@ -141,21 +141,6 @@ func split(path string) (head, tail string) {
|
||||
// string is returned.
|
||||
//
|
||||
func (m *Mapping) ToAbsolute(path string) string {
|
||||
for _, e := range m.list {
|
||||
if strings.HasPrefix(path, e.path) {
|
||||
// /absolute/prefix/foo -> prefix/foo
|
||||
return pathutil.Join(e.prefix, path[len(e.path):]) // Join will remove a trailing '/'
|
||||
}
|
||||
}
|
||||
return "" // no match
|
||||
}
|
||||
|
||||
|
||||
// ToRelative maps an absolute path to a relative path using the Mapping
|
||||
// specified by the receiver. If the path cannot be mapped, the empty
|
||||
// string is returned.
|
||||
//
|
||||
func (m *Mapping) ToRelative(path string) string {
|
||||
prefix, tail := split(path)
|
||||
for _, e := range m.list {
|
||||
switch {
|
||||
@ -174,3 +159,18 @@ func (m *Mapping) ToRelative(path string) string {
|
||||
|
||||
return "" // no match
|
||||
}
|
||||
|
||||
|
||||
// ToRelative maps an absolute path to a relative path using the Mapping
|
||||
// specified by the receiver. If the path cannot be mapped, the empty
|
||||
// string is returned.
|
||||
//
|
||||
func (m *Mapping) ToRelative(path string) string {
|
||||
for _, e := range m.list {
|
||||
if strings.HasPrefix(path, e.path) {
|
||||
// /absolute/prefix/foo -> prefix/foo
|
||||
return pathutil.Join(e.prefix, path[len(e.path):]) // Join will remove a trailing '/'
|
||||
}
|
||||
}
|
||||
return "" // no match
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user