| 623 | } |
| 624 | |
| 625 | static void path_candidate(const uint32_t *t, int a, int b, candv_t *cv) { |
| 626 | /* s.strip("./~"), split on '/', drop empties */ |
| 627 | int sa = a; |
| 628 | int sb = b; |
| 629 | while (sa < sb && (t[sa] == '.' || t[sa] == '/' || t[sa] == '~')) { |
| 630 | sa++; |
| 631 | } |
| 632 | while (sb > sa && (t[sb - 1] == '.' || t[sb - 1] == '/' || t[sb - 1] == '~')) { |
| 633 | sb--; |
| 634 | } |
| 635 | bool any_seg = false; |
| 636 | bool all_numeric = true; |
| 637 | int last_s = -1; |
| 638 | int last_e = -1; |
| 639 | for (int i = sa; i <= sb;) { |
| 640 | int j = i; |
| 641 | while (j < sb && t[j] != '/') { |
| 642 | j++; |
| 643 | } |
| 644 | if (j > i) { |
| 645 | any_seg = true; |
| 646 | for (int k = i; k < j; k++) { |
| 647 | if (!((t[k] >= '0' && t[k] <= '9') || t[k] == '.' || t[k] == '-')) { |
| 648 | all_numeric = false; |
| 649 | } |
| 650 | } |
| 651 | last_s = i; |
| 652 | last_e = j; |
| 653 | } |
| 654 | i = j + 1; |
| 655 | } |
| 656 | if (!any_seg || all_numeric) { |
| 657 | return; /* numeric-path */ |
| 658 | } |
| 659 | if (in_list_lower(t + a, b - a, SLASH_STOP)) { |
| 660 | return; |
| 661 | } |
| 662 | int slashes = 0; |
| 663 | for (int i = a; i < b; i++) { |
| 664 | slashes += t[i] == '/'; |
| 665 | } |
| 666 | bool has_ext = has_code_ext(t + last_s, last_e - last_s); |
| 667 | bool prefixed = |
| 668 | lit_at(t, b, a, "./") || lit_at(t, b, a, "../") || lit_at(t, b, a, "~/") || t[a] == '/'; |
| 669 | cand_t c = {a, b, (slashes >= 2 || has_ext || prefixed) ? MK_PATH : MK_PATH1, 0, 0}; |
| 670 | /* norm: leading ../ ./ ~/ / removed (repeatedly), trailing '/' removed */ |
| 671 | int na = a; |
| 672 | for (;;) { |
| 673 | if (lit_at(t, b, na, "../")) { |
| 674 | na += 3; |
| 675 | } else if (lit_at(t, b, na, "./") || lit_at(t, b, na, "~/")) { |
| 676 | na += 2; |
| 677 | } else if (na < b && t[na] == '/') { |
| 678 | na += 1; |
| 679 | } else { |
| 680 | break; |
| 681 | } |
| 682 | } |
no test coverage detected