2013-11-15 18:55:45 -05:00
|
|
|
package graphdb
|
2013-10-04 22:25:15 -04:00
|
|
|
|
|
|
|
import (
|
|
|
|
"path"
|
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Split p on /
|
|
|
|
func split(p string) []string {
|
|
|
|
return strings.Split(p, "/")
|
|
|
|
}
|
|
|
|
|
2015-06-16 05:51:27 -04:00
|
|
|
// PathDepth returns the depth or number of / in a given path
|
2013-10-24 19:49:28 -04:00
|
|
|
func PathDepth(p string) int {
|
2013-10-04 22:25:15 -04:00
|
|
|
parts := split(p)
|
|
|
|
if len(parts) == 2 && parts[1] == "" {
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
return len(parts)
|
|
|
|
}
|
|
|
|
|
|
|
|
func splitPath(p string) (parent, name string) {
|
|
|
|
if p[0] != '/' {
|
|
|
|
p = "/" + p
|
|
|
|
}
|
|
|
|
parent, name = path.Split(p)
|
|
|
|
l := len(parent)
|
|
|
|
if parent[l-1] == '/' {
|
|
|
|
parent = parent[:l-1]
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|