go.temporal.io/server/common/util/wildcard.go

50 LOC · 28 covered · 22 uncovered · 9 ranges · 22924 concepts · 5 introducers · 11233 tests

File neighbourhood

The centred file is linked to every concept that introduces one of its ranges, every test that runs code from the file, and the gray connector concepts standing between those tests and the file's own introducer concepts. Undirected links join concepts to every file where they introduce source and concepts to the tests they introduce; arrows show specialization between the displayed concepts and bridge only concepts omitted from this view. Concept colors match the source ranges below; connector concepts have no source color and are shown in gray.

Focused file, its introducer and connector concepts, their introduced files, and tests that run code from the file

In the embedded map, ordinary wheel input scrolls the page; use the visible controls to zoom and drag to pan. Open the full-screen map for canvas navigation: wheel pans, Ctrl/Command plus wheel zooms, and arrow keys pan when this region is focused. On touch screens, open the full-screen map to pan or pinch. If JavaScript or WebGL is unavailable, use the related-file, concept, and source links on this page.

Graph controls are ready.

Interactive rendering requires JavaScript and WebGL. Use the related-file, concept, and source links on this page while the interactive map is unavailable.

1 package util
2
3 import (
4 "errors"
5 "regexp"
6 "strings"
7 )
8
9 // WildCardStringToRegexp converts a given string pattern to a regular expression matching wildcards (*) with any
10 // substring.
11 > func WildCardStringToRegexp(pattern string) (*regexp.Regexp, error) { wildcard.go ×1
12 > if pattern == "" {
13 > return nil, errors.New("pattern cannot be empty")
14 > }
15 > return WildCardStringsToRegexp([]string{pattern})
16 }
17
18 // WildCardStringToRegexps converts a given slices of string patterns to a slice of regular expressions matching
19 // wildcards (*) with any substring.
20 > func WildCardStringsToRegexp(patterns []string) (*regexp.Regexp, error) { wildcard.go ×4
21 > var result strings.Builder
22 > result.WriteRune('^')
23 > for i, pattern := range patterns {
24 > result.WriteRune('(')
25 > first := true
26 > for literal := range strings.SplitSeq(pattern, "*") {
27 > if !first {
28 > // Replace * with .* wildcard.go ×1
29 > result.WriteString(".*")
30 > }
31 > result.WriteString(regexp.QuoteMeta(literal)) wildcard.go ×4
32 > first = false
33 }
34 > result.WriteRune(')') wildcard.go ×4
35 > if i < len(patterns)-1 {
36 > result.WriteRune('|') wildcard.go ×1
37 > }
38 }
39 > result.WriteRune('$') wildcard.go ×4
40 > return regexp.Compile(result.String())
41 }
42
43 // MustWildCardStringsToRegexp is like WildCardStringsToRegexp but panics on error.
44 > func MustWildCardStringsToRegexp(patterns []string) *regexp.Regexp { setting_gen.go ×51
45 > re, err := WildCardStringsToRegexp(patterns)
46 > if err != nil {
47 panic(err) //nolint:forbidigo // Must* functions conventionally panic on error.
48 }
49 > return re setting_gen.go ×51
50 }