Move utility package 'graphdb' to pkg/graphdb

This commit is contained in:
Solomon Hykes 2013-12-23 23:33:06 +00:00
parent 81b755db9b
commit ced35db5c1
8 changed files with 1130 additions and 0 deletions

32
graphdb/utils.go Normal file
View file

@ -0,0 +1,32 @@
package graphdb
import (
"path"
"strings"
)
// Split p on /
func split(p string) []string {
return strings.Split(p, "/")
}
// Returns the depth or number of / in a given path
func PathDepth(p string) int {
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
}