Source File
filepath.go
Belonging Package
github.com/evanw/esbuild/internal/fs
package fs
import (
)
type goFilepath struct {
cwd string
isWindows bool
pathSeparator byte
}
func ( uint8) bool {
return == '\\' || == '/'
}
var reservedNames = []string{
"CON", "PRN", "AUX", "NUL",
"COM1", "COM2", "COM3", "COM4", "COM5", "COM6", "COM7", "COM8", "COM9",
"LPT1", "LPT2", "LPT3", "LPT4", "LPT5", "LPT6", "LPT7", "LPT8", "LPT9",
}
func ( goFilepath) ( string) bool {
if !.isWindows {
return strings.HasPrefix(, "/")
}
if isReservedName() {
return true
}
:= .volumeNameLen()
if == 0 {
return false
}
= [:]
if == "" {
return false
}
return isSlash([0])
}
func ( goFilepath) ( uint8) bool {
return == '/' || (.isWindows && == '\\')
}
func ( goFilepath) ( string) int {
if !.isWindows {
return 0
}
if len() < 2 {
return 0
:= [0]
if [1] == ':' && ('a' <= && <= 'z' || 'A' <= && <= 'Z') {
return 2
if isSlash([]) {
func ( goFilepath) ( string) (string, error) {
:= .volumeNameLen()
:= string(.pathSeparator)
if < len() && .isPathSeparator([]) {
++
}
:= [:]
:=
:= 0
for , := , ; < len(); = {
for < len() && .isPathSeparator([]) {
++
}
=
for < len() && !.isPathSeparator([]) {
++
}
:= .isWindows && [.volumeNameLen():] == "."
break
continue
var int
for = len() - 1; >= ; -- {
if .isPathSeparator([]) {
break
}
}
if len() > {
+=
}
+= ".."
= [:]
}
continue
}
if len() > .volumeNameLen() && !.isPathSeparator([len()-1]) {
+=
}
+= [:]
break
}
= + [:]
:= .volumeNameLen()
if < len() && .isPathSeparator([]) {
++
}
= [:]
=
= len()
= [:1]
= 1
var int
for = len() - 1; >= ; -- {
if .isPathSeparator([]) {
break
}
}
if < {
=
} else {
= [:]
}
= 0
}
}
return .clean(), nil
}
type lazybuf struct {
path string
buf []byte
w int
volAndPath string
volLen int
}
func ( *lazybuf) ( int) byte {
if .buf != nil {
return .buf[]
}
return .path[]
}
func ( *lazybuf) ( byte) {
if .buf == nil {
if .w < len(.path) && .path[.w] == {
.w++
return
}
.buf = make([]byte, len(.path))
copy(.buf, .path[:.w])
}
.buf[.w] =
.w++
}
func ( *lazybuf) () string {
if .buf == nil {
return .volAndPath[:.volLen+.w]
}
return .volAndPath[:.volLen] + string(.buf[:.w])
}
func ( goFilepath) ( string) string {
if !.isWindows {
return
}
return strings.ReplaceAll(, "/", "\\")
}
func ( goFilepath) ( string) string {
:=
:= .volumeNameLen()
= [:]
if == "" {
return .fromSlash()
}
return + "."
}
:= .isPathSeparator([0])
:= len()
:= lazybuf{path: , volAndPath: , volLen: }
, := 0, 0
if {
.append(.pathSeparator)
, = 1, 1
}
for < {
switch {
++
++
+= 2
switch {
if && .w != 1 || ! && .w != 0 {
.append(.pathSeparator)
for ; < && !.isPathSeparator([]); ++ {
.append([])
}
}
}
func ( goFilepath) ( string) string {
return [:.volumeNameLen()]
}
func ( goFilepath) ( string) string {
if == "" {
return "."
for len() > 0 && .isPathSeparator([len()-1]) {
= [0 : len()-1]
:= len() - 1
for >= 0 && !.isPathSeparator([]) {
--
}
if >= 0 {
= [+1:]
if == "" {
return string(.pathSeparator)
}
return
}
func ( goFilepath) ( string) string {
:= .volumeName()
:= len() - 1
for >= len() && !.isPathSeparator([]) {
--
}
:= .clean([len() : +1])
return
}
return +
}
func ( goFilepath) ( string) string {
for := len() - 1; >= 0 && !.isPathSeparator([]); -- {
if [] == '.' {
return [:]
}
}
return ""
}
func ( goFilepath) ( []string) string {
for , := range {
if != "" {
if .isWindows {
return .joinNonEmpty([:])
}
return .clean(strings.Join([:], string(.pathSeparator)))
}
}
return ""
}
func ( goFilepath) ( []string) string {
:= .clean(strings.Join([1:], string(.pathSeparator)))
if [len()-1] == .pathSeparator {
return +
}
return + string(.pathSeparator) +
}
func ( goFilepath) ( string) bool {
return .volumeNameLen() > 2
}
func ( goFilepath) (, string) (string, error) {
:= .volumeName()
:= .volumeName()
:= .clean()
:= .clean()
if .sameWord(, ) {
return ".", nil
}
= [len():]
= [len():]
if == "." {
= ""
:= len() > 0 && [0] == .pathSeparator
:= len() > 0 && [0] == .pathSeparator
if != || !.sameWord(, ) {
return "", errors.New("Rel: can't make " + + " relative to " + )
:= len()
:= len()
var , , , int
for {
for < && [] != .pathSeparator {
++
}
for < && [] != .pathSeparator {
++
}
if !.sameWord([:], [:]) {
break
}
if < {
++
}
if < {
++
}
=
=
}
if [:] == ".." {
return "", errors.New("Rel: can't make " + + " relative to " + )
}
:= strings.Count([:], string(.pathSeparator))
:= 2 + *3
if != {
+= 1 + -
}
:= make([]byte, )
:= copy(, "..")
for := 0; < ; ++ {
[] = .pathSeparator
copy([+1:], "..")
+= 3
}
if != {
[] = .pathSeparator
copy([+1:], [:])
}
return string(), nil
}
return [:], nil
}
func ( goFilepath) (, string) bool {
if !.isWindows {
return ==
}
return strings.EqualFold(, )
![]() |
The pages are generated with Golds v0.3.2-preview. (GOOS=darwin GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds. |