| 953 | // |
| 954 | |
| 955 | std::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 | |
| 984 | std::vector<uint32_t> unicode_cpts_normalize_nfd(const std::vector<uint32_t> & cpts) { |
| 985 | auto comp = [] (const uint32_t cpt, const range_nfd & range) { |
no outgoing calls
no test coverage detected