MCPcopy
hub / github.com/caddyserver/caddy / Match

Method Match

modules/caddytls/matchers.go:199–229  ·  view source on GitHub ↗

Match returns true if input matches the compiled regular expression in m. It sets values on the replacer repl associated with capture groups, using the given scope (namespace).

(input string, repl *caddy.Replacer)

Source from the content-addressed store, hash-verified

197// associated with capture groups, using the given scope
198// (namespace).
199func (mre *MatchRegexp) Match(input string, repl *caddy.Replacer) bool {
200 matches := mre.compiled.FindStringSubmatch(input)
201 if matches == nil {
202 return false
203 }
204
205 // save all capture groups, first by index
206 for i, match := range matches {
207 keySuffix := "." + strconv.Itoa(i)
208 if mre.Name != "" {
209 repl.Set(regexpPlaceholderPrefix+"."+mre.Name+keySuffix, match)
210 }
211 repl.Set(regexpPlaceholderPrefix+keySuffix, match)
212 }
213
214 // then by name
215 for i, name := range mre.compiled.SubexpNames() {
216 // skip the first element (the full match), and empty names
217 if i == 0 || name == "" {
218 continue
219 }
220
221 keySuffix := "." + name
222 if mre.Name != "" {
223 repl.Set(regexpPlaceholderPrefix+"."+mre.Name+keySuffix, matches[i])
224 }
225 repl.Set(regexpPlaceholderPrefix+keySuffix, matches[i])
226 }
227
228 return true
229}
230
231// UnmarshalCaddyfile implements caddyfile.Unmarshaler.
232func (mre *MatchRegexp) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {

Callers

nothing calls this directly

Calls 1

SetMethod · 0.45

Tested by

no test coverage detected