/
githubmirror
/
node
Обзор
Документация
Войти
/
githubmirror
/
node
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
v26.0.0
src/embedded_data.cc
33 строки
1 KB
Joyee Cheung
build: encode non-ASCII Latin1 characters as one byte in JS2C
17 фев 2024, 20:09
Не верифицирован
17 фев 2024, 20:09
72df124
Код
Авторство
О чём код?
#include "embedded_data.h" #include <vector> namespace node { std::string ToOctalString(const uint8_t ch) { // We can print most printable characters directly. The exceptions are '\' // (escape characters), " (would end the string), and ? (trigraphs). The // latter may be overly conservative: we compile with C++17 which doesn't // support trigraphs. if (ch >= ' ' && ch <= '~' && ch != '\\' && ch != '"' && ch != '?') { return std::string(1, static_cast<char>(ch)); } // All other characters are blindly output as octal. const char c0 = '0' + ((ch >> 6) & 7); const char c1 = '0' + ((ch >> 3) & 7); const char c2 = '0' + (ch & 7); return std::string("\\") + c0 + c1 + c2; } std::vector<std::string> GetOctalTable() { size_t size = 1 << 8; std::vector<std::string> code_table(size); for (size_t i = 0; i < size; ++i) { code_table[i] = ToOctalString(static_cast<uint8_t>(i)); } return code_table; } const std::string& GetOctalCode(uint8_t index) { static std::vector<std::string> table = GetOctalTable(); return table[index]; } } // namespace node