diff options
author | Ian Lance Taylor <ian@gcc.gnu.org> | 2011-09-16 15:47:21 +0000 |
---|---|---|
committer | Ian Lance Taylor <ian@gcc.gnu.org> | 2011-09-16 15:47:21 +0000 |
commit | adb0401dac41c81571722312d4586b2693f95aa6 (patch) | |
tree | ea2b52e3c258d6b6d9356977c683c7f72a4a5fd5 /libgo/go/path/filepath/path_windows.go | |
parent | 5548ca3540bccbc908a45942896d635ea5f1c23f (diff) | |
download | gcc-adb0401dac41c81571722312d4586b2693f95aa6.tar.gz |
Update Go library to r60.
From-SVN: r178910
Diffstat (limited to 'libgo/go/path/filepath/path_windows.go')
-rw-r--r-- | libgo/go/path/filepath/path_windows.go | 45 |
1 files changed, 27 insertions, 18 deletions
diff --git a/libgo/go/path/filepath/path_windows.go b/libgo/go/path/filepath/path_windows.go index dbd1c1e401d..2535697fd9e 100644 --- a/libgo/go/path/filepath/path_windows.go +++ b/libgo/go/path/filepath/path_windows.go @@ -4,34 +4,43 @@ package filepath -const ( - Separator = '\\' // OS-specific path separator - ListSeparator = ':' // OS-specific path list separator -) - -// isSeparator returns true if c is a directory separator character. -func isSeparator(c uint8) bool { - // NOTE: Windows accept / as path separator. - return c == '\\' || c == '/' -} +import "strings" // IsAbs returns true if the path is absolute. -func IsAbs(path string) bool { - return path != "" && (volumeName(path) != "" || isSeparator(path[0])) +func IsAbs(path string) (b bool) { + v := VolumeName(path) + if v == "" { + return false + } + path = path[len(v):] + if path == "" { + return false + } + return path[0] == '/' || path[0] == '\\' } -// volumeName return leading volume name. -// If given "C:\foo\bar", return "C:" on windows. -func volumeName(path string) string { - if path == "" { +// VolumeName returns leading volume name. +// Given "C:\foo\bar" it returns "C:" under windows. +// On other platforms it returns "". +func VolumeName(path string) (v string) { + if len(path) < 2 { return "" } // with drive letter c := path[0] - if len(path) > 2 && path[1] == ':' && isSeparator(path[2]) && + if path[1] == ':' && ('0' <= c && c <= '9' || 'a' <= c && c <= 'z' || 'A' <= c && c <= 'Z') { - return path[0:2] + return path[:2] } return "" } + +// HasPrefix tests whether the path p begins with prefix. +// It ignores case while comparing. +func HasPrefix(p, prefix string) bool { + if strings.HasPrefix(p, prefix) { + return true + } + return strings.HasPrefix(strings.ToLower(p), strings.ToLower(prefix)) +} |