| 2862 | } |
| 2863 | |
| 2864 | static bool Find(const uint8_t* begin, const uint8_t* end, |
| 2865 | const uint8_t** separator_begin, const uint8_t** separator_end, |
| 2866 | const SplitPatternOptions& options) { |
| 2867 | const uint8_t* pattern = reinterpret_cast<const uint8_t*>(options.pattern.c_str()); |
| 2868 | const int64_t pattern_length = options.pattern.length(); |
| 2869 | const uint8_t* i = begin; |
| 2870 | // this is O(n*m) complexity, we could use the Knuth-Morris-Pratt algorithm used in |
| 2871 | // the match kernel |
| 2872 | while ((i + pattern_length <= end)) { |
| 2873 | i = std::search(i, end, pattern, pattern + pattern_length); |
| 2874 | if (i != end) { |
| 2875 | *separator_begin = i; |
| 2876 | *separator_end = i + pattern_length; |
| 2877 | return true; |
| 2878 | } |
| 2879 | } |
| 2880 | return false; |
| 2881 | } |
| 2882 | |
| 2883 | static bool FindReverse(const uint8_t* begin, const uint8_t* end, |
| 2884 | const uint8_t** separator_begin, const uint8_t** separator_end, |