MCPcopy Index your code
hub / github.com/wavetermdev/waveterm / StarMatchString

Function StarMatchString

pkg/util/utilfn/utilfn.go:799–820  ·  view source on GitHub ↗

matches a delimited string with a pattern string the pattern string can contain "*" to match a single part, or "**" to match the rest of the string note that "**" may only appear at the end of the string

(pattern string, s string, delimiter string)

Source from the content-addressed store, hash-verified

797// the pattern string can contain "*" to match a single part, or "**" to match the rest of the string
798// note that "**" may only appear at the end of the string
799func StarMatchString(pattern string, s string, delimiter string) bool {
800 patternParts := strings.Split(pattern, delimiter)
801 stringParts := strings.Split(s, delimiter)
802 pLen, sLen := len(patternParts), len(stringParts)
803
804 for i := 0; i < pLen; i++ {
805 if patternParts[i] == "**" {
806 // '**' must be at the end to be valid
807 return i == pLen-1
808 }
809 if i >= sLen {
810 // If string is exhausted but pattern is not
811 return false
812 }
813 if patternParts[i] != "*" && patternParts[i] != stringParts[i] {
814 // If current parts don't match and pattern part is not '*'
815 return false
816 }
817 }
818 // Check if both pattern and string are fully matched
819 return pLen == sLen
820}
821
822func MergeStrMaps[T any](m1 map[string]T, m2 map[string]T) map[string]T {
823 rtn := make(map[string]T)

Callers 1

getMatchingRouteIdsMethod · 0.92

Calls

no outgoing calls

Tested by

no test coverage detected