MCPcopy
hub / github.com/gin-gonic/gin / findCaseInsensitivePathRec

Method findCaseInsensitivePathRec

tree.go:703–950  ·  view source on GitHub ↗

Recursive case-insensitive lookup function used by n.findCaseInsensitivePath

(path string, ciPath []byte, rb [4]byte, fixTrailingSlash bool)

Source from the content-addressed store, hash-verified

701
702// Recursive case-insensitive lookup function used by n.findCaseInsensitivePath
703func (n *node) findCaseInsensitivePathRec(path string, ciPath []byte, rb [4]byte, fixTrailingSlash bool) []byte {
704 npLen := len(n.path)
705
706walk: // Outer loop for walking the tree
707 for len(path) >= npLen && (npLen == 0 || strings.EqualFold(path[1:npLen], n.path[1:])) {
708 // Add common prefix to result
709 oldPath := path
710 path = path[npLen:]
711 ciPath = append(ciPath, n.path...)
712
713 if len(path) == 0 {
714 // We should have reached the node containing the handle.
715 // Check if this node has a handle registered.
716 if n.handlers != nil {
717 return ciPath
718 }
719
720 // No handle found.
721 // Try to fix the path by adding a trailing slash
722 if fixTrailingSlash {
723 for i, c := range []byte(n.indices) {
724 if c == '/' {
725 n = n.children[i]
726 if (len(n.path) == 1 && n.handlers != nil) ||
727 (n.nType == catchAll && n.children[0].handlers != nil) {
728 return append(ciPath, '/')
729 }
730 return nil
731 }
732 }
733 }
734 return nil
735 }
736
737 // If this node does not have a wildcard (param or catchAll) child,
738 // we can just look up the next child node and continue to walk down
739 // the tree
740 if !n.wildChild {
741 // Skip rune bytes already processed
742 rb = shiftNRuneBytes(rb, npLen)
743
744 if rb[0] != 0 {
745 // Old rune not finished
746 idxc := rb[0]
747 for i, c := range []byte(n.indices) {
748 if c == idxc {
749 // continue with child node
750 n = n.children[i]
751 npLen = len(n.path)
752 continue walk
753 }
754 }
755 } else {
756 // Process a new rune
757 var rv rune
758
759 // Find rune start.
760 // Runes are up to 4 byte long,

Callers 1

Calls 1

shiftNRuneBytesFunction · 0.85

Tested by

no test coverage detected