MCPcopy Create free account
hub / github.com/0xShug0/audio.cpp / unicode_cpts_from_utf8

Function unicode_cpts_from_utf8

external/llama_tokenizer/unicode.cpp:997–1012  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

995}
996
997std::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
1014unicode_cpt_flags unicode_cpt_flags_from_cpt(const uint32_t cpt) {
1015 static const unicode_cpt_flags undef(unicode_cpt_flags::UNDEFINED);

Calls 2

unicode_cpt_from_utf8Function · 0.85
sizeMethod · 0.45

Tested by

no test coverage detected