| 70 | } |
| 71 | |
| 72 | bool common_utf8_is_complete(const std::string & s) { |
| 73 | if (s.empty()) { |
| 74 | return true; |
| 75 | } |
| 76 | for (int i = 1; i <= std::min(4, (int)s.size()); i++) { |
| 77 | unsigned char c = s[s.size() - i]; |
| 78 | if ((c & 0xC0) != 0x80) { |
| 79 | int expected = (c >= 0xF0) ? 4 : (c >= 0xE0) ? 3 : (c >= 0xC0) ? 2 : 1; |
| 80 | return i >= expected; |
| 81 | } |
| 82 | } |
| 83 | return false; |
| 84 | } |
| 85 | |
| 86 | std::string common_unicode_cpts_to_utf8(const std::vector<uint32_t> & cps) { |
| 87 | std::string result; |