| 578 | range_matches(string_type haystack, matcher_type needle) noexcept : matcher_(needle), haystack_(haystack) {} |
| 579 | |
| 580 | class iterator { |
| 581 | matcher_type matcher_; |
| 582 | string_view_type remaining_; |
| 583 | |
| 584 | public: |
| 585 | using iterator_category = std::forward_iterator_tag; |
| 586 | using difference_type = std::ptrdiff_t; |
| 587 | using value_type = string_view_type; |
| 588 | using pointer = string_view_type; // Needed for compatibility with STL container constructors. |
| 589 | using reference = string_view_type; // Needed for compatibility with STL container constructors. |
| 590 | |
| 591 | iterator(string_view_type haystack, matcher_type matcher) noexcept : matcher_(matcher), remaining_(haystack) { |
| 592 | auto position = matcher_(remaining_); |
| 593 | remaining_.remove_prefix(position != string_type::npos ? position : remaining_.size()); |
| 594 | } |
| 595 | |
| 596 | pointer operator->() const noexcept = delete; |
| 597 | value_type operator*() const noexcept { return remaining_.substr(0, matcher_.needle_length()); } |
| 598 | |
| 599 | iterator &operator++() noexcept { |
| 600 | remaining_.remove_prefix(matcher_.skip_length()); |
| 601 | auto position = matcher_(remaining_); |
| 602 | remaining_.remove_prefix(position != string_type::npos ? position : remaining_.size()); |
| 603 | return *this; |
| 604 | } |
| 605 | |
| 606 | iterator operator++(int) noexcept { |
| 607 | iterator temp = *this; |
| 608 | ++(*this); |
| 609 | return temp; |
| 610 | } |
| 611 | |
| 612 | // Assumes both iterators point to the same underlying string. |
| 613 | bool operator!=(iterator const &other) const noexcept { return remaining_.data() != other.remaining_.data(); } |
| 614 | bool operator==(iterator const &other) const noexcept { return remaining_.data() == other.remaining_.data(); } |
| 615 | bool operator!=(end_sentinel_type) const noexcept { return !remaining_.empty(); } |
| 616 | bool operator==(end_sentinel_type) const noexcept { return remaining_.empty(); } |
| 617 | }; |
| 618 | |
| 619 | iterator begin() const noexcept { return {string_view_type(haystack_), matcher_}; } |
| 620 | iterator end() const noexcept { return {string_view_type(haystack_.data() + haystack_.size(), 0ull), matcher_}; } |
nothing calls this directly
no test coverage detected
searching dependent graphs…