6 Star 17 Fork 4

GiteeStudio / gitee

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
pathnode.go 933 Bytes
一键复制 编辑 原始数据 按行查看 历史
SURA 提交于 2022-06-08 14:42 . support multi-level PathNode
package gitee
import (
"strings"
)
const baseSuffix = ".git"
func filterPathNode(pv ...string) string {
var sb strings.Builder
var size int
for _, v := range pv[:len(pv)-1] {
if !IsPathReachable(v) {
return ""
}
size += len(v) + 1
}
path := strings.TrimSuffix(pv[len(pv)-1], baseSuffix)
size += len(path)
sb.Grow(size)
for _, v := range pv[:len(pv)-1] {
sb.WriteString(v)
sb.WriteString("/")
}
sb.WriteString(path)
return sb.String()
}
// IsPathReachable path reachable
func IsPathReachable(s string) bool {
return s != "." && s != ".."
}
// PathNodeCanonicalizeStrict todo
func PathNodeCanonicalizeStrict(u string) string {
pvv := StrSplitSkipEmpty(u, '/', 64)
if len(pvv) < 2 {
return ""
}
return filterPathNode(pvv...)
}
// PathNodeCanonicalize todo
func PathNodeCanonicalize(u string) string {
pv := PathSplit(u, 64)
if len(pv) < 2 {
return ""
}
return filterPathNode(pv...)
}
Go
1
https://gitee.com/oscstudio/gitee.git
git@gitee.com:oscstudio/gitee.git
oscstudio
gitee
gitee
v0.7.9

搜索帮助