// operating system paths, use the [path/filepath] package.
package path
+import "internal/bytealg"
+
// A lazybuf is a lazily constructed path buffer.
// It supports append, reading previously appended bytes,
// and retrieving the final string. It does not allocate a buffer
return out.string()
}
-// lastSlash(s) is strings.LastIndex(s, "/") but we can't import strings.
-func lastSlash(s string) int {
- i := len(s) - 1
- for i >= 0 && s[i] != '/' {
- i--
- }
- return i
-}
-
// Split splits path immediately following the final slash,
// separating it into a directory and file name component.
// If there is no slash in path, Split returns an empty dir and
// file set to path.
// The returned values have the property that path = dir+file.
func Split(path string) (dir, file string) {
- i := lastSlash(path)
+ i := bytealg.LastIndexByteString(path, '/')
return path[:i+1], path[i+1:]
}
path = path[0 : len(path)-1]
}
// Find the last element
- if i := lastSlash(path); i >= 0 {
+ if i := bytealg.LastIndexByteString(path, '/'); i >= 0 {
path = path[i+1:]
}
// If empty now, it had only slashes.