My homegrown improved Boyer-Moore string search, a fallback method
| 2767 | |
| 2768 | /// My homegrown improved Boyer-Moore string search, a fallback method |
| 2769 | bool Matcher::advance_string_bm(size_t loc) |
| 2770 | { |
| 2771 | const char *chr = pat_->chr_; |
| 2772 | const uint8_t *bms = pat_->bms_; |
| 2773 | const uint16_t len = pat_->len_; |
| 2774 | const uint16_t bmd = pat_->bmd_; |
| 2775 | const uint16_t lcp = pat_->lcp_; |
| 2776 | while (true) |
| 2777 | { |
| 2778 | const char *s = buf_ + loc + len - 1; |
| 2779 | const char *e = buf_ + end_; |
| 2780 | const char *t = chr + len - 1; |
| 2781 | while (s < e) |
| 2782 | { |
| 2783 | size_t k = 0; |
| 2784 | do |
| 2785 | s += k = bms[static_cast<uint8_t>(*s)]; |
| 2786 | while (k > 0 ? s < e : s[lcp - len + 1] != chr[lcp] && (s += bmd) < e); |
| 2787 | if (s >= e) |
| 2788 | break; |
| 2789 | const char *p = t - 1; |
| 2790 | const char *q = s - 1; |
| 2791 | while (p >= chr && *p == *q) |
| 2792 | { |
| 2793 | --p; |
| 2794 | --q; |
| 2795 | } |
| 2796 | if (p < chr) |
| 2797 | { |
| 2798 | k = q - buf_ + 1; |
| 2799 | set_current(k); |
| 2800 | return true; |
| 2801 | } |
| 2802 | if (chr + bmd >= p) |
| 2803 | { |
| 2804 | s += bmd; |
| 2805 | } |
| 2806 | else |
| 2807 | { |
| 2808 | k = bms[static_cast<uint8_t>(*q)]; |
| 2809 | if (p + k > t + bmd) |
| 2810 | s += k - (t - p); |
| 2811 | else |
| 2812 | s += bmd; |
| 2813 | } |
| 2814 | } |
| 2815 | s -= len - 1; |
| 2816 | loc = s - buf_; |
| 2817 | set_current_and_peek_more(loc); |
| 2818 | loc = cur_; |
| 2819 | if (loc + len > end_ && eof_) |
| 2820 | return false; |
| 2821 | } |
| 2822 | } |
| 2823 | |
| 2824 | /// My homegrown improved Boyer-Moore string search followed by minimal 1 byte long patterns, using PM |
| 2825 | bool Matcher::advance_string_bm_pma(size_t loc) |
nothing calls this directly
no outgoing calls
no test coverage detected