summaryrefslogtreecommitdiff
path: root/src/pkg/path/filepath/path_windows.go
diff options
context:
space:
mode:
Diffstat (limited to 'src/pkg/path/filepath/path_windows.go')
-rw-r--r--src/pkg/path/filepath/path_windows.go55
1 files changed, 43 insertions, 12 deletions
diff --git a/src/pkg/path/filepath/path_windows.go b/src/pkg/path/filepath/path_windows.go
index 3dcd03021..e99997257 100644
--- a/src/pkg/path/filepath/path_windows.go
+++ b/src/pkg/path/filepath/path_windows.go
@@ -14,29 +14,27 @@ func isSlash(c uint8) bool {
// IsAbs returns true if the path is absolute.
func IsAbs(path string) (b bool) {
- v := VolumeName(path)
- if v == "" {
+ l := volumeNameLen(path)
+ if l == 0 {
return false
}
- path = path[len(v):]
+ path = path[l:]
if path == "" {
return false
}
return isSlash(path[0])
}
-// VolumeName returns leading volume name.
-// Given "C:\foo\bar" it returns "C:" under windows.
-// Given "\\host\share\foo" it returns "\\host\share".
-// On other platforms it returns "".
-func VolumeName(path string) (v string) {
+// volumeNameLen returns length of the leading volume name on Windows.
+// It returns 0 elsewhere.
+func volumeNameLen(path string) int {
if len(path) < 2 {
- return ""
+ return 0
}
// with drive letter
c := path[0]
if path[1] == ':' && ('a' <= c && c <= 'z' || 'A' <= c && c <= 'Z') {
- return path[:2]
+ return 2
}
// is it UNC
if l := len(path); l >= 5 && isSlash(path[0]) && isSlash(path[1]) &&
@@ -56,13 +54,13 @@ func VolumeName(path string) (v string) {
break
}
}
- return path[:n]
+ return n
}
break
}
}
}
- return ""
+ return 0
}
// HasPrefix exists for historical compatibility and should not be used.
@@ -72,3 +70,36 @@ func HasPrefix(p, prefix string) bool {
}
return strings.HasPrefix(strings.ToLower(p), strings.ToLower(prefix))
}
+
+func splitList(path string) []string {
+ // The same implementation is used in LookPath in os/exec;
+ // consider changing os/exec when changing this.
+
+ if path == "" {
+ return []string{}
+ }
+
+ // Split path, respecting but preserving quotes.
+ list := []string{}
+ start := 0
+ quo := false
+ for i := 0; i < len(path); i++ {
+ switch c := path[i]; {
+ case c == '"':
+ quo = !quo
+ case c == ListSeparator && !quo:
+ list = append(list, path[start:i])
+ start = i + 1
+ }
+ }
+ list = append(list, path[start:])
+
+ // Remove quotes.
+ for i, s := range list {
+ if strings.Contains(s, `"`) {
+ list[i] = strings.Replace(s, `"`, ``, -1)
+ }
+ }
+
+ return list
+}