Skip to content

Commit 0e81adf

Browse files
feat: add support for *-word-* pattern (#267)
* feat: add support for *-word-* pattern * chore: update collections/slice.go Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * fix: tests --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent f990aa1 commit 0e81adf

2 files changed

Lines changed: 13 additions & 1 deletion

File tree

collections/slice.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,12 @@ func matchPattern(item, pattern string) bool {
120120
return true
121121
}
122122

123+
if strings.HasPrefix(pattern, "*") && strings.HasSuffix(pattern, "*") {
124+
if strings.Contains(item, strings.TrimPrefix(strings.TrimSuffix(pattern, "*"), "*")) {
125+
return true
126+
}
127+
}
128+
123129
if strings.HasPrefix(pattern, "*") {
124130
if strings.HasSuffix(item, strings.TrimPrefix(pattern, "*")) {
125131
return true

collections/slice_test.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,15 @@ func TestMatchItems(t *testing.T) {
6363
{
6464
name: "Multiple Wildcards",
6565
item: "apple",
66-
patterns: []string{"ap*e", "*p*"},
66+
patterns: []string{"ap*e", "*pl*e"},
6767
expected: false,
6868
},
69+
{
70+
name: "Glob",
71+
item: "apple",
72+
patterns: []string{"*ppl*"},
73+
expected: true,
74+
},
6975
{
7076
name: "Handle whitespaces | should be trimmed",
7177
item: "hello",

0 commit comments

Comments
 (0)