LEFT | RIGHT |
(no file at all) | |
1 // Copyright 2009 The Go Authors. All rights reserved. | 1 // Copyright 2009 The Go Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style | 2 // Use of this source code is governed by a BSD-style |
3 // license that can be found in the LICENSE file. | 3 // license that can be found in the LICENSE file. |
4 | 4 |
5 // Package path implements utility routines for manipulating slash-separated | 5 // Package path implements utility routines for manipulating slash-separated |
6 // paths. | 6 // paths. |
7 package path | 7 package path |
8 | 8 |
9 import ( | 9 import ( |
10 "strings" | 10 "strings" |
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
199 | 199 |
200 // Dir returns all but the last element of path, typically the path's directory. | 200 // Dir returns all but the last element of path, typically the path's directory. |
201 // After dropping the final element using Split, the path is Cleaned and trailin
g | 201 // After dropping the final element using Split, the path is Cleaned and trailin
g |
202 // slashes are removed. | 202 // slashes are removed. |
203 // If the path is empty, Dir returns ".". | 203 // If the path is empty, Dir returns ".". |
204 // If the path consists entirely of slashes followed by non-slash bytes, Dir | 204 // If the path consists entirely of slashes followed by non-slash bytes, Dir |
205 // returns a single slash. In any other case, the returned path does not end in
a | 205 // returns a single slash. In any other case, the returned path does not end in
a |
206 // slash. | 206 // slash. |
207 func Dir(path string) string { | 207 func Dir(path string) string { |
208 dir, _ := Split(path) | 208 dir, _ := Split(path) |
209 » dir = Clean(dir) | 209 » return Clean(dir) |
210 » last := len(dir) - 1 | 210 } |
211 » if last > 0 && dir[last] == '/' { | |
212 » » dir = dir[:last] | |
213 » } | |
214 » if dir == "" { | |
215 » » dir = "." | |
216 » } | |
217 » return dir | |
218 } | |
LEFT | RIGHT |