1 |
package gitignore
|
|
2 |
|
|
3 |
import (
|
|
4 |
"os"
|
|
5 |
"strings"
|
|
6 |
) |
|
7 |
|
|
8 |
func cutN(path string, n int) (string, bool) { |
2✔ |
9 |
isLast := true
|
2✔ |
10 |
|
2✔ |
11 |
var i, count int |
2✔ |
12 |
for i < len(path)-1 { |
20✔ |
13 |
if os.IsPathSeparator(path[i]) {
|
18✔ |
14 |
count++ |
× |
15 |
if count >= n {
|
× |
16 |
isLast = false
|
× |
17 |
break
|
× |
18 |
} |
|
19 |
} |
|
20 |
i++ |
18✔ |
21 |
} |
|
22 |
return path[:i+1], isLast |
2✔ |
23 |
} |
|
24 |
|
|
25 |
func cutLastN(path string, n int) (string, bool) { |
2,511✔ |
26 |
isLast := true
|
2,511✔ |
27 |
i := len(path) - 1 |
2,511✔ |
28 |
|
2,511✔ |
29 |
var count int |
2,511✔ |
30 |
for i >= 0 { |
54,739✔ |
31 |
if os.IsPathSeparator(path[i]) {
|
55,852✔ |
32 |
count++ |
3,624✔ |
33 |
if count >= n {
|
5,096✔ |
34 |
isLast = false
|
1,472✔ |
35 |
break
|
1,472✔ |
36 |
} |
|
37 |
} |
|
38 |
i-- |
50,756✔ |
39 |
} |
|
40 |
return path[i+1:], isLast |
2,511✔ |
41 |
} |
|
42 |
|
|
43 |
func hasMeta(path string) bool { |
54✔ |
44 |
return strings.IndexAny(path, "*?[") >= 0 |
54✔ |
45 |
} |
54✔ |