Lines Matching full:path
5 // Package path implements utility routines for manipulating slash-separated
7 package path
13 // A lazybuf is a lazily constructed path buffer.
50 // Clean returns the shortest path name equivalent to path
55 // 2. Eliminate each . path name element (the current directory).
56 // 3. Eliminate each inner .. path name element (the parent directory)
58 // 4. Eliminate .. elements that begin a rooted path:
59 // that is, replace "/.." by "/" at the beginning of a path.
61 // The returned path ends in a slash only if it is the root "/".
69 func Clean(path string) string {
70 if path == "" {
74 rooted := path[0] == '/'
75 n := len(path)
78 // reading from path; r is index of next byte to process.
82 out := lazybuf{s: path}
91 case path[r] == '/':
92 // empty path element
94 case path[r] == '.' && (r+1 == n || path[r+1] == '/'):
97 case path[r] == '.' && path[r+1] == '.' && (r+2 == n || path[r+2] == '/'):
117 // real path element.
123 for ; r < n && path[r] != '/'; r++ {
124 out.append(path[r])
137 // Split splits path immediately following the final slash,
139 // If there is no slash path, Split returns an empty dir and
140 // file set to path.
141 // The returned values have the property that path = dir+file.
142 func Split(path string) (dir, file string) {
143 i := strings.LastIndex(path, "/")
144 return path[:i+1], path[i+1:]
147 // Join joins any number of path elements into a single path, adding a
159 // Ext returns the file name extension used by path.
161 // in the final slash-separated element of path;
163 func Ext(path string) string {
164 for i := len(path) - 1; i >= 0 && path[i] != '/'; i-- {
165 if path[i] == '.' {
166 return path[i:]
172 // Base returns the last element of path.
174 // If the path is empty, Base returns ".".
175 // If the path consists entirely of slashes, Base returns "/".
176 func Base(path string) string {
177 if path == "" {
181 for len(path) > 0 && path[len(path)-1] == '/' {
182 path = path[0 : len(path)-1]
185 if i := strings.LastIndex(path, "/"); i >= 0 {
186 path = path[i+1:]
189 if path == "" {
192 return path
195 // IsAbs reports whether the path is absolute.
196 func IsAbs(path string) bool {
197 return len(path) > 0 && path[0] == '/'
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 trailing
203 // If the path is empty, Dir returns ".".
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
207 func Dir(path string) string {
208 dir, _ := Split(path)