recursive case-insensitive lookup function used by n.findCaseInsensitivePath
(path string, ciPath []byte, rb [4]byte, fixTrailingSlash bool)
| 490 | |
| 491 | // recursive case-insensitive lookup function used by n.findCaseInsensitivePath |
| 492 | func (n *node) findCaseInsensitivePathRec(path string, ciPath []byte, rb [4]byte, fixTrailingSlash bool) ([]byte, bool) { |
| 493 | npLen := len(n.path) |
| 494 | |
| 495 | walk: // outer loop for walking the tree |
| 496 | for len(path) >= npLen && (npLen == 0 || strings.EqualFold(path[1:npLen], n.path[1:])) { |
| 497 | // add common prefix to result |
| 498 | |
| 499 | oldPath := path |
| 500 | path = path[npLen:] |
| 501 | ciPath = append(ciPath, n.path...) |
| 502 | |
| 503 | if len(path) > 0 { |
| 504 | // If this node does not have a wildcard (param or catchAll) child, |
| 505 | // we can just look up the next child node and continue to walk down |
| 506 | // the tree |
| 507 | if !n.wildChild { |
| 508 | // skip rune bytes already processed |
| 509 | rb = shiftNRuneBytes(rb, npLen) |
| 510 | |
| 511 | if rb[0] != 0 { |
| 512 | // old rune not finished |
| 513 | for i := 0; i < len(n.indices); i++ { |
| 514 | if n.indices[i] == rb[0] { |
| 515 | // continue with child node |
| 516 | n = n.children[i] |
| 517 | npLen = len(n.path) |
| 518 | continue walk |
| 519 | } |
| 520 | } |
| 521 | } else { |
| 522 | // process a new rune |
| 523 | var rv rune |
| 524 | |
| 525 | // find rune start |
| 526 | // runes are up to 4 byte long, |
| 527 | // -4 would definitely be another rune |
| 528 | var off int |
| 529 | for max := min(npLen, 3); off < max; off++ { |
| 530 | if i := npLen - off; utf8.RuneStart(oldPath[i]) { |
| 531 | // read rune from cached path |
| 532 | rv, _ = utf8.DecodeRuneInString(oldPath[i:]) |
| 533 | break |
| 534 | } |
| 535 | } |
| 536 | |
| 537 | // calculate lowercase bytes of current rune |
| 538 | lo := unicode.ToLower(rv) |
| 539 | utf8.EncodeRune(rb[:], lo) |
| 540 | |
| 541 | // skip already processed bytes |
| 542 | rb = shiftNRuneBytes(rb, off) |
| 543 | |
| 544 | for i := 0; i < len(n.indices); i++ { |
| 545 | // lowercase matches |
| 546 | if n.indices[i] == rb[0] { |
| 547 | // must use a recursive approach since both the |
| 548 | // uppercase byte and the lowercase byte might exist |
| 549 | // as an index |
no test coverage detected