regex: [^\n]+|[\n]+ splits text into runs of non-newline characters and runs of newline characters
| 891 | // regex: [^\n]+|[\n]+ |
| 892 | // splits text into runs of non-newline characters and runs of newline characters |
| 893 | static std::vector<size_t> unicode_regex_split_custom_newlines(const std::string & text, const std::vector<size_t> & offsets) { |
| 894 | std::vector<size_t> bpe_offsets; |
| 895 | bpe_offsets.reserve(offsets.size()); |
| 896 | |
| 897 | const auto cpts = unicode_cpts_from_utf8(text); |
| 898 | |
| 899 | size_t start = 0; |
| 900 | for (auto offset : offsets) { |
| 901 | const size_t offset_ini = start; |
| 902 | const size_t offset_end = start + offset; |
| 903 | assert(offset_end <= cpts.size()); |
| 904 | start = offset_end; |
| 905 | |
| 906 | size_t pos = offset_ini; |
| 907 | while (pos < offset_end) { |
| 908 | const bool is_newline = (cpts[pos] == '\n'); |
| 909 | const size_t run_start = pos; |
| 910 | while (pos < offset_end && (cpts[pos] == '\n') == is_newline) { |
| 911 | pos++; |
| 912 | } |
| 913 | bpe_offsets.push_back(pos - run_start); |
| 914 | } |
| 915 | } |
| 916 | |
| 917 | return bpe_offsets; |
| 918 | } |
| 919 | |
| 920 | static std::vector<size_t> unicode_regex_split_custom(const std::string & text, const std::string & regex_expr, const std::vector<size_t> & offsets) { |
| 921 | std::vector<size_t> bpe_offsets; |
no test coverage detected