-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpath.go
More file actions
38 lines (35 loc) · 695 Bytes
/
path.go
File metadata and controls
38 lines (35 loc) · 695 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package quicktar
func BaseName(path string) string {
lastSlash := -1
for i, c := range path {
if c == '/' {
lastSlash = i
}
}
if lastSlash == -1 {
return path
}
return path[lastSlash+1:]
}
func Split(path string) []string {
list := []string{}
lastSlash := 0
for i, c := range path {
if c == '/' {
list = append(list, path[lastSlash:i])
lastSlash = i + 1
}
}
return append(list, path[lastSlash:])
}
// Parents returns all parent levels of path.
// The returned array doesn't contain root ("") or path itself.
func Parents(path string) []string {
list := []string{}
for i, c := range path {
if c == '/' {
list = append(list, path[:i])
}
}
return list
}