candidates(): line-local candidates of text, sorted by start. */
| 789 | |
| 790 | /* candidates(): line-local candidates of text, sorted by start. */ |
| 791 | static bool candidates(const uint32_t *t, int n, bool with_tok, candv_t *cv) { |
| 792 | uint8_t *taken = (uint8_t *)cbm_calloc(CBM_MEM_CLASS_EXTRACT, (size_t)(n ? n : 1)); |
| 793 | if (!taken) { |
| 794 | return false; |
| 795 | } |
| 796 | url_cache_t uc = {-1, -1, -1, -1}; |
| 797 | for (int p = 0; p < n;) { |
| 798 | int e = url_at(t, n, p, &uc); |
| 799 | if (e > p) { |
| 800 | span_take(taken, p, e); |
| 801 | p = e; |
| 802 | } else { |
| 803 | p++; |
| 804 | } |
| 805 | } |
| 806 | for (int p = 0; p < n;) { |
| 807 | int e = path_at(t, n, p); |
| 808 | if (e <= p) { |
| 809 | p++; |
| 810 | continue; |
| 811 | } |
| 812 | if (span_free(taken, p, e)) { |
| 813 | span_take(taken, p, e); |
| 814 | path_candidate(t, p, e, cv); |
| 815 | } |
| 816 | p = e; |
| 817 | } |
| 818 | for (int p = 0; p < n;) { |
| 819 | int e = qual_at(t, n, p); |
| 820 | if (e <= p) { |
| 821 | p++; |
| 822 | continue; |
| 823 | } |
| 824 | if (span_free(taken, p, e)) { |
| 825 | span_take(taken, p, e); |
| 826 | qual_candidate(t, p, e, cv); |
| 827 | } |
| 828 | p = e; |
| 829 | } |
| 830 | if (with_tok) { |
| 831 | for (int p = 0; p < n;) { |
| 832 | int e = tok_at(t, n, p); |
| 833 | if (e <= p) { |
| 834 | p++; |
| 835 | continue; |
| 836 | } |
| 837 | if (span_free(taken, p, e)) { |
| 838 | tok_candidate(t, n, p, e, taken, cv); |
| 839 | } |
| 840 | p = e; |
| 841 | } |
| 842 | } |
| 843 | cbm_free(CBM_MEM_CLASS_EXTRACT, taken); |
| 844 | if (cv->n > 1) { |
| 845 | qsort(cv->v, (size_t)cv->n, sizeof(cand_t), cand_cmp); |
| 846 | } |
| 847 | return !cv->fail && !cv->pool.fail; |
| 848 | } |
no test coverage detected