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

Function unicode_cpt_to_utf8

external/llama_tokenizer/unicode.cpp:955–982  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

953//
954
955std::string unicode_cpt_to_utf8(uint32_t cpt) {
956 std::string result;
957
958 if (/* 0x00 <= cpt && */ cpt <= 0x7f) {
959 result.push_back(cpt);
960 return result;
961 }
962 if (0x80 <= cpt && cpt <= 0x7ff) {
963 result.push_back(0xc0 | ((cpt >> 6) & 0x1f));
964 result.push_back(0x80 | (cpt & 0x3f));
965 return result;
966 }
967 if (0x800 <= cpt && cpt <= 0xffff) {
968 result.push_back(0xe0 | ((cpt >> 12) & 0x0f));
969 result.push_back(0x80 | ((cpt >> 6) & 0x3f));
970 result.push_back(0x80 | (cpt & 0x3f));
971 return result;
972 }
973 if (0x10000 <= cpt && cpt <= 0x10ffff) {
974 result.push_back(0xf0 | ((cpt >> 18) & 0x07));
975 result.push_back(0x80 | ((cpt >> 12) & 0x3f));
976 result.push_back(0x80 | ((cpt >> 6) & 0x3f));
977 result.push_back(0x80 | (cpt & 0x3f));
978 return result;
979 }
980
981 throw std::invalid_argument("invalid codepoint");
982}
983
984std::vector<uint32_t> unicode_cpts_normalize_nfd(const std::vector<uint32_t> & cpts) {
985 auto comp = [] (const uint32_t cpt, const range_nfd & range) {

Callers 8

unicode_lowercaseFunction · 0.85
lower_and_normalize_nfdFunction · 0.85
decode_bpeFunction · 0.85
unicode_cpts_to_utf8Function · 0.85
unicode_byte_to_utf8_mapFunction · 0.85
unicode_utf8_to_byte_mapFunction · 0.85
unicode_regex_splitFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected