1 // Copyright 2010 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
11 func isSlash(c uint8) bool {
12 return c == '\\' || c == '/'
15 // IsAbs returns true if the path is absolute.
16 func IsAbs(path string) (b bool) {
25 return isSlash(path[0])
28 // VolumeName returns leading volume name.
29 // Given "C:\foo\bar" it returns "C:" under windows.
30 // Given "\\host\share\foo" it returns "\\host\share".
31 // On other platforms it returns "".
32 func VolumeName(path string) (v string) {
39 ('0' <= c && c <= '9' || 'a' <= c && c <= 'z' ||
40 'A' <= c && c <= 'Z') {
44 if l := len(path); l >= 5 && isSlash(path[0]) && isSlash(path[1]) &&
45 !isSlash(path[2]) && path[2] != '.' {
46 // first, leading `\\` and next shouldn't be `\`. its server name.
47 for n := 3; n < l-1; n++ {
48 // second, next '\' shouldn't be repeated.
51 // third, following something characters. its share name.
52 if !isSlash(path[n]) {
70 // HasPrefix tests whether the path p begins with prefix.
71 // It ignores case while comparing.
72 func HasPrefix(p, prefix string) bool {
73 if strings.HasPrefix(p, prefix) {
76 return strings.HasPrefix(strings.ToLower(p), strings.ToLower(prefix))