| 272 | } |
| 273 | |
| 274 | std::u16string Utf8ToUtf16(const std::string& u8str) { |
| 275 | std::u16string u16str; |
| 276 | size_t i = 0; |
| 277 | while (i < u8str.size()) { |
| 278 | char32_t codePoint = 0; |
| 279 | unsigned char c = u8str[i++]; |
| 280 | |
| 281 | if (c <= 0x7F) { |
| 282 | codePoint = c; |
| 283 | } else if ((c & 0xE0) == 0xC0) { |
| 284 | if (i >= u8str.size()) throw std::runtime_error("Invalid UTF-8 sequence"); |
| 285 | codePoint = ((c & 0x1F) << 6) | (u8str[i++] & 0x3F); |
| 286 | } else if ((c & 0xF0) == 0xE0) { |
| 287 | if (i + 1 >= u8str.size()) throw std::runtime_error("Invalid UTF-8 sequence"); |
| 288 | codePoint = ((c & 0x0F) << 12) | ((u8str[i] & 0x3F) << 6) | (u8str[i + 1] & 0x3F); |
| 289 | i += 2; |
| 290 | } else if ((c & 0xF8) == 0xF0) { |
| 291 | if (i + 2 >= u8str.size()) throw std::runtime_error("Invalid UTF-8 sequence"); |
| 292 | codePoint = ((c & 0x07) << 18) | ((u8str[i] & 0x3F) << 12) | ((u8str[i + 1] & 0x3F) << 6) | |
| 293 | (u8str[i + 2] & 0x3F); |
| 294 | i += 3; |
| 295 | } else { |
| 296 | throw std::runtime_error("Invalid UTF-8 sequence"); |
| 297 | } |
| 298 | |
| 299 | if (codePoint <= 0xFFFF) { |
| 300 | u16str.push_back(static_cast<char16_t>(codePoint)); |
| 301 | } else if (codePoint <= 0x10FFFF) { |
| 302 | codePoint -= 0x10000; |
| 303 | u16str.push_back(static_cast<char16_t>(0xD800 | (codePoint >> 10))); |
| 304 | u16str.push_back(static_cast<char16_t>(0xDC00 | (codePoint & 0x3FF))); |
| 305 | } else { |
| 306 | throw std::runtime_error("Invalid Unicode code point"); |
| 307 | } |
| 308 | } |
| 309 | return u16str; |
| 310 | } |
| 311 | |
| 312 | std::string GetJavaScriptFromQRC(const QString& jsPath) { |
| 313 | QFile jsFile(jsPath); |
no test coverage detected