| 236 | } |
| 237 | |
| 238 | static size_t find_partial_stop_string(const std::string &stop, |
| 239 | const std::string &text) |
| 240 | { |
| 241 | if (!text.empty() && !stop.empty()) |
| 242 | { |
| 243 | const char text_last_char = text.back(); |
| 244 | for (int64_t char_index = stop.size() - 1; char_index >= 0; char_index--) |
| 245 | { |
| 246 | if (stop[char_index] == text_last_char) |
| 247 | { |
| 248 | const std::string current_partial = stop.substr(0, char_index + 1); |
| 249 | if (ends_with(text, current_partial)) |
| 250 | { |
| 251 | return text.size() - char_index - 1; |
| 252 | } |
| 253 | } |
| 254 | } |
| 255 | } |
| 256 | return std::string::npos; |
| 257 | } |
| 258 | |
| 259 | // TODO: reuse llama_detokenize |
| 260 | template <class Iter> |
no test coverage detected