Marcel van Lohuizen | b5dc192 | 2018-12-11 11:49:57 +0100 | [diff] [blame] | 1 | // Copyright 2018 The CUE Authors |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
| 15 | // Copyright 2018 The Go Authors. All rights reserved. |
| 16 | // Use of this source code is governed by a BSD-style |
| 17 | // license that can be found in the LICENSE file. |
| 18 | |
| 19 | //go:generate qgo -exclude=Split,Join extract path |
| 20 | |
| 21 | package path |
| 22 | |
| 23 | import "path" |
| 24 | |
| 25 | // Match reports whether name matches the shell pattern. |
| 26 | // The pattern syntax is: |
| 27 | // |
| 28 | // pattern: |
| 29 | // { term } |
| 30 | // term: |
| 31 | // '*' matches any sequence of non-/ characters |
| 32 | // '?' matches any single non-/ character |
| 33 | // '[' [ '^' ] { character-range } ']' |
| 34 | // character class (must be non-empty) |
| 35 | // c matches character c (c != '*', '?', '\\', '[') |
| 36 | // '\\' c matches character c |
| 37 | // |
| 38 | // character-range: |
| 39 | // c matches character c (c != '\\', '-', ']') |
| 40 | // '\\' c matches character c |
| 41 | // lo '-' hi matches character c for lo <= c <= hi |
| 42 | // |
| 43 | // Match requires pattern to match all of name, not just a substring. |
| 44 | // The only possible returned error is ErrBadPattern, when pattern |
| 45 | // is malformed. |
| 46 | // |
| 47 | func Match(pattern, name string) (matched bool, err error) { |
| 48 | return path.Match(pattern, name) |
| 49 | } |
| 50 | |
| 51 | // Clean returns the shortest path name equivalent to path |
| 52 | // by purely lexical processing. It applies the following rules |
| 53 | // iteratively until no further processing can be done: |
| 54 | // |
| 55 | // 1. Replace multiple slashes with a single slash. |
| 56 | // 2. Eliminate each . path name element (the current directory). |
| 57 | // 3. Eliminate each inner .. path name element (the parent directory) |
| 58 | // along with the non-.. element that precedes it. |
| 59 | // 4. Eliminate .. elements that begin a rooted path: |
| 60 | // that is, replace "/.." by "/" at the beginning of a path. |
| 61 | // |
| 62 | // The returned path ends in a slash only if it is the root "/". |
| 63 | // |
| 64 | // If the result of this process is an empty string, Clean |
| 65 | // returns the string ".". |
| 66 | // |
| 67 | // See also Rob Pike, ``Lexical File Names in Plan 9 or |
| 68 | // Getting Dot-Dot Right,'' |
| 69 | // https://9p.io/sys/doc/lexnames.html |
| 70 | func Clean(path string) string { return pathClean(path) } |
| 71 | |
| 72 | var pathClean = path.Clean |
| 73 | |
| 74 | // Ext returns the file name extension used by path. |
| 75 | // The extension is the suffix beginning at the final dot |
| 76 | // in the final slash-separated element of path; |
| 77 | // it is empty if there is no dot. |
| 78 | func Ext(path string) string { return pathExt(path) } |
| 79 | |
| 80 | var pathExt = path.Ext |
| 81 | |
| 82 | // Base returns the last element of path. |
| 83 | // Trailing slashes are removed before extracting the last element. |
| 84 | // If the path is empty, Base returns ".". |
| 85 | // If the path consists entirely of slashes, Base returns "/". |
| 86 | func Base(path string) string { return pathBase(path) } |
| 87 | |
| 88 | var pathBase = path.Base |
| 89 | |
| 90 | // IsAbs reports whether the path is absolute. |
| 91 | func IsAbs(path string) bool { return pathIsAbs(path) } |
| 92 | |
| 93 | var pathIsAbs = path.IsAbs |
| 94 | |
| 95 | // Dir returns all but the last element of path, typically the path's directory. |
| 96 | // After dropping the final element using Split, the path is Cleaned and trailing |
| 97 | // slashes are removed. |
| 98 | // If the path is empty, Dir returns ".". |
| 99 | // If the path consists entirely of slashes followed by non-slash bytes, Dir |
| 100 | // returns a single slash. In any other case, the returned path does not end in a |
| 101 | // slash. |
| 102 | func Dir(path string) string { return pathDir(path) } |
| 103 | |
| 104 | var pathDir = path.Dir |