recursive case-insensitive lookup function used by n.findCaseInsensitivePath
(path, loPath string, ciPath []byte, rb [4]byte, fixTrailingSlash bool)
| 617 | |
| 618 | // recursive case-insensitive lookup function used by n.findCaseInsensitivePath |
| 619 | func (n *Node) findCaseInsensitivePathRec(path, loPath string, ciPath []byte, rb [4]byte, fixTrailingSlash bool) ([]byte, bool) { |
| 620 | loNPath := strings.ToLower(n.path) |
| 621 | |
| 622 | walk: // outer loop for walking the tree |
| 623 | for len(loPath) >= len(loNPath) && (len(loNPath) == 0 || loPath[1:len(loNPath)] == loNPath[1:]) { |
| 624 | // add common path to result |
| 625 | ciPath = append(ciPath, n.path...) |
| 626 | |
| 627 | if path = path[len(n.path):]; len(path) > 0 { |
| 628 | loOld := loPath |
| 629 | loPath = loPath[len(loNPath):] |
| 630 | |
| 631 | // If this node does not have a wildcard (param or catchAll) child, |
| 632 | // we can just look up the next child node and continue to walk down |
| 633 | // the tree |
| 634 | if !n.wildChild { |
| 635 | // skip rune bytes already processed |
| 636 | rb = shiftNRuneBytes(rb, len(loNPath)) |
| 637 | |
| 638 | if rb[0] != 0 { |
| 639 | // old rune not finished |
| 640 | for i := 0; i < len(n.indices); i++ { |
| 641 | if n.indices[i] == rb[0] { |
| 642 | // continue with child node |
| 643 | n = n.children[i] |
| 644 | loNPath = strings.ToLower(n.path) |
| 645 | continue walk |
| 646 | } |
| 647 | } |
| 648 | } else { |
| 649 | // process a new rune |
| 650 | var rv rune |
| 651 | |
| 652 | // find rune start |
| 653 | // runes are up to 4 byte long, |
| 654 | // -4 would definitely be another rune |
| 655 | var off int |
| 656 | for max := min(len(loNPath), 3); off < max; off++ { |
| 657 | if i := len(loNPath) - off; utf8.RuneStart(loOld[i]) { |
| 658 | // read rune from cached lowercase path |
| 659 | rv, _ = utf8.DecodeRuneInString(loOld[i:]) |
| 660 | break |
| 661 | } |
| 662 | } |
| 663 | |
| 664 | // calculate lowercase bytes of current rune |
| 665 | utf8.EncodeRune(rb[:], rv) |
| 666 | // skipp already processed bytes |
| 667 | rb = shiftNRuneBytes(rb, off) |
| 668 | |
| 669 | for i := 0; i < len(n.indices); i++ { |
| 670 | // lowercase matches |
| 671 | if n.indices[i] == rb[0] { |
| 672 | // must use a recursive approach since both the |
| 673 | // uppercase byte and the lowercase byte might exist |
| 674 | // as an index |
| 675 | if out, found := n.children[i].findCaseInsensitivePathRec( |
| 676 | path, loPath, ciPath, rb, fixTrailingSlash, |
no test coverage detected