MCPcopy Create free account
hub / github.com/antirez/llama.cpp-deepseek-v4-flash / unicode_regex_split_custom_newlines

Function unicode_regex_split_custom_newlines

src/unicode.cpp:893–918  ·  view source on GitHub ↗

regex: [^\n]+|[\n]+ splits text into runs of non-newline characters and runs of newline characters

Source from the content-addressed store, hash-verified

891// regex: [^\n]+|[\n]+
892// splits text into runs of non-newline characters and runs of newline characters
893static 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
920static 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;

Callers 1

Calls 3

unicode_cpts_from_utf8Function · 0.85
sizeMethod · 0.45
push_backMethod · 0.45

Tested by

no test coverage detected