| 1841 | // Substring count |
| 1842 | |
| 1843 | struct CountSubstring { |
| 1844 | const PlainSubstringMatcher matcher_; |
| 1845 | |
| 1846 | explicit CountSubstring(PlainSubstringMatcher matcher) : matcher_(std::move(matcher)) {} |
| 1847 | |
| 1848 | template <typename OutValue, typename... Ignored> |
| 1849 | OutValue Call(KernelContext*, std::string_view val, Status*) const { |
| 1850 | OutValue count = 0; |
| 1851 | uint64_t start = 0; |
| 1852 | const auto pattern_size = std::max<uint64_t>(1, matcher_.options_.pattern.size()); |
| 1853 | while (start <= val.size()) { |
| 1854 | const int64_t index = matcher_.Find(val.substr(start)); |
| 1855 | if (index >= 0) { |
| 1856 | count++; |
| 1857 | start += index + pattern_size; |
| 1858 | } else { |
| 1859 | break; |
| 1860 | } |
| 1861 | } |
| 1862 | return count; |
| 1863 | } |
| 1864 | }; |
| 1865 | |
| 1866 | #ifdef ARROW_WITH_RE2 |
| 1867 | struct CountSubstringRegex { |