Source file
src/os/path_unix.go
1
2
3
4
5
6
7 package os
8
9 const (
10 PathSeparator = '/'
11 PathListSeparator = ':'
12 )
13
14
15 func IsPathSeparator(c uint8) bool {
16 return PathSeparator == c
17 }
18
19
20 func splitPath(path string) (string, string) {
21
22 dirname := "."
23
24
25 for len(path) > 1 && path[0] == '/' && path[1] == '/' {
26 path = path[1:]
27 }
28
29 i := len(path) - 1
30
31
32 for ; i > 0 && path[i] == '/'; i-- {
33 path = path[:i]
34 }
35
36
37 basename := path
38
39
40 for i--; i >= 0; i-- {
41 if path[i] == '/' {
42 if i == 0 {
43 dirname = path[:1]
44 } else {
45 dirname = path[:i]
46 }
47 basename = path[i+1:]
48 break
49 }
50 }
51
52 return dirname, basename
53 }
54
View as plain text