| 995 | } |
| 996 | |
| 997 | std::vector<uint32_t> unicode_cpts_from_utf8(const std::string & utf8) { |
| 998 | std::vector<uint32_t> result; |
| 999 | result.reserve(utf8.size()); |
| 1000 | size_t offset = 0; |
| 1001 | while (offset < utf8.size()) { |
| 1002 | try { |
| 1003 | result.push_back(unicode_cpt_from_utf8(utf8, offset)); |
| 1004 | } |
| 1005 | catch (const std::invalid_argument & /*ex*/) { |
| 1006 | // Silently ignore invalid UTF-8 input to avoid leaking the exception beyond llama_tokenize |
| 1007 | ++offset; |
| 1008 | result.emplace_back(0xFFFD); // replacement character |
| 1009 | } |
| 1010 | } |
| 1011 | return result; |
| 1012 | } |
| 1013 | |
| 1014 | unicode_cpt_flags unicode_cpt_flags_from_cpt(const uint32_t cpt) { |
| 1015 | static const unicode_cpt_flags undef(unicode_cpt_flags::UNDEFINED); |
no test coverage detected