|
6 | 6 | "os" |
7 | 7 | "os/signal" |
8 | 8 | "path/filepath" |
| 9 | + "strings" |
9 | 10 | "sync" |
10 | 11 | "syscall" |
11 | 12 | "time" |
@@ -96,22 +97,7 @@ func (w *Watcher) expandPattern(pattern string) ([]string, error) { |
96 | 97 | func containsDoublestar(pattern string) bool { |
97 | 98 | return len(pattern) >= 2 && (pattern[:2] == "**" || |
98 | 99 | (len(pattern) >= 3 && pattern[len(pattern)-3:] == "/**") || |
99 | | - contains(pattern, "/**/") || contains(pattern, "\\**\\")) |
100 | | -} |
101 | | - |
102 | | -func contains(s, substr string) bool { |
103 | | - return len(s) >= len(substr) && (s == substr || |
104 | | - (len(s) > len(substr) && (s[:len(substr)] == substr || s[len(s)-len(substr):] == substr || |
105 | | - containsMiddle(s, substr)))) |
106 | | -} |
107 | | - |
108 | | -func containsMiddle(s, substr string) bool { |
109 | | - for i := 0; i <= len(s)-len(substr); i++ { |
110 | | - if s[i:i+len(substr)] == substr { |
111 | | - return true |
112 | | - } |
113 | | - } |
114 | | - return false |
| 100 | + strings.Contains(pattern, "/**/") || strings.Contains(pattern, "\\**\\")) |
115 | 101 | } |
116 | 102 |
|
117 | 103 | func (w *Watcher) expandDoublestar(pattern string) ([]string, error) { |
@@ -148,21 +134,21 @@ func (w *Watcher) expandDoublestar(pattern string) ([]string, error) { |
148 | 134 |
|
149 | 135 | func splitPattern(pattern string) []string { |
150 | 136 | var parts []string |
151 | | - current := "" |
| 137 | + var current strings.Builder |
152 | 138 |
|
153 | 139 | for i := 0; i < len(pattern); i++ { |
154 | 140 | if pattern[i] == '/' || pattern[i] == '\\' { |
155 | | - if current != "" { |
156 | | - parts = append(parts, current) |
157 | | - current = "" |
| 141 | + if current.Len() > 0 { |
| 142 | + parts = append(parts, current.String()) |
| 143 | + current.Reset() |
158 | 144 | } |
159 | 145 | } else { |
160 | | - current += string(pattern[i]) |
| 146 | + current.WriteByte(pattern[i]) |
161 | 147 | } |
162 | 148 | } |
163 | 149 |
|
164 | | - if current != "" { |
165 | | - parts = append(parts, current) |
| 150 | + if current.Len() > 0 { |
| 151 | + parts = append(parts, current.String()) |
166 | 152 | } |
167 | 153 |
|
168 | 154 | return parts |
|
0 commit comments