Skip to content

Commit 9fbc436

Browse files
authored
Merge pull request #7 from Azuyamat/feat/command-handler
chore: Clean up some watcher code
2 parents 978106f + 7c1db5c commit 9fbc436

1 file changed

Lines changed: 9 additions & 23 deletions

File tree

internal/runner/watcher.go

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"os"
77
"os/signal"
88
"path/filepath"
9+
"strings"
910
"sync"
1011
"syscall"
1112
"time"
@@ -96,22 +97,7 @@ func (w *Watcher) expandPattern(pattern string) ([]string, error) {
9697
func containsDoublestar(pattern string) bool {
9798
return len(pattern) >= 2 && (pattern[:2] == "**" ||
9899
(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, "\\**\\"))
115101
}
116102

117103
func (w *Watcher) expandDoublestar(pattern string) ([]string, error) {
@@ -148,21 +134,21 @@ func (w *Watcher) expandDoublestar(pattern string) ([]string, error) {
148134

149135
func splitPattern(pattern string) []string {
150136
var parts []string
151-
current := ""
137+
var current strings.Builder
152138

153139
for i := 0; i < len(pattern); i++ {
154140
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()
158144
}
159145
} else {
160-
current += string(pattern[i])
146+
current.WriteByte(pattern[i])
161147
}
162148
}
163149

164-
if current != "" {
165-
parts = append(parts, current)
150+
if current.Len() > 0 {
151+
parts = append(parts, current.String())
166152
}
167153

168154
return parts

0 commit comments

Comments
 (0)