Pastebin
Retrouvez, créez et partagez vos snippets en temps réel.
Rechercher un Pastebin
Aucun paste trouvé.
Créer un paste
Pastebin
Blog
mariri le larili
#include <iostream> #include <string> #include <vector> // Convertit un codepoint Unicode → UTF-8 std::string utf8_from_codepoint(uint32_t cp) { std::string out; if (cp <= 0x7F) { out.push_back(cp); } else if (cp <= 0x7FF) { out.push_back(0xC0 | (cp >> 6)); out.push_back(0x80 | (cp & 0x3F)); } else if (cp <= 0xFFFF) { out.push_back(0xE0 | (cp >> 12)); out.push_back(0x80 | ((cp >> 6) & 0x3F)); out.push_back(0x80 | (cp & 0x3F)); } else { out.push_back(0xF0 | (cp >> 18)); out.push_back(0x80 | ((cp >> 12) & 0x3F)); out.push_back(0x80 | ((cp >> 6) & 0x3F)); out.push_back(0x80 | (cp & 0x3F)); } return out; } int main() { std::vector<uint32_t> codepoints; // Remplir la liste de tous les codepoints Unicode valides for (uint32_t cp = 0; cp <= 0x10FFFF; cp++) { // sauter les surrogates UTF-16 (non-caractères) if (cp >= 0xD800 && cp <= 0xDFFF) continue; codepoints.push_back(cp); } std::cout << "Total de codepoints valides: " << codepoints.size() << "\n"; // Exemple: accéder à un index size_t index = 5000; if (index < codepoints.size()) { uint32_t cp = codepoints[index]; std::string utf8 = utf8_from_codepoint(cp); std::cout << "Index = " << index << "\n"; std::cout << "Codepoint = U+" << std::hex << cp << std::dec << "\n"; std::cout << "UTF-8 = \"" << utf8 << "\"\n"; } return 0; }
Créé il y a 1 mois.