|
11 | 11 | // operating system paths, use the [path/filepath] package.
|
12 | 12 | package path
|
13 | 13 |
|
| 14 | +import "internal/bytealg" |
| 15 | + |
14 | 16 | // A lazybuf is a lazily constructed path buffer.
|
15 | 17 | // It supports append, reading previously appended bytes,
|
16 | 18 | // and retrieving the final string. It does not allocate a buffer
|
@@ -135,22 +137,13 @@ func Clean(path string) string {
|
135 | 137 | return out.string()
|
136 | 138 | }
|
137 | 139 |
|
138 |
| -// lastSlash(s) is strings.LastIndex(s, "/") but we can't import strings. |
139 |
| -func lastSlash(s string) int { |
140 |
| - i := len(s) - 1 |
141 |
| - for i >= 0 && s[i] != '/' { |
142 |
| - i-- |
143 |
| - } |
144 |
| - return i |
145 |
| -} |
146 |
| - |
147 | 140 | // Split splits path immediately following the final slash,
|
148 | 141 | // separating it into a directory and file name component.
|
149 | 142 | // If there is no slash in path, Split returns an empty dir and
|
150 | 143 | // file set to path.
|
151 | 144 | // The returned values have the property that path = dir+file.
|
152 | 145 | func Split(path string) (dir, file string) {
|
153 |
| - i := lastSlash(path) |
| 146 | + i := bytealg.LastIndexByteString(path, '/') |
154 | 147 | return path[:i+1], path[i+1:]
|
155 | 148 | }
|
156 | 149 |
|
@@ -205,7 +198,7 @@ func Base(path string) string {
|
205 | 198 | path = path[0 : len(path)-1]
|
206 | 199 | }
|
207 | 200 | // Find the last element
|
208 |
| - if i := lastSlash(path); i >= 0 { |
| 201 | + if i := bytealg.LastIndexByteString(path, '/'); i >= 0 { |
209 | 202 | path = path[i+1:]
|
210 | 203 | }
|
211 | 204 | // If empty now, it had only slashes.
|
|
0 commit comments