MCPcopy
hub / github.com/go-chi/chi / findPattern

Method findPattern

tree.go:578–618  ·  view source on GitHub ↗
(pattern string)

Source from the content-addressed store, hash-verified

576}
577
578func (n *node) findPattern(pattern string) bool {
579 nn := n
580 for _, nds := range nn.children {
581 if len(nds) == 0 {
582 continue
583 }
584
585 n = nn.findEdge(nds[0].typ, pattern[0])
586 if n == nil {
587 continue
588 }
589
590 var idx int
591 var xpattern string
592
593 switch n.typ {
594 case ntStatic:
595 idx = longestPrefix(pattern, n.prefix)
596 if idx < len(n.prefix) {
597 continue
598 }
599
600 case ntParam, ntRegexp:
601 idx = strings.IndexByte(pattern, '}') + 1
602
603 case ntCatchAll:
604 idx = longestPrefix(pattern, "*")
605
606 default:
607 panic("chi: unknown node type")
608 }
609
610 xpattern = pattern[idx:]
611 if len(xpattern) == 0 {
612 return true
613 }
614
615 return n.findPattern(xpattern)
616 }
617 return false
618}
619
620func (n *node) routes() []Route {
621 rts := []Route{}

Callers 2

TestTreeFindPatternFunction · 0.95
MountMethod · 0.80

Calls 2

longestPrefixFunction · 0.85
findEdgeMethod · 0.45

Tested by 1

TestTreeFindPatternFunction · 0.76