mirror of
https://github.com/terorie/od-database-crawler.git
synced 2025-12-17 00:39:04 +00:00
kill perf
This commit is contained in:
44
runespath/path.go
Normal file
44
runespath/path.go
Normal file
@@ -0,0 +1,44 @@
|
||||
// Copyright 2009 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
// Package path implements utility routines for manipulating slash-separated
|
||||
// paths.
|
||||
//
|
||||
// The path package should only be used for paths separated by forward
|
||||
// slashes, such as the paths in URLs. This package does not deal with
|
||||
// Windows paths with drive letters or backslashes; to manipulate
|
||||
// operating system paths, use the path/filepath package.
|
||||
package runespath
|
||||
|
||||
import (
|
||||
"github.com/terorie/oddb-go/runes"
|
||||
)
|
||||
|
||||
// Base returns the last element of path.
|
||||
// Trailing slashes are removed before extracting the last element.
|
||||
// If the path is empty, Base returns ".".
|
||||
// If the path consists entirely of slashes, Base returns "/".
|
||||
func Base(path []rune) []rune {
|
||||
if len(path) == 0 {
|
||||
return []rune(".")
|
||||
}
|
||||
// Strip trailing slashes.
|
||||
for len(path) > 0 && path[len(path)-1] == '/' {
|
||||
path = path[0 : len(path)-1]
|
||||
}
|
||||
// Find the last element
|
||||
if i := runes.LastIndexRune(path, '/'); i >= 0 {
|
||||
path = path[i+1:]
|
||||
}
|
||||
// If empty now, it had only slashes.
|
||||
if len(path) == 0 {
|
||||
return []rune("/")
|
||||
}
|
||||
return path
|
||||
}
|
||||
|
||||
// IsAbs reports whether the path is absolute.
|
||||
func IsAbs(path string) bool {
|
||||
return len(path) > 0 && path[0] == '/'
|
||||
}
|
||||
Reference in New Issue
Block a user